]> git.andy128k.dev Git - ipf.git/commitdiff
unify adding templates to a record
authorAndrey Kutejko <andy128k@gmail.com>
Sat, 27 Jul 2013 14:19:27 +0000 (17:19 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Sat, 27 Jul 2013 14:19:27 +0000 (17:19 +0300)
ipf/admin/models/_generated/BaseAdminLog.php
ipf/auth/models/_generated/BasePermission.php
ipf/auth/models/_generated/BaseRole.php
ipf/auth/models/_generated/BaseRolePermission.php
ipf/auth/models/_generated/BaseUser.php
ipf/auth/models/_generated/BaseUserPermission.php
ipf/auth/models/_generated/BaseUserRole.php
ipf/orm/import/builder.php
ipf/orm/record/abstract.php
ipf/orm/table.php
ipf/session/models/_generated/BaseSession.php

index 930e5eb311643c9d636a349d91fe0d37114684f0..e71aaedcbd5c54a16cfe85ac615cc9156f51b1be 100644 (file)
@@ -1,8 +1,11 @@
 <?php
 
 /**
- * This class has been auto-generated by the IPF_ORM Framework
+ * This class has been auto-generated by the IPF_ORM Framework.
+ * Changes to this file may cause incorrect behavior
+ * and will be lost if the code is regenerated.
  */
+
 abstract class BaseAdminLog extends IPF_ORM_Record
 {
   public function setTableDefinition()
@@ -15,8 +18,6 @@ abstract class BaseAdminLog extends IPF_ORM_Record
     $this->hasColumn('object_repr', 'string', 200, array('type' => 'string', 'length' => '200'));
     $this->hasColumn('action_flag', 'integer', null, array('type' => 'integer'));
     $this->hasColumn('change_message', 'string', 200, array('type' => 'string', 'length' => '200'));
-
-
     $this->index('idx_object_id', array('fields' => 'object_id'));
     $this->index('idx_object_class', array('fields' => 'object_class'));
     $this->index('idx_created_at', array('fields' => 'created_at'));
@@ -24,11 +25,22 @@ abstract class BaseAdminLog extends IPF_ORM_Record
     $this->option('type', 'INNODB');
     $this->option('collate', 'utf8_unicode_ci');
     $this->option('charset', 'utf8');
+
   }
 
   public function setUp()
   {
     $timestampable0 = new IPF_ORM_Template_Timestampable(array('updated' => array('disabled' => true)));
-    $this->actAs($timestampable0);
+    $this->getTable()->addTemplate($timestampable0);
+  }
+
+  public static function table()
+  {
+    return IPF_ORM::getTable('AdminLog');
+  }
+
+  public static function query($alias='')
+  {
+    return IPF_ORM::getTable('AdminLog')->createQuery($alias);
   }
 }
\ No newline at end of file
index 683a3b67abf2adee74a1ce0e97139e826e09a192..351ce329569532671e1962b59f2d6dd710fb7bb1 100644 (file)
@@ -1,18 +1,21 @@
 <?php
 
 /**
- * This class has been auto-generated by the IPF_ORM Framework
+ * This class has been auto-generated by the IPF_ORM Framework.
+ * Changes to this file may cause incorrect behavior
+ * and will be lost if the code is regenerated.
  */
+
 abstract class BasePermission extends IPF_ORM_Record
 {
   public function setTableDefinition()
   {
     $this->setTableName('auth_permission');
     $this->hasColumn('name', 'string', 255, array('unique' => true, 'type' => 'string', 'length' => '255'));
-
     $this->option('type', 'INNODB');
     $this->option('collate', 'utf8_unicode_ci');
     $this->option('charset', 'utf8');
+
   }
 
   public function setUp()
@@ -20,6 +23,7 @@ abstract class BasePermission extends IPF_ORM_Record
     $this->hasMany('User as Users', array('refClass' => 'UserPermission',
                                           'local' => 'permission_id',
                                           'foreign' => 'user_id'));
+
     $this->hasMany('Role as Roles', array('refClass' => 'RolePermission',
                                           'local' => 'permission_id',
                                           'foreign' => 'role_id'));
@@ -30,4 +34,14 @@ abstract class BasePermission extends IPF_ORM_Record
     $this->hasMany('UserPermission', array('local' => 'id',
                                            'foreign' => 'permission_id'));
   }
-}
+
+  public static function table()
+  {
+    return IPF_ORM::getTable('Permission');
+  }
+
+  public static function query($alias='')
+  {
+    return IPF_ORM::getTable('Permission')->createQuery($alias);
+  }
+}
\ No newline at end of file
index a32dd819a38538dd60d6a3600022f32aa80fe85f..8eef3477461380fdfa639b361e5acbb08c96010d 100644 (file)
@@ -1,29 +1,32 @@
 <?php
 
 /**
- * This class has been auto-generated by the IPF_ORM Framework
+ * This class has been auto-generated by the IPF_ORM Framework.
+ * Changes to this file may cause incorrect behavior
+ * and will be lost if the code is regenerated.
  */
