fromIdentifier() public static method

Initiliaze from identifier
public static fromIdentifier ( string $identifier ) : Model
$identifier string Identifier
return Model
Beispiel #1
0
 /**
  * Returns script from identifier.
  *
  * @param string $name   Name of view script
  * @param array  $values Variables to populate in the view
  *
  * @return mixed
  */
 public function __invoke($name = null, $values = array())
 {
     if (empty($name)) {
         return $this;
     }
     $view = $this->cloneView();
     $this->assignVars($view, $values);
     try {
         $viewModel = ViewModel::fromIdentifier($name);
     } catch (\Exception $e) {
         //don't care
     }
     if (empty($viewModel)) {
         return $view->render($name);
     }
     $name = 'view/' . $name;
     return $view->render($name);
 }
Beispiel #2
0
 /**
  * Test
  *
  * @return void
  */
 public function testEditActionWithPostData()
 {
     $viewModel = ViewModel::fromArray(array('name' => 'ViewName', 'identifier' => 'ViewIdentifier'));
     $viewModel->save();
     $this->dispatch('/admin/development/view/edit/' . $viewModel->getId(), 'POST', array('name' => 'ViewName', 'identifier' => 'Identifier', 'description' => 'Description'));
     $this->assertResponseStatusCode(302);
     $this->assertModuleName('GcDevelopment');
     $this->assertControllerName('ViewController');
     $this->assertControllerClass('ViewController');
     $this->assertMatchedRouteName('development/view/edit');
     ViewModel::fromIdentifier('Identifier')->delete();
 }
Beispiel #3
0
 public function testImportScript()
 {
     $this->assertFalse($this->object->import('<xml></xml>'));
     $this->assertFalse($this->object->import(''));
     $this->assertFalse($this->object->import('<a></b>'));
     $this->createUser();
     $this->createContent();
     $data = $this->object->export($this->what);
     $this->removeContent();
     $this->assertTrue($this->object->import($data));
     $view = ViewModel::fromIdentifier('ViewContentIdentifier');
     $layout = LayoutModel::fromIdentifier('LayoutContentIdentifier');
     $script = ScriptModel::fromIdentifier('ScriptContentIdentifier');
     $this->assertInstanceOf('Gc\\View\\Model', $view);
     $this->assertInstanceOf('Gc\\Layout\\Model', $layout);
     $this->assertInstanceOf('Gc\\Script\\Model', $script);
     //Test datatype
     $datatype = new DatatypeModel();
     $datatype = $datatype->fromArray($datatype->fetchRow($datatype->select(array('name' => 'DatatypeTest'))));
     $this->assertInstanceOf('Gc\\Datatype\\Model', $datatype);
     //Test document type
     $documentType = new DocumentTypeModel();
     $documentType = $documentType->fromArray($documentType->fetchRow($documentType->select(array('name' => 'DocumentType'))));
     $this->assertInstanceOf('Gc\\DocumentType\\Model', $documentType);
     $this->assertCount(1, $documentType->getDependencies());
     $this->assertCount(1, $documentType->getAvailableViews()->getViews());
     $tabs = $documentType->getTabs();
     $this->assertCount(1, $tabs);
     $properties = $tabs[0]->getProperties();
     $this->assertCount(1, $properties);
     //Test document
     $document = DocumentModel::fromUrlKey('');
     $this->assertInstanceOf('Gc\\Document\\Model', $document);
     $property = $document->getProperty('azd');
     $this->assertInstanceof('Gc\\Property\\Model', $property);
     $this->assertEquals('string', $property->getValue());
     $document->delete();
     //Delete data
     $properties[0]->delete();
     $tabs[0]->delete();
     $datatype->delete();
     $view->delete();
     $script->delete();
     $layout->delete();
     $documentType->delete();
     $this->removeUser();
 }
Beispiel #4
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();
 }
Beispiel #5
0
 /**
  * Upload a file to the server
  *
  * @return \Zend\Http\Response
  */
 public function uploadAction()
 {
     $viewId = $this->getRouteMatch()->getParam('id', null);
     if (!empty($viewId)) {
         $view = View\Model::fromId($viewId);
         if (empty($view) or empty($_FILES['upload']['tmp_name']) or $_FILES['upload']['error'] != UPLOAD_ERR_OK) {
             $this->flashMessenger()->addErrorMessage('Can not upload view');
             return $this->redirect()->toRoute('development/view/edit', array('id' => $viewId));
         }
         $view->setContent(file_get_contents($_FILES['upload']['tmp_name']));
         $view->save();
         $this->flashMessenger()->addSuccessMessage('View updated');
         return $this->redirect()->toRoute('development/view/edit', array('id' => $viewId));
     }
     if (empty($_FILES['upload'])) {
         $this->flashMessenger()->addErrorMessage('Can not upload views');
         return $this->redirect()->toRoute('development/view');
     }
     foreach ($_FILES['upload']['name'] as $idx => $name) {
         if ($_FILES['upload']['error'][$idx] != UPLOAD_ERR_OK) {
             continue;
         }
         $identifier = preg_replace('~\\.phtml$~', '', $name);
         $view = View\Model::fromIdentifier($identifier);
         if (empty($view)) {
             continue;
         }
         $view->setContent(file_get_contents($_FILES['upload']['tmp_name'][$idx]));
         $view->save();
     }
     $this->flashMessenger()->addSuccessMessage('Views updated');
     return $this->redirect()->toRoute('development/view');
 }
Beispiel #6
0
 /**
  * Test
  *
  * @return void
  */
 public function testFromFakeIdentifier()
 {
     $model = $this->object->fromIdentifier('fake-identifier');
     $this->assertFalse($model);
 }