public function __construct(&$po_request, &$po_response, $pa_view_paths = null)
 {
     $this->ops_theme = __CA_THEME__;
     // get current theme
     if (!is_dir(__CA_APP_DIR__ . '/plugins/NovaMuse/themes/' . $this->ops_theme . '/views')) {
         // if theme is not defined for this plugin, try to use "default" theme
         $this->ops_theme = 'default';
     }
     parent::__construct($po_request, $po_response, array(__CA_APP_DIR__ . '/plugins/NovaMuse/themes/' . $this->ops_theme . '/views'));
     $this->opo_plugin_config = Configuration::load($this->request->getAppConfig()->get('application_plugins') . '/NovaMuse/conf/NovaMuse.conf');
     if (!(bool) $this->opo_plugin_config->get('enabled')) {
         die(_t('NovaMuse plugin is not enabled'));
     }
     MetaTagManager::addLink('stylesheet', $po_request->getBaseUrlPath() . "/app/plugins/NovaMuse/themes/" . $this->ops_theme . "/css/dashboard.css", 'text/css');
     $this->opo_result_context = new ResultContext($po_request, 'ca_objects', 'dashboard');
     $t_list = new ca_lists();
     $this->opn_member_institution_id = $t_list->getItemIDFromList('entity_types', 'member_institution');
     $this->opn_individual_id = $t_list->getItemIDFromList('entity_types', 'ind');
     $this->opn_family_id = $t_list->getItemIDFromList('entity_types', 'fam');
     $this->opn_organization_id = $t_list->getItemIDFromList('entity_types', 'org');
     $t_object = new ca_objects();
     $this->opn_objectTableNum = $t_object->tableNum();
     $va_access_values = caGetUserAccessValues($this->request);
     $this->opa_access_values = $va_access_values;
     $this->view->setVar('access_values', $va_access_values);
 }
Example #2
0
 public function __construct(&$po_request, &$po_response, $pa_view_paths = null)
 {
     $this->ops_theme = __CA_THEME__;
     // get current theme
     if (!is_dir(__CA_APP_DIR__ . '/plugins/MetabolicChronology/themes/' . $this->ops_theme . '/views')) {
         // if theme is not defined for this plugin, try to use "default" theme
         $this->ops_theme = 'default';
     }
     parent::__construct($po_request, $po_response, array(__CA_APP_DIR__ . '/plugins/MetabolicChronology/themes/' . $this->ops_theme . '/views'));
     $this->opo_plugin_config = Configuration::load($this->request->getAppConfig()->get('application_plugins') . '/MetabolicChronology/conf/Chronology.conf');
     if (!(bool) $this->opo_plugin_config->get('enabled')) {
         die(_t('Metabolic Chronology plugin is not enabled'));
     }
     $this->_initView($pa_options);
     $this->opo_result_context = new ResultContext($po_request, 'ca_objects', 'MetabolicChronology');
     MetaTagManager::addLink('stylesheet', $po_request->getBaseUrlPath() . "/app/plugins/MetabolicChronology/themes/" . $this->ops_theme . "/css/chronology.css", 'text/css');
     JavascriptLoadManager::register('jcarousel');
     JavascriptLoadManager::register('maps');
     $t_list = new ca_lists();
     $this->opn_silo_type_id = $t_list->getItemIDFromList('collection_types', 'silo');
     $this->opn_action_type_id = $t_list->getItemIDFromList('occurrence_types', 'action');
     $this->opn_context_type_id = $t_list->getItemIDFromList('occurrence_types', 'context');
     $this->opn_yes_list_id = $t_list->getItemIDFromList('yes_no', 'yes');
     $t_relationship_types = new ca_relationship_types();
     $this->opn_rel_type_action_display_image = $t_relationship_types->getRelationshipTypeID("ca_objects_x_occurrences", "display");
     $this->opn_rel_type_action_secondary_images = $t_relationship_types->getRelationshipTypeID("ca_objects_x_occurrences", "secondary");
     $va_access_values = caGetUserAccessValues($this->request);
     $this->opa_access_values = $va_access_values;
     $this->view->setVar('access_values', $va_access_values);
 }
Example #3
0
 /**
  *
  */
 public function __construct(&$po_request, &$po_response, $pa_view_paths = null)
 {
     $this->ops_theme = __CA_THEME__;
     // get current theme
     if (!is_dir(__CA_APP_DIR__ . '/plugins/Contribute/themes/' . $this->ops_theme . '/views')) {
         // if theme is not defined for this plugin, try to use "default" theme
         $this->ops_theme = 'default';
     }
     parent::__construct($po_request, $po_response, array(__CA_APP_DIR__ . '/plugins/Contribute/themes/' . $this->ops_theme . '/views'));
     #$this->opo_plugin_config = Configuration::load($po_request->getAppConfig()->get('application_plugins').'/Contribute/conf/contribute.conf');
     if (file_exists($po_request->getAppConfig()->get('application_plugins') . '/Contribute/themes/' . $this->ops_theme . '/conf/contribute.conf')) {
         // check if there is a config file in the theme first
         $this->opo_plugin_config = Configuration::load($po_request->getAppConfig()->get('application_plugins') . '/Contribute/themes/' . $this->ops_theme . '/conf/contribute.conf');
     } else {
         $this->opo_plugin_config = Configuration::load($po_request->getAppConfig()->get('application_plugins') . '/Contribute/conf/contribute.conf');
     }
     if (!(bool) $this->opo_plugin_config->get('enabled')) {
         die(_t('Contribute plugin is not enabled'));
     }
     $vs_default_ui = $this->opo_plugin_config->get('default_ui');
     $vs_requested_ui = $this->request->getParameter('ui', pString);
     $va_ui_list = $this->opo_plugin_config->getAssoc('uis');
     $o_dm = Datamodel::load();
     if (isset($va_ui_list[$vs_requested_ui]) && is_array($va_ui_list[$vs_requested_ui])) {
         $this->opa_ui_info = $va_ui_list[$vs_requested_ui];
         $this->ops_ui_code = $vs_requested_ui;
     } else {
         if (isset($va_ui_list[$vs_default_ui]) && is_array($va_ui_list[$vs_default_ui])) {
             $this->opa_ui_info = $va_ui_list[$vs_default_ui];
         } else {
             $vs_default_ui = array_shift(array_keys($va_ui_list));
             $this->opa_ui_info = $va_ui_list[$vs_default_ui];
         }
         $this->ops_ui_code = $vs_default_ui;
     }
     $this->ops_table_name = $this->opa_ui_info['table'];
     if (!($this->opo_instance = $o_dm->getInstanceByTableName($this->ops_table_name, true))) {
         die(_t('Invalid table "%1" specified in Contribute plugin for form "%2"', $this->ops_table_name, $vs_default_ui));
     }
     $t_list = new ca_lists();
     if (isset($this->opa_ui_info['type']) && $this->opa_ui_info['type']) {
         $this->opa_ui_info['type_id'] = $t_list->getItemIDFromList($this->opo_instance->getTypeListCode(), $this->opa_ui_info['type']);
     }
     if (isset($this->opa_ui_info['representation_type']) && $this->opa_ui_info['representation_type']) {
         $this->opa_ui_info['representation_type_id'] = $t_list->getItemIDFromList('object_representation_types', $this->opa_ui_info['representation_type']);
     }
     ContributePlugin::setUIInfo($this->ops_ui_code, $this->opa_ui_info);
     JavascriptLoadManager::register('panel');
     MetaTagManager::addLink('stylesheet', $po_request->getBaseUrlPath() . "/app/plugins/Contribute/themes/" . $this->ops_theme . "/css/contribute.css", 'text/css');
     $this->request->setParameter('dont_set_pawtucket2_last_page', '1');
     // Setting this parameter ensures that the "last page" we (may) redirect to after submission isn't the Contribute form itself
     if ($this->opa_ui_info['require_login'] && !$po_request->isLoggedIn()) {
         $this->notification->addNotification(_t("You must be logged in to use user contribution features."), __NOTIFICATION_TYPE_ERROR__);
         $this->response->setRedirect(caNavUrl($this->request, '', 'LoginReg', 'form'));
         return;
     }
 }
Example #4
0
function caGetListItemID($ps_list_code, $ps_idno)
{
    global $g_list_item_id_cache;
    if (isset($g_list_item_id_cache[$ps_list_code . '/' . $ps_idno])) {
        return $g_list_item_id_cache[$ps_list_code . '/' . $ps_idno];
    }
    $t_list = new ca_lists();
    return $g_list_item_id_cache[$ps_list_code . '/' . $ps_idno] = $t_list->getItemIDFromList($ps_list_code, $ps_idno);
}
 public function __construct(&$po_request, &$po_response, $pa_view_paths = null)
 {
     $this->ops_theme = __CA_THEME__;
     // get current theme
     if (!is_dir(__CA_APP_DIR__ . '/plugins/eastend/themes/' . $this->ops_theme . '/views')) {
         // if theme is not defined for this plugin, try to use "default" theme
         $this->ops_theme = 'default';
     }
     parent::__construct($po_request, $po_response, array(__CA_APP_DIR__ . '/plugins/eastend/themes/' . $this->ops_theme . '/views'));
     MetaTagManager::addLink('stylesheet', $po_request->getBaseUrlPath() . "/app/plugins/eastend/themes/" . $this->ops_theme . "/css/eastend.css", 'text/css');
     $this->opo_plugin_config = Configuration::load($this->request->getAppConfig()->get('application_plugins') . '/eastend/conf/eastend.conf');
     if (!(bool) $this->opo_plugin_config->get('enabled')) {
         die(_t('eastend plugin is not enabled'));
     }
     // redirect user if not logged in
     if ($this->request->config->get('pawtucket_requires_login') && !$this->request->isLoggedIn()) {
         $this->response->setRedirect(caNavUrl($this->request, "", "LoginReg", "form"));
     }
     JavascriptLoadManager::register('cycle');
     $t_list = new ca_lists();
     $this->view->setVar("user_contributed_source_id", $t_list->getItemIDFromList('object_sources', 'user_contributed'));
     $this->view->setVar("user_contributed_other_source_id", $t_list->getItemIDFromList('object_sources', 'user_contributed_other'));
 }
Example #6
0
 /**
  *
  */
 public function __call($ps_function, $pa_args)
 {
     $ps_function = strtolower($ps_function);
     # --- which type of set is configured for display in gallery section
     $t_list = new ca_lists();
     $vn_gallery_set_type_id = $t_list->getItemIDFromList('set_types', $this->config->get('gallery_set_type'));
     $t_set = new ca_sets();
     if ($ps_function == "index") {
         if ($vn_gallery_set_type_id) {
             $va_sets = caExtractValuesByUserLocale($t_set->getSets(array('table' => 'ca_objects', 'checkAccess' => $this->opa_access_values, 'setType' => $vn_gallery_set_type_id)));
             $va_set_first_items = $t_set->getFirstItemsFromSets(array_keys($va_sets), array("version" => "icon", "checkAccess" => $this->opa_access_values));
             $o_front_config = caGetFrontConfig();
             $vs_front_page_set = $o_front_config->get('front_page_set_code');
             $vb_omit_front_page_set = (bool) $this->config->get('omit_front_page_set_from_gallery');
             foreach ($va_sets as $vn_set_id => $va_set) {
                 if ($vb_omit_front_page_set && $va_set['set_code'] == $vs_front_page_set) {
                     unset($va_sets[$vn_set_id]);
                 }
             }
             $this->view->setVar('sets', $va_sets);
             $this->view->setVar('first_items_from_sets', $va_set_first_items);
         }
         MetaTagManager::setWindowTitle($this->request->config->get("app_display_name") . ": " . ($this->config->get('gallery_section_name') ? $this->config->get('gallery_section_name') : _t("Gallery")));
         $this->render("Gallery/index_html.php");
     } else {
         $ps_set_id = $ps_function;
         $this->view->setVar("set_id", $ps_set_id);
         $t_set->load($ps_set_id);
         $this->view->setVar("set", $t_set);
         $this->view->setVar("label", $t_set->getLabelForDisplay());
         $this->view->setVar("description", $t_set->get($this->config->get('gallery_set_description_element_code')));
         $this->view->setVar("set_items", caExtractValuesByUserLocale($t_set->getItems(array("thumbnailVersions" => array("icon", "iconlarge"), "checkAccess" => $this->opa_access_values))));
         $pn_set_item_id = $this->request->getParameter('set_item_id', pInteger);
         if (!in_array($pn_set_item_id, array_keys($t_set->getItemIDs()))) {
             $pn_set_item_id = "";
         }
         $this->view->setVar("set_item_id", $pn_set_item_id);
         MetaTagManager::setWindowTitle($this->request->config->get("app_display_name") . ": " . ($this->config->get('gallery_section_name') ? $this->config->get('gallery_section_name') : _t("Gallery")) . ": " . $t_set->getLabelForDisplay());
         $this->render("Gallery/detail_html.php");
     }
 }
Example #7
0
 public function Index()
 {
     JavascriptLoadManager::register('imageScroller');
     $va_access_values = caGetUserAccessValues($this->request);
     // get sets for public display
     $t_list = new ca_lists();
     $vn_public_set_type_id = $t_list->getItemIDFromList('set_types', $t_list->getAppConfig()->get('features_set_type'));
     // get value for public access status value
     $va_tmp = $t_list->getItemFromList('access_statuses', 'public_access');
     $vn_public_access = $va_tmp['item_value'];
     $t_set = new ca_sets();
     $va_sets = caExtractValuesByUserLocale($t_set->getSets(array('table' => 'ca_objects', 'checkAccess' => $va_access_values, 'setType' => $vn_public_set_type_id)));
     $va_set_ids = array();
     foreach ($va_sets as $va_set) {
         $va_set_ids[] = $va_set['set_id'];
     }
     $this->view->setVar('sets', $va_sets);
     $this->view->setVar('set_ids', $va_set_ids);
     $this->view->setVar('set_display_items', ca_sets::getFirstItemsFromSets($va_set_ids, array("version" => "preview160")));
     $this->render('features_landing_html.php');
 }
Example #8
0
 public function addNewSet()
 {
     if (!$this->request->isLoggedIn()) {
         $this->response->setRedirect(caNavUrl($this->request, '', 'LoginReg', 'form'));
         return;
     }
     global $g_ui_locale_id;
     // current locale_id for user
     $va_errors_new_set = array();
     $t_new_set = new ca_sets();
     $pn_set_id = $this->request->getParameter('set_id', pInteger);
     $ps_name = $this->request->getParameter('name', pString);
     if (!$ps_name) {
         $va_errors_new_set["name"] = _t("Please enter the name of your collection");
     }
     $vs_desc = $this->request->getParameter('description', pString);
     $t_list = new ca_lists();
     $vn_set_type_user = $t_list->getItemIDFromList('set_types', 'user');
     if (sizeof($va_errors_new_set) == 0) {
         $t_new_set->setMode(ACCESS_WRITE);
         $t_new_set->set('access', $this->request->getParameter('access', pInteger));
         $t_new_set->set('table_num', 57);
         // 57=ca_objects
         $t_new_set->set('type_id', $vn_set_type_user);
         // type="user"
         $t_new_set->set('user_id', $this->request->getUserID());
         $t_new_set->set('set_code', $this->request->getUserID() . '_' . time());
         // create new attribute
         $t_new_set->addAttribute(array('set_intro' => $vs_desc, 'locale_id' => $g_ui_locale_id), 'set_intro');
         $t_new_set->insert();
         if ($vn_new_set_id = $t_new_set->getPrimaryKey()) {
             $t_new_set->addLabel(array('name' => $ps_name), $g_ui_locale_id, null, true);
             // select the current set
             $this->request->user->setVar('current_set_id', $vn_new_set_id);
             //clear t_new_set object so form appears blank and load t_set so edit form is populated
             $t_new_set = new ca_sets();
             $t_set = new ca_sets($vn_new_set_id);
         }
     }
     $this->view->setVar('errors_new_set', $va_errors_new_set);
     $this->index();
 }