+
 abstract class BaseRole extends IPF_ORM_Record
 {
   public function setTableDefinition()
   {
     $this->setTableName('auth_role');
-    $this->hasColumn('name', 'string', 255, array('unique' => true, 'notblank' => true, 'type' => 'string', 'length' => '255'));
-
+    $this->hasColumn('name', 'string', 255, array('unique' => true, 'type' => 'string', 'notblank' => true, 'length' => '255'));
     $this->option('type', 'INNODB');
     $this->option('collate', 'utf8_unicode_ci');
     $this->option('charset', 'utf8');
+
   }
 
   public function setUp()
   {
-    $this->hasMany('User as Users', array('refClass' => 'UserRole',
-                                          'local' => 'role_id',
-                                          'foreign' => 'user_id'));
     $this->hasMany('Permission as Permissions', array('refClass' => 'RolePermission',
                                                       'local' => 'role_id',
                                                       'foreign' => 'permission_id'));
-                                         
+
+    $this->hasMany('User as Users', array('refClass' => 'UserRole',
+                                          'local' => 'role_id',
+                                          'foreign' => 'user_id'));
 
     $this->hasMany('RolePermission', array('local' => 'id',
                                            'foreign' => 'role_id'));
@@ -31,4 +34,14 @@ abstract class BaseRole extends IPF_ORM_Record
     $this->hasMany('UserRole', array('local' => 'id',
                                      'foreign' => 'role_id'));
   }
-}
+
+  public static function table()
+  {
+    return IPF_ORM::getTable('Role');
+  }
+
+  public static function query($alias='')
+  {
+    return IPF_ORM::getTable('Role')->createQuery($alias);
+  }
+}
\ No newline at end of file
index 2cef6dd2fea4992f73cace606b1a1031e69d0424..084fed076f283465fdcad1ab1f35f84976cdd723 100644 (file)
@@ -1,8 +1,11 @@
 <?php
 
 /**
- * This class has been auto-generated by the IPF_ORM Framework
+ * This class has been auto-generated by the IPF_ORM Framework.
+ * Changes to this file may cause incorrect behavior
+ * and will be lost if the code is regenerated.
  */
+
 abstract class BaseRolePermission extends IPF_ORM_Record
 {
   public function setTableDefinition()
@@ -10,10 +13,10 @@ abstract class BaseRolePermission extends IPF_ORM_Record
     $this->setTableName('auth_role_permission');
     $this->hasColumn('role_id', 'integer', null, array('type' => 'integer', 'primary' => true));
     $this->hasColumn('permission_id', 'integer', null, array('type' => 'integer', 'primary' => true));
-
     $this->option('type', 'INNODB');
     $this->option('collate', 'utf8_unicode_ci');
     $this->option('charset', 'utf8');
+
   }
 
   public function setUp()
@@ -26,4 +29,14 @@ abstract class BaseRolePermission extends IPF_ORM_Record
                                       'foreign' => 'id',
                                       'onDelete' => 'CASCADE'));
   }
-}
+
+  public static function table()
+  {
+    return IPF_ORM::getTable('RolePermission');
+  }
+
+  public static function query($alias='')
+  {
+    return IPF_ORM::getTable('RolePermission')->createQuery($alias);
+  }
+}
\ No newline at end of file
index 85e5e88255959c4b074f4c52b2da8bc9b3bc5b9a..296e39a323b1949ae8a7b31ebee66d0e52e38b31 100644 (file)
@@ -1,8 +1,11 @@
 <?php
 
 /**
- * This class has been auto-generated by the IPF_ORM Framework
+ * This class has been auto-generated by the IPF_ORM Framework.
+ * Changes to this file may cause incorrect behavior
+ * and will be lost if the code is regenerated.
  */
+
 abstract class BaseUser extends IPF_ORM_Record
 {
   public function setTableDefinition()
@@ -17,10 +20,10 @@ abstract class BaseUser extends IPF_ORM_Record
     $this->hasColumn('is_active', 'boolean', null, array('type' => 'boolean', 'notnull' => true, 'default' => false));
     $this->hasColumn('is_superuser', 'boolean', null, array('type' => 'boolean', 'notnull' => true, 'default' => false));
     $this->hasColumn('last_login', 'timestamp', null, array('type' => 'timestamp'));
-
     $this->option('type', 'INNODB');
     $this->option('collate', 'utf8_unicode_ci');
     $this->option('charset', 'utf8');
+
   }
 
   public function setUp()
