/** * 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; }