Example #9
0
 /**
  * When source restrictions are specified, the search will only consider items of the given sources. 
  * If you specify a source that has hierarchical children then the children will automatically be included
  * in the restriction. You may pass numeric source_id and alphanumeric source codes interchangeably.
  *
  * @param array $pa_source_codes_or_ids List of source_id or code values to filter search by. When set, the search will only consider items of the specified sources. Using a hierarchical parent source will automatically include its children in the restriction. 
  * @param array $pa_options Options include
  *		includeSubsources = include any child sources in the restriction. Default is true.
  * @return boolean True on success, false on failure
  */
 public function setSourceRestrictions($pa_source_codes_or_ids, $pa_options = null)
 {
     $t_instance = $this->opo_datamodel->getInstanceByTableName($this->ops_tablename, true);
     if (!$pa_source_codes_or_ids) {
         return false;
     }
     if (is_array($pa_source_codes_or_ids) && !sizeof($pa_source_codes_or_ids)) {
         return false;
     }
     if (!is_array($pa_source_codes_or_ids)) {
         $pa_source_codes_or_ids = array($pa_source_codes_or_ids);
     }
     $t_list = new ca_lists();
     if (!method_exists($t_instance, 'getSourceListCode')) {
         return false;
     }
     if (!($vs_list_name = $t_instance->getSourceListCode())) {
         return false;
     }
     $va_source_list = $t_instance->getSourceList();
     $this->opa_search_source_ids = array();
     foreach ($pa_source_codes_or_ids as $vs_code_or_id) {
         if (!strlen($vs_code_or_id)) {
             continue;
         }
         if (!is_numeric($vs_code_or_id)) {
             $vn_source_id = $t_list->getItemIDFromList($vs_list_name, $vs_code_or_id);
         } else {
             $vn_source_id = (int) $vs_code_or_id;
         }
         if (!$vn_source_id) {
             return false;
         }
         if (isset($va_source_list[$vn_source_id]) && $va_source_list[$vn_source_id]) {
             // is valid source for this subject
             if (caGetOption('includeSubsources', $pa_options, true)) {
                 // See if there are any child sources
                 $t_item = new ca_list_items($vn_source_id);
                 $va_ids = $t_item->getHierarchyChildren(null, array('idsOnly' => true));
                 $va_ids[] = $vn_source_id;
                 $this->opa_search_source_ids = array_merge($this->opa_search_source_ids, $va_ids);
             }
         }
     }
     return true;
 }
Example #10
0
 /**
  *
  *
  * @param array $pa_source_codes_or_ids List of source codes or ids 
  * @param array $pa_options Options include
  *		includeSubsources = include any child sources in the restriction. Default is true.
  * @return array List of source_ids
  */
 private function _convertSourceCodesToIDs($pa_source_codes_or_ids, $pa_options = null)
 {
     $vs_md5 = caMakeCacheKeyFromOptions($pa_source_codes_or_ids);
     if (isset(BrowseEngine::$s_source_id_cache[$vs_md5])) {
         return BrowseEngine::$s_source_id_cache[$vs_md5];
     }
     if (isset($pa_options['instance']) && is_object($pa_options['instance'])) {
         $t_instance = $pa_options['instance'];
     } else {
         $t_instance = $this->getSubjectInstance();
     }
     $va_source_ids = array();
     if (!$pa_source_codes_or_ids) {
         return false;
     }
     if (is_array($pa_source_codes_or_ids) && !sizeof($pa_source_codes_or_ids)) {
         return false;
     }
     if (!is_array($pa_source_codes_or_ids)) {
         $pa_source_codes_or_ids = array($pa_source_codes_or_ids);
     }
     $t_list = new ca_lists();
     if (!method_exists($t_instance, 'getSourceListCode')) {
         return false;
     }
     if (!($vs_list_name = $t_instance->getSourceListCode())) {
         return false;
     }
     $va_source_list = $t_instance->getSourceList();
     foreach ($pa_source_codes_or_ids as $vs_code_or_id) {
         if (!trim($vs_code_or_id)) {
             continue;
         }
         if (!is_numeric($vs_code_or_id)) {
             $vn_source_id = $t_list->getItemIDFromList($vs_list_name, $vs_code_or_id);
         } else {
             $vn_source_id = (int) $vs_code_or_id;
         }
         if (!$vn_source_id) {
             return false;
         }
         if (isset($va_source_list[$vn_source_id]) && $va_source_list[$vn_source_id]) {
             // is valid source for this subject
             // See if there are any child sources
             if (caGetOption('includeSubsources', $pa_options, true) && $this->opb_dont_expand_source_restrictions) {
                 $t_item = new ca_list_items($vn_source_id);
                 $va_ids = $t_item->getHierarchyChildren(null, array('idsOnly' => true));
             }
             $va_ids[] = $vn_source_id;
             $va_source_ids = array_merge($va_source_ids, $va_ids);
         }
     }
     $va_source_ids = array_keys(array_flip($va_source_ids));
     BrowseEngine::$s_source_id_cache[$vs_md5] = $va_source_ids;
     return $va_source_ids;
 }