@@ -40,6 +43,16 @@ abstract class BaseUser extends IPF_ORM_Record
                                            'foreign' => 'user_id'));
 
     $timestampable0 = new IPF_ORM_Template_Timestampable();
-    $this->actAs($timestampable0);
+    $this->getTable()->addTemplate($timestampable0);
+  }
+
+  public static function table()
+  {
+    return IPF_ORM::getTable('User');
+  }
+
+  public static function query($alias='')
+  {
+    return IPF_ORM::getTable('User')->createQuery($alias);
   }
 }
\ No newline at end of file
index 738077c485229e5fe9ddd0e82fbcff7ae24aa3c1..9cfd2e3f5424e29e19aff2c8237fbe395497214f 100644 (file)
@@ -1,8 +1,11 @@
 <?php
 
 /**
- * This class has been auto-generated by the IPF_ORM Framework
+ * This class has been auto-generated by the IPF_ORM Framework.
+ * Changes to this file may cause incorrect behavior
+ * and will be lost if the code is regenerated.
  */
+
 abstract class BaseUserPermission extends IPF_ORM_Record
 {
   public function setTableDefinition()
@@ -10,10 +13,10 @@ abstract class BaseUserPermission extends IPF_ORM_Record
     $this->setTableName('auth_user_permission');
     $this->hasColumn('user_id', 'integer', null, array('type' => 'integer', 'primary' => true));
     $this->hasColumn('permission_id', 'integer', null, array('type' => 'integer', 'primary' => true));
-
     $this->option('type', 'INNODB');
     $this->option('collate', 'utf8_unicode_ci');
     $this->option('charset', 'utf8');
+
   }
 
   public function setUp()
@@ -26,4 +29,14 @@ abstract class BaseUserPermission extends IPF_ORM_Record
                                       'foreign' => 'id',
                                       'onDelete' => 'CASCADE'));
   }
-}
+
+  public static function table()
+  {
+    return IPF_ORM::getTable('UserPermission');
+  }
+
+  public static function query($alias='')
+  {
+    return IPF_ORM::getTable('UserPermission')->createQuery($alias);
+  }
+}
\ No newline at end of file
index adb583b0017463db0c374ee6220e04b2a53bb462..24d47329722bf97de0f4438450d88bfb77d3e9a9 100644 (file)
@@ -1,8 +1,11 @@
 <?php
 
 /**
- * This class has been auto-generated by the IPF_ORM Framework
+ * This class has been auto-generated by the IPF_ORM Framework.
+ * Changes to this file may cause incorrect behavior
+ * and will be lost if the code is regenerated.
  */
+
 abstract class BaseUserRole extends IPF_ORM_Record
 {
   public function setTableDefinition()
@@ -10,10 +13,10 @@ abstract class BaseUserRole extends IPF_ORM_Record
     $this->setTableName('auth_user_role');
     $this->hasColumn('user_id', 'integer', null, array('type' => 'integer', 'primary' => true));
     $this->hasColumn('role_id', 'integer', null, array('type' => 'integer', 'primary' => true));
-
     $this->option('type', 'INNODB');
     $this->option('collate', 'utf8_unicode_ci');
     $this->option('charset', 'utf8');
+
   }
 
   public function setUp()
@@ -26,4 +29,14 @@ abstract class BaseUserRole extends IPF_ORM_Record
                                 'foreign' => 'id',
                                 'onDelete' => 'CASCADE'));
   }
-}
+
+  public static function table()
+  {
+    return IPF_ORM::getTable('UserRole');
+  }
+
+  public static function query($alias='')
+  {
+    return IPF_ORM::getTable('UserRole')->createQuery($alias);
+  }
+}
\ No newline at end of file
index 3b34351604020690d1d5f5d5c9e89a02942d77f0..2f6d6aefdc5b68d522a506f2251e243308299857 100644 (file)
@@ -228,12 +228,12 @@ class IPF_ORM_Import_Builder
             if (is_array($options) && !empty($options)) {
                 $optionsPhp = self::varExport($options);
 
-                $build .= "    \$this->loadTemplate('" . $name . "', " . $optionsPhp . ");" . PHP_EOL;
+                $build .= "    \$this->getTable()->addTemplate('" . $name . "', " . $optionsPhp . ");" . PHP_EOL;
             } else {
                 if (isset($templates[0])) {
-                    $build .= "    \$this->loadTemplate('" . $options . "');" . PHP_EOL;
+                    $build .= "    \$this->getTable()->addTemplate('" . $options . "');" . PHP_EOL;
                 } else {
-                    $build .= "    \$this->loadTemplate('" . $name . "');" . PHP_EOL;
+                    $build .= "    \$this->getTable()->addTemplate('" . $name . "');" . PHP_EOL;
                 }
             }
         }
