private function getListItemsAsDOM($pn_parent_id)
 {
     $qr_items = $this->opo_db->query("SELECT * FROM ca_list_items WHERE parent_id=? AND deleted=0", $pn_parent_id);
     if (!($qr_items->numRows() > 0)) {
         return false;
     }
     $vo_items = $this->opo_dom->createElement("items");
     $vs_default_locale = $this->opt_locale->localeIDToCode($this->opt_locale->getDefaultCataloguingLocaleID());
     while ($qr_items->nextRow()) {
         $vo_item = $this->opo_dom->createElement("item");
         $vs_idno = $this->makeIDNOFromInstance($qr_items, 'idno');
         $vo_item->setAttribute("idno", $vs_idno);
         $vo_item->setAttribute("enabled", $qr_items->get("is_enabled"));
         $vo_item->setAttribute("default", $qr_items->get("is_default"));
         if (is_numeric($vn_value = $qr_items->get("item_value"))) {
             $vo_item->setAttribute("value", $vn_value);
         }
         $vo_labels = $this->opo_dom->createElement("labels");
         $qr_list_item_labels = $this->opo_db->query("SELECT * FROM ca_list_item_labels WHERE item_id=?", $qr_items->get("item_id"));
         if ($qr_list_item_labels->numRows() > 0) {
             while ($qr_list_item_labels->nextRow()) {
                 $vo_label = $this->opo_dom->createElement("label");
                 $vo_label->setAttribute("locale", $this->opt_locale->localeIDToCode($qr_list_item_labels->get("locale_id")));
                 $vo_label->setAttribute("preferred", $qr_list_item_labels->get("is_preferred"));
                 $vo_label->appendChild($this->opo_dom->createElement("name_singular", caEscapeForXML($qr_list_item_labels->get("name_singular"))));
                 $vo_label->appendChild($this->opo_dom->createElement("name_plural", caEscapeForXML($qr_list_item_labels->get("name_plural"))));
                 $vo_labels->appendChild($vo_label);
             }
         } else {
             // fallback if list item has no labels: add idno label in the default cataloguing locale
             $vo_label = $this->opo_dom->createElement("label");
             $vo_label->setAttribute("preferred", "1");
             $vo_label->setAttribute("locale", $vs_default_locale);
             $vo_label->appendChild($this->opo_dom->createElement("name_singular", caEscapeForXML($vs_idno)));
             $vo_label->appendChild($this->opo_dom->createElement("name_plural", caEscapeForXML($vs_idno)));
             $vo_labels->appendChild($vo_label);
         }
         $vo_item->appendChild($vo_labels);
         if ($vo_sub_items = $this->getListItemsAsDOM($qr_items->get("item_id"))) {
             $vo_item->appendChild($vo_sub_items);
         }
         $vo_items->appendChild($vo_item);
     }
     return $vo_items;
 }
示例#2
0
			itemID: '<?php 
    print $vs_id_prefix;
    ?>
Item_',
			templateClassName: 'caItemTemplate',
			itemListClassName: 'caItemList',
			minRepeats: <?php 
    print ($vn_n = $this->getVar('min_num_repeats')) ? $vn_n : 0;
    ?>
,
			maxRepeats: <?php 
    print ($vn_n = $this->getVar('max_num_repeats')) ? $vn_n : 65535;
    ?>
,
			defaultValues: <?php 
    print json_encode($va_element_value_defaults);
    ?>
,
			readonly: <?php 
    print $vb_read_only ? "1" : "0";
    ?>
,
			defaultLocaleID: <?php 
    print ca_locales::getDefaultCataloguingLocaleID();
    ?>
		});
<?php 
}
?>
	});
