Gc\View\Collection::save PHP Method

save() public method

Save properties
public save ( ) : boolean
return boolean
    public function save()
    {
        $this->events()->trigger(__CLASS__, 'before.save', $this);
        if (!empty($this->data['document_type_id'])) {
            $this->delete();
            $insert = new Insert();
            $insert->into('document_type_view');
            foreach ($this->getElements() as $view) {
                $insert->values(array('document_type_id' => $this->getDocumentTypeId(), 'view_id' => $view->getId()));
                $this->execute($insert);
            }
            $this->events()->trigger(__CLASS__, 'after.save', $this);
            return true;
        }
        $this->events()->trigger(__CLASS__, 'after.save.failed', $this);
        return false;
    }

Usage Example

Beispiel #1
0
 /**
  * Test
  *
  * @return void
  */
 public function testDelete()
 {
     $model = Model::fromIdentifier('identifier-collection-test');
     $documentType = DocumentTypeModel::fromArray(array('name' => 'Document type name', 'description' => 'Document type description', 'defaultview_id' => $model->getId(), 'icon_id' => 1, 'user_id' => 1));
     $documentType->save();
     $this->object->init($documentType->getId());
     $this->object->addElement($model);
     $this->object->save();
     $this->assertTrue($this->object->delete());
     $documentType->delete();
 }