Example #11
0
 private function fetchAndImport($pa_item_queue, $po_client, $pa_config, $pa_tables, $ps_code)
 {
     if (!is_array($pa_tables)) {
         $pa_tables = array();
     }
     $t_rel_type = new ca_relationship_types();
     $vs_base_url = $pa_config['baseUrl'];
     $o_dm = Datamodel::load();
     $t_locale = new ca_locales();
     $t_list = new ca_lists();
     $vn_source_id = $t_list->getItemIDFromList('object_sources', $pa_config['code']);
     $pn_rep_type_id = $t_list->getItemIDFromList('object_representation_types', 'front');
     foreach ($pa_item_queue as $vn_i => $va_item) {
         $vs_table = $va_item['table'];
         $va_import_relationships_from = $pa_config['importRelatedFor'][$va_item['table']];
         print "oo";
         print_r($va_import_relationships_from);
         $vn_id = $va_item['id'];
         if (!$vn_id) {
             print "[Notice] SKIP CAUSE NO ID ({$ps_code})\n";
             continue;
         }
         if (isset($this->opa_processed_records[$vs_table . '/' . $vn_id])) {
             continue;
         }
         $vs_idno = trim((string) $va_item['idno']);
         try {
             $o_xml = $po_client->getItem($vs_table, $vn_id)->get();
         } catch (exception $e) {
             print "[ERROR] While trying to get item information: " . $e->getMessage() . "\n";
             continue;
         }
         $o_item = $o_xml->getItem;
         $t_instance = $o_dm->getInstanceByTableName($vs_table, false);
         $t_instance_label = $t_instance->getLabelTableInstance();
         // Look for existing record
         $vb_skip = false;
         $vb_update = false;
         $vs_label_fld = $t_instance->getLabelDisplayField();
         $vs_label = (string) $o_item->preferred_labels->en_US->{$vs_label_fld};
         print "[Notice] Processing [{$vs_table}] {$vs_label} [{$vs_idno}] ({$ps_code})\n";
         $t_instance_label->clear();
         if ($vs_idno && ($vs_table == 'ca_objects' && $t_instance->load(array('idno' => $vs_idno)) || $vs_table != 'ca_objects' && $t_instance->load(array('idno' => $vs_idno)))) {
             if ($t_instance->hasField('deleted') && $t_instance->get('deleted') == 1) {
                 $t_instance->set('deleted', 0);
             }
             //print "[Notice] Update [{$vs_idno}] for {$vs_table} 'cause it already exists ({$ps_code})\n";
             if (!$t_instance->getPrimaryKey()) {
                 $vb_skip = true;
                 print "[ERROR] Could not load instance for [{$vs_idno}]\n";
             }
             $vb_update = true;
             $t_instance->setMode(ACCESS_WRITE);
             // Clear labels
             $t_instance->removeAllLabels();
             if ($t_instance->numErrors()) {
                 print "[ERROR] Could not remove labels for updating: " . join("; ", $t_instance->getErrors()) . "\n";
             }
             // Clear attributes
             $t_instance->removeAttributes(null, array('dontCheckMinMax' => true));
             if ($t_instance->numErrors()) {
                 print "[ERROR] Could not remove attributes for updating: " . join("; ", $t_instance->getErrors()) . "\n";
             }
             // Clear relationships
             if (is_array($va_import_relationships_from)) {
                 foreach ($va_import_relationships_from as $vs_rel_table => $va_table_info) {
                     $t_instance->removeRelationships($vs_rel_table);
                     if ($t_instance->numErrors()) {
                         print "[ERROR] Could not remove {$vs_rel_table} relationships for updating: " . join("; ", $t_instance->getErrors()) . "\n";
                     }
                 }
             }
             if ($t_instance->tableName() == 'ca_objects') {
                 //$t_instance->set('source_id', $vn_source_id);
             }
             $t_instance->update();
             if ($t_instance->numErrors()) {
                 print "[ERROR] Could not clear record for updating: " . join("; ", $t_instance->getErrors()) . "\n";
             }
         }
         // create new one
         if (!$vb_update) {
             $t_instance->clear();
             if ($t_instance->tableName() == 'ca_objects') {
                 //$t_instance->set('source_id', $vn_source_id);
             }
         }
         $t_instance->setMode(ACCESS_WRITE);
         // add intrinsics
         switch ($vs_table) {
             case 'ca_collections':
                 $va_intrinsics = array('status', 'access', 'idno');
                 break;
             case 'ca_occurrences':
                 $va_intrinsics = array('status', 'access', 'idno');
                 break;
             case 'ca_objects':
                 $va_intrinsics = array('status', 'access', 'idno');
                 break;
             case 'ca_entities':
                 $va_intrinsics = array('status', 'access', 'lifespan', 'source_id', 'idno');
                 break;
             case 'ca_object_lots':
                 $va_intrinsics = array('status', 'access', 'idno_stub');
                 break;
             default:
                 $va_intrinsics = array('status', 'access', 'idno');
                 break;
         }
         // TODO: Need to properly handle foreign-key intrinsics when the item they point to doesn't exist
         // eg. source_id fields, various ca_objects and ca_object_lots intrinsics, etc.
         if ($vs_table == 'ca_list_items') {
             // does list exist?
             $vs_list_code = (string) $o_item->{'list_code'};
             $t_list = new ca_lists();
             if (!$t_list->load(array('list_code' => $vs_list_code))) {
                 // create list
                 $t_list->setMode(ACCESS_WRITE);
                 // TODO: should we bother to replicate the is_hierarchical, use_as_vocabulary and default_sort settings via a service?
                 // For now just set reasonable values
                 $t_list->set('list_code', $vs_list_code);
                 $t_list->set('is_hierarchical', 1);
                 $t_list->set('use_as_vocabulary', 1);
                 $t_list->set('default_sort', 0);
                 $t_list->insert();
                 if ($t_list->numErrors()) {
                     print "[ERROR] Could not insert new list '{$vs_list_code}': " . join('; ', $t_list->getErrors()) . "\n";
                 } else {
                     $t_list->addLabel(array('name' => $vs_list_code), $pn_locale_id, null, true);
                     if ($t_list->numErrors()) {
                         print "[ERROR] Could not add label to new list '{$vs_list_code}': " . join('; ', $t_list->getErrors()) . "\n";
                     }
                 }
             }
             $t_instance->set('list_id', $t_list->getPrimaryKey());
         }
         foreach ($va_intrinsics as $vs_f) {
             $t_instance->set($vs_f, $o_item->{$vs_f});
         }
         if (!$vb_update) {
             $vn_type_id = $t_instance->getTypeIDForCode((string) $o_item->type_id);
             if (!$vn_type_id) {
                 print "NO TYPE FOR {$vs_table}/" . $o_item->type_id . "\n";
             }
             $t_instance->set('type_id', $vn_type_id);
             if ($t_instance->tableName() == 'ca_objects') {
                 //$t_instance->set('source_id', $vn_source_id);
             }
             // TODO: add hook onBeforeInsert()
             $t_instance->insert();
             // TODO: add hook onInsert()
             if ($t_instance->numErrors()) {
                 print "[ERROR] Could not insert record: " . join('; ', $t_instance->getErrors()) . "\n";
             }
         }
         // add attributes
         // TODO: make this configurable
         $va_codes = $t_instance->getApplicableElementCodes();
         // $va_codes = array(
         // 				'description',
         // 				'georeference', 'geonames', 'internal_notes',
         // 				'oclc_number', 'file_name',
         // 				'digitized_by', 'digitized_date', 'call_number',
         // 				'other_call_number', 'collection_title', 'collection_number',
         // 				'box_number', 'folder_number', 'volume_number', 'page_number', 'shelf',
         // 				'pulled_digitization', 'pulled_name', 'pulled_date', 'returned_digitization',
         // 				'returned_name', 'returned_date', 'needs_redigitization', 'donor', 'copyright_holder',
         // 				'reproduction_restrictions', 'administrative_notes', 'date_view', 'date_item',
         // 				'view_format', 'item_format', 'dimensions', 'map_scale', 'image_description', 'address',
         // 				'lcsh_terms',  'inscription'
         //
         // 			);
         foreach ($va_codes as $vs_code) {
             $t_element = $t_instance->_getElementInstance($vs_code);
             switch ($t_element->get('datatype')) {
                 case 0:
                     // container
                     $va_elements = $t_element->getElementsInSet();
                     $o_attr = $o_item->{'ca_attribute_' . $vs_code};
                     foreach ($o_attr as $va_tag => $o_tags) {
                         foreach ($o_tags as $vs_locale => $o_values) {
                             if (!($vn_locale_id = $t_locale->localeCodeToID($vs_locale))) {
                                 $vn_locale_id = null;
                             }
                             $va_container_data = array('locale_id' => $vn_locale_id);
                             foreach ($o_values as $o_value) {
                                 foreach ($va_elements as $vn_i => $va_element_info) {
                                     if ($va_element_info['datatype'] == 0) {
                                         continue;
                                     }
                                     if ($vs_value = trim((string) $o_value->{$va_element_info['element_code']})) {
                                         switch ($va_element_info['datatype']) {
                                             case 3:
                                                 //list
                                                 $va_tmp = explode(":", $vs_value);
                                                 //<item_id>:<item_idno>
                                                 //print "CONTAINER LIST CODE=".$va_tmp[1]."/$vs_value/".$va_element_info['list_id']."\n";
                                                 $va_container_data[$va_element_info['element_code']] = $t_list->getItemIDFromList($va_element_info['list_id'], $va_tmp[1]);
                                                 break;
                                             default:
                                                 $va_container_data[$va_element_info['element_code']] = $vs_value;
                                                 break;
                                         }
                                     }
                                 }
                                 $t_instance->replaceAttribute($va_container_data, $vs_code);
                             }
                         }
                     }
                     break;
                 case 3:
                     // list
                     $o_attr = $o_item->{'ca_attribute_' . $vs_code};
                     foreach ($o_attr as $va_tag => $o_tags) {
                         foreach ($o_tags as $vs_locale => $o_values) {
                             if (!($vn_locale_id = $t_locale->localeCodeToID($vs_locale))) {
                                 $vn_locale_id = null;
                             }
                             foreach ($o_values as $o_value) {
                                 if ($vs_value = trim((string) $o_value->{$vs_code})) {
                                     $va_tmp = explode(":", $vs_value);
                                     //<item_id>:<item_idno>
                                     // TODO: create lists and list items if they don't already exist
                                     if ($vn_item_id = $t_list->getItemIDFromList($t_element->get('list_id'), $va_tmp[1])) {
                                         $t_instance->replaceAttribute(array($vs_code => $vn_item_id, 'locale_id' => $vn_locale_id), $vs_code);
                                     }
                                 }
                             }
                         }
                     }
                     break;
                 case 15:
                     // File
                 // File
                 case 16:
                     // Media
                     $t_instance->update();
                     if ($t_instance->numErrors()) {
                         print "[ERROR] Could not update record before media: " . join('; ', $t_instance->getErrors()) . "\n";
                     }
                     // TODO: detect if media has changes and only pull if it has
                     $o_attr = $o_item->{'ca_attribute_' . $vs_code};
                     foreach ($o_attr as $va_tag => $o_tags) {
                         foreach ($o_tags as $vs_locale => $o_values) {
                             if (!($vn_locale_id = $t_locale->localeCodeToID($vs_locale))) {
                                 $vn_locale_id = null;
                             }
                             foreach ($o_values as $o_value) {
                                 if ($vs_value = trim((string) $o_value->{$vs_code})) {
                                     $t_instance->replaceAttribute(array($vs_code => $vs_value, 'locale_id' => $vn_locale_id), $vs_code);
                                 }
                             }
                         }
                     }
                     $t_instance->update();
                     if ($t_instance->numErrors()) {
                         print "[ERROR] Could not update record after media: " . join('; ', $t_instance->getErrors()) . "\n";
                     }
                     break;
                 default:
                     $o_attr = $o_item->{'ca_attribute_' . $vs_code};
                     foreach ($o_attr as $va_tag => $o_tags) {
                         foreach ($o_tags as $vs_locale => $o_values) {
                             if (!($vn_locale_id = $t_locale->localeCodeToID($vs_locale))) {
                                 $vn_locale_id = null;
                             }
                             foreach ($o_values as $o_value) {
                                 if ($vs_value = trim((string) $o_value->{$vs_code})) {
                                     $t_instance->replaceAttribute(array($vs_code => $vs_value, 'locale_id' => $vn_locale_id), $vs_code);
                                 }
                             }
                         }
                     }
                     break;
             }
         }
         $t_instance->update();
         if ($t_instance->numErrors()) {
             print "[ERROR] Could not update [1] record: " . join('; ', $t_instance->getErrors()) . "\n";
         }
         // TODO: add hook onBeforeUpdate()
         $t_instance->update();
         // TODO: add hook onUpdate()
         if ($t_instance->numErrors()) {
             print "[ERROR] Could not update [2] record: " . join('; ', $t_instance->getErrors()) . "\n";
         }
         // get label fields
         $va_label_data = array();
         foreach ($t_instance->getLabelUIFields() as $vs_field) {
             if (!($va_label_data[$vs_field] = $o_item->preferred_labels->en_US->{$vs_field})) {
                 $va_label_data[$vs_field] = $o_item->preferred_labels->en_US->{$vs_field};
             }
         }
         // TODO: add hook onBeforeAddLabel()
         $t_instance->addLabel($va_label_data, 1, null, true);
         // TODO: add hook onAddLabel()
         if ($t_instance->numErrors()) {
             print "ERROR adding label: " . join('; ', $t_instance->getErrors()) . "\n";
         }
         $this->opa_processed_records[$va_item['table'] . '/' . (int) $va_item['id']] = $t_instance->getPrimaryKey();
         if ($vb_skip) {
             continue;
         }
         if (!is_array($va_import_relationships_from)) {
             continue;
         }
         $pa_tables[$va_item['table']] = true;
         // Are there relationships?
         $pb_imported_self_relations = false;
         print_r($va_import_relationships_from);
         foreach ($va_import_relationships_from as $vs_rel_table => $va_table_info) {
             $vb_is_self_relation = $vs_rel_table == $t_instance->tableName() && !$pb_imported_self_relations ? true : false;
             if (!$pa_tables[$vs_rel_table] || $vb_is_self_relation) {
                 // load related records recursively
                 if ($vs_rel_table == $t_instance->tableName()) {
                     $pb_imported_self_relations = true;
                 }
                 if ($o_item->{'related_' . $vs_rel_table}) {
                     $t_rel = $o_dm->getInstanceByTableName($vs_rel_table, false);
                     // TODO: add hook onBeforeAddRelationships()
                     foreach ($o_item->{'related_' . $vs_rel_table} as $vs_tag => $o_related_items) {
                         foreach ($o_related_items as $vs_i => $o_related_item) {
                             if (is_array($pa_config['importRelatedFor'][$va_item['table']][$vs_rel_table])) {
                                 $va_rel_types = array_keys($pa_config['importRelatedFor'][$va_item['table']][$vs_rel_table]);
                                 if (is_array($va_rel_types) && sizeof($va_rel_types) && !in_array((string) $o_related_item->relationship_type_code, $va_rel_types)) {
                                     print "[INFO] Skipped relationship for {$vs_display_name} because type='" . (string) $o_related_item->relationship_type_code . "' is excluded\n";
                                     continue;
                                 }
                             }
                             $vs_pk = $t_rel->primaryKey();
                             $vn_id = (int) $o_related_item->{$vs_pk};
                             $va_queue = array($vs_rel_table . "/" . $vn_id => array('table' => $vs_rel_table, 'id' => $vn_id, 'idno' => (string) $o_related_item->idno));
                             // TODO: Add from/until support
                             $this->fetchAndImport($va_queue, $po_client, $pa_config, $pa_tables, $ps_code);
                             $vn_rel_record_id = $this->opa_processed_records[$vs_rel_table . '/' . (int) $vn_id];
                             $vb_skip = false;
                             if ($vb_is_self_relation) {
                                 if ($this->opa_processed_self_relations[$vs_rel_table][$vn_rel_record_id][$t_instance->getPrimaryKey()][(string) $o_related_item->relationship_type_code] || $this->opa_processed_self_relations[$vs_rel_table][$t_instance->getPrimaryKey()][$vn_rel_record_id][(string) $o_related_item->relationship_type_code]) {
                                     $vb_skip = true;
                                 } else {
                                     $this->opa_processed_self_relations[$vs_rel_table][$t_instance->getPrimaryKey()][$vn_rel_record_id][(string) $o_related_item->relationship_type_code] = $this->opa_processed_self_relations[$vs_rel_table][$vn_rel_record_id][$t_instance->getPrimaryKey()][(string) $o_related_item->relationship_type_code] = true;
                                 }
                             }
                             if (!$vb_skip) {
                                 $t_instance->addRelationship($vs_rel_table, $vn_rel_record_id, (string) $o_related_item->relationship_type_code);
                                 if ($t_instance->numErrors()) {
                                     print "[ERROR] Could not add relationship to {$vs_rel_table} for row_id={$vn_rel_record_id}: " . join('; ', $t_instance->getErrors()) . "\n";
                                 }
                             }
                         }
                     }
                     // TODO: add hook onAddRelationships()
                 }
             }
         }
         // Is there media?
         if ($t_instance->tableName() == 'ca_objects') {
             try {
                 $o_rep_xml = $po_client->getObjectRepresentations((int) $va_item['id'], array('large', 'original'))->get();
             } catch (exception $e) {
                 print "[ERROR] While getting object representations: " . $e->getMessage() . "\n";
             }
             $va_existing_reps = $t_instance->getRepresentations(array('large', 'original'));
             $va_existing_md5s = array();
             $va_rep_ids = array();
             $va_dupe_reps = array();
             foreach ($va_existing_reps as $va_rep) {
                 if ($va_existing_md5s[$va_rep['info']['original']['MD5']] && $va_existing_md5s[$va_rep['info']['large']['MD5']]) {
                     // dupe
                     $va_dupe_reps[] = $va_rep['representation_id'];
                     continue;
                 }
                 $va_existing_md5s[$va_rep['info']['original']['MD5']] = $va_rep['representation_id'];
                 $va_existing_md5s[$va_rep['info']['large']['MD5']] = $va_rep['representation_id'];
                 $va_rep_ids[] = $va_rep['representation_id'];
             }
             if ($o_rep_xml->getObjectRepresentations) {
                 foreach ($o_rep_xml->getObjectRepresentations as $vs_x => $o_reps) {
                     foreach ($o_reps as $vs_key => $o_rep) {
                         if ($vs_url = trim((string) $o_rep->urls->large)) {
                             $vs_remote_original_md5 = (string) $o_rep->info->original->MD5;
                             $vs_remote_large_md5 = (string) $o_rep->info->large->MD5;
                             if (isset($va_existing_md5s[$vs_remote_original_md5]) && $va_existing_md5s[$vs_remote_original_md5] || isset($va_existing_md5s[$vs_remote_large_md5]) && $va_existing_md5s[$vs_remote_large_md5]) {
                                 print "[NOTICE] Skipping representation at {$vs_url} because it already exists (MD5={$vs_remote_original_md5}/{$vs_remote_large_md5}) ({$ps_code})\n";
                                 if (!($vn_kill_rep_id = $va_existing_md5s[$vs_remote_large_md5])) {
                                     $vn_kill_rep_id = $va_existing_md5s[$vs_remote_original_md5];
                                 }
                                 foreach ($va_existing_md5s as $vs_md5 => $vn_rep_id) {
                                     if ($vn_kill_rep_id == $vn_rep_id) {
                                         $t_existing_rep_link = new ca_objects_x_object_representations();
                                         if ($t_existing_rep_link->load(array('object_id' => $t_instance->getPrimaryKey(), 'representation_id' => $vn_rep_id))) {
                                             $t_existing_rep_link->setMode(ACCESS_WRITE);
                                             //	print "update object_id ".$t_instance->getPrimaryKey()."/rep=$vn_rep_id to rank=".$o_rep->rank."/primary=".$o_rep->is_primary."\n";
                                             $t_existing_rep_link->set('is_primary', (int) $o_rep->is_primary);
                                             $t_existing_rep_link->set('rank', (int) $o_rep->rank);
                                             $t_existing_rep_link->update();
                                             if ($t_existing_rep_link->numErrors()) {
                                                 print_r($t_existing_rep_link->getErrors());
                                             }
                                         }
                                         unset($va_existing_md5s[$vs_md5]);
                                     }
                                 }
                                 continue;
                             }
                             print "[Notice] Importing for [{$vs_idno}] media from {$vs_url}: primary=" . (string) $o_rep->is_primary . " ({$ps_code})\n";
                             print "instance has id=" . $t_instance->getPrimaryKey() . "\n";
                             // TODO: add hook onBeforeAddMedia()
                             $vn_link_id = $t_instance->addRepresentation($vs_url, $pn_rep_type_id, 1, (int) $o_rep->status, (int) $o_rep->access, (int) $o_rep->is_primary);
                             // TODO: add hook onAddMedia()
                             if ($t_instance->numErrors()) {
                                 print "[ERROR] Could not load object representation: " . join("; ", $t_instance->getErrors()) . " ({$ps_code})\n";
                             } else {
                                 $t_link = new ca_objects_x_object_representations($vn_link_id);
                                 $t_new_rep = new ca_object_representations($t_link->get('representation_id'));
                                 //unlink($x=$t_new_rep->getMediaPath('media', 'original'));
                             }
                         }
                     }
                 }
             }
             $va_rep_ids = array();
             foreach ($va_existing_md5s as $vs_md5 => $vn_rep_id) {
                 if ($va_rep_ids[$vn_rep_id]) {
                     continue;
                 }
                 $t_obj_x_rep = new ca_objects_x_object_representations();
                 while ($t_obj_x_rep->load(array('object_id' => $t_instance->getPrimaryKey(), 'representation_id' => $vn_rep_id))) {
                     $t_obj_x_rep->setMode(ACCESS_WRITE);
                     $t_obj_x_rep->delete(true);
                     if ($t_obj_x_rep->numErrors()) {
                         print "[ERROR] Could not load remove object-to-representation link: " . join("; ", $t_obj_x_rep->getErrors()) . " ({$ps_code})\n";
                         break;
                     }
                     if (!$t_obj_x_rep->load(array('representation_id' => $vn_rep_id))) {
                         $t_rep = new ca_object_representations();
                         if ($t_rep->load($vn_rep_id)) {
                             $t_rep->setMode(ACCESS_WRITE);
                             $t_rep->delete(true, array('hard' => true));
                             if ($t_rep->numErrors()) {
                                 print "[ERROR] Could not remove representation: " . join("; ", $t_rep->getErrors()) . "\n";
                                 break;
                             }
                         }
                     }
                 }
                 $va_rep_ids[$vn_rep_id] = true;
             }
             foreach ($va_dupe_reps as $vn_dupe_rep_id) {
                 $t_rep = new ca_object_representations();
                 if ($t_rep->load($vn_dupe_rep_id)) {
                     print "[Notice] DELETE DUPE {$vn_dupe_rep_id}\n";
                     $t_rep->setMode(ACCESS_WRITE);
                     $t_rep->delete(true, array('hard' => true));
                     if ($t_rep->numErrors()) {
                         print "[ERROR] Could not remove dupe representation: " . join("; ", $t_rep->getErrors()) . "\n";
                         break;
                     }
                 }
             }
         }
         unset($pa_tables[$va_item['table']]);
     }
 }
