public function removeMetadataElementFromType($pm_element_code_or_id, $pn_type_id) { require_once __CA_APP_DIR__ . '/models/ca_metadata_elements.php'; require_once __CA_APP_DIR__ . '/models/ca_metadata_type_restrictions.php'; if (!($t_element = $this->_getElementInstance($pm_element_code_or_id))) { return false; } $t_restriction = new ca_metadata_type_restrictions(); if ($t_restriction->load(array('element_id' => $t_element->getPrimaryKey(), 'type_id' => $pn_type_id, 'table_num' => $this->tableNum()))) { $t_restriction->setMode(ACCESS_WRITE); $t_restriction->delete(); if ($t_restriction->numErrors()) { $this->postError(1981, _t("Couldn't remove element from restriction list: %1", join('; ', $t_restriction->getErrors())), 'BaseModelWithAttributes->addMetadataElementToType()'); return false; } } return true; }
/** * Adds restriction (a binding between a specific item and optional type and the attribute) * * $pn_table_num: the number of the table to bind to * */ public function addTypeRestriction($pn_table_num, $pn_type_id, $va_settings) { if (!($vn_element = $this->getPrimaryKey())) { return null; } // element must be loaded if ($this->get('parent_id')) { return null; } // element must be root of hierarchy if (!is_array($va_settings)) { $va_settings = array(); } $t_restriction = new ca_metadata_type_restrictions(); $t_restriction->setMode(ACCESS_WRITE); $t_restriction->set('table_num', $pn_table_num); $t_restriction->set('type_id', $pn_type_id); $t_restriction->set('element_id', $this->getPrimaryKey()); foreach ($va_settings as $vs_setting => $vs_setting_value) { $t_restriction->setSetting($vs_setting, $vs_setting_value); } $t_restriction->insert(); if ($t_restriction->numErrors()) { $this->errors = $t_restriction->errors(); return false; } return true; }