public function processMetadataElements() { require_once __CA_MODELS_DIR__ . "/ca_lists.php"; require_once __CA_MODELS_DIR__ . "/ca_list_items.php"; require_once __CA_MODELS_DIR__ . "/ca_relationship_types.php"; $vo_dm = Datamodel::load(); $t_rel_types = new ca_relationship_types(); $t_list = new ca_lists(); $va_elements = array(); if ($this->ops_base_name) { // "merge" profile and its base foreach ($this->opo_base->elementSets->children() as $vo_element) { $va_elements[self::getAttribute($vo_element, "code")] = $vo_element; } foreach ($this->opo_profile->elementSets->children() as $vo_element) { $va_elements[self::getAttribute($vo_element, "code")] = $vo_element; } } else { foreach ($this->opo_profile->elementSets->children() as $vo_element) { $va_elements[self::getAttribute($vo_element, "code")] = $vo_element; } } foreach ($va_elements as $vs_element_code => $vo_element) { if ($vn_element_id = $this->processMetadataElement($vo_element, null)) { // handle restrictions foreach ($vo_element->typeRestrictions->children() as $vo_restriction) { $vs_restriction_code = self::getAttribute($vo_restriction, "code"); if (!($vn_table_num = $vo_dm->getTableNum((string) $vo_restriction->table))) { $this->addError("Invalid table specified for restriction {$vs_restriction_code} in element {$vs_element_code}"); return false; } $t_instance = $vo_dm->getTableInstance((string) $vo_restriction->table); $vn_type_id = null; $vs_type = trim((string) $vo_restriction->type); // is this restriction further restricted on a specific type? -> get real id from code if (strlen($vs_type) > 0) { // interstitial with type restriction -> code is relationship type code if ($t_instance instanceof BaseRelationshipModel) { $vn_type_id = $t_rel_types->getRelationshipTypeID($t_instance->tableName(), $vs_type); } else { // "normal" type restriction -> code is from actual type list $vs_type_list_name = $t_instance->getFieldListCode($t_instance->getTypeFieldName()); $vn_type_id = $t_list->getItemIDFromList($vs_type_list_name, $vs_type); } } // add restriction $t_restriction = $this->opb_updating ? ca_metadata_type_restrictions::find(array('table_num' => $vn_table_num, 'type_id' => $vn_type_id, 'element_id' => $vn_element_id), array('returnAs' => 'firstModelInstance')) : false; $t_restriction = $t_restriction ? $t_restriction : new ca_metadata_type_restrictions(); $t_restriction->setMode(ACCESS_WRITE); $t_restriction->set('table_num', $vn_table_num); $t_restriction->set('include_subtypes', (bool) $vo_restriction->includeSubtypes ? 1 : 0); $t_restriction->set('type_id', $vn_type_id); $t_restriction->set('element_id', $vn_element_id); $this->_processSettings($t_restriction, $vo_restriction->settings); if ($t_restriction->getPrimaryKey()) { $t_restriction->update(); } else { $t_restriction->insert(); } if ($t_restriction->numErrors()) { $this->addError("There was an error while inserting type restriction {$vs_restriction_code} for metadata element {$vs_element_code}: " . join("; ", $t_restriction->getErrors())); } } } } return true; }