Exemplo n.º 1
0
 public function processMiscHierarchicalSetup()
 {
     require_once __CA_MODELS_DIR__ . "/ca_storage_locations.php";
     #
     # Create roots for storage locations hierarchies
     #
     $t_storage_location = new ca_storage_locations();
     $t_storage_location->setMode(ACCESS_WRITE);
     $t_storage_location->set('status', 0);
     $t_storage_location->set('parent_id', null);
     $t_storage_location->insert();
     if ($t_storage_location->numErrors()) {
         $this->addError("Errors inserting the storage location root: " . join("; ", $t_storage_location->getErrors()));
         return;
     }
 }
Exemplo n.º 2
0
/**
 * 
 *
 * @param string $ps_refinery_name
 * @param string $ps_table
 * @param array $pa_parents 
 * @param array $pa_source_data
 * @param array $pa_item
 * @param int $pn_c
 * @param KLogger $o_log
 * 
 * @return int
 */
function caProcessRefineryParents($ps_refinery_name, $ps_table, $pa_parents, $pa_source_data, $pa_item, $pn_c, $pa_options = null)
{
    global $g_ui_locale_id;
    if (!is_array($pa_options)) {
        $pa_options = array();
    }
    $o_log = caGetOption('log', $pa_options, null);
    $o_reader = caGetOption('reader', $pa_options, null);
    $o_trans = caGetOption('transaction', $pa_options, null);
    $vn_list_id = caGetOption('list_id', $pa_options, null);
    $vb_hierarchy_mode = caGetOption('hierarchyMode', $pa_options, false);
    if (!is_array($pa_parents)) {
        $pa_parents = array($pa_parents);
    }
    $vn_id = null;
    $pa_parents = array_reverse($pa_parents);
    foreach ($pa_parents as $vn_i => $va_parent) {
        if (!is_array($va_parent)) {
            $o_log->logWarn(_t('[%2] Parents options invalid. Did you forget to pass a list? Parents list passed was: %1', print_r($pa_parents, true), $ps_refinery_name));
            break;
        }
        $vs_name = BaseRefinery::parsePlaceholder($va_parent['name'], $pa_source_data, $pa_item, $pn_c, array('reader' => $o_reader, 'returnAsString' => true, 'delimiter' => ' '));
        $vs_idno = BaseRefinery::parsePlaceholder($va_parent['idno'], $pa_source_data, $pa_item, $pn_c, array('reader' => $o_reader, 'returnAsString' => true, 'delimiter' => ' '));
        $vs_type = BaseRefinery::parsePlaceholder($va_parent['type'], $pa_source_data, $pa_item, $pn_c, array('reader' => $o_reader, 'returnAsString' => true, 'delimiter' => ' '));
        if (!$vs_name && !$vs_idno) {
            continue;
        }
        if (!$vs_name) {
            continue;
        }
        //$vs_name = $vs_idno; }
        $va_attributes = isset($va_parent['attributes']) && is_array($va_parent['attributes']) ? $va_parent['attributes'] : array();
        foreach ($va_attributes as $vs_element_code => $va_attrs) {
            if (is_array($va_attrs)) {
                foreach ($va_attrs as $vs_k => $vs_v) {
                    // BaseRefinery::parsePlaceholder may return an array if the input format supports repeated values (as XML does)
                    // DataMigrationUtils::getCollectionID(), which ca_data_importers::importDataFromSource() uses to create related collections
                    // only supports non-repeating attribute values, so we join any values here and call it a day.
                    $va_attributes[$vs_element_code][$vs_k] = BaseRefinery::parsePlaceholder($vs_v, $pa_source_data, $pa_item, $pn_c, array('reader' => $o_reader, 'returnAsString' => true, 'delimiter' => ' '));
                }
            } else {
                $va_attributes[$vs_element_code] = array($vs_element_code => BaseRefinery::parsePlaceholder($va_attrs, $pa_source_data, $pa_item, $pn_c, array('reader' => $o_reader, 'returnAsString' => true, 'delimiter' => ' ')));
            }
        }
        $va_attributes['idno'] = $vs_idno;
        $va_attributes['parent_id'] = $vn_id;
        if (isset($va_parent['rules']) && is_array($va_parent['rules'])) {
            foreach ($va_parent['rules'] as $va_rule) {
                $vm_ret = ExpressionParser::evaluate($va_rule['trigger'], $pa_source_data);
                if (!ExpressionParser::hadError() && (bool) $vm_ret) {
                    foreach ($va_rule['actions'] as $va_action) {
                        if (!is_array($va_action) && strtolower($va_action) == 'skip') {
                            $va_action = array('action' => 'skip');
                        }
                        switch ($vs_action_code = strtolower($va_action['action'])) {
                            case 'set':
                                switch ($va_action['target']) {
                                    case 'name':
                                        $vs_name = BaseRefinery::parsePlaceholder($va_action['value'], $pa_source_data, $pa_item, $pn_c, array('reader' => $o_reader, 'returnAsString' => true, 'delimiter' => ' '));
                                        break;
                                    case 'type':
                                        $vs_type = BaseRefinery::parsePlaceholder($va_action['value'], $pa_source_data, $pa_item, $pn_c, array('reader' => $o_reader, 'returnAsString' => true, 'delimiter' => ' '));
                                        break;
                                    default:
                                        $va_attributes[$va_action['target']] = BaseRefinery::parsePlaceholder($va_action['value'], $pa_source_data, $pa_item, $pn_c, array('reader' => $o_reader, 'returnAsString' => true, 'delimiter' => ' '));
                                        break;
                                }
                                break;
                            case 'skip':
                            default:
                                if ($o_log) {
                                    if ($vs_action_code != 'skip') {
                                        $o_log->logInfo(_t('[%3] Parent was skipped using rule "%1" with default action because an invalid action ("%2") was specified', $va_rule['trigger'], $vs_action_code, $ps_refinery_name));
                                    } else {
                                        $o_log->logDebug(_t('[%3] Parent was skipped using rule "%1" with action "%2"', $va_rule['trigger'], $vs_action_code, $ps_refinery_name));
                                    }
                                }
                                continue 4;
                                break;
                        }
                    }
                } elseif (ExpressionParser::hadError() && $o_log) {
                    $o_log->logError(_t('[%3] Error processing rule "%1" as an error occurred. Error number was "%2"', $va_rule['trigger'], ExpressionParser::$s_last_error, $ps_refinery_name));
                }
            }
        }
        $va_match_on = caGetOption("{$ps_refinery_name}_dontMatchOnLabel", $pa_item['settings'], false) ? array('idno') : array('idno', 'label');
        $pa_options = array_merge(array('matchOn' => $va_match_on), $pa_options);
        switch ($ps_table) {
            case 'ca_objects':
                $vn_id = DataMigrationUtils::getObjectID($vs_name, $vn_id, $vs_type, $g_ui_locale_id, $va_attributes, $pa_options);
                $va_attributes['preferred_labels']['name'] = $va_attributes['_preferred_labels'] = $vs_name;
                break;
            case 'ca_entities':
                $vn_id = DataMigrationUtils::getEntityID($va_entity_label = DataMigrationUtils::splitEntityName($vs_name, $pa_options), $vs_type, $g_ui_locale_id, $va_attributes, $pa_options);
                $va_attributes['preferred_labels'] = $va_entity_label;
                $va_attributes['_preferred_labels'] = $vs_name;
                break;
            case 'ca_places':
                if (!$vn_id) {
                    // get place hierarchy root
                    require_once __CA_MODELS_DIR__ . "/ca_places.php";
                    $t_place = new ca_places();
                    if ($o_trans) {
                        $t_place->setTransaction($o_trans);
                    }
                    $vn_id = $pa_options['defaultParentID'];
                    if (!$vn_id) {
                        $vn_id = $t_place->getHierarchyRootID($pa_options['hierarchyID']);
                    }
                    $va_attributes['parent_id'] = $vn_id;
                }
                $vn_id = DataMigrationUtils::getPlaceID($vs_name, $vn_id, $vs_type, $g_ui_locale_id, $va_attributes, $pa_options);
                $va_attributes['preferred_labels']['name'] = $va_attributes['_preferred_labels'] = $vs_name;
                break;
            case 'ca_occurrences':
                $vn_id = DataMigrationUtils::getOccurrenceID($vs_name, $vn_id, $vs_type, $g_ui_locale_id, $va_attributes, $pa_options);
                $va_attributes['preferred_labels']['name'] = $va_attributes['_preferred_labels'] = $vs_name;
                break;
            case 'ca_collections':
                $vn_id = DataMigrationUtils::getCollectionID($vs_name, $vs_type, $g_ui_locale_id, $va_attributes, $pa_options);
                $va_attributes['preferred_labels']['name'] = $va_attributes['_preferred_labels'] = $vs_name;
                break;
            case 'ca_loans':
                $vn_id = DataMigrationUtils::getLoanID($vs_name, $vs_type, $g_ui_locale_id, $va_attributes, $pa_options);
                $va_attributes['preferred_labels']['name'] = $va_attributes['_preferred_labels'] = $vs_name;
                break;
            case 'ca_movements':
                $vn_id = DataMigrationUtils::getMovementID($vs_name, $vs_type, $g_ui_locale_id, $va_attributes, $pa_options);
                $va_attributes['preferred_labels']['name'] = $va_attributes['_preferred_labels'] = $vs_name;
                break;
            case 'ca_list_items':
                if (!$vn_list_id) {
                    if ($o_log) {
                        $o_log->logDebug(_t('[importHelpers:caProcessRefineryParents] List was not specified'));
                    }
                    return null;
                }
                if (!$vn_id) {
                    // get place hierarchy root
                    require_once __CA_MODELS_DIR__ . "/ca_lists.php";
                    $t_list = new ca_lists();
                    if ($o_trans) {
                        $t_list->setTransaction($o_trans);
                    }
                    $vn_id = $t_list->getRootItemIDForList($vn_list_id);
                    $va_attributes['parent_id'] = $vn_id;
                }
                $vn_id = DataMigrationUtils::getListItemID($vn_list_id, $vs_name, $vs_type, $g_ui_locale_id, $va_attributes, $pa_options);
                $va_attributes['preferred_labels']['name_singular'] = $va_attributes['preferred_labels']['name_plural'] = $vs_name;
                break;
            case 'ca_storage_locations':
                if (!$vn_id) {
                    // get storage location hierarchy root
                    require_once __CA_MODELS_DIR__ . "/ca_storage_locations.php";
                    $t_loc = new ca_storage_locations();
                    if ($o_trans) {
                        $t_loc->setTransaction($o_trans);
                    }
                    $vn_id = $t_loc->getHierarchyRootID();
                    $va_attributes['parent_id'] = $vn_id;
                }
                $vn_id = DataMigrationUtils::getStorageLocationID($vs_name, $vn_id, $vs_type, $g_ui_locale_id, $va_attributes, $pa_options);
                $va_attributes['preferred_labels']['name'] = $va_attributes['_preferred_labels'] = $vs_name;
                break;
            default:
                if ($o_log) {
                    $o_log->logDebug(_t('[importHelpers:caProcessRefineryParents] Invalid table %1', $ps_table));
                }
                return null;
                break;
        }
        $va_attributes['locale_id'] = $g_ui_locale_id;
        if ($o_log) {
            $o_log->logDebug(_t('[%6] Got parent %1 (%2) with id %3 and type %4 for %5', $vs_name, $vs_idno, $vn_id, $vs_type, $vs_name, $ps_refinery_name));
        }
    }
    if ($vb_hierarchy_mode) {
        return $va_attributes;
    }
    return $vn_id;
}
 /**
  *
  */
 private function _getStorageLocationInfo()
 {
     $t_loc = new ca_storage_locations($this->get('location_id'));
     if ($t_loc->getPrimaryKey()) {
         return array('path' => $t_loc->get('ca_storage_locations.hierarchy.preferred_labels.name', array('returnAsArray' => true)), 'ids' => $t_loc->get('ca_storage_locations.hierarchy.location_id', array('returnAsArray' => true)));
     } else {
         return array('path' => array('?'), 'ids' => array(0));
     }
 }
