コード例 #1
0
ファイル: ActiveRowMapper.php プロジェクト: redwormik/niceorm
 public function save(Entity $entity)
 {
     $data = array();
     foreach ($entity->getDataModified() as $name => $value) {
         if (isset($this->fields[$name])) {
             $column = $this->fields[$name];
             $data[$column] = $value;
             continue;
         }
         if (isset($this->refs[$name])) {
             list($table, $column, $type) = $this->refs[$name];
             if ($value instanceof Entity) {
                 $this->manager->getMapper($type)->save($value);
                 $value = $this->manager->getEntityData($value)->getPrimary();
             }
             if ($column === NULL) {
                 list($table, $column) = $this->connection->databaseReflection->getBelongsToReference($this->tableName, $table);
             }
             $data[$column] = $value;
             continue;
         }
         if (isset($this->related[$name])) {
             // TODO
             throw new Nette\NotImplementedException();
         }
         throw new Nette\InvalidArgumentException();
     }
     $row = $this->manager->getEntityData($entity);
     if ($row === NULL) {
         $row = $this->createTable()->insert($data);
         $this->manager->setEntityData($this->type, $entity, $row);
     } else {
         $this->createTable()->wherePrimary($row->getPrimary())->update($data);
     }
 }
コード例 #2
0
ファイル: Manager.php プロジェクト: redwormik/niceorm
 public function setEntityData($type, Entity $entity, $data)
 {
     $accessor = $this->createAccessor($type, $data);
     $entity->injectDataAccessor($accessor);
     $this->data[$entity] = $data;
 }