Gc\Document\Model::save PHP Метод

save() публичный Метод

Save Model
public save ( ) : integer
Результат integer
    public function save()
    {
        $this->events()->trigger(__CLASS__, 'before.save', $this);
        $arraySave = array('name' => $this->getName(), 'url_key' => $this->getUrlKey(), 'updated_at' => new Expression('NOW()'), 'status' => $this->getStatus() === null ? self::STATUS_DISABLE : $this->getStatus(), 'sort_order' => (int) $this->getSortOrder(), 'user_id' => (int) $this->getUserId(), 'document_type_id' => (int) $this->getDocumentTypeId() == 0 ? null : (int) $this->getDocumentTypeId(), 'view_id' => (int) $this->getViewId() == 0 ? null : (int) $this->getViewId(), 'layout_id' => (int) $this->getLayoutId() == 0 ? null : (int) $this->getLayoutId(), 'parent_id' => (int) $this->getParentId() == 0 ? null : (int) $this->getParentId(), 'locale' => $this->getLocale());
        if ($this->getDriverName() == 'pdo_pgsql') {
            $arraySave['show_in_nav'] = $this->showInNav() === true ? 'true' : 'false';
            $arraySave['can_be_cached'] = $this->canBeCached() === true ? 'true' : 'false';
        } else {
            $arraySave['show_in_nav'] = $this->showInNav() === true ? 1 : 0;
            $arraySave['can_be_cached'] = $this->canBeCached() === true ? 1 : 0;
        }
        try {
            $documentId = $this->getId();
            if (empty($documentId)) {
                $arraySave['created_at'] = new Expression('NOW()');
                $this->insert($arraySave);
                $this->setId($this->getLastInsertId());
            } else {
                $this->update($arraySave, array('id' => $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

Пример #1
0
 protected function createContent()
 {
     $this->view = ViewModel::fromArray(array('name' => 'View', 'identifier' => 'ViewContentIdentifier', 'description' => 'Description', 'content' => 'Content of the webpage <br/>This is my view'));
     $this->view->save();
     $this->layout = LayoutModel::fromArray(array('name' => 'Layout', 'identifier' => 'LayoutContentIdentifier', 'description' => 'Description', 'content' => '<?php echo $this->content; '));
     $this->layout->save();
     $this->script = ScriptModel::fromArray(array('name' => 'Script', 'identifier' => 'ScriptContentIdentifier', 'description' => 'Description', 'content' => ''));
     $this->script->save();
     $this->documentType = DocumentTypeModel::fromArray(array('name' => 'DocumentType', 'description' => 'description', 'icon_id' => 1, 'default_view_id' => $this->view->getId(), 'user_id' => $this->user->getId()));
     $this->documentType->save();
     $this->documentType->setDependencies(array($this->documentType->getId()));
     $this->documentType->addView($this->view->getId());
     $this->documentType->save();
     $this->datatype = DatatypeModel::fromArray(array('name' => 'DatatypeTest', 'model' => 'Textstring'));
     $this->datatype->save();
     $this->tabModel = TabModel::fromArray(array('name' => 'test', 'description' => 'test', 'document_type_id' => $this->documentType->getId()));
     $this->tabModel->save();
     $this->property = PropertyModel::fromArray(array('name' => 'test', 'identifier' => 'azd', 'description' => 'test', 'tab_id' => $this->tabModel->getId(), 'datatype_id' => $this->datatype->getId(), 'is_required' => true));
     $this->property->save();
     $this->document = DocumentModel::fromArray(array('name' => 'test', 'url_key' => '', 'status' => DocumentModel::STATUS_ENABLE, 'user_id' => $this->user->getId(), 'document_type_id' => $this->documentType->getId(), 'view_id' => $this->view->getId(), 'layout_id' => $this->layout->getId(), 'parent_id' => null));
     $this->document->save();
     $this->property->setDocumentId($this->document->getId());
     $this->property->setValue('string');
     $this->property->saveValue();
 }
All Usage Examples Of Gc\Document\Model::save