Inheritance: extends Gc\Db\AbstractTable
Beispiel #1
0
 /**
  * Test
  *
  * @return void
  */
 public function testIndexActionWithCache()
 {
     $enableCache = $this->config->setValue('cache_is_active', 1);
     $enableCache = $this->config->setValue('cache_handler', 'filesystem');
     $document = DocumentModel::fromArray(array('name' => 'test', 'url_key' => 'test', '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));
     $document->save();
     $this->property->setDocumentId($document->getId());
     $this->property->setValue('string');
     $this->property->saveValue();
     $this->dispatch($document->getUrl());
     $this->assertResponseStatusCode(200);
     $this->assertModuleName('GcFrontend');
     $this->assertControllerName('IndexController');
     $this->assertControllerClass('IndexController');
     $this->assertMatchedRouteName('cms');
     $document->delete();
 }
Beispiel #2
0
 /**
  * Tears down the fixture, for example, closes a network connection.
  * This method is called after a test is executed.
  *
  * @return void
  */
 protected function tearDown()
 {
     $this->datatype->delete();
     $this->documentType->delete();
     $this->layout->delete();
     $this->property->delete();
     $this->tab->delete();
     $this->user->delete();
     $this->view->delete();
     unset($this->datatype);
     unset($this->documentType);
     unset($this->layout);
     unset($this->property);
     unset($this->tab);
     unset($this->user);
     unset($this->view);
     unset($this->object);
 }
 /**
  * Tears down the fixture, for example, closes a network connection.
  * This method is called after a test is executed.
  *
  * @return void
  */
 public function tearDown()
 {
     $this->document->delete();
     $this->documentType->delete();
     $this->property->delete();
     $this->tabModel->delete();
     $this->view->delete();
     $this->layout->delete();
     $this->user->delete();
     $this->datatype->delete();
     unset($this->documentType);
     unset($this->document);
     unset($this->property);
     unset($this->tabModel);
     unset($this->view);
     unset($this->layout);
     unset($this->user);
     unset($this->datatype);
 }
Beispiel #4
0
 protected function removeContent()
 {
     $this->documentType->delete();
     $this->property->delete();
     $this->tabModel->delete();
     $this->view->delete();
     $this->layout->delete();
     $this->script->delete();
     $this->datatype->delete();
     $this->document->delete();
     unset($this->documentType);
     unset($this->property);
     unset($this->tabModel);
     unset($this->view);
     unset($this->layout);
     unset($this->script);
     unset($this->datatype);
     unset($this->document);
 }
Beispiel #5
0
 /**
  * Load editor
  *
  * @param ServiceManager $serviceManager Service manager
  * @param PropertyModel  $property       Property
  *
  * @return mixed
  */
 public static function loadEditor(ServiceManager $serviceManager, PropertyModel $property)
 {
     $datatype = self::loadDatatype($serviceManager, $property->getDatatypeId(), $property->getDocumentId());
     return $datatype->getEditor($property)->load();
 }
 /**
  * Save properties
  *
  * @param Zend\InputFilter\InputFilter $propertiesSubform Properties sub form
  * @param array                        $existingTabs      Array of tabs
  *
  * @return array
  */
 protected function saveProperties($propertiesSubform, $existingTabs)
 {
     $existingProperties = array();
     $idx = 0;
     foreach ($propertiesSubform->getValidInput() as $propertyId => $propertyValues) {
         if (!preg_match('~^property(\\d+)$~', $propertyId, $matches)) {
             continue;
         }
         $propertyId = $matches[1];
         $propertyModel = Property\Model::fromId($propertyId);
         if (empty($propertyModel) or !in_array($propertyModel->getTabId(), $existingTabs)) {
             $propertyModel = new Property\Model();
         }
         $propertyModel->setDescription($propertyValues->getValue('description'));
         $propertyModel->setName($propertyValues->getValue('name'));
         $propertyModel->setIdentifier($propertyValues->getValue('identifier'));
         $propertyModel->setTabId($existingTabs[$propertyValues->getValue('tab')]);
         $propertyModel->setDatatypeId($propertyValues->getValue('datatype'));
         $required = $propertyValues->getValue('required');
         $propertyModel->isRequired(!empty($required) ? true : false);
         $propertyModel->setSortOrder(++$idx);
         $propertyModel->save();
         $existingProperties[] = $propertyModel->getId();
     }
     return $existingProperties;
 }
Beispiel #7
0
 /**
  * Get property
  *
  * @param string $propertyName Property name
  *
  * @return false | PropertyModel
  */
 public function getProperty($propertyName)
 {
     if (!$this->hasData('id')) {
         return false;
     }
     return PropertyModel::fromIdentifier($propertyName, $this->getId());
 }
Beispiel #8
0
 /**
  * Import Document types
  *
  * @param array &$ids     Ids
  * @param array &$errors  Errors
  * @param array $children Children list
  *
  * @return void
  */
 protected function importDocumentTypes(&$ids, &$errors, $children)
 {
     $documentTypes = array();
     foreach ($children['children'] as $child) {
         $attributes = $child->attributes();
         $id = (int) $attributes['id'];
         $model = DocumentType\Model::fromId($id);
         if (empty($model)) {
             $model = new DocumentType\Model();
         }
         $viewid = isset($ids['views'][(int) $child->default_view_id]) ? $ids['views'][(int) $child->default_view_id] : (int) $child->default_view_id;
         $name = (string) $child->name;
         $model->addData(array('name' => empty($name) ? $model->getName() : $name, 'description' => (string) $child->description, 'icon_id' => (int) $child->icon_id, 'default_view_id' => $viewid));
         if ($model->getUserId() === null) {
             $model->setUserId($this->serviceLocator->get('Auth')->getIdentity()->getId());
         }
         try {
             if (!empty($model)) {
                 $model->save();
                 $tabs = (array) $child->tabs;
                 if (isset($tabs['tab']) and is_array($tabs['tab'])) {
                     $tabs = $tabs['tab'];
                 }
                 foreach ($tabs as $tab) {
                     $tabAttributes = $tab->attributes();
                     $tabId = (int) $tabAttributes['id'];
                     $tabModel = Tab\Model::fromId($tabId);
                     if (empty($tabModel)) {
                         $tabModel = new Tab\Model();
                     }
                     $tabModel->addData(array('name' => (string) $tab->name, 'description' => (string) $tab->description, 'sort_order' => (int) $tab->sort_order, 'document_type_id' => $model->getId()));
                     $tabModel->save();
                     $properties = (array) $tab->properties;
                     if (isset($properties['property']) and is_array($properties['property'])) {
                         $properties = $properties['property'];
                     }
                     foreach ($properties as $property) {
                         $propAttributes = $property->attributes();
                         $propertyId = (int) $propAttributes['id'];
                         $propertyModel = Property\Model::fromId($propertyId);
                         if (empty($propertyModel)) {
                             $propertyModel = new Property\Model();
                         }
                         $datatypeId = isset($ids['datatypes'][(int) $property->datatype_id]) ? $ids['datatypes'][(int) $property->datatype_id] : (string) $property->datatype_id;
                         $propertyModel->addData(array('name' => (string) $property->name, 'description' => (string) $property->description, 'identifier' => (string) $property->identifier, 'sort_order' => (int) $property->sort_order, 'tab_id' => $tabModel->getId(), 'datatype_id' => $datatypeId));
                         $propertyModel->save();
                         $ids['properties'][$propertyId] = $propertyModel->getId();
                     }
                 }
                 $ids['document_types'][$id] = $model->getId();
                 $documentTypes[] = array('model' => $model, 'dependencies' => (array) $child->dependencies, 'views' => (array) $child->available_views);
             }
         } catch (Exception $e) {
             $errors[] = sprintf($this->serviceLocator->get('MvcTranslator')->translate('Cannot save document type with id (%d)'), $id);
         }
     }
     return $documentTypes;
 }
Beispiel #9
0
 /**
  * Initiliaze model from identifier
  *
  * @param string  $identifier Identifier
  * @param integer $documentId Document id
  *
  * @return \Gc\Property\Model
  */
 public static function fromIdentifier($identifier, $documentId)
 {
     $propertyTable = new Model();
     $row = $propertyTable->fetchRow($propertyTable->select(function (Select $select) use($documentId, $identifier) {
         $select->join(array('t' => 'tab'), 't.id = property.tab_id', array());
         $select->join(array('dt' => 'document_type'), 'dt.id = t.document_type_id', array());
         $select->join(array('d' => 'document'), 'd.document_type_id = dt.id', array());
         $select->where->equalTo('d.id', $documentId);
         $select->where->equalTo('identifier', $identifier);
     }));
     $propertyTable->events()->trigger(__CLASS__, 'before.load', $propertyTable);
     if (!empty($row)) {
         $propertyTable->setData((array) $row);
         $propertyTable->setDocumentId($documentId);
         $propertyTable->setOrigData();
         $propertyTable->events()->trigger(__CLASS__, 'after.load', $propertyTable);
         return $propertyTable;
     } else {
         $propertyTable->events()->trigger(__CLASS__, 'after.load.failed', $propertyTable);
         return false;
     }
 }
Beispiel #10
0
 /**
  * Test
  *
  * @return void
  */
 public function testLoadEditor()
 {
     $model = PropertyModel::fromArray(array('datatype_id' => $this->object->getId(), 'document_id' => 1));
     //Specific to Textstring editor
     $this->assertInstanceOf('Zend\\Form\\Element\\Text', Model::loadEditor(Registry::get('Application')->getServiceManager(), $model));
 }
 /**
  * Test
  *
  * @return void
  */
 public function testLoad()
 {
     $user = UserModel::fromArray(array('lastname' => 'Test', 'firstname' => 'Test', 'email' => '*****@*****.**', 'login' => 'test-user-model', 'user_acl_role_id' => 1));
     $user->setPassword('test-user-model-password');
     $user->save();
     $view = ViewModel::fromArray(array('name' => 'View', 'identifier' => 'ViewIdentifier', 'description' => 'Description', 'content' => ''));
     $view->save();
     $layout = LayoutModel::fromArray(array('name' => 'View', 'identifier' => 'ViewIdentifier', 'description' => 'Description', 'content' => ''));
     $layout->save();
     $documenttype = DocumentTypeModel::fromArray(array('name' => 'DocumentType', 'description' => 'description', 'icon_id' => 1, 'default_view_id' => $view->getId(), 'user_id' => $user->getId()));
     $documenttype->save();
     $documenttype->setDependencies(array($documenttype->getId()));
     $documenttype->save();
     $datatype = DatatypeModel::fromArray(array('name' => 'DatatypeTest', 'model' => 'Textstring'));
     $datatype->save();
     $tab = TabModel::fromArray(array('name' => 'test', 'description' => 'test', 'document_type_id' => $documenttype->getId()));
     $tab->save();
     $property = PropertyModel::fromArray(array('name' => 'test', 'identifier' => 'test', 'description' => 'test', 'tab_id' => $tab->getId(), 'datatype_id' => $datatype->getId(), 'is_required' => true));
     $property->save();
     $document = DocumentModel::fromArray(array('name' => 'test', 'url_key' => '', 'status' => DocumentModel::STATUS_ENABLE, 'user_id' => $user->getId(), 'document_type_id' => $documenttype->getId(), 'view_id' => $view->getId(), 'layout_id' => $layout->getId(), 'parent_id' => null));
     $document->save();
     $this->assertNull($this->object->load($document, array('locales' => array('en_GB' => 'English'))));
     $this->object->setData(array());
     $this->assertFalse($this->object->isValid());
     $document->delete();
     $documenttype->delete();
     $property->delete();
     $tab->delete();
     $view->delete();
     $layout->delete();
     $user->delete();
     $datatype->delete();
     unset($documenttype);
     unset($document);
     unset($property);
     unset($tab);
     unset($view);
     unset($layout);
     unset($user);
     unset($datatype);
 }
Beispiel #12
0
 /**
  * Set properties
  *
  * @param array $properties Properties
  *
  * @return \Gc\Property\Collection
  */
 public function setProperties(array $properties)
 {
     $array = array();
     foreach ($properties as $property) {
         $array[] = Model::fromArray($property);
     }
     $this->setData('properties', $array);
     return $this;
 }
Beispiel #13
0
 /**
  * Test
  *
  * @return void
  */
 public function testGetName()
 {
     $this->assertEquals('datatype' . $this->property->getId(), $this->object->getName());
 }
Beispiel #14
0
 /**
  * Delete file
  *
  * @return \Zend\View\Model\JsonModel
  */
 public function removeAction()
 {
     $property = Property\Model::fromId($this->getRouteMatch()->getParam('property_id'));
     $document = Document\Model::fromId($this->getRouteMatch()->getParam('document_id'));
     if ($this->getRequest()->getMethod() != 'DELETE' or empty($document) or empty($property)) {
         return $this->returnJson(array('error' => true));
     }
     $file = base64_decode($this->getRouteMatch()->getParam('file'));
     $fileClass = new File();
     $fileClass->load($property, $document);
     return $this->returnJson(array($fileClass->remove($file)));
 }
Beispiel #15
0
 /**
  * Test
  *
  * @return void
  */
 public function testAddPropertyWithPropertyModel()
 {
     $propertyModel = PropertyModel::fromArray(array('name' => 'Name', 'description' => 'Description', 'identifier' => 'Identifier', 'sort_order' => 1, 'tab_id' => 1, 'datatype_id' => 1, 'id' => 1));
     $this->assertInstanceOf('GcDevelopment\\Form\\DocumentType', $this->object->addProperty($propertyModel));
 }
Beispiel #16
0
 /**
  * Test
  *
  * @return void
  */
 public function testLoad()
 {
     $this->assertInstanceOf('Gc\\Property\\Value\\Model', $this->object->load($this->object->getId(), $this->document->getId(), $this->property->getId()));
 }
Beispiel #17
0
 /**
  * Initiliaze files
  *
  * @return void
  */
 protected function initializeFiles()
 {
     $_FILES = array('test' => array('name' => __DIR__ . '/_files/test.jpg', 'type' => 'plain/text', 'size' => 8, 'tmp_name' => __DIR__ . '/_files/test.jpg', 'error' => 0));
     $property = PropertyModel::fromArray(array('id' => 'test-upload'));
     $document = DocumentModel::fromArray(array('id' => 'test-upload'));
     $this->object->load($property, $document, 'test');
 }
 /**
  * Test
  *
  * @return void
  */
 public function testImportTabActionWithPostData()
 {
     $viewModel = ViewModel::fromArray(array('name' => 'Test', 'identifier' => 'Test', 'content' => 'Test'));
     $viewModel->save();
     $datatypeModel = DatatypeModel::fromArray(array('name' => 'DatatypeTest', 'model' => 'Textstring'));
     $datatypeModel->save();
     $documentTypeModel = DocumentTypeModel::fromArray(array('name' => 'TestDocumentType', 'icon_id' => 3, 'default_view_id' => $viewModel->getId(), 'user_id' => $this->user->getId()));
     $documentTypeModel->save();
     $tabModel = TabModel::fromArray(array('name' => 'test', 'description' => 'test', 'document_type_id' => $documentTypeModel->getId()));
     $tabModel->save();
     $propertyModel = PropertyModel::fromArray(array('name' => 'test', 'identifier' => 'test', 'description' => 'test', 'tab_id' => $tabModel->getId(), 'datatype_id' => $datatypeModel->getId()));
     $propertyModel->save();
     $this->dispatch('/admin/development/document-type/import-tab', 'POST', array('tab_id' => $tabModel->getId()));
     $this->assertResponseStatusCode(200);
     $this->assertModuleName('GcDevelopment');
     $this->assertControllerName('DocumentTypeController');
     $this->assertControllerClass('DocumentTypeController');
     $this->assertMatchedRouteName('development/document-type/import-tab');
     $documentTypeModel->delete();
     $propertyModel->delete();
     $tabModel->delete();
     $viewModel->delete();
     $datatypeModel->delete();
 }
Beispiel #19
0
 /**
  * Test
  *
  * @return void
  */
 public function testFromIdentifier()
 {
     $documentModel = DocumentModel::fromArray(array('name' => 'DocumentTest', 'url_key' => 'document-test', 'status' => DocumentModel::STATUS_ENABLE, 'sort_order' => 1, 'show_in_nav' => true, 'user_id' => $this->user->getId(), 'document_type_id' => $this->documentType->getId(), 'view_id' => $this->view->getId(), 'layout_id' => $this->layout->getId(), 'parent_id' => 0));
     $documentModel->save();
     $this->assertInstanceOf('Gc\\Property\\Model', Model::fromIdentifier($this->object->getIdentifier(), $documentModel->getId()));
 }
Beispiel #20
0
 /**
  * Test
  *
  * @return void
  */
 public function testDelete()
 {
     $this->object->setProperties(array($this->property->getData()));
     $this->assertTrue($this->object->delete());
 }