Example #12
0
 public function processUserInterfaces()
 {
     require_once __CA_MODELS_DIR__ . "/ca_editor_uis.php";
     require_once __CA_MODELS_DIR__ . "/ca_editor_ui_screens.php";
     require_once __CA_MODELS_DIR__ . "/ca_lists.php";
     require_once __CA_MODELS_DIR__ . "/ca_list_items.php";
     require_once __CA_MODELS_DIR__ . "/ca_relationship_types.php";
     $vo_dm = Datamodel::load();
     $t_list = new ca_lists();
     $t_rel_types = new ca_relationship_types();
     $va_uis = array();
     if ($this->ops_base_name) {
         // "merge" profile and its base
         foreach ($this->opo_base->userInterfaces->children() as $vo_ui) {
             $va_uis[self::getAttribute($vo_ui, "code")] = $vo_ui;
         }
         foreach ($this->opo_profile->userInterfaces->children() as $vo_ui) {
             $va_uis[self::getAttribute($vo_ui, "code")] = $vo_ui;
         }
     } else {
         foreach ($this->opo_profile->userInterfaces->children() as $vo_ui) {
             $va_uis[self::getAttribute($vo_ui, "code")] = $vo_ui;
         }
     }
     foreach ($va_uis as $vs_ui_code => $vo_ui) {
         $vs_type = self::getAttribute($vo_ui, "type");
         if (!($vn_type = $vo_dm->getTableNum($vs_type))) {
             $this->addError("Invalid type {$vs_type} for UI code {$vs_ui_code}");
             return false;
         }
         // model instance of UI type
         $t_instance = $vo_dm->getInstanceByTableNum($vn_type);
         // create ui row
         $t_ui = ca_editor_uis::find(array('editor_code' => $vs_ui_code, 'editor_type' => $vn_type), array('returnAs' => 'firstModelInstance'));
         $t_ui = $t_ui ? $t_ui : new ca_editor_uis();
         $t_ui->setMode(ACCESS_WRITE);
         $t_ui->set('user_id', null);
         $t_ui->set('is_system_ui', 1);
         $t_ui->set('editor_code', $vs_ui_code);
         $t_ui->set('editor_type', $vn_type);
         if ($t_ui->getPrimaryKey()) {
             $t_ui->update();
         } else {
             $t_ui->insert();
         }
         if ($t_ui->numErrors()) {
             $this->addError("Errors inserting UI {$vs_ui_code}: " . join("; ", $t_ui->getErrors()));
             return false;
         }
         $vn_ui_id = $t_ui->getPrimaryKey();
         self::addLabelsFromXMLElement($t_ui, $vo_ui->labels, $this->opa_locales);
         // create ui type restrictions
         if ($vo_ui->typeRestrictions) {
             foreach ($vo_ui->typeRestrictions->children() as $vo_restriction) {
                 $vs_restriction_type = self::getAttribute($vo_restriction, "type");
                 if (strlen($vs_restriction_type) > 0) {
                     // interstitial with type restriction -> code is relationship type code
                     if ($t_instance instanceof BaseRelationshipModel) {
                         $vn_type_id = $t_rel_types->getRelationshipTypeID($t_instance->tableName(), $vs_restriction_type);
                     } else {
                         // "normal" type restriction -> code is from actual type list
                         $vs_type_list_name = $t_instance->getFieldListCode($t_instance->getTypeFieldName());
                         $vn_type_id = $t_list->getItemIDFromList($vs_type_list_name, $vs_restriction_type);
                     }
                     if ($vn_type_id) {
                         $t_ui->addTypeRestriction($vn_type_id);
                     }
                 }
             }
         }
         // create ui screens
         foreach ($vo_ui->screens->children() as $vo_screen) {
             $vs_screen_idno = self::getAttribute($vo_screen, "idno");
             $vn_is_default = self::getAttribute($vo_screen, "default");
             $t_ui_screens = ca_editor_ui_screens::find(array('idno' => $vs_screen_idno, 'ui_id' => $vn_ui_id), array('returnAs' => 'firstModelInstance'));
             $t_ui_screens = $t_ui_screens ? $t_ui_screens : new ca_editor_ui_screens();
             $t_ui_screens->setMode(ACCESS_WRITE);
             $t_ui_screens->set('idno', $vs_screen_idno);
             $t_ui_screens->set('ui_id', $vn_ui_id);
             $t_ui_screens->set('is_default', $vn_is_default);
             if ($t_ui_screens->getPrimaryKey()) {
                 $t_ui_screens->update();
             } else {
                 $t_ui_screens->set('parent_id', null);
                 $t_ui_screens->insert();
             }
             if ($t_ui_screens->numErrors()) {
                 $this->addError("Errors inserting UI screen {$vs_screen_idno} for UI {$vs_ui_code}: " . join("; ", $t_ui_screens->getErrors()));
                 return false;
             }
             self::addLabelsFromXMLElement($t_ui_screens, $vo_screen->labels, $this->opa_locales);
             $va_available_bundles = $t_ui_screens->getAvailableBundles(null, array('dontCache' => true));
             // create ui bundle placements
             foreach ($vo_screen->bundlePlacements->children() as $vo_placement) {
                 $vs_placement_code = self::getAttribute($vo_placement, "code");
                 $vs_bundle = trim((string) $vo_placement->bundle);
                 $va_settings = $this->_processSettings(null, $vo_placement->settings);
                 $t_ui_screens->addPlacement($vs_bundle, $vs_placement_code, $va_settings, null, array('additional_settings' => $va_available_bundles[$vs_bundle]['settings']));
             }
             // create ui screen type restrictions
             if ($vo_screen->typeRestrictions) {
                 foreach ($vo_screen->typeRestrictions->children() as $vo_restriction) {
                     $vs_restriction_type = self::getAttribute($vo_restriction, "type");
                     if (strlen($vs_restriction_type) > 0) {
                         // interstitial with type restriction -> code is relationship type code
                         if ($t_instance instanceof BaseRelationshipModel) {
                             $vn_type_id = $t_rel_types->getRelationshipTypeID($t_instance->tableName(), $vs_restriction_type);
                         } else {
                             // "normal" type restriction -> code is from actual type list
                             $vs_type_list_name = $t_instance->getFieldListCode($t_instance->getTypeFieldName());
                             $vn_type_id = $t_list->getItemIDFromList($vs_type_list_name, $vs_restriction_type);
                         }
                         if ($vn_type_id) {
                             $t_ui_screens->addTypeRestriction($vn_type_id);
                         }
                     }
                 }
             }
         }
         // set user and group access
         if ($vo_ui->userAccess) {
             $t_user = new ca_users();
             $va_ui_users = array();
             foreach ($vo_ui->userAccess->children() as $vo_permission) {
                 $vs_user = trim((string) self::getAttribute($vo_permission, "user"));
                 $vn_access = $this->_convertUserGroupAccessStringToInt(self::getAttribute($vo_permission, 'access'));
                 if ($vn_access && $t_user->load(array('user_name' => $vs_user))) {
                     $va_ui_users[$t_user->getUserID()] = $vn_access;
                 } else {
                     $this->addError("User name or access value invalid for UI {$vs_ui_code} (permission item with user name '{$vs_user}')");
                 }
             }
             if (sizeof($va_ui_users) > 0) {
                 $t_ui->addUsers($va_ui_users);
             }
         }
         if ($vo_ui->groupAccess) {
             $t_group = new ca_user_groups();
             $va_ui_groups = array();
             foreach ($vo_ui->groupAccess->children() as $vo_permission) {
                 $vs_group = trim((string) self::getAttribute($vo_permission, "group"));
                 $vn_access = $this->_convertUserGroupAccessStringToInt(self::getAttribute($vo_permission, 'access'));
                 if ($vn_access && $t_group->load(array('code' => $vs_group))) {
                     $va_ui_groups[$t_group->getPrimaryKey()] = $vn_access;
                 } else {
                     $this->addError("Group code or access value invalid for UI {$vs_ui_code} (permission item with group code '{$vs_group}')");
                 }
             }
             if (sizeof($va_ui_groups) > 0) {
                 $t_ui->addUserGroups($va_ui_groups);
             }
         }
     }
     return true;
 }
Example #13
0
    $t_list->set('is_hierarchical', 1);
    $t_list->set('use_as_vocabulary', 1);
    $t_list->insert();
    if ($t_list->numErrors()) {
        print "ERROR: couldn't create ca_list row for AAT: " . join('; ', $t_list->getErrors()) . "\n";
        die;
    }
    $t_list->addLabel(array('name' => 'Art & Architecture Thesaurus [Nederlands]'), $pn_en_locale_id, null, true);
}
$vn_list_id = $t_list->getPrimaryKey();
// get list item types (should be defined by base installation profile [base.profile])
// if your installation didn't use a profile inheriting from base.profile then you should make sure
// that a list with code='list_item_types' is defined and the following four item codes are defined.
// If these are not defined then the AAT will still import, but without any distinction between
// terms, facets and guide terms
$vn_list_item_type_concept = $t_list->getItemIDFromList('list_item_types', 'concept');
$vn_list_item_type_facet = $t_list->getItemIDFromList('list_item_types', 'facet');
$vn_list_item_type_guide_term = $t_list->getItemIDFromList('list_item_types', 'guide_term');
$vn_list_item_type_hierarchy_name = $t_list->getItemIDFromList('list_item_types', 'hierarchy_name');
// get list item label types (should be defined by base installation profile [base.profile])
// if your installation didn't use a profile inheriting from base.profile then you should make sure
// that a list with code='list_item_label_types' is defined and the following four item codes are defined.
// If these are not defined then the AAT will still import, but without any distinction between
// terms, facets and guide terms
$vn_list_item_label_type_uf = $t_list->getItemIDFromList('list_item_label_types', 'uf');
$vn_list_item_label_type_alt = $t_list->getItemIDFromList('list_item_label_types', 'alt');
// get list item-to-item relationship type (should be defined by base installation profile [base.profile])
// if your installation didn't use a profile inheriting from base.profile then you should make sure
// that a ca_list_items_x_list_items relationship type with code='related' is defined. Otherwise import of term-to-term
// relationships will fail.
$t_rel_types = new ca_relationship_types();
Example #14
0
 public function displaySet()
 {
     # --- set info
     $pn_set_id = $this->request->getParameter('set_id', pInteger);
     $t_set = new ca_sets($pn_set_id);
     $va_access_values = caGetUserAccessValues($this->request);
     # Enforce access control
     if (sizeof($va_access_values) && !in_array($t_set->get("access"), $va_access_values)) {
         $this->notification->addNotification(_t("This set is not available for view"), "message");
         $this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
         return;
     }
     $this->view->setVar('t_set', $t_set);
     $va_items = caExtractValuesByUserLocale($t_set->getItems(array('thumbnailVersions' => array('widepreview', 'medium', 'setimage'), "checkAccess" => $va_access_values)));
     $this->view->setVar('items', $va_items);
     $va_row_ids = array();
     foreach ($va_items as $vn_item_id => $va_item_info) {
         $va_row_ids[] = $va_item_info['row_id'];
     }
     # --- all featured sets - for display in right hand column
     // get sets for public display
     $t_list = new ca_lists();
     $vn_public_set_type_id = $t_list->getItemIDFromList('set_types', $t_list->getAppConfig()->get('simpleGallery_set_type'));
     $t_set = new ca_sets($pn_set_id);
     $va_sets = caExtractValuesByUserLocale($t_set->getSets(array('table' => 'ca_objects', 'checkAccess' => $va_access_values, 'setType' => $vn_public_set_type_id)));
     $va_set_first_items = array();
     $va_set_first_items = $t_set->getFirstItemsFromSets(array_keys($va_sets), array("version" => "icon", "checkAccess" => $va_access_values));
     $this->view->setVar('sets', $va_sets);
     $this->view->setVar('first_items_from_sets', $va_set_first_items);
     $this->view->setVar('set_title', $t_set->getLabelForDisplay());
     $this->view->setVar('set_description', $t_set->get($this->opo_plugin_config->get('set_description_element_code'), array('convertLinkBreaks' => true)));
     // Needed to figure out what result context to use on details
     $this->opo_result_context->setParameter('set_id', $pn_set_id);
     $this->opo_result_context->setResultList($va_row_ids);
     $this->opo_result_context->setAsLastFind();
     $this->opo_result_context->saveContext();
     $this->render($this->ops_theme . '/set_info_html.php');
 }
Example #15
0
 /**
  * Returns the type of access the user has to the specified source.
  * Types of access are:
  *		__CA_BUNDLE_ACCESS_EDIT__ (implies ability to view and change bundle content)
  *		__CA_BUNDLE_ACCESS_READONLY__ (implies ability to view bundle content only)
  *		__CA_BUNDLE_ACCESS_NONE__ (indicates that the user has no access to bundle)
  */
 public function getSourceAccessLevel($ps_table_name, $pm_source_code_or_id)
 {
     $vs_cache_key = $ps_table_name . '/' . $pm_source_code_or_id . "/" . $this->getPrimaryKey();
     if (isset(ca_users::$s_user_source_access_cache[$vs_cache_key])) {
         return ca_users::$s_user_source_access_cache[$vs_cache_key];
     }
     if (in_array($ps_table_name, ca_users::$s_bundlable_tables)) {
         // source-level access control only applies to these tables
         $va_roles = array_merge($this->getUserRoles(), $this->getGroupRoles());
         if (is_numeric($pm_source_code_or_id)) {
             $vn_source_id = (int) $pm_source_code_or_id;
         } else {
             $t_list = new ca_lists();
             $t_instance = $this->getAppDatamodel()->getInstanceByTableName($ps_table_name, true);
             $vn_source_id = (int) $t_list->getItemIDFromList($t_instance->getSourceListCode(), $pm_source_code_or_id);
         }
         $vn_access = -1;
         foreach ($va_roles as $vn_role_id => $va_role_info) {
             $va_vars = $va_role_info['vars'];
             if (is_array($va_vars['source_access_settings'])) {
                 if (isset($va_vars['source_access_settings'][$ps_table_name . '.' . $vn_source_id]) && (int) $va_vars['source_access_settings'][$ps_table_name . '.' . $vn_source_id] > $vn_access) {
                     $vn_access = (int) $va_vars['source_access_settings'][$ps_table_name . '.' . $vn_source_id];
                     if ($vn_access == __CA_BUNDLE_ACCESS_EDIT__) {
                         break;
                     }
                     // already at max
                 }
             } else {
                 // for roles that don't have 'source_access_settings' set, use default.
                 // those are most likely roles that came from a profile, didn't have source-level
                 // access settings set in the profile and haven't been saved through the UI
                 $vn_access = $this->getAppConfig()->get('default_source_access_level');
                 if ($vn_access == __CA_BUNDLE_ACCESS_EDIT__) {
                     break;
                 }
                 // already at max
             }
         }
         if ($vn_access < 0) {
             $vn_access = (int) $this->getAppConfig()->get('default_source_access_level');
         }
         ca_users::$s_user_source_access_cache[$ps_table_name . '/' . $vn_source_id . "/" . $this->getPrimaryKey()] = ca_users::$s_user_source_access_cache[$vs_cache_key] = $vn_access;
         return $vn_access;
     } else {
         // no source level access control for tables not explicitly listed in $s_bundlable_tables
         ca_users::$s_user_source_access_cache[$ps_table_name . '/' . $vn_source_id . "/" . $this->getPrimaryKey()] = ca_users::$s_user_source_access_cache[$vs_cache_key] = __CA_BUNDLE_ACCESS_EDIT__;
         return __CA_BUNDLE_ACCESS_EDIT__;
     }
 }