</script>
 /**
  * @param array $pa_options
  * @param $t_rel
  * @param bool $pb_update
  */
 private function _processInterstitials($pa_options, $t_rel, $pb_update)
 {
     global $g_ui_locale_id;
     // Are there interstitials to add?
     if (isset($pa_options['interstitialValues']) && is_array($pa_options['interstitialValues'])) {
         $t_rel->setMode(ACCESS_WRITE);
         foreach ($pa_options['interstitialValues'] as $vs_element => $va_value) {
             if ($t_rel->hasField($vs_element)) {
                 $t_rel->set($vs_element, $va_value);
                 continue;
             }
             // Convert a scalar or key-value array to an indexed array with a single element
             if (!is_array($va_value) || array_keys($va_value) !== range(0, sizeof($va_value) - 1)) {
                 $va_value = array($va_value);
             }
             // Iterate through indexed array
             foreach ($va_value as $va_value_instance) {
                 // Convert scalar to key-value array
                 if (!is_array($va_value_instance)) {
                     $va_value_instance = array($vs_element => $va_value_instance);
                 }
                 // Ensure we have a locale
                 if (!isset($va_value_instance['locale_id'])) {
                     $va_value_instance['locale_id'] = $g_ui_locale_id ? $g_ui_locale_id : ca_locales::getDefaultCataloguingLocaleID();
                 }
                 // Create or update the attribute
                 if ($pb_update) {
                     $t_rel->editAttribute($va_value_instance, $vs_element);
                 } else {
                     $t_rel->addAttribute($va_value_instance, $vs_element);
                 }
             }
         }
         $t_rel->update();
     }
 }
 /**
  * Edits the data in an existing relationship between the currently loaded row and the specified row.
  *
  * @param mixed $pm_rel_table_name_or_num Table name (eg. "ca_entities") or number as defined in datamodel.conf of table containing row to create relationships to.
  * @param int $pn_relation_id primary key value of the relation to edit.
  * @param int $pn_rel_id primary key value of row to creation relationship to.
  * @param mixed $pm_type_id Relationship type type_code or type_id, as defined in the ca_relationship_types table. This is required for all relationships that use relationship types. This includes all of the most common types of relationships.
  * @param string $ps_effective_date Optional date expression to qualify relation with. Any expression that the TimeExpressionParser can handle is supported here.
  * @param mixed $pa_source_info Array or text for storing information about source of relationship. Not currently used.
  * @param string $ps_direction Optional direction specification for self-relationships (relationships linking two rows in the same table). Valid values are 'ltor' (left-to-right) and  'rtol' (right-to-left); the direction determines which "side" of the relationship the currently loaded row is on: 'ltor' puts the current row on the left side. For many self-relations the direction determines the nature and display text for the relationship.
  * @param null|int $pn_rank
  * @param array $pa_options Array of additional options:
  *		allowDuplicates = if set to true, attempts to edit a relationship to match one that already exists will succeed. Default is false – duplicate relationships will not be created.
  *		setErrorOnDuplicate = if set to true, an error will be set if an attempt is made to create a duplicate relationship. Default is false – don't set error. editRelationship() will always return false when editing of a relationship fails, no matter how the setErrorOnDuplicate option is set.
  * @return BaseRelationshipModel Loaded relationship model instance on success, false on error.
  */
 public function editRelationship($pm_rel_table_name_or_num, $pn_relation_id, $pn_rel_id, $pm_type_id = null, $ps_effective_date = null, $pa_source_info = null, $ps_direction = null, $pn_rank = null, $pa_options = null)
 {
     global $g_ui_locale_id;
     if ($t_rel = parent::editRelationship($pm_rel_table_name_or_num, $pn_relation_id, $pn_rel_id, $pm_type_id, $ps_effective_date, $pa_source_info, $ps_direction, $pn_rank, $pa_options)) {
         // are there interstitials to add?
         if (isset($pa_options['interstitialValues']) && is_array($pa_options['interstitialValues'])) {
             $t_rel->setMode(ACCESS_WRITE);
             foreach ($pa_options['interstitialValues'] as $vs_element => $va_value) {
                 if ($t_rel->hasField($vs_element)) {
                     $t_rel->set($vs_element, $va_value);
                     continue;
                 }
                 if (is_array($va_value)) {
                     if (!isset($va_value['locale_id'])) {
                         $va_value['locale_id'] = $g_ui_locale_id ? $g_ui_locale_id : ca_locales::getDefaultCataloguingLocaleID();
                     }
                     // array of values (complex multi-valued attribute)
                     $t_rel->replaceAttribute($va_value, $vs_element);
                 } else {
                     // scalar value (simple single value attribute)
                     if ($va_value) {
                         $t_rel->replaceAttribute(array('locale_id' => $g_ui_locale_id ? $g_ui_locale_id : ca_locales::getDefaultCataloguingLocaleID(), $vs_element => $va_value), $vs_element);
                     }
                 }
             }
             $t_rel->update();
             if ($t_rel->numErrors()) {
                 $this->errors = $t_rel->errors;
                 return false;
             }
         }
     }
     return $t_rel;
 }
