Gc\Tab\Model::save PHP Method

save() public method

Save tab
public save ( ) : integer
return integer
    public function save()
    {
        $this->events()->trigger(__CLASS__, 'before.save', $this);
        $arraySave = array('name' => $this->getName(), 'description' => $this->getDescription(), 'sort_order' => $this->getSortOrder(), 'document_type_id' => $this->getDocumentTypeId());
        try {
            $id = $this->getId();
            if (empty($id)) {
                $this->insert($arraySave);
                $this->setId($this->getLastInsertId());
            } else {
                $this->update($arraySave, array('id' => (int) $this->getId()));
            }
            $this->events()->trigger(__CLASS__, 'after.save', $this);
            return $this->getId();
        } catch (\Exception $e) {
            $this->events()->trigger(__CLASS__, 'after.save.failed', $this);
            throw new \Gc\Exception($e->getMessage(), $e->getCode(), $e);
        }
    }

Usage Example

Beispiel #1
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return void
  */
 protected function setUp()
 {
     $this->view = ViewModel::fromArray(array('name' => 'View Name', 'identifier' => 'View identifier', 'description' => 'View Description', 'content' => 'View Content'));
     $this->view->save();
     $this->layout = LayoutModel::fromArray(array('name' => 'Layout Name', 'identifier' => 'Layout identifier', 'description' => 'Layout Description', 'content' => 'Layout Content'));
     $this->layout->save();
     $this->user = UserModel::fromArray(array('lastname' => 'User test', 'firstname' => 'User test', 'email' => '*****@*****.**', 'login' => 'test', 'user_acl_role_id' => 1));
     $this->user->setPassword('test');
     $this->user->save();
     $this->documentType = DocumentTypeModel::fromArray(array('name' => 'Document Type Name', 'description' => 'Document Type description', 'icon_id' => 1, 'defaultview_id' => $this->view->getId(), 'user_id' => $this->user->getId()));
     $this->documentType->save();
     $this->tab = Model::fromArray(array('name' => 'TabTest', 'description' => 'TabTest', 'sort_order' => 1, 'document_type_id' => $this->documentType->getId()));
     $this->tab->save();
     $this->object = new Collection();
 }
All Usage Examples Of Gc\Tab\Model::save