Skip to content

Commit

Permalink
add IDaoMap2 interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonhinkle committed Oct 13, 2014
1 parent c6a0e9f commit 7610b34
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 20 deletions.
55 changes: 35 additions & 20 deletions builder/code/phreeze.php/libs/Model/DAO/ModelMap.php.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

/** import supporting libraries */
require_once("verysimple/Phreeze/IDaoMap.php");
require_once("verysimple/Phreeze/IDaoMap2.php");

/**
* {$singular}Map is a static class with functions used to get FieldMap and KeyMap information that
Expand All @@ -18,44 +19,58 @@ require_once("verysimple/Phreeze/IDaoMap.php");
* @author ClassBuilder
* @version 1.0
*/
class {$singular}Map implements IDaoMap
class {$singular}Map implements IDaoMap, IDaoMap2
{ldelim}

private static $KM;
private static $FM;

/**
* {ldelim}@inheritdoc{rdelim}
*/
public static function AddMap($property,FieldMap $map)
{
self::GetFieldMaps();
self::$FM[$property] = $map;
}

/**
* {ldelim}@inheritdoc{rdelim}
*/
public static function SetFetchingStrategy($property,$loadType)
{
self::GetKeyMaps();
self::$KM[$property]->LoadType = $loadType;
}

/**
* Returns a singleton array of FieldMaps for the {$singular} object
*
* @access public
* @return array of FieldMaps
* {ldelim}@inheritdoc{rdelim}
*/
public static function GetFieldMaps()
{ldelim}
static $fm = null;
if ($fm == null)
if (self::$FM == null)
{ldelim}
$fm = Array();
{foreach from=$table->Columns item=column} $fm["{$column->NameWithoutPrefix|studlycaps}"] = new FieldMap("{$column->NameWithoutPrefix|studlycaps}","{$table->Name}","{$column->Name}",{if $column->Key == "PRI"}true{else}false{/if},{$column->GetPhreezeType()},{if $column->IsEnum()}array({foreach name=enumvals from=$column->GetEnumValues() item=enumval}{if !$smarty.foreach.enumvals.first},{/if}"{$enumval|replace:'"':'\"'}"{/foreach}){elseif $column->Size}{$column->Size|replace:',':'.'}{else}null{/if},{if $column->Default}"{$column->Default}"{else}null{/if},{if $column->Extra == 'auto_increment'}true{else}false{/if});
self::$FM = Array();
{foreach from=$table->Columns item=column} self::$FM["{$column->NameWithoutPrefix|studlycaps}"] = new FieldMap("{$column->NameWithoutPrefix|studlycaps}","{$table->Name}","{$column->Name}",{if $column->Key == "PRI"}true{else}false{/if},{$column->GetPhreezeType()},{if $column->IsEnum()}array({foreach name=enumvals from=$column->GetEnumValues() item=enumval}{if !$smarty.foreach.enumvals.first},{/if}"{$enumval|replace:'"':'\"'}"{/foreach}){elseif $column->Size}{$column->Size|replace:',':'.'}{else}null{/if},{if $column->Default}"{$column->Default}"{else}null{/if},{if $column->Extra == 'auto_increment'}true{else}false{/if});
{/foreach}
{rdelim}
return $fm;
return self::$FM;
{rdelim}

/**
* Returns a singleton array of KeyMaps for the {$singular} object
*
* @access public
* @return array of KeyMaps
* {ldelim}@inheritdoc{rdelim}
*/
public static function GetKeyMaps()
{ldelim}
static $km = null;
if ($km == null)
if (self::$KM == null)
{ldelim}
$km = Array();
{foreach from=$table->Sets item=set} $km["{$set->Name}"] = new KeyMap("{$set->Name}", "{$set->KeyColumnNoPrefix|studlycaps}", "{$set->SetTableName|studlycaps}", "{$set->SetKeyColumnNoPrefix|studlycaps}", KM_TYPE_ONETOMANY, KM_LOAD_LAZY); // use KM_LOAD_EAGER with caution here (one-to-one relationships only)
self::$KM = Array();
{foreach from=$table->Sets item=set} self::$KM["{$set->Name}"] = new KeyMap("{$set->Name}", "{$set->KeyColumnNoPrefix|studlycaps}", "{$set->SetTableName|studlycaps}", "{$set->SetKeyColumnNoPrefix|studlycaps}", KM_TYPE_ONETOMANY, KM_LOAD_LAZY); // use KM_LOAD_EAGER with caution here (one-to-one relationships only)
{/foreach}
{foreach from=$table->Constraints item=constraint} $km["{$constraint->Name}"] = new KeyMap("{$constraint->Name}", "{$constraint->KeyColumnNoPrefix|studlycaps}", "{$constraint->ReferenceTableName|studlycaps}", "{$constraint->ReferenceKeyColumnNoPrefix|studlycaps}", KM_TYPE_MANYTOONE, KM_LOAD_LAZY); // you change to KM_LOAD_EAGER here or (preferrably) make the change in _config.php
{foreach from=$table->Constraints item=constraint} self::$KM["{$constraint->Name}"] = new KeyMap("{$constraint->Name}", "{$constraint->KeyColumnNoPrefix|studlycaps}", "{$constraint->ReferenceTableName|studlycaps}", "{$constraint->ReferenceKeyColumnNoPrefix|studlycaps}", KM_TYPE_MANYTOONE, KM_LOAD_LAZY); // you change to KM_LOAD_EAGER here or (preferrably) make the change in _config.php
{/foreach}
{rdelim}
return $km;
return self::$KM;
{rdelim}

{rdelim}
Expand Down
49 changes: 49 additions & 0 deletions libs/verysimple/Phreeze/IDaoMap2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/** @package verysimple::Phreeze */

/** import supporting libraries */
require_once("FieldMap.php");
require_once("KeyMap.php");

/**
* IDaoMap2 is an interface for a mapped object that can be persisted by Phreeze
* Version 2 includes AddMap and SetFetchingStrategy
*
* @package verysimple::Phreeze
* @author VerySimple Inc.
* @copyright 1997-2007 VerySimple, Inc.
* @license http://www.gnu.org/licenses/lgpl.html LGPL
* @version 2.0
*/
interface IDaoMap2
{
/**
* Add a new FieldMap
* @param string $property
* @param FieldMap $map
*/
static function AddMap($property,FieldMap $map);

/**
* Change the fetching strategy for a KeyMap
* @param unknown $property
* @param int $loadType (KM_LOAD_LAZY | KM_LOAD_INNER | KM_LOAD_EAGER)
*/
static function SetFetchingStrategy($property,$loadType);

/**
* Returns a singleton array of FieldMaps for a Phreezable object
* @access public
* @return FieldMap[]
*/
static function GetFieldMaps();

/**
* Returns a singleton array of KeyMaps for the Phreezable object
* @access public
* @return KeyMap[]
*/
static function GetKeyMaps();
}

?>

0 comments on commit 7610b34

Please sign in to comment.