示例#5
0
 /**
  *
  */
 public function insert($pa_options = null)
 {
     $vn_rc = parent::insert($pa_options);
     if ($this->getPrimaryKey()) {
         // create root in ca_list_items
         $t_item_root = new ca_list_items();
         $t_item_root->setMode(ACCESS_WRITE);
         if ($this->inTransaction()) {
             $t_item_root->setTransaction($this->getTransaction());
         }
         $t_item_root->set('list_id', $this->getPrimaryKey());
         $t_item_root->set('idno', $vs_title = 'Root node for ' . $this->get('list_code'));
         $t_item_root->set('is_enabled', 0);
         $t_item_root->set('item_value', 'Root');
         $t_item_root->insert();
         if ($t_item_root->numErrors()) {
             $this->delete();
             $this->errors = array_merge($this->errors, $t_item_root->errors);
             return false;
         }
         $vn_locale_id = ca_locales::getDefaultCataloguingLocaleID();
         $t_item_root->addLabel(array('name_singular' => $vs_title, 'name_plural' => $vs_title), $vn_locale_id, null, true);
         if ($t_item_root->numErrors()) {
             $this->delete();
             $this->errors = array_merge($this->errors, $t_item_root->errors);
             return false;
         }
     }
     return $vn_rc;
 }
 /** 
  * Add media represention to currently loaded item
  *
  * @param $ps_media_path - the path to the media you want to add
  * @param $pn_type_id - the item_id of the representation type, in the ca_list with list_code 'object_represention_types'
  * @param $pn_locale_id - the locale_id of the locale of the representation
  * @param $pn_status - the status code for the representation (as defined in item_value fields of items in the 'workflow_statuses' ca_list)
  * @param $pn_access - the access code for the representation (as defined in item_value fields of items in the 'access_statuses' ca_list)
  * @param $pb_is_primary - if set to true, representation is designated "primary." Primary representation are used in cases where only one representation is required (such as search results). If a primary representation is already attached to this item, then it will be changed to non-primary as only one representation can be primary at any given time. If no primary representations exist, then the new representation will always be marked primary no matter what the setting of this parameter (there must always be a primary representation, if representations are defined).
  * @param $pa_values - array of attributes to attach to new representation
  * @param $pa_options - an array of options passed through to BaseModel::set() when creating the new representation. Currently supported options:
  *		original_filename - the name of the file being uploaded; will be recorded in the database and used as the filename when the file is subsequently downloaded
  *		rank - a numeric rank used to order the representations when listed
  *		returnRepresentation = if set the newly created ca_object_representations instance is returned rather than the link_id of the newly created relationship record
  *
  * @return mixed Returns primary key (link_id) of the relatipnship row linking the newly created representation to the item; if the 'returnRepresentation' is set then an instance for the newly created ca_object_representations is returned instead; boolean false is returned on error
  */
 public function addRepresentation($ps_media_path, $pn_type_id, $pn_locale_id, $pn_status, $pn_access, $pb_is_primary, $pa_values = null, $pa_options = null)
 {
     if (!($vn_id = $this->getPrimaryKey())) {
         return null;
     }
     if (!$pn_locale_id) {
         $pn_locale_id = ca_locales::getDefaultCataloguingLocaleID();
     }
     $t_rep = new ca_object_representations();
     if ($this->inTransaction()) {
         $o_trans = $this->getTransaction();
         $t_rep->setTransaction($o_trans);
     }
     $t_rep->setMode(ACCESS_WRITE);
     $t_rep->set('type_id', $pn_type_id);
     $t_rep->set('locale_id', $pn_locale_id);
     $t_rep->set('status', $pn_status);
     $t_rep->set('access', $pn_access);
     $t_rep->set('media', $ps_media_path, $pa_options);
     if (is_array($pa_values)) {
         if (isset($pa_values['idno'])) {
             $t_rep->set('idno', $pa_values['idno']);
         }
         foreach ($pa_values as $vs_element => $va_value) {
             if (is_array($va_value)) {
                 // array of values (complex multi-valued attribute)
                 $t_rep->addAttribute(array_merge($va_value, array('locale_id' => $pn_locale_id)), $vs_element);
             } else {
                 // scalar value (simple single value attribute)
                 if ($va_value) {
                     $t_rep->addAttribute(array('locale_id' => $pn_locale_id, $vs_element => $va_value), $vs_element);
                 }
             }
         }
     }
     $t_rep->insert();
     if ($t_rep->numErrors()) {
         $this->errors = array_merge($this->errors, $t_rep->errors());
         return false;
     }
     if ($t_rep->getPreferredLabelCount() == 0) {
         $vs_label = isset($pa_values['name']) && $pa_values['name'] ? $pa_values['name'] : '[' . _t('BLANK') . ']';
         $t_rep->addLabel(array('name' => $vs_label), $pn_locale_id, null, true);
         if ($t_rep->numErrors()) {
             $this->errors = array_merge($this->errors, $t_rep->errors());
             return false;
         }
     }
     if (!($t_oxor = $this->_getRepresentationRelationshipTableInstance())) {
         return null;
     }
     $vs_pk = $this->primaryKey();
     if ($this->inTransaction()) {
         $o_trans = $this->getTransaction();
         $t_oxor->setTransaction($o_trans);
     }
     $t_oxor->setMode(ACCESS_WRITE);
     $t_oxor->set($vs_pk, $vn_id);
     $t_oxor->set('representation_id', $t_rep->getPrimaryKey());
     $t_oxor->set('is_primary', $pb_is_primary ? 1 : 0);
     $t_oxor->set('rank', isset($pa_options['rank']) ? (int) $pa_options['rank'] : null);
     if ($t_oxor->hasField('type_id')) {
         $t_oxor->set('type_id', isset($pa_options['type_id']) ? (int) $pa_options['type_id'] : null);
     }
     $t_oxor->insert();
     if ($t_oxor->numErrors()) {
         $this->errors = array_merge($this->errors, $t_oxor->errors());
         $t_rep->delete();
         if ($t_rep->numErrors()) {
             $this->errors = array_merge($this->errors, $t_rep->errors());
         }
         return false;
     }
     //
     // Perform mapping of embedded metadata for newly uploaded representation with respect
     // to ca_objects and ca_object_representation records
     //
     $va_metadata = $t_rep->get('media_metadata', array('binary' => true));
     if (caExtractEmbeddedMetadata($this, $va_metadata, $pn_locale_id)) {
         $this->update();
     }
     if (isset($pa_options['returnRepresentation']) && (bool) $pa_options['returnRepresentation']) {
         return $t_rep;
     }
     return $t_oxor->getPrimaryKey();
 }
 /**
  *
  */
 public function refine(&$pa_destination_data, $pa_group, $pa_item, $pa_source_data, $pa_options = null)
 {
     global $g_ui_locale_id;
     $vs_delimiter = caGetOption('delimiter', $pa_options, null);
     if (!($pn_locale_id = ca_locales::getDefaultCataloguingLocaleID())) {
         $pn_locale_id = $g_ui_locale_id;
     }
     $o_log = isset($pa_options['log']) && is_object($pa_options['log']) ? $pa_options['log'] : null;
     $t_mapping = caGetOption('mapping', $pa_options, null);
     if ($t_mapping) {
         $o_dm = Datamodel::load();
         if ($t_mapping->get('table_num') != $o_dm->getTableNum('ca_list_items')) {
             if ($o_log) {
                 $o_log->logError(_t("listItemIndentedHierarchyBuilder refinery may only be used in imports to ca_list_items"));
             }
             return null;
         }
     }
     $va_group_dest = explode(".", $pa_group['destination']);
     $vs_terminal = array_pop($va_group_dest);
     $pm_value = $pa_source_data[$pa_item['source']];
     // Get list of fields to insert
     if (!is_array($va_levels = $pa_item['settings']['listItemIndentedHierarchyBuilder_levels'])) {
         if ($o_log) {
             $o_log->logError(_t("listItemIndentedHierarchyBuilder requires levels option be set to a list of data source placeholders"));
         }
         return null;
     } else {
         $va_level_types = $pa_item['settings']['listItemIndentedHierarchyBuilder_levelTypes'];
     }
     // Get list, or create if it doesn't already exist
     if (!($vs_list_code = $pa_item['settings']['listItemIndentedHierarchyBuilder_list'])) {
         if ($o_log) {
             $o_log->logError(_t("listItemIndentedHierarchyBuilder requires list option be set"));
         }
         return null;
     }
     $t_list = new ca_lists();
     if (!$t_list->load(array('list_code' => $vs_list_code))) {
         // create list
         $t_list->set('list_code', $vs_list_code);
         $t_list->setMode(ACCESS_WRITE);
         $t_list->insert();
         if ($t_list->numErrors()) {
             if ($o_log) {
                 $o_log->logError(_t("listItemIndentedHierarchyBuilder could not create list %1: %2", $vs_list_code, join("; ", $t_list->getErrors())));
             }
             return null;
         }
         $t_list->addLabel(array('name' => caUcFirstUTF8Safe($vs_list_code)), $pn_locale_id, null, true);
         if ($t_list->numErrors()) {
             if ($o_log) {
                 $o_log->logError(_t("listItemIndentedHierarchyBuilder could not create list label %1: %2", $vs_list_code, join("; ", $t_list->getErrors())));
             }
             return null;
         }
     }
     // Handle each level
     if (!is_array($va_level_values = listItemIndentedHierarchyBuilderRefinery::$opa_level_values)) {
         $va_level_values = $va_level_value_ids = array();
     }
     $va_level_value_ids = listItemIndentedHierarchyBuilderRefinery::$opa_level_value_ids;
     $vn_max_level = 0;
     $vn_parent_id = null;
     foreach ($va_levels as $vn_i => $vs_level_placeholder) {
         $vs_level_value = null;
         if (strlen($vs_level_placeholder)) {
             if ($vs_level_value = BaseRefinery::parsePlaceholder($vs_level_placeholder, $pa_source_data, $pa_item, 0, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true))) {
                 if (!$vn_parent_id && isset(listItemIndentedHierarchyBuilderRefinery::$opa_level_value_ids[$vn_i - 1])) {
                     $vn_parent_id = listItemIndentedHierarchyBuilderRefinery::$opa_level_value_ids[$vn_i - 1];
                 }
                 $vs_type = isset($va_level_types[$vn_i]) ? $va_level_types[$vn_i] : null;
                 if ($vn_item_id = DataMigrationUtils::getListItemID($vs_list_code, preg_replace("![^A-Za-z0-9_]+!", "_", $vs_level_value), $vs_type, $pn_locale_id, array('is_enabled' => 1, 'parent_id' => $vn_parent_id, 'preferred_labels' => array('name_singular' => $vs_level_value, 'name_plural' => $vs_level_value)), array('matchOnIdno' => true, 'log' => $o_log, 'transaction' => caGetOption('transaction', $pa_options, null), 'importEvent' => caGetOption('event', $pa_options, null), 'importEventSource' => 'listItemIndentedHierarchyBuilder'))) {
                     $vn_parent_id = $vn_item_id;
                     $va_level_values[$vn_i] = $vs_level_value;
                     $va_level_value_ids[$vn_i] = $vn_item_id;
                     $vn_max_level = $vn_i;
                 }
             }
         }
     }
     listItemIndentedHierarchyBuilderRefinery::$opa_level_values = array_slice($va_level_values, 0, $vn_max_level + 1);
     listItemIndentedHierarchyBuilderRefinery::$opa_level_value_ids = array_slice($va_level_value_ids, 0, $vn_max_level + 1);
     if ($pa_item['settings']['listItemIndentedHierarchyBuilder_list'] == 'returnData') {
         return $vn_parent_id;
     }
     return null;
 }
 /** 
  * Link existing media represention to currently loaded item
  *
  * @param $pn_representation_id - 
  * @param $pb_is_primary - if set to true, representation is designated "primary." Primary representation are used in cases where only one representation is required (such as search results). If a primary representation is already attached to this item, then it will be changed to non-primary as only one representation can be primary at any given time. If no primary representations exist, then the new representation will always be marked primary no matter what the setting of this parameter (there must always be a primary representation, if representations are defined).
  * @param $pa_options - an array of options passed through to BaseModel::set() when creating the new representation. Currently supported options:
  *		rank - a numeric rank used to order the representations when listed
  *
  * @return mixed Returns primary key (link_id) of the relatipnship row linking the  representation to the item; boolean false is returned on error
  */
 public function linkRepresentation($pn_representation_id, $pb_is_primary, $pa_options = null)
 {
     if (!($vn_id = $this->getPrimaryKey())) {
         return null;
     }
     if (!$pn_locale_id) {
         $pn_locale_id = ca_locales::getDefaultCataloguingLocaleID();
     }
     if (!ca_object_representations::find(array('representation_id' => $pn_representation_id), array('transaction' => $this->getTransaction()))) {
         return null;
     }
     if (!($t_oxor = $this->_getRepresentationRelationshipTableInstance())) {
         return null;
     }
     $vs_pk = $this->primaryKey();
     if ($this->inTransaction()) {
         $t_oxor->setTransaction($this->getTransaction());
     }
     $t_oxor->setMode(ACCESS_WRITE);
     $t_oxor->set($vs_pk, $vn_id);
     $t_oxor->set('representation_id', $pn_representation_id);
     $t_oxor->set('is_primary', $pb_is_primary ? 1 : 0);
     $t_oxor->set('rank', isset($pa_options['rank']) ? (int) $pa_options['rank'] : $pn_representation_id);
     if ($t_oxor->hasField('type_id')) {
         $t_oxor->set('type_id', isset($pa_options['type_id']) ? (int) $pa_options['type_id'] : null);
     }
     $t_oxor->insert();
     if ($t_oxor->numErrors()) {
         $this->errors = array_merge($this->errors, $t_oxor->errors());
         return false;
     }
     return $t_oxor->getPrimaryKey();
 }