Exemplo n.º 4
0
 /**
  * Return array with list of significant events in object life cycle as configured for 
  * a ca_objects_history editor bundle.
  *
  * @param array $pa_bundle_settings The settings for a ca_objects_history editing BUNDLES
  * @param array $pa_options Array of options. Options include:
  *		noCache = Don't use any cached history data. [Default is false]
  *		currentOnly = Only return history entries dates before or on the current date. [Default is false]
  *		limit = Only return a maximum number of history entries. [Default is null; no limit]
  *
  * @return array A list of life cycle events, indexed by historic timestamp for date of occurrrence. Each list value is an array of history entries.
  *
  * @used-by ca_objects::getObjectHistoryHTMLFormBundle
  */
 public function getObjectHistory($pa_bundle_settings = null, $pa_options = null)
 {
     global $g_ui_locale;
     if (!is_array($pa_options)) {
         $pa_options = array();
     }
     if (!is_array($pa_bundle_settings)) {
         $pa_bundle_settings = array();
     }
     $vs_cache_key = caMakeCacheKeyFromOptions(array_merge($pa_bundle_settings, $pa_options, array('object_id' => $this->getPrimaryKey())));
     $pb_no_cache = caGetOption('noCache', $pa_options, false);
     if (!$pb_no_cache && isset(ca_objects::$s_object_use_cache[$vs_cache_key])) {
         return ca_objects::$s_object_use_cache[$vs_cache_key];
     }
     $pb_display_label_only = caGetOption('displayLabelOnly', $pa_options, false);
     $pb_get_current_only = caGetOption('currentOnly', $pa_options, false);
     $pn_limit = caGetOption('limit', $pa_options, null);
     $vs_display_template = caGetOption('display_template', $pa_bundle_settings, _t('No template defined'));
     $vs_history_template = caGetOption('history_template', $pa_bundle_settings, $vs_display_template);
     $vn_current_date = caDateToHistoricTimestamp(_t('now'));
     $o_media_coder = new MediaInfoCoder();
     //
     // Get history
     //
     $va_history = array();
     // Lots
     if (is_array($va_lot_types = caGetOption('ca_object_lots_showTypes', $pa_bundle_settings, null)) && ($vn_lot_id = $this->get('lot_id'))) {
         $t_lot = new ca_object_lots($vn_lot_id);
         if (!$t_lot->get('deleted')) {
             $va_lot_type_info = $t_lot->getTypeList();
             $vn_type_id = $t_lot->get('type_id');
             $vs_color = $va_lot_type_info[$vn_type_id]['color'];
             if (!$vs_color || $vs_color == '000000') {
                 $vs_color = caGetOption("ca_object_lots_{$va_lot_type_info[$vn_type_id]['idno']}_color", $pa_bundle_settings, 'ffffff');
             }
             $va_dates = array();
             $va_date_elements = caGetOption("ca_object_lots_{$va_lot_type_info[$vn_type_id]['idno']}_dateElement", $pa_bundle_settings, null);
             if (!is_array($va_date_elements) && $va_date_elements) {
                 $va_date_elements = array($va_date_elements);
             }
             if (is_array($va_date_elements) && sizeof($va_date_elements)) {
                 foreach ($va_date_elements as $vs_date_element) {
                     $va_dates[] = array('sortable' => $t_lot->get($vs_date_element, array('getDirectDate' => true)), 'display' => $t_lot->get($vs_date_element));
                 }
             }
             if (!sizeof($va_dates)) {
                 $va_dates[] = array('sortable' => $vn_date = caUnixTimestampToHistoricTimestamps($t_lot->getCreationTimestamp(null, array('timestampOnly' => true))), 'display' => caGetLocalizedDate($vn_date));
             }
             foreach ($va_dates as $va_date) {
                 if (!$va_date['sortable']) {
                     continue;
                 }
                 if (!in_array($vn_type_id, $va_lot_types)) {
                     continue;
                 }
                 if ($pb_get_current_only && $va_date['sortable'] > $vn_current_date) {
                     continue;
                 }
                 $vs_default_display_template = '^ca_object_lots.preferred_labels.name (^ca_object_lots.idno_stub)';
                 $vs_display_template = $pb_display_label_only ? "" : caGetOption("ca_object_lots_{$va_lot_type_info[$vn_type_id]['idno']}_displayTemplate", $pa_bundle_settings, $vs_default_display_template);
                 $va_history[$va_date['sortable']][] = array('type' => 'ca_object_lots', 'id' => $vn_lot_id, 'display' => $t_lot->getWithTemplate($vs_display_template), 'color' => $vs_color, 'icon_url' => $vs_icon_url = $o_media_coder->getMediaTag($va_lot_type_info[$vn_type_id]['icon'], 'icon'), 'typename_singular' => $vs_typename = $va_lot_type_info[$vn_type_id]['name_singular'], 'typename_plural' => $va_lot_type_info[$vn_type_id]['name_plural'], 'type_id' => $vn_type_id, 'icon' => '<div class="caUseHistoryIconContainer" style="background-color: #' . $vs_color . '"><div class="caUseHistoryIcon">' . ($vs_icon_url ? $vs_icon_url : '<div class="caUseHistoryIconText">' . $vs_typename . '</div>') . '</div></div>', 'date' => $va_date['display']);
             }
         }
     }
     // Loans
     $va_loans = $this->get('ca_loans.loan_id', array('returnAsArray' => true));
     if (is_array($va_loan_types = caGetOption('ca_loans_showTypes', $pa_bundle_settings, null)) && is_array($va_loans) && sizeof($va_loans)) {
         $qr_loans = caMakeSearchResult('ca_loans', $va_loans);
         $t_loan = new ca_loans();
         $va_loan_type_info = $t_loan->getTypeList();
         $va_date_elements_by_type = array();
         foreach ($va_loan_types as $vn_type_id) {
             if (!is_array($va_date_elements = caGetOption("ca_loans_{$va_loan_type_info[$vn_type_id]['idno']}_dateElement", $pa_bundle_settings, null)) && $va_date_elements) {
                 $va_date_elements = array($va_date_elements);
             }
             if (!$va_date_elements) {
                 continue;
             }
             $va_date_elements_by_type[$vn_type_id] = $va_date_elements;
         }
         while ($qr_loans->nextHit()) {
             $vn_loan_id = $qr_loans->get('loan_id');
             if ((string) $qr_loans->get('ca_loans.deleted') !== '0') {
                 continue;
             }
             // filter out deleted
             $vn_type_id = $qr_loans->get('type_id');
             $va_dates = array();
             if (is_array($va_date_elements_by_type[$vn_type_id]) && sizeof($va_date_elements_by_type[$vn_type_id])) {
                 foreach ($va_date_elements_by_type[$vn_type_id] as $vs_date_element) {
                     $va_dates[] = array('sortable' => $qr_loans->get("ca_loans.{$vs_date_element}", array('getDirectDate' => true)), 'display' => $qr_loans->get("ca_loans.{$vs_date_element}"));
                 }
             }
             if (!sizeof($va_dates)) {
                 $va_dates[] = array('sortable' => $vn_date = caUnixTimestampToHistoricTimestamps($qr_loans->get('lastModified')), 'display' => caGetLocalizedDate($vn_date));
             }
             $vs_default_display_template = '^ca_loans.preferred_labels.name (^ca_loans.idno)';
             $vs_display_template = $pb_display_label_only ? $vs_default_display_template : caGetOption("ca_loans_{$va_loan_type_info[$vn_type_id]['idno']}_displayTemplate", $pa_bundle_settings, $vs_default_display_template);
             foreach ($va_dates as $va_date) {
                 if (!$va_date['sortable']) {
                     continue;
                 }
                 if (!in_array($vn_type_id, $va_loan_types)) {
                     continue;
                 }
                 if ($pb_get_current_only && $va_date['sortable'] > $vn_current_date) {
                     continue;
                 }
                 $vs_color = $va_loan_type_info[$vn_type_id]['color'];
                 if (!$vs_color || $vs_color == '000000') {
                     $vs_color = caGetOption("ca_loans_{$va_loan_type_info[$vn_type_id]['idno']}_color", $pa_bundle_settings, 'ffffff');
                 }
                 $va_history[$va_date['sortable']][] = array('type' => 'ca_loans', 'id' => $vn_loan_id, 'display' => $qr_loans->getWithTemplate($vs_display_template), 'color' => $vs_color, 'icon_url' => $vs_icon_url = $o_media_coder->getMediaTag($va_loan_type_info[$vn_type_id]['icon'], 'icon'), 'typename_singular' => $vs_typename = $va_loan_type_info[$vn_type_id]['name_singular'], 'typename_plural' => $va_loan_type_info[$vn_type_id]['name_plural'], 'type_id' => $vn_type_id, 'icon' => '<div class="caUseHistoryIconContainer" style="background-color: #' . $vs_color . '"><div class="caUseHistoryIcon">' . ($vs_icon_url ? $vs_icon_url : '<div class="caUseHistoryIconText">' . $vs_typename . '</div>') . '</div></div>', 'date' => $va_date['display']);
             }
         }
     }
     // Movements
     $va_movements = $this->get('ca_movements.movement_id', array('returnAsArray' => true));
     if (is_array($va_movement_types = caGetOption('ca_movements_showTypes', $pa_bundle_settings, null)) && is_array($va_movements) && sizeof($va_movements)) {
         $qr_movements = caMakeSearchResult('ca_movements', $va_movements);
         $t_movement = new ca_movements();
         $va_movement_type_info = $t_movement->getTypeList();
         $va_date_elements_by_type = array();
         foreach ($va_movement_types as $vn_type_id) {
             if (!is_array($va_date_elements = caGetOption("ca_movements_{$va_movement_type_info[$vn_type_id]['idno']}_dateElement", $pa_bundle_settings, null)) && $va_date_elements) {
                 $va_date_elements = array($va_date_elements);
             }
             if (!$va_date_elements) {
                 continue;
             }
             $va_date_elements_by_type[$vn_type_id] = $va_date_elements;
         }
         while ($qr_movements->nextHit()) {
             $vn_movement_id = $qr_movements->get('movement_id');
             if ((string) $qr_movements->get('ca_movements.deleted') !== '0') {
                 continue;
             }
             // filter out deleted
             $vn_type_id = $qr_movements->get('type_id');
             $va_dates = array();
             if (is_array($va_date_elements_by_type[$vn_type_id]) && sizeof($va_date_elements_by_type[$vn_type_id])) {
                 foreach ($va_date_elements_by_type[$vn_type_id] as $vs_date_element) {
                     $va_dates[] = array('sortable' => $qr_movements->get("ca_movements.{$vs_date_element}", array('getDirectDate' => true)), 'display' => $qr_movements->get("ca_movements.{$vs_date_element}"));
                 }
             }
             if (!sizeof($va_dates)) {
                 $va_dates[] = array('sortable' => $vn_date = caUnixTimestampToHistoricTimestamps($qr_movements->get('lastModified')), 'display' => caGetLocalizedDate($vn_date));
             }
             $vs_default_display_template = '^ca_movements.preferred_labels.name (^ca_movements.idno)';
             $vs_display_template = $pb_display_label_only ? $vs_default_display_template : caGetOption("ca_movements_{$va_movement_type_info[$vn_type_id]['idno']}_displayTemplate", $pa_bundle_settings, $vs_default_display_template);
             foreach ($va_dates as $va_date) {
                 if (!$va_date['sortable']) {
                     continue;
                 }
                 if (!in_array($vn_type_id, $va_movement_types)) {
                     continue;
                 }
                 if ($pb_get_current_only && $va_date['sortable'] > $vn_current_date) {
                     continue;
                 }
                 $vs_color = $va_movement_type_info[$vn_type_id]['color'];
                 if (!$vs_color || $vs_color == '000000') {
                     $vs_color = caGetOption("ca_movements_{$va_movement_type_info[$vn_type_id]['idno']}_color", $pa_bundle_settings, 'ffffff');
                 }
                 $va_history[$va_date['sortable']][] = array('type' => 'ca_movements', 'id' => $vn_movement_id, 'display' => $qr_movements->getWithTemplate($vs_display_template), 'color' => $vs_color, 'icon_url' => $vs_icon_url = $o_media_coder->getMediaTag($va_movement_type_info[$vn_type_id]['icon'], 'icon'), 'typename_singular' => $vs_typename = $va_movement_type_info[$vn_type_id]['name_singular'], 'typename_plural' => $va_movement_type_info[$vn_type_id]['name_plural'], 'type_id' => $vn_type_id, 'icon' => '<div class="caUseHistoryIconContainer" style="background-color: #' . $vs_color . '"><div class="caUseHistoryIcon">' . ($vs_icon_url ? $vs_icon_url : '<div class="caUseHistoryIconText">' . $vs_typename . '</div>') . '</div></div>', 'date' => $va_date['display']);
             }
         }
     }
     // Occurrences
     $va_occurrences = $this->get('ca_occurrences.occurrence_id', array('returnAsArray' => true));
     if (is_array($va_occurrence_types = caGetOption('ca_occurrences_showTypes', $pa_bundle_settings, null)) && is_array($va_occurrences) && sizeof($va_occurrences)) {
         $qr_occurrences = caMakeSearchResult('ca_occurrences', $va_occurrences);
         $t_occurrence = new ca_occurrences();
         $va_occurrence_type_info = $t_occurrence->getTypeList();
         $va_date_elements_by_type = array();
         foreach ($va_occurrence_types as $vn_type_id) {
             if (!is_array($va_date_elements = caGetOption("ca_occurrences_{$va_occurrence_type_info[$vn_type_id]['idno']}_dateElement", $pa_bundle_settings, null)) && $va_date_elements) {
                 $va_date_elements = array($va_date_elements);
             }
             if (!$va_date_elements) {
                 continue;
             }
             $va_date_elements_by_type[$vn_type_id] = $va_date_elements;
         }
         while ($qr_occurrences->nextHit()) {
             $vn_occurrence_id = $qr_occurrences->get('occurrence_id');
             if ((string) $qr_occurrences->get('ca_occurrences.deleted') !== '0') {
                 continue;
             }
             // filter out deleted
             $vn_type_id = $qr_occurrences->get('type_id');
             $va_dates = array();
             if (is_array($va_date_elements_by_type[$vn_type_id]) && sizeof($va_date_elements_by_type[$vn_type_id])) {
                 foreach ($va_date_elements_by_type[$vn_type_id] as $vs_date_element) {
                     $va_dates[] = array('sortable' => $qr_occurrences->get("ca_occurrences.{$vs_date_element}", array('getDirectDate' => true)), 'display' => $qr_occurrences->get("ca_occurrences.{$vs_date_element}"));
                 }
             }
             if (!sizeof($va_dates)) {
                 $va_dates[] = array('sortable' => $vn_date = caUnixTimestampToHistoricTimestamps($qr_occurrences->get('lastModified')), 'display' => caGetLocalizedDate($vn_date));
             }
             $vs_default_display_template = '^ca_occurrences.preferred_labels.name (^ca_occurrences.idno)';
             $vs_display_template = $pb_display_label_only ? $vs_default_display_template : caGetOption("ca_occurrences_{$va_occurrence_type_info[$vn_type_id]['idno']}_displayTemplate", $pa_bundle_settings, $vs_default_display_template);
             foreach ($va_dates as $va_date) {
                 if (!$va_date['sortable']) {
                     continue;
                 }
                 if (!in_array($vn_type_id, $va_occurrence_types)) {
                     continue;
                 }
                 if ($pb_get_current_only && $va_date['sortable'] > $vn_current_date) {
                     continue;
                 }
                 $vs_color = $va_occurrence_type_info[$vn_type_id]['color'];
                 if (!$vs_color || $vs_color == '000000') {
                     $vs_color = caGetOption("ca_occurrences_{$va_occurrence_type_info[$vn_type_id]['idno']}_color", $pa_bundle_settings, 'ffffff');
                 }
                 $va_history[$va_date['sortable']][] = array('type' => 'ca_occurrences', 'id' => $vn_occurrence_id, 'display' => $qr_occurrences->getWithTemplate($vs_display_template), 'color' => $vs_color, 'icon_url' => $vs_icon_url = $o_media_coder->getMediaTag($va_occurrence_type_info[$vn_type_id]['icon'], 'icon'), 'typename_singular' => $vs_typename = $va_occurrence_type_info[$vn_type_id]['name_singular'], 'typename_plural' => $va_occurrence_type_info[$vn_type_id]['name_plural'], 'type_id' => $vn_type_id, 'icon' => '<div class="caUseHistoryIconContainer" style="background-color: #' . $vs_color . '"><div class="caUseHistoryIcon">' . ($vs_icon_url ? $vs_icon_url : '<div class="caUseHistoryIconText">' . $vs_typename . '</div>') . '</div></div>', 'date' => $va_date['display']);
             }
         }
     }
     // Storage locations
     $va_locations = $this->get('ca_objects_x_storage_locations.relation_id', array('returnAsArray' => true));
     if (is_array($va_location_types = caGetOption('ca_storage_locations_showRelationshipTypes', $pa_bundle_settings, null)) && is_array($va_locations) && sizeof($va_locations)) {
         $t_location = new ca_storage_locations();
         $va_location_type_info = $t_location->getTypeList();
         $vs_name_singular = $t_location->getProperty('NAME_SINGULAR');
         $vs_name_plural = $t_location->getProperty('NAME_PLURAL');
         $qr_locations = caMakeSearchResult('ca_objects_x_storage_locations', $va_locations);
         $vs_default_display_template = '^ca_storage_locations.parent.preferred_labels.name ➜ ^ca_storage_locations.preferred_labels.name (^ca_storage_locations.idno)';
         $vs_display_template = $pb_display_label_only ? $vs_default_display_template : caGetOption('ca_storage_locations_displayTemplate', $pa_bundle_settings, $vs_default_display_template);
         Debug::msg($qr_locations->numHits());
         while ($qr_locations->nextHit()) {
             $vn_location_id = $qr_locations->get('ca_objects_x_storage_locations.location_id');
             if ((string) $qr_locations->get('ca_storage_locations.deleted') !== '0') {
                 continue;
             }
             // filter out deleted
             $va_date = array('sortable' => $qr_locations->get("ca_objects_x_storage_locations.effective_date", array('getDirectDate' => true)), 'display' => $qr_locations->get("ca_objects_x_storage_locations.effective_date"));
             if (!$va_date['sortable']) {
                 continue;
             }
             if (!in_array($vn_rel_type_id = $qr_locations->get('ca_objects_x_storage_locations.type_id'), $va_location_types)) {
                 continue;
             }
             $vn_type_id = $qr_locations->get('ca_storage_locations.type_id');
             if ($pb_get_current_only && $va_date['sortable'] > $vn_current_date) {
                 continue;
             }
             $vs_color = $va_location_type_info[$vn_type_id]['color'];
             if (!$vs_color || $vs_color == '000000') {
                 $vs_color = caGetOption("ca_storage_locations_color", $pa_bundle_settings, 'ffffff');
             }
             $va_history[$va_date['sortable']][] = array('type' => 'ca_storage_locations', 'id' => $vn_location_id, 'relation_id' => $qr_locations->get('relation_id'), 'display' => $qr_locations->getWithTemplate("<unit relativeTo='ca_storage_locations'>{$vs_display_template}</unit>"), 'color' => $vs_color, 'icon_url' => $vs_icon_url = $o_media_coder->getMediaTag($va_location_type_info[$vn_type_id]['icon'], 'icon'), 'typename_singular' => $vs_name_singular, 'typename_plural' => $vs_name_plural, 'type_id' => $vn_type_id, 'rel_type_id' => $vn_rel_type_id, 'icon' => '<div class="caUseHistoryIconContainer" style="background-color: #' . $vs_color . '"><div class="caUseHistoryIcon">' . ($vs_icon_url ? $vs_icon_url : '<div class="caUseHistoryIconText">' . $vs_name_singular . '</div>') . '</div></div>', 'date' => $va_date['display']);
         }
     }
     // Deaccession
     if ($this->get('is_deaccessioned') && caGetOption('showDeaccessionInformation', $pa_bundle_settings, false)) {
         $vs_color = caGetOption('deaccession_color', $pa_bundle_settings, 'cccccc');
         $vn_date = $this->get('deaccession_date', array('getDirectDate' => true));
         $vs_default_display_template = '^ca_objects.deaccession_notes';
         $vs_display_template = $pb_display_label_only ? $vs_default_display_template : caGetOption('deaccession_displayTemplate', $pa_bundle_settings, $vs_default_display_template);
         if (!($pb_get_current_only && $vn_date > $vn_current_date)) {
             $va_history[$vn_date][] = array('type' => 'ca_objects_deaccession', 'id' => $this->getPrimaryKey(), 'display' => $this->getWithTemplate("<unit>{$vs_display_template}</unit>"), 'color' => $vs_color, 'icon_url' => '', 'typename_singular' => $vs_name_singular = _t('deaccession'), 'typename_plural' => $vs_name_plural = _t('deaccessions'), 'type_id' => null, 'icon' => '<div class="caUseHistoryIconContainer" style="background-color: #' . $vs_color . '"><div class="caUseHistoryIcon"><div class="caUseHistoryIconText">' . $vs_name_singular . '</div>' . '</div></div>', 'date' => $this->get('deaccession_date'));
         }
     }
     ksort($va_history);
     $va_history = array_reverse($va_history);
     if ($pn_limit > 0) {
         $va_history = array_slice($va_history, 0, $pn_limit);
     }
     if (sizeof(ca_objects::$s_object_use_cache[$vs_cache_key]) > 100) {
         ca_objects::$s_object_use_cache[$vs_cache_key] = array_slice(ca_objects::$s_object_use_cache[$vs_cache_key], 0, 50);
     }
     return ca_objects::$s_object_use_cache[$vs_cache_key] = $va_history;
 }
