00001 <?php
00027 load_module('ormMapParser', MOD_INTERNAL);
00033 class orm_CodeGen extends ormMapParser{
00039 var $__tableAliasClassList = array();
00045 var $__projectName;
00051 var $__mapName;
00052
00053 function orm_CodeGen($mapName, $projectName){
00054 $this->__construct($mapName, $projectName);
00055 }
00056 function __construct($mapName, $projectName){
00057 $this->__mapName = $mapName;
00058 $this->__projectName = $projectName;
00059 parent::__construct();
00060 parent::loadMap(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.fstab_getProjectDirByName($projectName).DRS.ZIGSETTINGSDIR.DRS.Z_DIR_ETC_CONF.DRS.$mapName.'.orm.map.php');
00061 }
00068 function gen_class(){
00069 global $__ZigOrm;
00070
00071 if(file_exists(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.fstab_getProjectDirByName($this->__projectName).DRS.Z_DIR_APPS.DRS.Z_DIR_MVC_MODEL.DRS.'orm'.DRS.$this->__mapName.'.orm.php')){
00072 include(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.fstab_getProjectDirByName($this->__projectName).DRS.Z_DIR_APPS.DRS.Z_DIR_MVC_MODEL.DRS.'orm'.DRS.$this->__mapName.'.orm.php');
00073 $this->__tableAliasClassList = $__zigOrmLoadedClassList;
00074
00075 $__ZigOrm->connections[$this->__struct->connection->alias] = $this->__struct->connection;
00076 return true;
00077 }
00078 $__ZigOrm->connections[$this->__struct->connection->alias] = $this->__struct->connection;
00079 $var_str = 'var';
00080 $fnc_str = 'function';
00081 $parent_class = $this->__projectName.'OrmTable';
00082 $file_str = "<?php\n/**\n *\tThis File is auto generated By Zigmoyd ORM Handler by reading the ORM Map on File $this->__map_file_name\n */\n\n";
00083 foreach($this->__struct->tables as $table_name => $table_obj){
00084
00085 $file_str .= "if(!class_exists('$table_obj->alias')):";
00086 $file_str .= "//{ Writting Class ".$table_obj->alias." for Table $table_name\n";
00087 $this->__tableAliasClassList[] = $table_obj->alias;
00088 $file_str .= "class ".$table_obj->alias." extends $parent_class{\n";
00089
00090 $file_str .= "\t".$var_str." \$connAlias = '".$this->__struct->connection->alias."';//Connection Alias name";
00091 $file_str .= "\n\t".$var_str." \$realTableName = '".$table_name."';//Real Table Name";
00092
00093 $file_str .= "\n\t".$var_str." \$__struct = '".base64_encode(serialize($table_obj))."';//Writting Structure\n";
00094
00095
00096 $file_str .= "\n\t".$fnc_str." $table_obj->alias"."(){\n\t\t//Writting The Constructor Method\n";
00097 $file_str .= "\t\tif(function_exists('overload'))overload(get_class(\$this));\n";
00098 $file_str .= "\t\t\$this->__struct = unserialize(base64_decode(\$this->__struct));\n\t\t\$this->init();\n";
00099 $file_str .= "\t}\n";
00100
00101
00102 $file_str .= "}\n";
00103 $file_str .= "//}\nendif;\nif(!class_exists('$table_obj->alias"."RowSet')):\nclass ".$table_obj->alias."RowSet extends ".$this->__projectName."OrmRowSet{\n\t//you can write your own custom Access Methods methods here
00104 \n\t$fnc_str $table_obj->alias"."RowSet(){\n\t\tif(function_exists('overload'))overload(get_class(\$this));\n\t}\n}\nendif;\n";
00105
00106 }
00107 $file_str .= "?>";
00108
00109 $listStr = "<?php\n//{Generating the List of Classes in this file\n";
00110 foreach($this->__tableAliasClassList as $class){
00111 $listStr .= "\$__zigOrmLoadedClassList[] = '$class';\n";
00112 }
00113 $listStr .= "//}\n?>\n";
00114
00115 $this->__write($listStr.$file_str);
00116 }
00125 function __write($str){
00126 $dest_file = ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.fstab_getProjectDirByName($this->__projectName).DRS.Z_DIR_APPS.DRS.Z_DIR_MVC_MODEL.DRS.'orm'.DRS.$this->__mapName.'.orm.php';
00127 file_put_contents($dest_file, $str);
00128 include_once($dest_file);
00129 }
00135 function getClassList(){
00136 return $this->__tableAliasClassList;
00137 }
00138 }
00149 function load_orm_map($mapName, $projectName){
00150 $hwnd = new orm_CodeGen($mapName, $projectName);
00151 $hwnd->gen_class();
00152 return $hwnd->getClassList();
00153 }
00155 ?>