Example #16
0
 /**
  * Returns the place_id in ca_places table for root of specified hierarchy. Place hierarchies are enumerated in the "place_hierarchies" list,
  * so hierarchy specifications are really just plain old list items (ca_list_items records). You can specify a hierarchy using an hierarchy id 
  * (really just a ca_list_items item_id value for the item representing the hierarchy), or by passing the idno of the hierarchy (eg. ca_list_items.idno).
  *
  * @param mixed $pm_hierarchy_code_or_id The numeric id or alphanumeric code for the hierarchy. Since hierarchies are represented with list items these are the item_id or idno values of the hierarchy's list item.
  * @return int Place ID of the place hierarchy root
  */
 public function getRootIDForHierarchy($pm_hierarchy_code_or_id)
 {
     $o_db = $this->getDb();
     if (!is_numeric($pm_hierarchy_code_or_id)) {
         $t_list = new ca_lists();
         $pn_hierarchy_id = (int) $t_list->getItemIDFromList('place_hierarchies', $pm_hierarchy_code_or_id);
     } else {
         $pn_hierarchy_id = (int) $pm_hierarchy_code_or_id;
     }
     $qr_res = $o_db->query("\n\t\t\tSELECT place_id\n\t\t\tFROM ca_places \n\t\t\tWHERE \n\t\t\t\t(parent_id IS NULL) AND (hierarchy_id = ?)\n\t\t", (int) $pn_hierarchy_id);
     if ($qr_res->nextRow()) {
         return $qr_res->get('place_id');
     }
     return null;
 }