Exemplo n.º 5
0
 /** 
  * Returns location_id for the storage location with the specified name, regardless of specified type. If the location does not already 
  * exist then it will be created with the specified name, type and locale, as well as with any specified values in the $pa_values array.
  * $pa_values keys should be either valid storage location fields or attributes.
  *
  * @param string $ps_location_name Storage location label name
  * @param int $pn_parent_id The parent_id of the location; must be set to a non-null value
  * @param int $pn_type_id The type_id of the location type to use if the location needs to be created
  * @param int $pn_locale_id The locale_id to use if the location needs to be created (will be used for both the location locale as well as the label locale)
  * @param array $pa_values An optional array of additional values to populate newly created location records with. These values are *only* used for newly created locations; they will not be applied if the location named already exists. The array keys should be names of ca_storage_locations fields or valid storage location attributes. Values should be either a scalar (for single-value attributes) or an array of values for (multi-valued attributes)
  * @param array $pa_options An optional array of options, which include:
  *				outputErrors - if true, errors will be printed to console [default=false]
  *				matchOnIdno - try to match on idno if name match fails [default=false]
  *				dontCreate - if true then new entities will not be created [default=false]
  * 				transaction - if Transaction object is passed, use it for all Db-related tasks [default=null]
  *				returnInstance = return ca_storage_locations instance rather than location_id. Default is false. 
  *				generateIdnoWithTemplate = A template to use when setting the idno. The template is a value with automatically-set SERIAL values replaced with % characters. Eg. 2012.% will set the created row's idno value to 2012.121 (assuming that 121 is the next number in the serial sequence.) The template is NOT used if idno is passed explicitly as a value in $pa_values.
  *				importEvent = if ca_data_import_events instance is passed then the insert/update of the storage location will be logged as part of the import
  *				importEventSource = if importEvent is passed, then the value set for importEventSource is used in the import event log as the data source. If omitted a default value of "?" is used
  *				log = if KLogger instance is passed then actions will be logged
  */
 static function getStorageLocationID($ps_location_name, $pn_parent_id, $pn_type_id, $pn_locale_id, $pa_values = null, $pa_options = null)
 {
     if (!is_array($pa_options)) {
         $pa_options = array();
     }
     if (!isset($pa_options['outputErrors'])) {
         $pa_options['outputErrors'] = true;
     }
     $pb_match_on_idno = caGetOption('matchOnIdno', $pa_options, false);
     $t_location = new ca_storage_locations();
     if (isset($pa_options['transaction']) && $pa_options['transaction'] instanceof Transaction) {
         $t_location->setTransaction($pa_options['transaction']);
     }
     $o_event = isset($pa_options['importEvent']) && $pa_options['importEvent'] instanceof ca_data_import_events ? $pa_options['importEvent'] : null;
     $vs_event_source = isset($pa_options['importEventSource']) && $pa_options['importEventSource'] ? $pa_options['importEventSource'] : "?";
     $o_log = isset($pa_options['log']) && $pa_options['log'] instanceof KLogger ? $pa_options['log'] : null;
     if (!($vs_idno = isset($pa_values['idno']) ? (string) $pa_values['idno'] : null)) {
         if (isset($pa_options['generateIdnoWithTemplate']) && $pa_options['generateIdnoWithTemplate']) {
             $vs_idno = $t_location->setIdnoTWithTemplate($pa_options['generateIdnoWithTemplate'], array('dontSetValue' => true));
         }
     }
     $va_find_arr = array();
     if ($pn_type_id) {
         $va_find_arr['type_id'] = $pn_type_id;
     }
     if ($pn_parent_id) {
         $va_find_arr['parent_id'] = $pn_parent_id;
     }
     if (!($vn_id = ca_storage_locations::find(array_merge(array('preferred_labels' => array('name' => $ps_location_name)), $va_find_arr), array('returnAs' => 'firstId', 'transaction' => $pa_options['transaction'])))) {
         if ($pb_match_on_idno && $vs_idno) {
             $va_find_arr['idno'] = $vs_idno;
             $vn_id = ca_storage_locations::find($va_find_arr, array('returnAs' => 'firstId', 'transaction' => $pa_options['transaction']));
         }
     }
     if (!$vn_id) {
         if (isset($pa_options['dontCreate']) && $pa_options['dontCreate']) {
             return false;
         }
         if ($o_event) {
             $o_event->beginItem($vs_event_source, 'ca_storage_locations', 'I');
         }
         $t_location->setMode(ACCESS_WRITE);
         $t_location->set('locale_id', $pn_locale_id);
         $t_location->set('type_id', $pn_type_id);
         $t_location->set('parent_id', $pn_parent_id);
         $t_location->set('access', isset($pa_values['access']) ? $pa_values['access'] : 0);
         $t_location->set('status', isset($pa_values['status']) ? $pa_values['status'] : 0);
         $t_location->set('idno', $vs_idno);
         $t_location->insert();
         if ($t_location->numErrors()) {
             if (isset($pa_options['outputErrors']) && $pa_options['outputErrors']) {
                 print "[Error] " . _t("Could not insert storage location %1: %2", $ps_location_name, join('; ', $t_location->getErrors())) . "\n";
             }
             if ($o_log) {
                 $o_log->logError(_t("Could not insert storage location %1: %2", $ps_location_name, join('; ', $t_location->getErrors())));
             }
             return null;
         }
         $vb_label_errors = false;
         $t_location->addLabel(array('name' => $ps_location_name), $pn_locale_id, null, true);
         if ($t_location->numErrors()) {
             if (isset($pa_options['outputErrors']) && $pa_options['outputErrors']) {
                 print "[Error] " . _t("Could not set preferred label for storage location %1: %2", $ps_location_name, join('; ', $t_location->getErrors())) . "\n";
             }
             if ($o_log) {
                 $o_log->logError(_t("Could not set preferred label for storage location %1: %2", $ps_location_name, join('; ', $t_location->getErrors())));
             }
             $vb_label_errors = true;
         }
         unset($pa_values['access']);
         unset($pa_values['status']);
         unset($pa_values['idno']);
         $vb_attr_errors = false;
         if (is_array($pa_values)) {
             foreach ($pa_values as $vs_element => $va_value) {
                 if (is_array($va_value)) {
                     // array of values (complex multi-valued attribute)
                     $t_location->addAttribute(array_merge($va_value, array('locale_id' => $pn_locale_id)), $vs_element);
                 } else {
                     // scalar value (simple single value attribute)
                     if ($va_value) {
                         $t_location->addAttribute(array('locale_id' => $pn_locale_id, $vs_element => $va_value), $vs_element);
                     }
                 }
             }
         }
         $t_location->update();
         if ($t_location->numErrors()) {
             if (isset($pa_options['outputErrors']) && $pa_options['outputErrors']) {
                 print "[Error] " . _t("Could not set values for storage location %1: %2", $ps_location_name, join('; ', $t_location->getErrors())) . "\n";
             }
             if ($o_log) {
                 $o_log->logError(_t("Could not set values for storage location %1: %2", $ps_location_name, join('; ', $t_location->getErrors())));
             }
             $vb_attr_errors = true;
         }
         $vn_location_id = $t_location->getPrimaryKey();
         if ($o_event) {
             if ($vb_attr_errors || $vb_label_errors) {
                 $o_event->endItem($vn_location_id, __CA_DATA_IMPORT_ITEM_PARTIAL_SUCCESS__, _t("Errors setting field values: %1", join('; ', $t_location->getErrors())));
             } else {
                 $o_event->endItem($vn_location_id, __CA_DATA_IMPORT_ITEM_SUCCESS__, '');
             }
         }
         if ($o_log) {
             $o_log->logInfo(_t("Created new storage location %1", $ps_location_name));
         }
         if (isset($pa_options['returnInstance']) && $pa_options['returnInstance']) {
             return $t_location;
         }
     } else {
         if ($o_event) {
             $o_event->beginItem($vs_event_source, 'ca_storage_locations', 'U');
         }
         $vn_location_id = $vn_id;
         if ($o_event) {
             $o_event->endItem($vn_location_id, __CA_DATA_IMPORT_ITEM_SUCCESS__, '');
         }
         if ($o_log) {
             $o_log->logDebug(_t("Found existing storage location %1 in DataMigrationUtils::getStorageLocationID(); total of %2 storage locations were found", $ps_location_name, sizeof($va_location_ids) + 1));
         }
         if (isset($pa_options['returnInstance']) && $pa_options['returnInstance']) {
             return new ca_storage_locations($vn_location_id);
         }
     }
     return $vn_location_id;
 }
