コード例 #1
0
ファイル: Saveable.class.php プロジェクト: oparoz/thebuggenie
 protected function _populatePropertiesFromRow(\b2db\Row $row, $traverse = true, $foreign_key = null)
 {
     $table = self::getB2DBTable();
     $table_name = $table->getB2DBName();
     $id_column = $table->getIdColumn();
     $this_class = \get_class($this);
     foreach ($table->getColumns() as $column) {
         if ($column['name'] == $id_column) {
             continue;
         }
         $property_name = $column['property'];
         //Core::getCachedColumnClassProperty($this_class, $column['name']);
         $property_type = $column['type'];
         if (!property_exists($this, $property_name)) {
             throw new \Exception("Could not find class property {$property_name} in class " . $this_class . ". The class must have all properties from the corresponding B2DB table class available");
         }
         if ($traverse && in_array($column['name'], $table->getForeignColumns())) {
             if ($row->get($column['name']) > 0) {
                 $relation_details = Core::getCachedEntityRelationDetails($this_class, $property_name);
                 if ($relation_details && class_exists($relation_details['class'])) {
                     $b2dbtablename = Core::getCachedB2DBTableClass($relation_details['class']);
                     $b2dbtable = $b2dbtablename::getTable();
                     foreach ($row->getJoinedTables() as $join_details) {
                         if ($join_details['original_column'] == $column['name']) {
                             $property_type = 'class';
                             break;
                         }
                     }
                 }
             }
         }
         switch ($property_type) {
             case 'class':
                 $value = (int) $row->get($column['name']);
                 $this->{$property_name} = new $type_name($value, $row, false, $column['name']);
                 break;
             case 'boolean':
                 $this->{$property_name} = (bool) $row->get($column['name'], $foreign_key);
                 break;
             case 'integer':
                 $this->{$property_name} = (int) $row->get($column['name'], $foreign_key);
                 break;
             case 'float':
                 $this->{$property_name} = floatval($row->get($column['name'], $foreign_key));
                 break;
             case 'text':
             case 'varchar':
                 $this->{$property_name} = (string) $row->get($column['name'], $foreign_key);
                 break;
             default:
                 $this->{$property_name} = $row->get($column['name'], $foreign_key);
         }
     }
 }
コード例 #2
0
ファイル: Module.php プロジェクト: pkdevboxy/thebuggenie
 /**
  * Class constructor
  */
 public final function _construct(\b2db\Row $row, $foreign_key = null)
 {
     if ($this->_version != $row->get(tables\Modules::VERSION)) {
         throw new \Exception('This module must be upgraded to the latest version');
     }
 }