@@ -258,7 +258,7 @@ class IPF_ORM_Import_Builder
 
     private function emitActAs($level, $name)
     {
-        return "    \$this->actAs(\$" . strtolower($name) . "$level);" . PHP_EOL;
+        return "    \$this->getTable()->addTemplate(\$" . strtolower($name) . "$level);" . PHP_EOL;
     }
 
     private function buildActAs($actAs)
index 2bef5075d63894f34875ad766b4b98b297cd7632..f34c98cd2b067b9db286f37632d1023a0c2d5335 100644 (file)
@@ -114,11 +114,6 @@ abstract class IPF_ORM_Record_Abstract extends IPF_ORM_Access
         }
     } 
 
-    public function loadTemplate($template, array $options = array())
-    {
-        $this->actAs($template, $options);
-    }
-
     public function bindQueryParts(array $queryParts)
     {
         $this->_table->bindQueryParts($queryParts);
@@ -131,35 +126,6 @@ abstract class IPF_ORM_Record_Abstract extends IPF_ORM_Access
         $this->_table->addGenerator($generator, get_class($generator));
     }
 
-    public function actAs($tpl, array $options = array())
-    {
-        if ( ! is_object($tpl)) {
-            $className = 'IPF_ORM_Template_' . $tpl;
-
-            if (class_exists($className, true)) {
-                $tpl = new $className($options);
-            } else if (class_exists($tpl, true)) {
-                $tpl = new $tpl($options);
-            } else {
-                throw new IPF_ORM_Record_Exception('Could not load behavior named: "' . $tpl . '"');
-            }
-        }
-
-        if ( ! ($tpl instanceof IPF_ORM_Template)) {
-            throw new IPF_ORM_Record_Exception('Loaded behavior class is not an istance of IPF_ORM_Template.');
-        }
-
-        $className = get_class($tpl);
-
-        $this->_table->addTemplate($className, $tpl);
-
-        $tpl->setTable($this->_table);
-        $tpl->setUp();
-        $tpl->setTableDefinition();
-
-        return $this;
-    }
-
     public function check($constraint, $name = null)
     {
         if (is_array($constraint)) {
index 73ce2a40a99598624028353323fdd4aa8202fc75..5328b9ff0c3c8a82348bd6b833a63672baed38b6 100644 (file)
@@ -997,11 +997,30 @@ class IPF_ORM_Table extends IPF_ORM_Configurable implements Countable
         return isset($this->_templates[$template]);
     }
 
-    public function addTemplate($template, IPF_ORM_Template $impl)
+    public function addTemplate($tpl, array $options=array())
     {
-        $this->_templates[$template] = $impl;
+        if (!is_object($tpl)) {
+            $className = 'IPF_ORM_Template_' . $tpl;
 
-        return $this;
+            if (class_exists($className, true)) {
+                $tpl = new $className($options);
+            } else if (class_exists($tpl, true)) {
+                $tpl = new $tpl($options);
+            } else {
+                throw new IPF_ORM_Record_Exception('Could not load behavior named: "' . $tpl . '"');
+            }
+        }
+
+        if (!($tpl instanceof IPF_ORM_Template)) {
+            throw new IPF_ORM_Record_Exception('Loaded behavior class is not an istance of IPF_ORM_Template.');
+        }
+
+        $className = get_class($tpl);
+        $this->_templates[$className] = $tpl;
+
+        $tpl->setTable($this);
+        $tpl->setUp();
+        $tpl->setTableDefinition();
     }
 
     public function getGenerators()
index b126310ad95b67c03a8cfdd6c689a5e92b3fdb74..760b01a595c78fa54c492e892ecf2971767a0141 100644 (file)
@@ -1,8 +1,11 @@
 <?php
 
 /**
- * This class has been auto-generated by the IPF_ORM Framework
+ * This class has been auto-generated by the IPF_ORM Framework.
+ * Changes to this file may cause incorrect behavior
+ * and will be lost if the code is regenerated.
  */
+
 abstract class BaseSession extends IPF_ORM_Record
 {
   public function setTableDefinition()
@@ -13,4 +16,15 @@ abstract class BaseSession extends IPF_ORM_Record
     $this->hasColumn('expire_data', 'timestamp', null, array('type' => 'timestamp'));
   }
 
+
+
+  public static function table()
+  {
+    return IPF_ORM::getTable('Session');
+  }
+
+  public static function query($alias='')
+  {
+    return IPF_ORM::getTable('Session')->createQuery($alias);
+  }
 }
\ No newline at end of file