Exemplo n.º 6
0
 /**
  * Returns location_id for the storage location with the specified name (and type) or idno (regardless of specified type.) If the location does not already
  * exist then it will be created with the specified name, type and locale, as well as with any specified values in the $pa_values array.
  * $pa_values keys should be either valid storage location fields or attributes.
  *
  * @param string $ps_location_name Storage location label name
  * @param int $pn_parent_id The parent_id of the location; must be set to a non-null value
  * @param int $pn_type_id The type_id of the location type to use if the location needs to be created
  * @param int $pn_locale_id The locale_id to use if the location needs to be created (will be used for both the location locale as well as the label locale)
  * @param array $pa_values An optional array of additional values to populate newly created location records with. These values are *only* used for newly created locations; they will not be applied if the location named already exists. The array keys should be names of ca_storage_locations fields or valid storage location attributes. Values should be either a scalar (for single-value attributes) or an array of values for (multi-valued attributes)
  * @param array $pa_options An optional array of options, which include:
  *                outputErrors - if true, errors will be printed to console [default=false]
  *                matchOn = optional list indicating sequence of checks for an existing record; values of array can be "label" and "idno". Ex. array("idno", "label") will first try to match on idno and then label if the first match fails.
  *                dontCreate - if true then new locations will not be created [default=false]
  *                transaction - if Transaction object is passed, use it for all Db-related tasks [default=null]
  *                returnInstance = return ca_storage_locations instance rather than location_id. Default is false.
  *                generateIdnoWithTemplate = A template to use when setting the idno. The template is a value with automatically-set SERIAL values replaced with % characters. Eg. 2012.% will set the created row's idno value to 2012.121 (assuming that 121 is the next number in the serial sequence.) The template is NOT used if idno is passed explicitly as a value in $pa_values.
  *                importEvent = if ca_data_import_events instance is passed then the insert/update of the storage location will be logged as part of the import
  *                importEventSource = if importEvent is passed, then the value set for importEventSource is used in the import event log as the data source. If omitted a default value of "?" is used
  *                nonPreferredLabels = an optional array of nonpreferred labels to add to any newly created storage locations. Each label in the array is an array with required storage location label values.
  *                log = if KLogger instance is passed then actions will be logged
  * @return bool|\ca_storage_locations|mixed|null
  */
 static function getStorageLocationID($ps_location_name, $pn_parent_id, $pn_type_id, $pn_locale_id, $pa_values = null, $pa_options = null)
 {
     if (!is_array($pa_options)) {
         $pa_options = array();
     }
     if (!isset($pa_options['outputErrors'])) {
         $pa_options['outputErrors'] = true;
     }
     $pa_match_on = caGetOption('matchOn', $pa_options, array('label', 'idno'), array('castTo' => "array"));
     /** @var ca_data_import_events $o_event */
     $o_event = isset($pa_options['importEvent']) && $pa_options['importEvent'] instanceof ca_data_import_events ? $pa_options['importEvent'] : null;
     $t_location = new ca_storage_locations();
     if (isset($pa_options['transaction']) && $pa_options['transaction'] instanceof Transaction) {
         $t_location->setTransaction($pa_options['transaction']);
         if ($o_event) {
             $o_event->setTransaction($pa_options['transaction']);
         }
     }
     $vs_event_source = isset($pa_options['importEventSource']) && $pa_options['importEventSource'] ? $pa_options['importEventSource'] : "?";
     /** @var KLogger $o_log */
     $o_log = isset($pa_options['log']) && $pa_options['log'] instanceof KLogger ? $pa_options['log'] : null;
     $vs_idno = isset($pa_values['idno']) ? (string) $pa_values['idno'] : null;
     if (preg_match('!\\%!', $vs_idno)) {
         $pa_options['generateIdnoWithTemplate'] = $vs_idno;
         $vs_idno = null;
     }
     if (!$vs_idno) {
         if (isset($pa_options['generateIdnoWithTemplate']) && $pa_options['generateIdnoWithTemplate']) {
             $vs_idno = $t_location->setIdnoWithTemplate($pa_options['generateIdnoWithTemplate'], array('dontSetValue' => true));
         }
     }
     if (!$pn_parent_id) {
         $pn_parent_id = $t_location->getHierarchyRootID();
     }
     $vn_id = null;
     foreach ($pa_match_on as $vs_match_on) {
         switch (strtolower($vs_match_on)) {
             case 'label':
             case 'labels':
                 if (trim($ps_location_name)) {
                     if ($vn_id = ca_storage_locations::find(array('preferred_labels' => array('name' => $ps_location_name), 'parent_id' => $pn_parent_id, 'type_id' => $pn_type_id), array('returnAs' => 'firstId', 'transaction' => $pa_options['transaction']))) {
                         break 2;
                     }
                     break;
                 }
             case 'idno':
                 if ($vs_idno == '%') {
                     break;
                 }
                 // don't try to match on an unreplaced idno placeholder
                 if ($vn_id = ca_storage_locations::find(array('idno' => $vs_idno ? $vs_idno : $ps_location_name), array('returnAs' => 'firstId', 'transaction' => $pa_options['transaction']))) {
                     break 2;
                 }
                 break;
         }
     }
     if (!$vn_id) {
         if (isset($pa_options['dontCreate']) && $pa_options['dontCreate']) {
             return false;
         }
         if ($o_event) {
             $o_event->beginItem($vs_event_source, 'ca_storage_locations', 'I');
         }
         $t_location->setMode(ACCESS_WRITE);
         $t_location->set('locale_id', $pn_locale_id);
         $t_location->set('type_id', $pn_type_id);
         $t_location->set('parent_id', $pn_parent_id);
         $t_location->set('access', isset($pa_values['access']) ? $pa_values['access'] : 0);
         $t_location->set('status', isset($pa_values['status']) ? $pa_values['status'] : 0);
         $t_location->set('idno', $vs_idno);
         $t_location->insert();
         if ($t_location->numErrors()) {
             if (isset($pa_options['outputErrors']) && $pa_options['outputErrors']) {
                 print "[Error] " . _t("Could not insert storage location %1: %2", $ps_location_name, join('; ', $t_location->getErrors())) . "\n";
             }
             if ($o_log) {
                 $o_log->logError(_t("Could not insert storage location %1: %2", $ps_location_name, join('; ', $t_location->getErrors())));
             }
             return null;
         }
         $vb_label_errors = false;
         $t_location->addLabel(array('name' => $ps_location_name), $pn_locale_id, null, true);
         if ($t_location->numErrors()) {
             if (isset($pa_options['outputErrors']) && $pa_options['outputErrors']) {
                 print "[Error] " . _t("Could not set preferred label for storage location %1: %2", $ps_location_name, join('; ', $t_location->getErrors())) . "\n";
             }
             if ($o_log) {
                 $o_log->logError(_t("Could not set preferred label for storage location %1: %2", $ps_location_name, join('; ', $t_location->getErrors())));
             }
             $vb_label_errors = true;
         }
         /** @var IIDNumbering $o_idno */
         if ($o_idno = $t_location->getIDNoPlugInInstance()) {
             $va_values = $o_idno->htmlFormValuesAsArray('idno', $vs_idno);
             if (!is_array($va_values)) {
                 $va_values = array($va_values);
             }
             if (!($vs_sep = $o_idno->getSeparator())) {
                 $vs_sep = '';
             }
             if (($vs_proc_idno = join($vs_sep, $va_values)) && $vs_proc_idno != $vs_idno) {
                 $t_location->set('idno', $vs_proc_idno);
                 $t_location->update();
                 if ($t_location->numErrors()) {
                     if (isset($pa_options['outputErrors']) && $pa_options['outputErrors']) {
                         print "[Error] " . _t("Could not update idno for %1: %2", $ps_location_name, join('; ', $t_location->getErrors())) . "\n";
                     }
                     if ($o_log) {
                         $o_log->logError(_t("Could not update idno for %1: %2", $ps_location_name, join('; ', $t_location->getErrors())));
                     }
                     return null;
                 }
             }
         }
         unset($pa_values['access']);
         unset($pa_values['status']);
         unset($pa_values['idno']);
         $vb_attr_errors = false;
         if (is_array($pa_values)) {
             foreach ($pa_values as $vs_element => $va_values) {
                 if (!caIsIndexedArray($va_values)) {
                     $va_values = array($va_values);
                 }
                 foreach ($va_values as $va_value) {
                     if (is_array($va_value)) {
                         // array of values (complex multi-valued attribute)
                         $t_location->addAttribute(array_merge($va_value, array('locale_id' => $pn_locale_id)), $vs_element);
                     } else {
                         // scalar value (simple single value attribute)
                         if ($va_value) {
                             $t_location->addAttribute(array('locale_id' => $pn_locale_id, $vs_element => $va_value), $vs_element);
                         }
                     }
                 }
             }
             $t_location->update();
             if ($t_location->numErrors()) {
                 if (isset($pa_options['outputErrors']) && $pa_options['outputErrors']) {
                     print "[Error] " . _t("Could not set values for storage location %1: %2", $ps_location_name, join('; ', $t_location->getErrors())) . "\n";
                 }
                 if ($o_log) {
                     $o_log->logError(_t("Could not set values for storage location %1: %2", $ps_location_name, join('; ', $t_location->getErrors())));
                 }
                 $vb_attr_errors = true;
             }
         }
         if (is_array($va_nonpreferred_labels = caGetOption("nonPreferredLabels", $pa_options, null))) {
             if (caIsAssociativeArray($va_nonpreferred_labels)) {
                 // single non-preferred label
                 $va_labels = array($va_nonpreferred_labels);
             } else {
                 // list of non-preferred labels
                 $va_labels = $va_nonpreferred_labels;
             }
             foreach ($va_labels as $va_label) {
                 $t_location->addLabel($va_label, $pn_locale_id, null, false);
                 if ($t_location->numErrors()) {
                     if (isset($pa_options['outputErrors']) && $pa_options['outputErrors']) {
                         print "[Error] " . _t("Could not set non-preferred label for location %1: %2", $ps_location_name, join('; ', $t_location->getErrors())) . "\n";
                     }
                     if ($o_log) {
                         $o_log->logError(_t("Could not set non-preferred label for location %1: %2", $ps_location_name, join('; ', $t_location->getErrors())));
                     }
                 }
             }
         }
         $vn_location_id = $t_location->getPrimaryKey();
         if ($o_event) {
             if ($vb_attr_errors || $vb_label_errors) {
                 $o_event->endItem($vn_location_id, __CA_DATA_IMPORT_ITEM_PARTIAL_SUCCESS__, _t("Errors setting field values: %1", join('; ', $t_location->getErrors())));
             } else {
                 $o_event->endItem($vn_location_id, __CA_DATA_IMPORT_ITEM_SUCCESS__, '');
             }
         }
         if ($o_log) {
             $o_log->logInfo(_t("Created new storage location %1", $ps_location_name));
         }
         if (isset($pa_options['returnInstance']) && $pa_options['returnInstance']) {
             return $t_location;
         }
     } else {
         if ($o_event) {
             $o_event->beginItem($vs_event_source, 'ca_storage_locations', 'U');
         }
         $vn_location_id = $vn_id;
         if ($o_event) {
             $o_event->endItem($vn_location_id, __CA_DATA_IMPORT_ITEM_SUCCESS__, '');
         }
         if ($o_log) {
             $o_log->logDebug(_t("Found existing storage location %1 in DataMigrationUtils::getStorageLocationID()", $ps_location_name));
         }
         if (isset($pa_options['returnInstance']) && $pa_options['returnInstance']) {
             $t_location = new ca_storage_locations($vn_location_id);
             if (isset($pa_options['transaction']) && $pa_options['transaction'] instanceof Transaction) {
                 $t_location->setTransaction($pa_options['transaction']);
             }
             return $t_location;
         }
     }
     return $vn_location_id;
 }
