fromIdentifier() public static method

Initiliaze from id
public static fromIdentifier ( integer $identifier ) : Model
$identifier integer Identifier
return Model
示例#1
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();
 }
示例#2
0
 /**
  * Test
  *
  * @return void
  */
 public function testEditActionWithPostData()
 {
     $scriptModel = ScriptModel::fromArray(array('name' => 'ScriptName', 'identifier' => 'ScriptIdentifier'));
     $scriptModel->save();
     $this->dispatch('/admin/development/script/edit/' . $scriptModel->getId(), 'POST', array('name' => 'ScriptName', 'identifier' => 'Identifier', 'description' => 'Description'));
     $this->assertResponseStatusCode(302);
     $this->assertModuleName('GcDevelopment');
     $this->assertControllerName('ScriptController');
     $this->assertControllerClass('ScriptController');
     $this->assertMatchedRouteName('development/script/edit');
     ScriptModel::fromIdentifier('Identifier')->delete();
 }
示例#3
0
 /**
  * Test
  *
  * @return void
  */
 public function testFromFakeIdentifier()
 {
     $model = $this->object->fromIdentifier('fake-identifier');
     $this->assertFalse($model);
 }
示例#4
0
文件: Script.php 项目: gotcms/gotcms
 /**
  * Returns script from identifier.
  *
  * @param string $identifier Identifier
  * @param array  $params     Parameters
  *
  * @return mixed
  */
 public function __invoke($identifier, $params = array())
 {
     $script = ScriptModel::fromIdentifier($identifier);
     if (empty($script)) {
         return false;
     }
     $this->helperScriptParameters = $params;
     return include GC_TEMPLATE_PATH . '/script/' . $identifier . '.phtml';
 }
示例#5
0
 /**
  * Upload a file to the server
  *
  * @return \Zend\Http\Response
  */
 public function uploadAction()
 {
     $scriptId = $this->getRouteMatch()->getParam('id', null);
     if (!empty($scriptId)) {
         $script = Script\Model::fromId($scriptId);
         if (empty($script) or empty($_FILES['upload']['tmp_name']) or $_FILES['upload']['error'] != UPLOAD_ERR_OK) {
             $this->flashMessenger()->addErrorMessage('Can not upload script');
             return $this->redirect()->toRoute('development/script/edit', array('id' => $scriptId));
         }
         $script->setContent(file_get_contents($_FILES['upload']['tmp_name']));
         $script->save();
         $this->flashMessenger()->addSuccessMessage('Script updated');
         return $this->redirect()->toRoute('development/script/edit', array('id' => $scriptId));
     }
     if (empty($_FILES['upload'])) {
         $this->flashMessenger()->addErrorMessage('Can not upload scripts');
         return $this->redirect()->toRoute('development/script');
     }
     foreach ($_FILES['upload']['name'] as $idx => $name) {
         if ($_FILES['upload']['error'][$idx] != UPLOAD_ERR_OK) {
             continue;
         }
         $identifier = preg_replace('~\\.phtml$~', '', $name);
         $script = Script\Model::fromIdentifier($identifier);
         if (empty($script)) {
             continue;
         }
         $script->setContent(file_get_contents($_FILES['upload']['tmp_name'][$idx]));
         $script->save();
     }
     $this->flashMessenger()->addSuccessMessage('Scripts updated');
     return $this->redirect()->toRoute('development/script');
 }