/** * Test * * @return void */ public function testFromWithWrongId() { $this->assertFalse(Model::fromId('undefined')); }
/** * 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; }
/** * 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; }
/** * 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))); }