Exemplo n.º 7
0
 /**
  * Return array containing information about all storage location hierarchies, including their root_id's
  */
 public function getHierarchyList($pb_dummy = false)
 {
     $vn_root_id = $this->getHierarchyRootID();
     $t_root = new ca_storage_locations($vn_root_id);
     $qr_children = $t_root->getHierarchyChildrenAsQuery();
     $va_preferred_labels = $t_root->getPreferredLabels(null, false);
     return array(array('location_id' => $vn_id = $t_root->getPrimaryKey(), 'item_id' => $vn_id, 'name' => _t('Storage locations'), 'children' => $qr_children->numRows(), 'has_children' => $qr_children->numRows() ? true : false));
 }
 /**
  *
  */
 public function refine(&$pa_destination_data, $pa_group, $pa_item, $pa_source_data, $pa_options = null)
 {
     $t_loc = new ca_storage_locations();
     $pa_options['defaultParentID'] = $t_loc->getHierarchyRootID();
     return caGenericImportSplitter('storageLocationSplitter', 'storageLocation', 'ca_storage_locations', $this, $pa_destination_data, $pa_group, $pa_item, $pa_source_data, $pa_options);
 }
Exemplo n.º 9
0
        }
    }
    if ($vs_theme_display) {
        print "<H6>" . _t("Themes") . "</H6>";
        print $vs_theme_display;
    }
}
if ($vs_style_display || $vs_theme_display || sizeof($va_collections)) {
    print "<HR/>";
}
?>
		{{{<ifdef code="ca_objects.idno"><H6>Steelcase Number</H6>^ca_objects.idno</ifdef>}}}			
