Example #1
0
 public function update($pa_options = null)
 {
     $this->_generateSortableValue();
     // populate sort field
     // Invalid entire labels-by-id cache since we can't know what entries pertain to the label we just changed
     LabelableBaseModelWithAttributes::$s_labels_by_id_cache = array();
     // Unset label cache entry for modified label only
     unset(LabelableBaseModelWithAttributes::$s_label_cache[$this->getSubjectTableName()][$this->get($this->getSubjectKey())]);
     return parent::update($pa_options);
 }
 /**
  * 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)
 {
     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)) {
         if ($t_rel->numErrors()) {
             $this->errors = $t_rel->errors;
             return false;
         }
         $this->_processInterstitials($pa_options, $t_rel, true);
         if ($t_rel->numErrors()) {
             $this->errors = $t_rel->errors;
             return false;
         }
     }
     return $t_rel;
 }
Example #3
0
 /**
  * @param LabelableBaseModelWithAttributes $t_instance
  * @param SimpleXMLElement $po_labels
  * @param array $pa_locales array
  * @param bool $pb_force_preferred
  * @return bool
  */
 protected static function addLabelsFromXMLElement($t_instance, $po_labels, $pa_locales, $pb_force_preferred = false)
 {
     require_once __CA_LIB_DIR__ . "/ca/LabelableBaseModelWithAttributes.php";
     if (!$t_instance instanceof LabelableBaseModelWithAttributes) {
         return false;
     }
     /** @var LabelableBaseModelWithAttributes $t_instance */
     foreach ($po_labels->children() as $vo_label) {
         $va_label_values = array();
         $vs_locale = self::getAttribute($vo_label, "locale");
         $vn_locale_id = $pa_locales[$vs_locale];
         $vb_preferred = self::getAttribute($vo_label, "preferred");
         if ($pb_force_preferred || (bool) $vb_preferred || is_null($vb_preferred)) {
             $vb_preferred = true;
         } else {
             $vb_preferred = false;
         }
         foreach ($vo_label->children() as $vo_field) {
             $va_label_values[$vo_field->getName()] = (string) $vo_field;
         }
         $va_existing_labels = $vb_preferred ? $t_instance->getPreferredLabels(array($vn_locale_id)) : $t_instance->getNonPreferredLabels(array($vn_locale_id));
         if ($va_existing_labels && ($vn_label_id = $va_existing_labels[(int) $t_instance->getPrimaryKey()][(int) $vn_locale_id][0]['label_id'])) {
             $t_instance->editLabel($vn_label_id, $va_label_values, $vn_locale_id, null, $vb_preferred);
         } else {
             $t_instance->addLabel($va_label_values, $vn_locale_id, false, $vb_preferred);
         }
     }
     return true;
 }
Example #4
0
 /**
  * Results are speculatively pre-fetched in blocks to improve performance. This can cause issues
  * if you're inserting rows and expect a previously create SearchResult to "see" those new rows. 
  * SearchResult::clearResultCacheForRow() will clear the result cache for a single row, specified by its primary key,
  * causing get() to re-fetch fresh data for the row. If applicable, the table storing related labels will also be purged. 
  *
  * @param string $ps_table Name of table to purge cache for
  * @pram int $pn_row_id The primary key of the row to purge cache for
  * @return void
  */
 public static function clearResultCacheForRow($ps_table, $pn_row_id)
 {
     unset(self::$s_prefetch_cache[$ps_table][$pn_row_id]);
     unset(self::$s_rel_prefetch_cache[$ps_table][$pn_row_id]);
     $ps_label_table = LabelableBaseModelWithAttributes::getLabelTable($ps_table);
     if ($ps_label_table) {
         unset(self::$s_prefetch_cache[$ps_label_table][$pn_row_id]);
         unset(self::$s_rel_prefetch_cache[$ps_label_table][$pn_row_id]);
     }
 }
 /**
  * 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;
 }
 /**
  *
  */
 public function htmlFormElement($ps_field, $ps_format = null, $pa_options = null)
 {
     if ($ps_field == 'list_id') {
         // Custom list drop-down
         $vs_format = $this->_CONFIG->get('form_element_display_format');
         $t_list = new ca_lists();
         $va_lists = caExtractValuesByUserLocale($t_list->getListOfLists());
         $va_opts = array();
         foreach ($va_lists as $vn_list_id => $va_list_info) {
             $va_opts[$va_list_info['name'] . ' (' . $va_list_info['list_code'] . ')'] = $vn_list_id;
         }
         ksort($va_opts);
         $vs_format = str_replace('^LABEL', $vs_field_label = $this->getFieldInfo('list_id', 'LABEL'), $vs_format);
         $vs_format = str_replace('^EXTRA', '', $vs_format);
         $vs_format = str_replace('^ELEMENT', caHTMLSelect($ps_field, $va_opts, array('id' => $ps_field), array('value' => $this->get('list_id'))), $vs_format);
         if (!isset($pa_options['no_tooltips']) || !$pa_options['no_tooltips']) {
             TooltipManager::add('#list_id', "<h3>{$vs_field_label}</h3>" . $this->getFieldInfo('list_id', 'DESCRIPTION'), $pa_options['tooltip_namespace']);
         }
         return $vs_format;
     }
     return parent::htmlFormElement($ps_field, $ps_format, $pa_options);
 }