Example #17
0
function caGetListItemID($ps_list_code, $ps_idno, $pa_options = null)
{
    global $g_list_item_id_cache;
    if (isset($g_list_item_id_cache[$ps_list_code . '/' . $ps_idno])) {
        return $g_list_item_id_cache[$ps_list_code . '/' . $ps_idno];
    }
    $t_list = new ca_lists();
    if ($o_trans = caGetOption('transaction', $pa_options, null)) {
        $t_list->setTransaction($o_trans);
    }
    return $g_list_item_id_cache[$ps_list_code . '/' . $ps_idno] = $t_list->getItemIDFromList($ps_list_code, $ps_idno);
}
Example #18
0
require_once __CA_LIB_DIR__ . "/ca/Search/ObjectSearch.php";
require_once __CA_MODELS_DIR__ . "/ca_objects.php";
require_once __CA_MODELS_DIR__ . "/ca_sets.php";
require_once __CA_APP_DIR__ . '/helpers/accessHelpers.php';
$t_object = new ca_objects();
$t_featured = new ca_sets();
# --- get access setting so can check access of objects
if ($this->request->config->get("dont_enforce_access_settings")) {
    $va_access_values = array();
} else {
    $va_access_values = caGetUserAccessValues($this->request);
}
# --- grab 1 archival showcase collection to feature in side box
# -- get the collection type
$o_lists = new ca_lists();
$vn_showcase_collection_type_id = $o_lists->getItemIDFromList('collection_types', 'archival_showcase');
$o_collectionSearch = new CollectionSearch();
$o_collectionSearch->addResultFilter("ca_collections.access", "IN", join($va_access_values, ", "));
$o_collectionSearch->addResultFilter("ca_collections.type_id", "=", $vn_showcase_collection_type_id);
$o_showcase_collection_results = $o_collectionSearch->search("*");
if ($o_showcase_collection_results->numHits() > 0) {
    $o_showcase_collection_results->nextHit();
    $vn_featured_collection_id = $o_showcase_collection_results->get("ca_collections.collection_id");
    $vs_featured_collection_text = strip_tags($o_showcase_collection_results->get("ca_collections.description"));
    $vs_featured_collection_label = join($o_showcase_collection_results->getDisplayLabels($this->request), "; ");
    $vs_featured_collection_thumb = "";
    # --- get an item from the collection to use it's media as the thumbnail
    $o_collectionItemSearch = new ObjectSearch();
    $o_collectionItemSearch->addResultFilter("ca_collections.collection_id", "=", $o_showcase_collection_results->get("collection_id"));
    $o_collectionItemSearch->addResultFilter("ca_objects.access", "IN", join($va_access_values, ", "));
    $o_collectionItemSearchResults = $o_collectionItemSearch->search("*");
}
# --- occurrences
$va_occurrences = $t_object->get("ca_occurrences", array("returnAsArray" => 1, 'checkAccess' => $va_access_values));
$va_sorted_occurrences = array();
if (sizeof($va_occurrences) > 0) {
    $t_occ = new ca_occurrences();
    $va_item_types = $t_occ->getTypeList();
    foreach ($va_occurrences as $va_occurrence) {
        $t_occ->load($va_occurrence['occurrence_id']);
        $va_rel_entities = array();
        $va_rel_entities = $t_occ->get("ca_entities", array('restrictToTypes' => array('organization'), "returnAsArray" => 1, 'checkAccess' => $va_access_values, 'sort' => 'surname'));
        $va_occurrence["related_entities"] = $va_rel_entities;
        $va_sorted_occurrences[$va_occurrence['item_type_id']][$va_occurrence['occurrence_id']] = $va_occurrence;
    }
    $t_list = new ca_lists();
    $vn_exhibition_type_id = $t_list->getItemIDFromList("occurrence_types", "exhibition");
    foreach ($va_sorted_occurrences as $vn_occurrence_type_id => $va_occurrence_list) {
        ?>
						<h3><?php 
        print _t("Related") . " " . $va_item_types[$vn_occurrence_type_id]['name_singular'] . (sizeof($va_occurrence_list) > 1 ? "s" : "");
        ?>
</h3>
					<div class='scrollPane'>
<?php 
        foreach ($va_occurrence_list as $vn_rel_occurrence_id => $va_info) {
            print "<p>" . ($this->request->config->get('allow_detail_for_ca_occurrences') ? caNavLink($this->request, $va_info["label"], '', 'Detail', 'Occurrence', 'Show', array('occurrence_id' => $vn_rel_occurrence_id)) : $va_info["label"]);
            if ($vn_exhibition_type_id == $vn_occurrence_type_id) {
                # --- this is an exhibition, so try to display organizations related to the exhibition
                $vn_i = 1;
                foreach ($va_info['related_entities'] as $va_organization) {
                    print ", " . $va_organization["displayname"];
Example #20
0
 public function getSetsForUser($pa_options)
 {
     if (!is_array($pa_options)) {
         $pa_options = array();
     }
     $pn_user_id = isset($pa_options['user_id']) ? (int) $pa_options['user_id'] : null;
     $pm_table_name_or_num = isset($pa_options['table']) ? $pa_options['table'] : null;
     if ($pm_table_name_or_num && !($vn_table_num = $this->_getTableNum($pm_table_name_or_num))) {
         return null;
     }
     $pm_type = isset($pa_options['setType']) ? $pa_options['setType'] : null;
     $pn_access = isset($pa_options['access']) ? $pa_options['access'] : null;
     $pa_public_access = isset($pa_options['checkAccess']) ? $pa_options['checkAccess'] : null;
     if ($pa_public_access && is_numeric($pa_public_access) && !is_array($pa_public_access)) {
         $pa_public_access = array($pa_public_access);
     }
     for ($vn_i = 0; $vn_i < sizeof($pa_public_access); $vn_i++) {
         $pa_public_access[$vn_i] = intval($pa_public_access[$vn_i]);
     }
     if ($pn_user_id) {
         $va_extra_joins = array();
         $va_sql_wheres = array("(cs.deleted = 0)");
         $va_sql_params = array();
         $o_db = $this->getDb();
         if ($vn_table_num) {
             $va_sql_wheres[] = "(cs.table_num = ?)";
             $va_sql_params[] = (int) $vn_table_num;
         }
         if (!is_null($pa_public_access) && is_array($pa_public_access) && sizeof($pa_public_access)) {
             $va_sql_wheres[] = "(cs.access IN (?))";
             $va_sql_params[] = $pa_public_access;
         }
         if (isset($pm_type) && $pm_type) {
             if (is_numeric($pm_type)) {
                 $va_sql_wheres[] = "(cs.type_id = ?)";
                 $va_sql_params[] = (int) $pm_type;
             } else {
                 # --- look up code of set type
                 $t_list = new ca_lists();
                 $vn_type_id = $t_list->getItemIDFromList("set_types", $pm_type);
                 if ($vn_type_id) {
                     $va_sql_wheres[] = "(cs.type_id = ?)";
                     $va_sql_params[] = (int) $vn_type_id;
                 }
             }
         }
         if ($pa_options["owner"]) {
             $va_sql_wheres[] = "(cs.user_id = " . $pn_user_id . ")";
         } else {
             # --- if owner is not set to true, we're finding all sets the user has access to or is owner of
             # --- we also check the users' access to the set if set
             $t_user = new ca_users();
             $t_user->load($pn_user_id);
             if ($t_user->getPrimaryKey()) {
                 $vs_access_sql = $pn_access > 0 ? " AND (access >= " . intval($pn_access) . ")" : "";
                 if (is_array($va_groups = $t_user->getUserGroups()) && sizeof($va_groups)) {
                     $vs_sql = "(\n\t\t\t\t\t\t\t(cs.user_id = " . intval($pn_user_id) . ") OR \n\t\t\t\t\t\t\t(cs.set_id IN (\n\t\t\t\t\t\t\t\t\tSELECT set_id \n\t\t\t\t\t\t\t\t\tFROM ca_sets_x_user_groups \n\t\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\t\tgroup_id IN (" . join(',', array_keys($va_groups)) . ") {$vs_access_sql}\n\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t\t (sdatetime IS NULL AND edatetime IS NULL)\n\t\t\t\t\t\t\t\t\t\t\t OR \n\t\t\t\t\t\t\t\t\t\t\t (\n\t\t\t\t\t\t\t\t\t\t\t\tsdatetime <= " . time() . " AND edatetime >= " . time() . "\n\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)";
                 } else {
                     $vs_sql = "(cs.user_id = {$pn_user_id})";
                 }
                 $vs_sql .= " OR (cs.set_id IN (\n\t\t\t\t\t\t\t\t\t\t\tSELECT set_id \n\t\t\t\t\t\t\t\t\t\t\tFROM ca_sets_x_users \n\t\t\t\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\t\t\t\tuser_id = {$pn_user_id} {$vs_access_sql}\n\t\t\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t\t\t\t (sdatetime IS NULL AND edatetime IS NULL)\n\t\t\t\t\t\t\t\t\t\t\t\t\t OR \n\t\t\t\t\t\t\t\t\t\t\t\t\t (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsdatetime <= " . time() . " AND edatetime >= " . time() . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t)";
                 $va_sql_wheres[] = "({$vs_sql})";
             }
         }
         $qr_res = $o_db->query("SELECT cs.set_id, cs.user_id, type_id, cu.fname, cu.lname\n\t\t\t\t\t\t\t\t\tFROM ca_sets cs\n\t\t\t\t\t\t\t\t\tINNER JOIN ca_users AS cu ON cs.user_id = cu.user_id\n\t\t\t\t\t\t\t\t\t" . join("\n", $va_extra_joins) . "\n\t\t\t\t\t\t\t\t\t" . (sizeof($va_sql_wheres) ? "WHERE " : "") . " " . join(" AND ", $va_sql_wheres) . "\n\t\t\t\t\t\t\t\t\t", $va_sql_params);
         $va_sets = array();
         $t_list = new ca_lists();
         while ($qr_res->nextRow()) {
             $vn_table_num = $qr_res->get('table_num');
             if (!isset($va_type_name_cache[$vn_table_num]) || !($vs_set_type = $va_type_name_cache[$vn_table_num])) {
                 $vs_set_type = $va_type_name_cache[$vn_table_num] = $this->getSetContentTypeName($vn_table_num, array('number' => 'plural'));
             }
             $vs_type = $t_list->getItemFromListForDisplayByItemID('set_types', $qr_res->get('type_id'));
             $va_sets[$qr_res->get('set_id')] = array_merge($qr_res->getRow(), array('set_content_type' => $vs_set_type, 'set_type' => $vs_type));
         }
         return $va_sets;
     } else {
         return false;
     }
 }
Example #21
0
<?php

require_once __CA_LIB_DIR__ . "/ca/Search/EntitySearch.php";
$o_entity_search = new EntitySearch();
$t_list = new ca_lists();
$vn_member_institution_id = $t_list->getItemIDFromList('entity_types', 'member_institution');
$qr_member_institutions = $o_entity_search->search("ca_entities.access:1 AND ca_entities.type_id:{$vn_member_institution_id}", array("sort" => "ca_entity_labels.displayname"));
# -- put in an array based on the region
$va_member_inst_by_region = array();
if ($qr_member_institutions->numHits() > 0) {
    while ($qr_member_institutions->nextHit()) {
        $va_member_inst_by_region[$qr_member_institutions->get("mem_inst_region", array('convertCodesToDisplayText' => true))][$qr_member_institutions->get("entity_id")] = caNavLink($this->request, join("; ", $qr_member_institutions->getDisplayLabels()), '', 'Detail', 'Entity', 'Show', array('entity_id' => $qr_member_institutions->get("entity_id")));
    }
}
ksort($va_member_inst_by_region);
?>
<div id='pageBody'>
	<div class="imageRightCol">
<?php 
print $this->render("About/sideNav.php");
?>
		<img src="<?php 
print $this->request->getThemeUrlPath();
?>
/graphics/novamuse/hope-digby.jpg">
		<div class="caption">Photo credit: Sheryl Stanton, Admiral Digby Museum</div><br/>
		<img src="<?php 
print $this->request->getThemeUrlPath();
?>
/graphics/novamuse/AntigonishHeritageMuseum.jpg">
		<div class="caption">Antigonish Heritage Museum</div><br/>
 * GNU General Public License. (http://www.gnu.org/copyleft/gpl.html). See
 * the "license.txt" file for details, or visit the CollectiveAccess web site at
 * http://www.CollectiveAccess.org
 *
 * ----------------------------------------------------------------------
 */
$t_object = $this->getVar('t_item');
$vn_object_id = $t_object->get('object_id');
$vs_title = $this->getVar('label');
$t_rep = $this->getVar('t_primary_rep');
$vs_display_version = $this->getVar('primary_rep_display_version');
$va_display_options = $this->getVar('primary_rep_display_options');
$va_access_values = $this->getVar('access_values');
# -- get the various object types
$o_lists = new ca_lists();
$vn_fond_id = $o_lists->getItemIDFromList('object_types', 'fonds');
$vn_sub_fond_id = $o_lists->getItemIDFromList('object_types', 'sub_fonds');
$vn_series_id = $o_lists->getItemIDFromList('object_types', 'series');
?>
	
	<div id="detailBody">		
		<div id="leftCol" >
			<!--img src="<?php 
print $this->request->getThemeUrlPath();
?>
/graphics/city/city-archives.jpg" alt="" title="" /-->
			<div class="maincol">
				
				<h1>City Archives</h1>
		
		<div id="pageNav">
/**
 * Perform mapping of extracted media metadata to CollectiveAccess bundles.
 *
 * @param BundlableLabelableBaseModelWithAttributes $po_instance Model instance to insert extracted metadata into
 * @param array $pa_metadata Extracted metadata
 * @param int $pn_locale_id The current locale as a numeric locale_id
 * @return bool True extracted metadata was mapped and the model changed, false if no change was made to the model
 */
function caExtractEmbeddedMetadata($po_instance, $pa_metadata, $pn_locale_id)
{
    if (!is_array($pa_metadata)) {
        return false;
    }
    $vb_did_mapping = false;
    if (!($vs_media_metadata_config = $po_instance->getAppConfig()->get('media_metadata'))) {
        return false;
    }
    $o_metadata_config = Configuration::load($vs_media_metadata_config);
    $va_mappings = $o_metadata_config->getAssoc('import_mappings');
    $vs_tablename = $po_instance->tableName();
    // set extracted georef?
    $va_georef_elements = $o_metadata_config->getList('extract_embedded_exif_georeferencing_to');
    $va_georef_containers = $o_metadata_config->getAssoc('extract_embedded_exif_georeferencing_to_container');
    $va_date_elements = $o_metadata_config->getList('extract_embedded_exif_creation_date_to');
    $va_date_containers = $o_metadata_config->getAssoc('extract_embedded_exif_creation_date_to_container');
    if (isset($pa_metadata['EXIF']) && is_array($pa_metadata['EXIF']) && (is_array($va_georef_elements) && sizeof($va_georef_elements) || is_array($va_georef_containers) && sizeof($va_georef_containers) || is_array($va_date_elements) && sizeof($va_date_elements) || is_array($va_date_containers) && sizeof($va_date_containers))) {
        $va_exif_data = $pa_metadata['EXIF'];
        if (is_array($va_georef_elements)) {
            if (is_array($va_coords = caParseEXIFLatLong($va_exif_data))) {
                foreach ($va_georef_elements as $vs_element) {
                    $va_tmp = explode('.', $vs_element);
                    $po_instance->addAttribute(array($va_tmp[1] => "[" . $va_coords['latitude'] . ", " . $va_coords['longitude'] . "]", 'locale_id' => $pn_locale_id), $va_tmp[1]);
                }
                $vb_did_mapping = true;
            }
        }
        if (is_array($va_georef_containers)) {
            if (is_array($va_coords = caParseEXIFLatLong($va_exif_data))) {
                foreach ($va_georef_containers as $vs_container => $va_info) {
                    $va_tmp = explode('.', $vs_container);
                    $vs_value_element = array_pop(explode('.', $va_info['value']));
                    $va_data = array($vs_value_element => "[" . $va_coords['latitude'] . ", " . $va_coords['longitude'] . "]", 'locale_id' => $pn_locale_id);
                    if (isset($va_info['map']) && is_array($va_info['map'])) {
                        foreach ($va_info['map'] as $vs_sub_element => $vs_value) {
                            $va_tmp2 = explode('.', $vs_sub_element);
                            $vs_sub_element = array_pop($va_tmp2);
                            if ($t_element = $po_instance->_getElementInstance($vs_sub_element)) {
                                switch ($t_element->get('datatype')) {
                                    case 3:
                                        // List
                                        $t_list = new ca_lists();
                                        $va_data[$vs_sub_element] = $t_list->getItemIDFromList($t_element->get('list_id'), $vs_value);
                                        break;
                                    default:
                                        $va_data[$vs_sub_element] = $vs_value;
                                        break;
                                }
                            }
                        }
                    }
                    $po_instance->addAttribute($va_data, $va_tmp[1]);
                }
                $vb_did_mapping = true;
            }
        }
        if (is_array($va_date_elements)) {
            if (($vs_raw_date = $va_exif_data['IFD0']['DateTimeOriginal']) || ($vs_raw_date = $va_exif_data['EXIF']['DateTimeOriginal']) || ($vs_raw_date = $va_exif_data['ExifIFD']['DateTimeOriginal'])) {
                $va_date_tmp = preg_split('![: ]+!', $vs_raw_date);
                $vs_date = $va_date_tmp[0] . '-' . $va_date_tmp[1] . '-' . $va_date_tmp[2] . 'T' . $va_date_tmp[3] . ':' . $va_date_tmp[4] . ':' . $va_date_tmp[5];
                foreach ($va_date_elements as $vs_element) {
                    $va_tmp = explode('.', $vs_element);
                    if (strlen($po_instance->get($vs_element)) > 0) {
                        $po_instance->addAttribute(array($va_tmp[1] => $vs_date, 'locale_id' => $pn_locale_id), $va_tmp[1]);
                    } else {
                        $po_instance->replaceAttribute(array($va_tmp[1] => $vs_date, 'locale_id' => $pn_locale_id), $va_tmp[1]);
                    }
                }
                $vb_did_mapping = true;
            }
        }
        if (is_array($va_date_containers)) {
            $t_list = new ca_lists();
            if (($vs_raw_date = $va_exif_data['IFD0']['DateTimeOriginal']) || ($vs_raw_date = $va_exif_data['EXIF']['DateTimeOriginal']) || ($vs_raw_date = $va_exif_data['ExifIFD']['DateTimeOriginal'])) {
                $va_date_tmp = preg_split('![: ]+!', $vs_raw_date);
                $vs_date = $va_date_tmp[0] . '-' . $va_date_tmp[1] . '-' . $va_date_tmp[2] . 'T' . $va_date_tmp[3] . ':' . $va_date_tmp[4] . ':' . $va_date_tmp[5];
                foreach ($va_date_containers as $vs_container => $va_info) {
                    $va_tmp = explode('.', $vs_container);
                    $vs_value_element = array_pop(explode('.', $va_info['value']));
                    $va_data = array($vs_value_element => $vs_date, 'locale_id' => $pn_locale_id);
                    if (isset($va_info['map']) && is_array($va_info['map'])) {
                        foreach ($va_info['map'] as $vs_sub_element => $vs_value) {
                            $va_tmp2 = explode('.', $vs_sub_element);
                            $vs_sub_element = array_pop($va_tmp2);
                            if ($t_element = $po_instance->_getElementInstance($vs_sub_element)) {
                                switch ($t_element->get('datatype')) {
                                    case 3:
                                        // List
                                        $va_data[$vs_sub_element] = $t_list->getItemIDFromList($t_element->get('list_id'), $vs_value);
                                        break;
                                    default:
                                        $va_data[$vs_sub_element] = $vs_value;
                                        break;
                                }
                            }
                        }
                    }
                    $po_instance->addAttribute($va_data, $va_tmp[1]);
                }
                $vb_did_mapping = true;
            }
        }
    }
    if (!isset($va_mappings[$po_instance->tableName()])) {
        return $vb_did_mapping;
    }
    $va_mapping = $va_mappings[$vs_tablename];
    $vs_type = $po_instance->getTypeCode();
    if (isset($va_mapping[$vs_type]) && is_array($va_mapping[$vs_type])) {
        $va_mapping = $va_mapping[$vs_type];
    } else {
        if (isset($va_mapping['__default__']) && is_array($va_mapping['__default__'])) {
            $va_mapping = $va_mapping['__default__'];
        } else {
            return $vb_did_mapping;
        }
    }
    foreach ($va_mapping as $vs_metadata => $va_attr) {
        $va_tmp = explode(":", $vs_metadata);
        $vs_delimiter = caGetOption('delimiter', $va_attr, false);
        foreach ($va_attr as $vs_attr) {
            if ($vs_attr == 'delimiter') {
                continue;
            }
            $va_metadata =& $pa_metadata;
            foreach ($va_tmp as $vs_el) {
                if (isset($va_metadata[$vs_el])) {
                    $va_metadata =& $va_metadata[$vs_el];
                } else {
                    continue 2;
                }
            }
            if (is_array($va_metadata)) {
                $va_metadata = join(";", $va_metadata);
            }
            if (!is_int($va_metadata)) {
                // pass ints through for values like WhiteBalance = 0
                if (!trim($va_metadata)) {
                    continue 2;
                }
            }
            if (!caSeemsUTF8($va_metadata)) {
                $va_metadata = caEncodeUTF8Deep($va_metadata);
            }
            $va_tmp2 = explode(".", $vs_attr);
            switch ($va_tmp2[0]) {
                case 'preferred_labels':
                    $po_instance->replaceLabel(array($va_tmp2[1] => $va_metadata), $pn_locale_id, null, true);
                    break;
                case 'nonpreferred_labels':
                    $po_instance->replaceLabel(array($va_tmp2[1] => $va_metadata), $pn_locale_id, null, false);
                    break;
                default:
                    if ($po_instance->hasField($vs_attr)) {
                        $po_instance->set($vs_attr, $va_metadata);
                    } else {
                        // try as attribute
                        if (sizeof($va_tmp2) == 2) {
                            // format ca_objects.foo, we only want "foo"
                            if ($vs_delimiter) {
                                $va_m = explode($vs_delimiter, $va_metadata);
                                $po_instance->removeAttributes($va_tmp2[1]);
                                foreach ($va_m as $vs_m) {
                                    $po_instance->addAttribute(array($va_tmp2[1] => trim($vs_m), 'locale_id' => $pn_locale_id), $va_tmp2[1]);
                                }
                            } else {
                                $po_instance->replaceAttribute(array($va_tmp2[1] => $va_metadata, 'locale_id' => $pn_locale_id), $va_tmp2[1]);
                            }
                        }
                    }
            }
            $vb_did_mapping = true;
        }
    }
    return $vb_did_mapping;
}
 /**
  * Returns content for overlay containing details for object representation
  */
 private function _renderMediaView($ps_view_name, $ps_media_context)
 {
     $pn_object_id = $this->request->getParameter('object_id', pInteger);
     $pn_representation_id = $this->request->getParameter('representation_id', pInteger);
     $pn_year = $this->request->getParameter('year', pInteger);
     $this->view->setVar("year", $pn_year);
     $va_periods = $this->ops_periods;
     $this->view->setVar('object_id', $pn_object_id);
     $t_object = new ca_objects($pn_object_id);
     # --- get caption and photocredit
     $this->view->setVar("caption", $t_object->get("description"));
     $this->view->setVar("photographer", $t_object->get("provenance"));
     $t_rep = new ca_object_representations($pn_representation_id);
     $this->view->setVar('representation_id', $pn_representation_id);
     $this->view->setVar('t_object_representation', $t_rep);
     if ($this->request->config->get("dont_enforce_access_settings")) {
         $va_access_values = array();
     } else {
         $va_access_values = caGetUserAccessValues($this->request);
     }
     if (!$t_object->getPrimaryKey()) {
         die("Invalid object_id");
     }
     if (!$t_rep->getPrimaryKey()) {
         die("Invalid representation_id");
     }
     if (sizeof($va_access_values) && !in_array($t_object->get('access'), $va_access_values)) {
         die("Invalid object_id");
     }
     if (sizeof($va_access_values) && !in_array($t_rep->get('access'), $va_access_values)) {
         die("Invalid rep_id");
     }
     $this->view->setVar('t_display_rep', $t_rep);
     // Get media for display using configured rules
     $va_rep_display_info = caGetMediaDisplayInfo($ps_media_context, $t_rep->getMediaInfo('media', 'INPUT', 'MIMETYPE'));
     // set version
     $this->view->setVar('display_version', $va_rep_display_info['display_version']);
     // set other options
     $this->view->setVar('display_options', $va_rep_display_info);
     // Get all representation as icons for navigation
     # --- do a search for all chronology image objects
     # --- determine the period from the year
     foreach ($va_periods as $i => $va_per_info) {
         if ($pn_year >= $va_per_info["start"] && $pn_year <= $va_per_info["end"]) {
             $vn_period = $i;
             break;
         }
     }
     # --- what is year to search by?
     $vn_y = "";
     if ($va_periods[$vn_period]["displayAllYears"] == 1) {
         $vn_y = $va_periods[$vn_period]["start"] . "-" . $va_periods[$vn_period]["end"];
     } else {
         $vn_y = $pn_year;
     }
     # --- get type is for chron images
     $t_list = new ca_lists();
     $vn_chron_images_type_id = $t_list->getItemIDFromList('object_types', 'chronology_image');
     $o_obj_search = new ObjectSearch();
     $qr_chron_images = $o_obj_search->search("ca_objects.access:1 AND ca_objects.date.parsed_date:\"" . $vn_y . "\" AND ca_objects.type_id:{$vn_chron_images_type_id}", array("sort" => "ca_objects.date.parsed_date", "no_cache" => !$this->opb_cache_searches));
     $va_thumbnails = array();
     if ($qr_chron_images->numHits() > 0) {
         $t_image_objects = new ca_objects();
         $i = 1;
         while ($qr_chron_images->nextHit()) {
             $t_image_objects->load($qr_chron_images->get("ca_objects.object_id"));
             if ($t_primary_rep = $t_image_objects->getPrimaryRepresentationInstance()) {
                 $va_temp = array();
                 if (!sizeof($va_access_values) || in_array($t_primary_rep->get('access'), $va_access_values)) {
                     $va_temp["representation_id"] = $t_primary_rep->get("representation_id");
                     $va_temp["rep_icon"] = $t_primary_rep->getMediaTag('media', 'icon');
                     $va_temp["rep_tiny"] = $t_primary_rep->getMediaTag('media', 'tinyicon');
                     $va_temp["object_id"] = $qr_chron_images->get("ca_objects.object_id");
                     $va_thumbnails[$qr_chron_images->get("ca_objects.object_id")] = $va_temp;
                     if ($vn_getNext == 1) {
                         $this->view->setVar("next_object_id", $qr_chron_images->get("object_id"));
                         $this->view->setVar("next_representation_id", $t_primary_rep->get("representation_id"));
                         $vn_getNext = 0;
                     }
                     if ($qr_chron_images->get("object_id") == $pn_object_id) {
                         $this->view->setVar("representation_index", $i);
                         $this->view->setVar("previous_object_id", $vn_prev_obj_id);
                         $this->view->setVar("previous_representation_id", $vn_prev_rep_id);
                         $vn_getNext = 1;
                     }
                     $vn_prev_obj_id = $qr_chron_images->get("object_id");
                     $vn_prev_rep_id = $t_primary_rep->get("representation_id");
                     $i++;
                 }
             }
         }
     }
     $this->view->setVar('reps', $va_thumbnails);
     return $this->render("Chronology/{$ps_view_name}.php");
 }
 * This source code is free and modifiable under the terms of 
 * GNU General Public License. (http://www.gnu.org/copyleft/gpl.html). See
 * the "license.txt" file for details, or visit the CollectiveAccess web site at
 * http://www.CollectiveAccess.org
 *
 * ----------------------------------------------------------------------
 */
$va_facet_list = $this->getVar('facet_list');
$vs_facet_name = $this->getVar("facet_name");
$vs_key = $this->getVar("key");
$vs_browse_type = $this->getVar("browse_type");
$vs_link_to = $this->request->getParameter('linkTo', pString);
$va_links = array();
if ($vs_facet_name == "place_facet_hier") {
    $t_lists = new ca_lists();
    $va_place_type_ids_to_exclude = array($t_lists->getItemIDFromList("place_types", "city"), $t_lists->getItemIDFromList("place_types", "basin"), $t_lists->getItemIDFromList("place_types", "other"), $t_lists->getItemIDFromList("place_types", "locality"));
}
foreach ($va_facet_list as $vn_key => $va_facet) {
    if ($vs_facet_name == "place_facet_hier") {
        require_once __CA_MODELS_DIR__ . "/ca_places.php";
        $va_child_ids = array_keys($va_facet);
        array_shift($va_child_ids);
        if (sizeof($va_child_ids) > 0) {
            $q_children = ca_places::createResultSet($va_child_ids);
            $va_children_type_ids = array();
            if ($q_children->numHits()) {
                while ($q_children->nextHit()) {
                    $va_children_type_ids[$q_children->get("place_id")] = $q_children->get("type_id");
                }
            }
        }
Example #26
0
 /**
  * Returns list of sets subject to options
  *
  * @param array $pa_options Array of options. Supported options are:
  *			table - if set, list is restricted to sets that can contain the specified item. You can pass a table name or number. If omitted sets containing any content will be returned.
  *			setType - Restricts returned sets to those of the specified type. You can pass a type_id or list item code for the set type. If omitted sets are returned regardless of type.
  *			user_id - Restricts returned sets to those accessible by the current user. If omitted then all sets, regardless of access are returned.
  *			access - Restricts returned sets to those with at least the specified access level for the specified user. If user_id is omitted then this option has no effect. If user_id is set and this option is omitted, then sets where the user has at least read access will be returned. 
  *			checkAccess - Restricts returned sets to those with an public access level with the specified values. If omitted sets are returned regardless of public access (ca_sets.access) value. Can be a single value or array if you wish to filter on multiple public access values.
  *			row_id = if set to an integer only sets containing the specified row are returned
  *			setIDsOnly = if set to true only set_id values are returned, in a simple array
  *			omitCounts = 
  *			all = 
  *			allUsers =
  *			publicUsers =
  *			name = 
  * @return array A list of sets keyed by set_id and then locale_id. Keys for the per-locale value array include: set_id, set_code, status, public access, owner user_id, content table_num, set type_id, set name, number of items in the set (item_count), set type name for display and set content type name for display. If setIDsOnly option is set then a simple array of set_id values is returned instead.
  */
 public function getSets($pa_options = null)
 {
     if (!is_array($pa_options)) {
         $pa_options = array();
     }
     $pm_table_name_or_num = isset($pa_options['table']) ? $pa_options['table'] : null;
     $pm_type = isset($pa_options['setType']) ? $pa_options['setType'] : null;
     $pn_user_id = isset($pa_options['user_id']) ? (int) $pa_options['user_id'] : null;
     $pn_access = isset($pa_options['access']) ? $pa_options['access'] : null;
     $pb_set_ids_only = isset($pa_options['setIDsOnly']) ? (bool) $pa_options['setIDsOnly'] : false;
     $pb_omit_counts = isset($pa_options['omitCounts']) ? (bool) $pa_options['omitCounts'] : false;
     $ps_set_name = isset($pa_options['name']) ? $pa_options['name'] : null;
     $pn_row_id = isset($pa_options['row_id']) && (int) $pa_options['row_id'] ? (int) $pa_options['row_id'] : null;
     $pa_public_access = isset($pa_options['checkAccess']) ? $pa_options['checkAccess'] : null;
     if ($pa_public_access && is_numeric($pa_public_access) && !is_array($pa_public_access)) {
         $pa_public_access = array($pa_public_access);
     }
     for ($vn_i = 0; $vn_i < sizeof($pa_public_access); $vn_i++) {
         $pa_public_access[$vn_i] = intval($pa_public_access[$vn_i]);
     }
     if ($pm_table_name_or_num && !($vn_table_num = $this->_getTableNum($pm_table_name_or_num))) {
         return null;
     }
     $va_extra_joins = array();
     $o_db = $this->getDb();
     $va_sql_wheres = array("(cs.deleted = 0)");
     $va_sql_params = array();
     if ($vn_table_num) {
         $va_sql_wheres[] = "(cs.table_num = ?)";
         $va_sql_params[] = (int) $vn_table_num;
     }
     if ($pb_set_ids_only) {
         $va_sql_selects = array('cs.set_id');
     } else {
         $va_sql_selects = array('cs.set_id', 'cs.set_code', 'cs.status', 'cs.access', 'cs.user_id', 'cs.table_num', 'cs.type_id', 'csl.label_id', 'csl.name', 'csl.locale_id', 'l.language', 'l.country', 'u.fname', 'u.lname', 'u.email');
     }
     if (isset($pa_options['all']) && $pa_options['all']) {
         $va_sql_wheres[] = "(cs.user_id IN (SELECT user_id FROM ca_users WHERE userclass != 255))";
     } elseif (isset($pa_options['allUsers']) && $pa_options['allUsers']) {
         $va_sql_wheres[] = "(cs.user_id IN (SELECT user_id FROM ca_users WHERE userclass = 0))";
     } elseif (isset($pa_options['publicUsers']) && $pa_options['publicUsers']) {
         $va_sql_wheres[] = "(cs.user_id IN (SELECT user_id FROM ca_users WHERE userclass = 1))";
     } else {
         if ($pn_user_id && !$this->getAppConfig()->get('dont_enforce_access_control_for_ca_sets')) {
             $o_dm = $this->getAppDatamodel();
             $t_user = $o_dm->getInstanceByTableName('ca_users', true);
             $t_user->load($pn_user_id);
             if ($t_user->getPrimaryKey()) {
                 $vs_access_sql = $pn_access > 0 ? " AND (access >= " . intval($pn_access) . ")" : "";
                 if (is_array($va_groups = $t_user->getUserGroups()) && sizeof($va_groups)) {
                     $vs_sql = "(\n\t\t\t\t\t\t\t(cs.user_id = " . intval($pn_user_id) . ") OR \n\t\t\t\t\t\t\t(cs.set_id IN (\n\t\t\t\t\t\t\t\t\tSELECT set_id \n\t\t\t\t\t\t\t\t\tFROM ca_sets_x_user_groups \n\t\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\t\tgroup_id IN (" . join(',', array_keys($va_groups)) . ") {$vs_access_sql}\n\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t\t (sdatetime IS NULL AND edatetime IS NULL)\n\t\t\t\t\t\t\t\t\t\t\t OR \n\t\t\t\t\t\t\t\t\t\t\t (\n\t\t\t\t\t\t\t\t\t\t\t\tsdatetime <= " . time() . " AND edatetime >= " . time() . "\n\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)";
                 } else {
                     $vs_sql = "(cs.user_id = {$pn_user_id})";
                 }
                 $vs_sql .= " OR (cs.set_id IN (\n\t\t\t\t\t\t\t\t\t\t\tSELECT set_id \n\t\t\t\t\t\t\t\t\t\t\tFROM ca_sets_x_users \n\t\t\t\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\t\t\t\tuser_id = {$pn_user_id} {$vs_access_sql}\n\t\t\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t\t\t\t (sdatetime IS NULL AND edatetime IS NULL)\n\t\t\t\t\t\t\t\t\t\t\t\t\t OR \n\t\t\t\t\t\t\t\t\t\t\t\t\t (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsdatetime <= " . time() . " AND edatetime >= " . time() . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t)";
                 $va_sql_wheres[] = "({$vs_sql})";
             }
         }
     }
     if (!is_null($pa_public_access) && is_array($pa_public_access) && sizeof($pa_public_access)) {
         $va_sql_wheres[] = "(cs.access IN (?))";
         $va_sql_params[] = $pa_public_access;
     }
     if (isset($pm_type) && $pm_type) {
         if (is_numeric($pm_type)) {
             $va_sql_wheres[] = "(cs.type_id = ?)";
             $va_sql_params[] = (int) $pm_type;
         } else {
             # --- look up code of set type
             $t_list = new ca_lists();
             $vn_type_id = $t_list->getItemIDFromList("set_types", $pm_type);
             if ($vn_type_id) {
                 $va_sql_wheres[] = "(cs.type_id = ?)";
                 $va_sql_params[] = (int) $vn_type_id;
             }
         }
     }
     if ($pn_row_id > 0) {
         $va_sql_wheres[] = "((csi.row_id = ?) AND (csi.table_num = ?))";
         $va_extra_joins[] = "INNER JOIN ca_set_items AS csi ON cs.set_id = csi.set_id";
         $va_sql_selects[] = 'csi.item_id';
         $va_sql_params[] = (int) $pn_row_id;
         $va_sql_params[] = (int) $vn_table_num;
     }
     if ($ps_set_name) {
         $va_sql_wheres[] = "(csl.name = ?)";
         $va_sql_params[] = (string) $ps_set_name;
     }
     if (!$pb_set_ids_only && !$pb_omit_counts) {
         // get set item counts
         $qr_table_nums = $o_db->query("\n\t\t\t\tSELECT DISTINCT cs.table_num \n\t\t\t\tFROM ca_sets cs\n\t\t\t\tINNER JOIN ca_set_items AS csi ON cs.set_id = csi.set_id\n\t\t\t\t" . (sizeof($va_sql_wheres) ? 'WHERE ' : '') . "\n\t\t\t\t" . join(' AND ', $va_sql_wheres) . "\n\t\t\t", $va_sql_params);
         $va_item_counts = array();
         while ($qr_table_nums->nextRow()) {
             $o_dm = $this->getAppDatamodel();
             $t_instance = $o_dm->getInstanceByTableNum($vn_table_num = (int) $qr_table_nums->get('table_num'), true);
             if (!$t_instance) {
                 continue;
             }
             $va_item_wheres = $va_sql_wheres;
             $va_item_wheres[] = "(cs.table_num = {$vn_table_num})";
             if ($t_instance->hasField('deleted')) {
                 $va_item_wheres[] = "(t.deleted = 0)";
             }
             $qr_res = $o_db->query("\n\t\t\t\t\tSELECT cs.set_id, count(distinct row_id) item_count\n\t\t\t\t\tFROM ca_sets cs\n\t\t\t\t\tINNER JOIN ca_set_items AS csi ON cs.set_id = csi.set_id\n\t\t\t\t\tINNER JOIN " . $t_instance->tableName() . " AS t ON t." . $t_instance->primaryKey() . " = csi.row_id\n\t\t\t\t\t" . (sizeof($va_item_wheres) ? 'WHERE ' : '') . "\n\t\t\t\t\t" . join(' AND ', $va_item_wheres) . "\n\t\t\t\t\tGROUP BY cs.set_id\n\t\t\t\t", $va_sql_params);
             while ($qr_res->nextRow()) {
                 $va_item_counts[(int) $qr_res->get('set_id')] = (int) $qr_res->get('item_count');
             }
         }
         // get sets
         $qr_res = $o_db->query("\n\t\t\t\tSELECT " . join(', ', $va_sql_selects) . "\n\t\t\t\tFROM ca_sets cs\n\t\t\t\tLEFT JOIN ca_set_labels AS csl ON cs.set_id = csl.set_id\n\t\t\t\tLEFT JOIN ca_locales AS l ON csl.locale_id = l.locale_id\n\t\t\t\tINNER JOIN ca_users AS u ON cs.user_id = u.user_id\n\t\t\t\t" . join("\n", $va_extra_joins) . "\n\t\t\t\t" . (sizeof($va_sql_wheres) ? 'WHERE ' : '') . "\n\t\t\t\t" . join(' AND ', $va_sql_wheres) . "\n\t\t\t\tORDER BY csl.name\n\t\t\t", $va_sql_params);
         $va_sets = array();
         $o_dm = $this->getAppDatamodel();
         $va_type_name_cache = array();
         $t_list = new ca_lists();
         while ($qr_res->nextRow()) {
             $vn_table_num = $qr_res->get('table_num');
             if (!isset($va_type_name_cache[$vn_table_num]) || !($vs_set_type = $va_type_name_cache[$vn_table_num])) {
                 $vs_set_type = $va_type_name_cache[$vn_table_num] = $this->getSetContentTypeName($vn_table_num, array('number' => 'plural'));
             }
             $vs_type = $t_list->getItemFromListForDisplayByItemID('set_types', $qr_res->get('type_id'));
             $va_sets[$qr_res->get('set_id')][$qr_res->get('locale_id')] = array_merge($qr_res->getRow(), array('item_count' => intval($va_item_counts[$qr_res->get('set_id')]), 'set_content_type' => $vs_set_type, 'set_type' => $vs_type));
         }
         return $va_sets;
     } else {
         if ($pb_set_ids_only) {
             // get sets
             $qr_res = $o_db->query("\n\t\t\t\t\tSELECT " . join(', ', $va_sql_selects) . "\n\t\t\t\t\tFROM ca_sets cs\n\t\t\t\t\tINNER JOIN ca_users AS u ON cs.user_id = u.user_id\n\t\t\t\t\tLEFT JOIN ca_set_labels AS csl ON cs.set_id = csl.set_id\n\t\t\t\t\t" . join("\n", $va_extra_joins) . "\n\t\t\t\t\t" . (sizeof($va_sql_wheres) ? 'WHERE ' : '') . "\n\t\t\t\t\t" . join(' AND ', $va_sql_wheres) . "\n\t\t\t\t", $va_sql_params);
             return $qr_res->getAllFieldValues("set_id");
         } else {
             $qr_res = $o_db->query("\n\t\t\t\t\tSELECT " . join(', ', $va_sql_selects) . "\n\t\t\t\t\tFROM ca_sets cs\n\t\t\t\t\tINNER JOIN ca_users AS u ON cs.user_id = u.user_id\n\t\t\t\t\tLEFT JOIN ca_set_labels AS csl ON cs.set_id = csl.set_id\n\t\t\t\t\tLEFT JOIN ca_locales AS l ON csl.locale_id = l.locale_id\n\t\t\t\t\t" . join("\n", $va_extra_joins) . "\n\t\t\t\t\t" . (sizeof($va_sql_wheres) ? 'WHERE ' : '') . "\n\t\t\t\t\t" . join(' AND ', $va_sql_wheres) . "\n\t\t\t\t", $va_sql_params);
             $t_list = new ca_lists();
             while ($qr_res->nextRow()) {
                 $vn_table_num = $qr_res->get('table_num');
                 if (!isset($va_type_name_cache[$vn_table_num]) || !($vs_set_type = $va_type_name_cache[$vn_table_num])) {
                     $vs_set_type = $va_type_name_cache[$vn_table_num] = $this->getSetContentTypeName($vn_table_num, array('number' => 'plural'));
                 }
                 $vs_type = $t_list->getItemFromListForDisplayByItemID('set_types', $qr_res->get('type_id'));
                 $va_sets[$qr_res->get('set_id')][$qr_res->get('locale_id')] = array_merge($qr_res->getRow(), array('item_count' => intval($va_item_counts[$qr_res->get('set_id')]), 'set_content_type' => $vs_set_type, 'set_type' => $vs_type));
             }
             return $va_sets;
         }
     }
 }
 /** 
  * Returns labels associated with this row. By default all labels - preferred and non-preferred, and from all locales -
  * are returned. You can limit the returned labels to specified locales by passing a list of locale_ids (numeric ids, *not* locale codes)
  * in $pn_locale_ids. Similarly you can limit return labels to preferred on non-preferred by setting $pn_mode to __CA_LABEL_TYPE_PREFERRED__
  * or __CA_LABEL_TYPE_NONPREFERRED__
  *
  * getLabels() returns an associated array keyed by the primary key of the item the label is attached to; each value is an array keyed by locale_id, the values of which
  * is a list of associative arrays with the label table data. This return format is designed to be digested by the displayHelper function caExtractValuesByUserLocale()
  *
  * @param array $pa_locale_ids
  * @param int $pn_mode
  * @param boolean $pb_dont_cache
  * @param array $pa_options Array of options. Supported options are:
  *			row_id = The row_id to return labels for. If omitted the id of the currently loaded row is used. If row_id is not set and now row is loaded then getLabels() will return null.
  *			restrict_to_types = an optional array of numeric type ids or alphanumeric type identifiers to restrict the returned labels to. The types are list items in a list specified in app.conf (or, if not defined there, by hardcoded constants in the model)
  *			restrictToTypes = synonym for restrict_to_types
  *			extractValuesByUserLocale = if set returned array of values is filtered to include only values appropriate for the current user's locale
  *			forDisplay = if true, a simple list of labels ready for display is returned; implies the extractValuesByUserLocale option
  *
  * @return array List of labels
  */
 public function getLabels($pa_locale_ids = null, $pn_mode = __CA_LABEL_TYPE_ANY__, $pb_dont_cache = true, $pa_options = null)
 {
     if (isset($pa_options['restrictToTypes']) && (!isset($pa_options['restrict_to_types']) || !$pa_options['restrict_to_types'])) {
         $pa_options['restrict_to_types'] = $pa_options['restrictToTypes'];
     }
     if (!($vn_id = $this->getPrimaryKey()) && !(isset($pa_options['row_id']) && ($vn_id = $pa_options['row_id']))) {
         return null;
     }
     if (isset($pa_options['forDisplay']) && $pa_options['forDisplay']) {
         $pa_options['extractValuesByUserLocale'] = true;
     }
     if ($pn_mode == __CA_LABEL_TYPE_ANY__ && caGetBundleAccessLevel($this->tableName(), 'preferred_labels') == __CA_BUNDLE_ACCESS_NONE__) {
         $pn_mode = __CA_LABEL_TYPE_NONPREFERRED__;
     }
     if ($pn_mode == __CA_LABEL_TYPE_ANY__ && caGetBundleAccessLevel($this->tableName(), 'nonpreferred_labels') == __CA_BUNDLE_ACCESS_NONE__) {
         $pn_mode = __CA_LABEL_TYPE_PREFERRED__;
     }
     if ($pn_mode == __CA_LABEL_TYPE_PREFERRED__ && caGetBundleAccessLevel($this->tableName(), 'preferred_labels') == __CA_BUNDLE_ACCESS_NONE__) {
         return null;
     }
     if ($pn_mode == __CA_LABEL_TYPE_NONPREFERRED__ && caGetBundleAccessLevel($this->tableName(), 'nonpreferred_labels') == __CA_BUNDLE_ACCESS_NONE__) {
         return null;
     }
     if (!is_array($pa_options)) {
         $pa_options = array();
     }
     $vs_cache_key = caMakeCacheKeyFromOptions(array_merge($pa_options, array('table_name' => $this->tableName(), 'id' => $vn_id, 'mode' => (int) $pn_mode)));
     if (!$pb_dont_cache && is_array($va_tmp = LabelableBaseModelWithAttributes::$s_label_cache[$this->tableName()][$vn_id][$vs_cache_key])) {
         return $va_tmp;
     }
     if (!($t_label = $this->_DATAMODEL->getInstanceByTableName($this->getLabelTableName(), true))) {
         return null;
     }
     if ($this->inTransaction()) {
         $o_trans = $this->getTransaction();
         $t_label->setTransaction($o_trans);
     }
     $vs_label_where_sql = 'WHERE (l.' . $this->primaryKey() . ' = ?)';
     $vs_locale_join_sql = '';
     if ($pa_locale_ids) {
         $vs_label_where_sql .= ' AND (l.locale_id IN (' . join(',', $pa_locale_ids) . '))';
     }
     $vs_locale_join_sql = 'INNER JOIN ca_locales AS loc ON loc.locale_id = l.locale_id';
     $vs_list_code = null;
     if ($t_label->hasField('is_preferred')) {
         switch ($pn_mode) {
             case __CA_LABEL_TYPE_PREFERRED__:
                 $vs_list_code = $this->_CONFIG->get($this->tableName() . '_preferred_label_type_list');
                 $vs_label_where_sql .= ' AND (l.is_preferred = 1)';
                 break;
             case __CA_LABEL_TYPE_NONPREFERRED__:
                 $vs_list_code = $this->_CONFIG->get($this->tableName() . '_nonpreferred_label_type_list');
                 $vs_label_where_sql .= ' AND (l.is_preferred = 0)';
                 break;
             default:
                 $vs_list_code = $this->_CONFIG->get($this->tableName() . '_preferred_label_type_list');
                 break;
         }
         if (!$vs_list_code) {
             if ($t_label_instance = $this->getLabelTableInstance()) {
                 $vs_list_code = $t_label_instance->getFieldInfo('type_id', 'LIST_CODE');
             }
         }
     }
     // limit related items to a specific type
     $vs_restrict_to_type_sql = '';
     if (isset($pa_options['restrict_to_type']) && $pa_options['restrict_to_type']) {
         if (!isset($pa_options['restrict_to_types']) || !is_array($pa_options['restrict_to_types'])) {
             $pa_options['restrict_to_types'] = array();
         }
         $pa_options['restrict_to_types'][] = $pa_options['restrict_to_type'];
     }
     if (isset($pa_options['restrict_to_types']) && $pa_options['restrict_to_types'] && is_array($pa_options['restrict_to_types']) && $vs_list_code) {
         $t_list = new ca_lists();
         $t_list_item = new ca_list_items();
         $va_ids = array();
         foreach ($pa_options['restrict_to_types'] as $vs_type) {
             if (!($vn_restrict_to_type_id = (int) $t_list->getItemIDFromList($vs_list_code, $vs_type))) {
                 $vn_restrict_to_type_id = (int) $vs_type;
             }
             if ($vn_restrict_to_type_id) {
                 $va_children = $t_list_item->getHierarchyChildren($vn_restrict_to_type_id, array('idsOnly' => true));
                 $va_ids = array_merge($va_ids, $va_children);
                 $va_ids[] = $vn_restrict_to_type_id;
             }
         }
         if (sizeof($va_ids) > 0) {
             $vs_restrict_to_type_sql = ' AND l.type_id IN (' . join(',', $va_ids) . ')';
         }
     }
     $o_db = $this->getDb();
     $qr_res = $o_db->query("\n \t\t\t\tSELECT l.*, loc.country locale_country, loc.language locale_language, loc.dialect locale_dialect, loc.name locale_name\n \t\t\t\tFROM " . $this->getLabelTableName() . " l\n \t\t\t\t{$vs_locale_join_sql}\n \t\t\t\t{$vs_label_where_sql}\n \t\t\t\t{$vs_restrict_to_type_sql}\n \t\t\t\tORDER BY\n \t\t\t\t\tloc.name\n \t\t\t", (int) $vn_id);
     $va_labels = array();
     $t_label->clear();
     while ($qr_res->nextRow()) {
         $va_labels[$vn_id][$qr_res->get('locale_id')][] = array_merge($qr_res->getRow(), array('form_element' => $t_label->htmlFormElement($this->getLabelDisplayField(), null)));
     }
     if (isset($pa_options['extractValuesByUserLocale']) && $pa_options['extractValuesByUserLocale']) {
         $va_labels = caExtractValuesByUserLocale($va_labels);
     }
     if (isset($pa_options['forDisplay']) && $pa_options['forDisplay']) {
         $vs_display_field = $this->getLabelDisplayField();
         $va_flattened_labels = array();
         foreach ($va_labels as $vn_id => $va_label_list) {
             foreach ($va_label_list as $vn_i => $va_label) {
                 $va_flattened_labels[] = $va_label[$vs_display_field];
             }
         }
         $va_labels = $va_flattened_labels;
     }
     LabelableBaseModelWithAttributes::$s_label_cache[$this->tableName()][$vn_id][$vs_cache_key] = $va_labels;
     return $va_labels;
 }
<?php

$t_object = $this->getVar("item");
$t_lists = new ca_lists();
$va_eggshell_type_ids = array($t_lists->getItemIDFromList("object_types", "fossil"), $t_lists->getItemIDFromList("object_types", "recent"), $t_lists->getItemIDFromList("object_types", "pseudo"), $t_lists->getItemIDFromList("object_types", "associated"));
$va_vertebrate_type_ids = array($t_lists->getItemIDFromList("object_types", "vertebrate"), $t_lists->getItemIDFromList("object_types", "vertebrate_item"), $t_lists->getItemIDFromList("object_types", "vertebrate_cast"), $t_lists->getItemIDFromList("object_types", "ost_specimen"));
$va_track_type_ids = array($t_lists->getItemIDFromList("object_types", "track"), $t_lists->getItemIDFromList("object_types", "track_item"), $t_lists->getItemIDFromList("object_types", "tracing"), $t_lists->getItemIDFromList("object_types", "cast"));
$va_access_values = $this->getVar('access_values');
?>
	<div id="detailBody">
		<div id="pageNav">
<?php 
if ($this->getVar('resultsLink') || $this->getVar("previousLink") || $this->getvar("nextLink")) {
    if ($this->getVar('previousLink')) {
        print $this->getVar('previousLink');
    } else {
        print "&lsaquo; " . _t("Previous");
    }
    if ($this->getVar('resultsLink')) {
        print "&nbsp;&nbsp;&nbsp;" . $this->getVar('resultsLink') . "&nbsp;&nbsp;&nbsp;";
    } else {
        print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    }
    if ($this->getVar('nextLink')) {
        print $this->getVar('nextLink');
    } else {
        print _t("Next") . " &rsaquo;";
    }
}
?>
		</div><!-- end nav -->
Example #29
0
/**
 * Converts the given list of source names or source_ids into an expanded list of numeric source_ids suitable for enforcing source restrictions. Processing
 * includes expansion of sources to include subsources and conversion of any source codes to source_ids.
 *
 * @param mixed $pm_table_name_or_num Table name or number to which sources apply
 * @param array $pa_sources List of source codes and/or source_ids that are the basis of the list
 * @param array $pa_options Array of options:
 * 		dont_include_subsources_in_source_restriction = if set, returned list is not expanded to include subsources
 *		dontIncludeSubsourcesInSourceRestriction = synonym for dont_include_subsources_in_source_restriction
 *
 * @return array List of numeric source_ids
 */
function caMakeSourceIDList($pm_table_name_or_num, $pa_sources, $pa_options = null)
{
    $o_dm = Datamodel::load();
    if (isset($pa_options['dontIncludeSubsourcesInSourceRestriction']) && (!isset($pa_options['dont_include_subsources_in_source_restriction']) || !$pa_options['dont_include_subsources_in_source_restriction'])) {
        $pa_options['dont_include_subsources_in_source_restriction'] = $pa_options['dontIncludeSubsourcesInSourceRestriction'];
    }
    if (isset($pa_options['dont_include_subsources_in_source_restriction']) && $pa_options['dont_include_subsources_in_source_restriction']) {
        $pa_options['noChildren'] = true;
    }
    if (is_numeric($pm_table_name_or_num)) {
        $vs_table_name = $o_dm->getTableName($pm_table_name_or_num);
    } else {
        $vs_table_name = $pm_table_name_or_num;
    }
    $t_instance = $o_dm->getInstanceByTableName($vs_table_name, true);
    if (!$t_instance) {
        return null;
    }
    // bad table
    if (!($vs_source_list_code = $t_instance->getSourceListCode())) {
        return null;
    }
    // table doesn't use sources
    $va_source_ids = array();
    $t_list = new ca_lists();
    $t_item = new ca_list_items();
    $vs_list_code = $t_instance->getSourceListCode();
    foreach ($pa_sources as $vm_source) {
        if (!$vm_source) {
            continue;
        }
        $vn_source_id = null;
        if (is_numeric($vm_source)) {
            $vn_source_id = (int) $vm_source;
        } else {
            $vn_source_id = (int) $t_list->getItemIDFromList($vs_source_list_code, $vm_source);
        }
        if ($vn_source_id && !(isset($pa_options['noChildren']) || $pa_options['noChildren'])) {
            if ($qr_children = $t_item->getHierarchy($vn_source_id, array())) {
                while ($qr_children->nextRow()) {
                    $va_source_ids[$qr_children->get('item_id')] = true;
                }
            }
        } else {
            if ($vn_source_id) {
                $va_source_ids[$vn_source_id] = true;
            }
        }
    }
    return array_keys($va_source_ids);
}
Example #30
0
 /**
  * Set setting value 
  * (you must call insert() or update() to write the settings to the database)
  */
 public function setSetting($ps_setting, $pm_value)
 {
     if (!$this->isValidSetting($ps_setting)) {
         return null;
     }
     $va_setting_info = $this->getSettingInfo($ps_setting);
     if ($va_setting_info['displayType'] == DT_CHECKBOXES) {
         $pm_value = (int) $pm_value;
     }
     if (isset($va_setting_info['useRelationshipTypeList']) && $va_setting_info['useRelationshipTypeList'] || isset($va_setting_info['useList']) && $va_setting_info['useList'] || isset($va_setting_info['showLists']) && $va_setting_info['showLists'] || isset($va_setting_info['showVocabularies']) && $va_setting_info['showVocabularies']) {
         if (!is_array($pm_value)) {
             $pm_value = array($pm_value);
         }
         foreach ($pm_value as $vn_i => $vm_value) {
             if (trim($vm_value) && !is_numeric($vm_value)) {
                 // need to convert codes to ids
                 if ($vs_t = $va_setting_info['useRelationshipTypeList']) {
                     $t_rel = new ca_relationship_types();
                     $pm_value[$vn_i] = $t_rel->getRelationshipTypeID($vs_t, $vm_value);
                 } else {
                     if ($vs_l = $va_setting_info['useList']) {
                         // is a list
                         $t_list = new ca_lists();
                         $pm_value[$vn_i] = $t_list->getItemIDFromList($vs_l, $vm_value);
                     } else {
                         if ($va_setting_info['showLists'] || $va_setting_info['showVocabularies']) {
                             // is a list
                             $t_list = new ca_lists();
                             $vn_list_id = null;
                             if ($t_list->load(array('list_code' => $vm_value))) {
                                 $vn_list_id = $t_list->getPrimaryKey();
                             } else {
                                 if ($t_list->load((int) $vm_value)) {
                                     $vn_list_id = $t_list->getPrimaryKey();
                                 }
                             }
                             if ($vn_list_id) {
                                 $pm_value[$vn_i] = $vn_list_id;
                             }
                         } else {
                             if ($va_setting_info['showSortableBundlesFor']) {
                             }
                         }
                     }
                 }
             }
         }
     }
     $va_settings = $this->getSettings();
     if ($va_setting_info['formatType'] == FT_NUMBER) {
         $pm_value = (double) $pm_value;
     }
     $va_settings[$ps_setting] = $pm_value;
     $this->o_instance->set($this->ops_settings_field, $va_settings);
     return true;
 }