<?php 
$va_storage_locations = $t_object->get("ca_storage_locations", array("returnAsArray" => true, "checkAccess" => $va_access_values));
if (sizeof($va_storage_locations)) {
    $t_location = new ca_storage_locations();
    $t_relationship = new ca_objects_x_storage_locations();
    $vn_now = date("Y.md");
    $va_location_display = array();
    foreach ($va_storage_locations as $va_storage_location) {
        $t_relationship->load($va_storage_location["relation_id"]);
        $va_daterange = $t_relationship->get("effective_daterange", array("rawDate" => true, "returnAsArray" => true));
        if (is_array($va_daterange) && sizeof($va_daterange)) {
            foreach ($va_daterange as $va_date) {
                break;
            }
            #print $vn_now." - ".$va_date["effective_daterange"]["start"]." - ".$va_date["effective_daterange"]["end"];
            if (is_array($va_date)) {
                if ($vn_now > $va_date["effective_daterange"]["start"] && $vn_now < $va_date["effective_daterange"]["end"]) {
                    # --- only display the top level from the hierarchy
                    $va_hierarchy_ancestors = array_reverse(caExtractValuesByUserLocale($t_location->getHierarchyAncestors($va_storage_location["location_id"], array("includeSelf" => 1, "additionalTableToJoin" => "ca_storage_location_labels", "additionalTableSelectFields" => array("name")))));