public function Index()
 {
     #
     # User-generated comments, tags and ratings
     #
     $t_siteComments = new SiteComments();
     $va_user_comments = $t_siteComments->getComments(null, true);
     $va_comments = array();
     if (is_array($va_user_comments)) {
         foreach ($va_user_comments as $va_user_comment) {
             $va_comment = array();
             if ($va_user_comment["comment"]) {
                 $va_comment["comment"] = $va_user_comment["comment"];
                 # TODO: format date based on locale
                 $va_comment["date"] = date("n/j/Y", $va_user_comment["created_on"]);
                 $va_comment["created_on"] = $va_user_comment["created_on"];
                 # -- get name of commenter
                 $t_user = new ca_users($va_user_comment["user_id"]);
                 $va_comment["author"] = $t_user->getName();
                 $va_comment["email"] = $va_user_comment["email"];
                 $va_comment["name"] = $va_user_comment["name"];
                 $va_comments[] = $va_comment;
             }
         }
     }
     $this->view->setVar('comments', $va_comments);
     $this->render('Comments/comments_html.php');
 }
 /**
  * Generates detail detail. Will use a view named according to the following convention:
  *		<table_name>_<type_code>_detail_html.php
  *
  * So for example, the detail for objects of type 'artwork' (where 'artwork' is the type code for the artwork object type)
  * the view would be named "ca_objects_artwork_detail_html.php
  *
  * If the type specific view does not exist, then Show() will attemp to use a generic table-wide view name like this:
  *		<table_name>_detail_html.php
  *
  * For example: "ca_objects_detail_html.php"
  *
  * In general you should always have the table wide views defined. Then you can define type-specific views for your
  * application on an as-needed basis.
  */
 public function Show($pa_options = null)
 {
     JavascriptLoadManager::register('viz');
     JavascriptLoadManager::register("ca", "panel");
     JavascriptLoadManager::register("jit");
     JavascriptLoadManager::register('browsable');
     JavascriptLoadManager::register('imageScroller');
     JavascriptLoadManager::register('jquery', 'expander');
     $va_access_values = caGetUserAccessValues($this->request);
     $this->view->setVar('access_values', $va_access_values);
     if (!($t_item = $this->opo_datamodel->getInstanceByTableName($this->ops_tablename, true))) {
         die("Invalid table name " . $this->ops_tablename . " for detail");
         // shouldn't happen
     }
     if (!($vn_item_id = $this->request->getParameter($t_item->primaryKey(), pInteger))) {
         $this->notification->addNotification(_t("Invalid ID"), "message");
         $this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
         return;
     }
     if (!$t_item->load($vn_item_id)) {
         $this->notification->addNotification(_t("ID does not exist"), "message");
         $this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
         return;
     }
     if ($t_item->hasField('deleted') && $t_item->get('deleted')) {
         $this->notification->addNotification(_t("ID has been deleted"), "message");
         $this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
         return;
     }
     // Check if item conforms to any configured display type restrictions
     if (method_exists($t_item, "getTypeID")) {
         $va_types = caMergeTypeRestrictionLists($t_item, array());
         if (is_array($va_types) && sizeof($va_types) && !in_array($t_item->getTypeID(), $va_types)) {
             $this->notification->addNotification(_t("This item is not viewable"), "message");
             $this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
             return;
         }
     }
     #
     # Enforce access control
     #
     if (sizeof($va_access_values) && !in_array($t_item->get("access"), $va_access_values)) {
         $this->notification->addNotification(_t("This item is not available for view"), "message");
         $this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
         return;
     }
     //
     // In-detail browsing of objects - limited to object linked to the item being displayed
     //
     if (($vs_browse_for_table = $this->request->config->get('allow_browse_within_detail_for_' . $this->ops_tablename)) && is_object($this->opo_browse)) {
         // set browse context for controller
         $this->setContext($this->opo_browse->getContext());
         //
         // Restrict facets to specific group for refine browse (if set in app.conf config)
         //
         if ($vs_facet_group = $this->request->config->get('ca_objects_refine_facet_group')) {
             $this->opo_browse->setFacetGroup($vs_facet_group);
         }
         $t_table = $this->opo_datamodel->getInstanceByTableName($this->ops_tablename, true);
         if ($this->request->session->getVar($this->ops_tablename . '_' . $this->ops_appname . '_detail_current_item_id') != $vn_item_id) {
             $this->opo_browse->removeAllCriteria();
         }
         // look for 'authority' facet for current detail table type so we can limit the object browse to the currently displayed item
         //$vs_limit_facet_name = null;
         //foreach($this->opo_browse->getInfoForFacets() as $vs_facet_name => $va_facet_info) {
         //	if (($va_facet_info['type'] === 'authority') && ($va_facet_info['table'] === $this->ops_tablename)) {
         //		$vs_limit_facet_name = $vs_facet_name;
         //		break;
         //	}
         //}
         $this->opo_browse->addFacetConfiguration($vs_limit_facet_name = '_detail_browse_' . $this->ops_tablename, array('type' => 'authority', 'table' => $this->ops_tablename, 'relationship_table' => 'ca_objects_x_entities', 'restrict_to_types' => array(), 'restrict_to_relationship_types' => array(), 'label_singular' => 'Detail browse by ' . $this->ops_tablename, 'label_plural' => 'Detail browse by ' . $this->ops_tablename, 'group_mode' => 'none', 'indefinite_article' => 'a'));
         if ($vs_limit_facet_name) {
             if (($va_configured_type_restrictions = $this->request->config->getList($this->ops_tablename . '_detail_browse_type_restrictions')) && is_array($va_configured_type_restrictions)) {
                 $this->opo_browse->setTypeRestrictions($va_configured_type_restrictions, array('includeChildren' => false));
             }
             $this->opo_browse->addCriteria($vs_limit_facet_name, array($vn_item_id));
             $this->opo_browse->execute(array('checkAccess' => $va_access_values));
             $this->request->session->setVar($this->ops_tablename . '_' . $this->ops_appname . '_detail_current_browse_id', $this->opo_browse->getBrowseID());
             $this->view->setVar('show_browse', true);
             //
             // Browse paging
             //
             $vn_items_per_page = $this->request->config->get("objects_per_page_for_detail_pages");
             if (!$vn_items_per_page) {
                 $vn_items_per_page = 12;
             }
             $this->view->setVar('page', ($vn_p = $this->request->getParameter('page', pInteger)) ? $vn_p : 1);
             $qr_hits = null;
             if ($this->opo_browse) {
                 $va_sort = array();
                 if ($vs_sort = $this->request->config->get('sort_browse_within_detail_for_' . $this->ops_tablename)) {
                     $va_sort = array('sort' => $vs_sort);
                 }
                 $qr_hits = $this->opo_browse->getResults($va_sort);
                 $vn_num_pages = ceil($qr_hits->numHits() / $vn_items_per_page);
                 $qr_hits->seek(($vn_p - 1) * $vn_items_per_page);
             } else {
                 $vn_num_pages = 0;
             }
             $this->view->setVar('browse_results', $qr_hits);
             $this->view->setVar('num_pages', (int) $vn_num_pages);
             $this->view->setVar('items_per_page', (int) $vn_items_per_page);
             $this->view->setVar('opo_browse', $this->opo_browse);
             $this->view->setVar('sorts', $this->opa_sorts);
             // supported sorts for the object browse
             // browse criteria in an easy-to-display format
             $va_browse_criteria = array();
             foreach ($this->opo_browse->getCriteriaWithLabels() as $vs_facet_code => $va_criteria) {
                 $va_facet_info = $this->opo_browse->getInfoForFacet($vs_facet_code);
                 $va_criteria_list = array();
                 foreach ($va_criteria as $vn_criteria_id => $vs_criteria_label) {
                     $va_criteria_list[] = $vs_criteria_label;
                 }
                 $va_browse_criteria[$va_facet_info['label_singular']] = join('; ', $va_criteria_list);
             }
             $this->view->setVar('browse_criteria', $va_browse_criteria);
         } else {
             // not configured for browse
             $this->request->session->setVar($this->ops_tablename . '_' . $this->ops_appname . '_detail_current_browse_id', null);
             $this->view->setVar('show_browse', false);
         }
     }
     $this->request->session->setVar($this->ops_tablename . '_' . $this->ops_appname . '_detail_current_item_id', $vn_item_id);
     # Next and previous navigation
     $opo_result_context = new ResultContext($this->request, $this->ops_tablename, ResultContext::getLastFind($this->request, $this->ops_tablename));
     $this->view->setVar('next_id', $opo_result_context->getNextID($vn_item_id));
     $this->view->setVar('previous_id', $opo_result_context->getPreviousID($vn_item_id));
     # Is the item we're show details for in the result set?
     $this->view->setVar('is_in_result_list', $opo_result_context->getIndexInResultList($vn_item_id) != '?');
     # Item instance and id
     $this->view->setVar('t_item', $t_item);
     $this->view->setVar($t_item->getPrimaryKey(), $vn_item_id);
     # Item  - preferred
     $this->view->setVar('label', $t_item->getLabelForDisplay());
     # Item  - nonpreferred
     $this->view->setVar('nonpreferred_labels', caExtractValuesByUserLocale($t_item->getNonPreferredLabels()));
     # Item timestamps (creation and last change)
     if ($va_entry_info = $t_item->getCreationTimestamp()) {
         $this->view->setVar('date_of_entry', date('m/d/Y', $va_entry_info['timestamp']));
     }
     if ($va_last_change_info = $t_item->getLastChangeTimestamp()) {
         $this->view->setVar('date_of_last_change', date('m/d/Y', $va_last_change_info['timestamp']));
     }
     # Media representations to display (objects only)
     if (method_exists($t_item, 'getPrimaryRepresentationInstance')) {
         if ($t_primary_rep = $t_item->getPrimaryRepresentationInstance()) {
             if (!sizeof($va_access_values) || in_array($t_primary_rep->get('access'), $va_access_values)) {
                 // check rep access
                 $this->view->setVar('t_primary_rep', $t_primary_rep);
                 $va_rep_display_info = caGetMediaDisplayInfo('detail', $t_primary_rep->getMediaInfo('media', 'INPUT', 'MIMETYPE'));
                 $this->view->setVar('primary_rep_display_version', $va_rep_display_info['display_version']);
                 unset($va_display_info['display_version']);
                 $va_rep_display_info['poster_frame_url'] = $t_primary_rep->getMediaUrl('media', $va_rep_display_info['poster_frame_version']);
                 unset($va_display_info['poster_frame_version']);
                 $this->view->setVar('primary_rep_display_options', $va_rep_display_info);
             }
         }
     }
     #
     # User-generated comments, tags and ratings
     #
     $va_user_comments = $t_item->getComments(null, true);
     $va_comments = array();
     if (is_array($va_user_comments)) {
         foreach ($va_user_comments as $va_user_comment) {
             if ($va_user_comment["comment"] || $va_user_comment["media1"] || $va_user_comment["media2"] || $va_user_comment["media3"] || $va_user_comment["media4"]) {
                 # TODO: format date based on locale
                 $va_user_comment["date"] = date("n/j/Y", $va_user_comment["created_on"]);
                 # -- get name of commenter
                 $t_user = new ca_users($va_user_comment["user_id"]);
                 $va_user_comment["author"] = $t_user->getName();
                 $va_comments[] = $va_user_comment;
             }
         }
     }
     $this->view->setVar('comments', $va_comments);
     $va_user_tags = $t_item->getTags(null, true);
     $va_tags = array();
     if (is_array($va_user_tags)) {
         foreach ($va_user_tags as $va_user_tag) {
             if (!in_array($va_user_tag["tag"], $va_tags)) {
                 $va_tags[] = $va_user_tag["tag"];
             }
         }
     }
     $this->view->setVar('tags_array', $va_tags);
     $this->view->setVar('tags', implode(", ", $va_tags));
     $this->view->setVar('result_context', $opo_result_context);
     # -- get average user ranking
     $this->view->setVar('ranking', $t_item->getAverageRating(null));
     // null makes it ignore moderation status
     # -- get number of user rankings
     $this->view->setVar('numRankings', $t_item->getNumRatings(null));
     // null makes it ignore moderation status
     #
     # Miscellaneous useful information
     #
     $this->view->setVar('t_relationship_types', new ca_relationship_types());
     // relationship types object - used for displaying relationship type of related authority information
     if (method_exists($t_item, 'getTypeName')) {
         $this->view->setVar('typename', $t_item->getTypeName());
     }
     // Record view
     $t_item->registerItemView($this->request->getUserID());
     //
     // Render view
     //
     if (isset($pa_options['view']) && $pa_options['view']) {
         $this->render($pa_options['view']);
     } else {
         if ($this->getView()->viewExists($this->ops_tablename . '_' . $t_item->getTypeCode() . '_detail_html.php')) {
             $this->render($this->ops_tablename . '_' . $t_item->getTypeCode() . '_detail_html.php');
         } else {
             $this->render($this->ops_tablename . '_detail_html.php');
         }
     }
 }
 /**
  *
  */
 public function __call($ps_function, $pa_args)
 {
     AssetLoadManager::register("panel");
     AssetLoadManager::register("mediaViewer");
     AssetLoadManager::register("carousel");
     AssetLoadManager::register("readmore");
     AssetLoadManager::register("maps");
     $ps_function = strtolower($ps_function);
     $ps_id = urldecode($this->request->getActionExtra());
     if (!isset($this->opa_detail_types[$ps_function]) || !isset($this->opa_detail_types[$ps_function]['table']) || !($vs_table = $this->opa_detail_types[$ps_function]['table'])) {
         // invalid detail type – throw error
         die("Invalid detail type");
     }
     $t_table = $this->opo_datamodel->getInstanceByTableName($vs_table, true);
     if (($vb_use_identifiers_in_urls = caUseIdentifiersInUrls()) && substr($ps_id, 0, 3) == "id:") {
         $va_tmp = explode(":", $ps_id);
         $ps_id = (int) $va_tmp[1];
         $vb_use_identifiers_in_urls = false;
     }
     if (!$t_table->load($vb_use_identifiers_in_urls && $t_table->getProperty('ID_NUMBERING_ID_FIELD') ? $t_table->hasField('deleted') ? array($t_table->getProperty('ID_NUMBERING_ID_FIELD') => $ps_id, 'deleted' => 0) : array($t_table->getProperty('ID_NUMBERING_ID_FIELD') => $ps_id) : ($t_table->hasField('deleted') ? array($t_table->primaryKey() => (int) $ps_id, 'deleted' => 0) : array($t_table->primaryKey() => (int) $ps_id)))) {
         // invalid id - throw error
         die("Invalid id");
     }
     // Printables
     // 	merge displays with drop-in print templates
     //
     $va_export_options = caGetAvailablePrintTemplates('summary', array('table' => $t_table->tableName()));
     $this->view->setVar('export_formats', $va_export_options);
     $va_options = array();
     foreach ($va_export_options as $vn_i => $va_format_info) {
         $va_options[$va_format_info['name']] = $va_format_info['code'];
     }
     // Get current display list
     $t_display = new ca_bundle_displays();
     foreach (caExtractValuesByUserLocale($t_display->getBundleDisplays(array('table' => $this->ops_tablename, 'user_id' => $this->request->getUserID(), 'access' => __CA_BUNDLE_DISPLAY_READ_ACCESS__, 'checkAccess' => caGetUserAccessValues($this->request)))) as $va_display) {
         $va_options[$va_display['name']] = "_display_" . $va_display['display_id'];
     }
     ksort($va_options);
     $this->view->setVar('export_format_select', caHTMLSelect('export_format', $va_options, array('class' => 'searchToolsSelect'), array('value' => $this->view->getVar('current_export_format'), 'width' => '150px')));
     #
     # Enforce access control
     #
     if (sizeof($this->opa_access_values) && $t_table->hasField('access') && !in_array($t_table->get("access"), $this->opa_access_values)) {
         $this->notification->addNotification(_t("This item is not available for view"), "message");
         $this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
         return;
     }
     MetaTagManager::setWindowTitle($this->request->config->get("app_display_name") . ": " . $t_table->getTypeName() . ": " . $t_table->get('preferred_labels') . (($vs_idno = $t_table->get($t_table->getProperty('ID_NUMBERING_ID_FIELD'))) ? " [{$vs_idno}]" : ""));
     $vs_type = $t_table->getTypeCode();
     $this->view->setVar('detailType', $vs_table);
     $this->view->setVar('item', $t_table);
     $this->view->setVar('itemType', $vs_type);
     caAddPageCSSClasses(array($vs_table, $ps_function, $vs_type));
     // Do we need to pull in the multisearch result set?
     if (ResultContext::getLastFind($this->request, $vs_table, array('noSubtype' => true)) === 'multisearch') {
         $o_context = new ResultContext($this->request, $vs_table, 'multisearch', $ps_function);
         $o_context->setAsLastFind();
         $o_context->saveContext();
     } else {
         $o_context = ResultContext::getResultContextForLastFind($this->request, $vs_table);
     }
     $this->view->setVar('previousID', $vn_previous_id = $o_context->getPreviousID($t_table->getPrimaryKey()));
     $this->view->setVar('nextID', $vn_next_id = $o_context->getNextID($t_table->getPrimaryKey()));
     $this->view->setVar('previousURL', caDetailUrl($this->request, $vs_table, $vn_previous_id));
     $this->view->setVar('nextURL', caDetailUrl($this->request, $vs_table, $vn_next_id));
     $this->view->setVar('resultsURL', ResultContext::getResultsUrlForLastFind($this->request, $vs_table));
     $va_options = isset($this->opa_detail_types[$ps_function]['options']) && is_array($this->opa_detail_types[$ps_function]['options']) ? $this->opa_detail_types[$ps_function]['options'] : array();
     $this->view->setVar('previousLink', $vn_previous_id > 0 ? caDetailLink($this->request, caGetOption('previousLink', $va_options, _t('Previous')), '', $vs_table, $vn_previous_id) : '');
     $this->view->setVar('nextLink', $vn_next_id > 0 ? caDetailLink($this->request, caGetOption('nextLink', $va_options, _t('Next')), '', $vs_table, $vn_next_id) : '');
     $this->view->setVar('resultsLink', ResultContext::getResultsLinkForLastFind($this->request, $vs_table, caGetOption('resultsLink', $va_options, _t('Back'))));
     $this->view->setVar('commentsEnabled', (bool) $va_options['enableComments']);
     //
     //
     //
     if (method_exists($t_table, 'getPrimaryRepresentationInstance')) {
         if ($pn_representation_id = $this->request->getParameter('representation_id', pInteger)) {
             $t_representation = $this->opo_datamodel->getInstanceByTableName("ca_object_representations", true);
             $t_representation->load($pn_representation_id);
         } else {
             $t_representation = $t_table->getPrimaryRepresentationInstance(array("checkAccess" => $this->opa_access_values));
         }
         if ($t_representation) {
             $this->view->setVar("t_representation", $t_representation);
             $this->view->setVar("representation_id", $t_representation->get("representation_id"));
         } else {
             $t_representation = $this->opo_datamodel->getInstanceByTableName("ca_object_representations", true);
         }
         $this->view->setVar("representationViewer", caObjectDetailMedia($this->request, $t_table->getPrimaryKey(), $t_representation, $t_table, array("primaryOnly" => caGetOption('representationViewerPrimaryOnly', $va_options, false), "dontShowPlaceholder" => caGetOption('representationViewerDontShowPlaceholder', $va_options, false))));
     }
     //
     // map
     //
     if (!is_array($va_map_attributes = caGetOption('map_attributes', $va_options, array())) || !sizeof($va_map_attributes)) {
         if ($vs_map_attribute = caGetOption('map_attribute', $va_options, false)) {
             $va_map_attributes = array($vs_map_attribute);
         }
     }
     $this->view->setVar("map", "");
     if (is_array($va_map_attributes) && sizeof($va_map_attributes)) {
         $o_map = new GeographicMap(($vn_width = caGetOption('map_width', $va_options, false)) ? $vn_width : 285, ($vn_height = caGetOption('map_height', $va_options, false)) ? $vn_height : 200, 'map');
         $vn_mapped_count = 0;
         foreach ($va_map_attributes as $vs_map_attribute) {
             if ($t_table->get($vs_map_attribute)) {
                 $o_map->mapFrom($t_table, $vs_map_attribute);
                 $vn_mapped_count++;
             }
         }
         if ($vn_mapped_count > 0) {
             $this->view->setVar("map", $o_map->render('HTML'));
         }
     }
     //
     // comments, tags, rank
     //
     $this->view->setVar('averageRank', $t_table->getAverageRating(true));
     $this->view->setVar('numRank', $t_table->getNumRatings(true));
     #
     # User-generated comments, tags and ratings
     #
     $va_user_comments = $t_table->getComments(null, true);
     $va_comments = array();
     if (is_array($va_user_comments)) {
         foreach ($va_user_comments as $va_user_comment) {
             if ($va_user_comment["comment"] || $va_user_comment["media1"] || $va_user_comment["media2"] || $va_user_comment["media3"] || $va_user_comment["media4"]) {
                 # TODO: format date based on locale
                 $va_user_comment["date"] = date("n/j/Y", $va_user_comment["created_on"]);
                 # -- get name of commenter
                 if ($va_user_comment["user_id"]) {
                     $t_user = new ca_users($va_user_comment["user_id"]);
                     $va_user_comment["author"] = $t_user->getName();
                 } elseif ($va_user_comment["name"]) {
                     $va_user_comment["author"] = $va_user_comment["name"];
                 }
                 $va_comments[] = $va_user_comment;
             }
         }
     }
     $this->view->setVar('comments', $va_comments);
     $va_user_tags = $t_table->getTags(null, true);
     $va_tags = array();
     if (is_array($va_user_tags)) {
         foreach ($va_user_tags as $va_user_tag) {
             if (!in_array($va_user_tag["tag"], $va_tags)) {
                 $va_tags[] = $va_user_tag["tag"];
             }
         }
     }
     $this->view->setVar('tags_array', $va_tags);
     $this->view->setVar('tags', implode(", ", $va_tags));
     $this->view->setVar("itemComments", caDetailItemComments($this->request, $t_table->getPrimaryKey(), $t_table, $va_comments, $va_tags));
     //
     // share link
     //
     $this->view->setVar("shareLink", "<a href='#' onclick='caMediaPanel.showPanel(\"" . caNavUrl($this->request, '', 'Detail', 'ShareForm', array("tablename" => $t_table->tableName(), "item_id" => $t_table->getPrimaryKey())) . "\"); return false;'>Share</a>");
     // find view
     //		first look for type-specific view
     if (!$this->viewExists($vs_path = "Details/{$vs_table}_{$vs_type}_html.php")) {
         // If no type specific view use the default
         $vs_path = "Details/{$vs_table}_default_html.php";
     }
     switch ($ps_view = $this->request->getParameter('view', pString)) {
         case 'pdf':
             $this->_genExport($t_table, $this->request->getParameter("export_format", pString), 'Detail', 'Detail');
             break;
         default:
             //
             // Tag substitution
             //
             // Views can contain tags in the form {{{tagname}}}. Some tags, such as "itemType" and "detailType" are defined by
             // the detail controller. More usefully, you can pull data from the item being detailed by using a valid "get" expression
             // as a tag (Eg. {{{ca_objects.idno}}}. Even more usefully for some, you can also use a valid bundle display template
             // (see http://docs.collectiveaccess.org/wiki/Bundle_Display_Templates) as a tag. The template will be evaluated in the
             // context of the item being detailed.
             //
             $va_defined_vars = array_keys($this->view->getAllVars());
             // get list defined vars (we don't want to copy over them)
             $va_tag_list = $this->getTagListForView($vs_path);
             // get list of tags in view
             foreach ($va_tag_list as $vs_tag) {
                 if (in_array($vs_tag, $va_defined_vars)) {
                     continue;
                 }
                 if (strpos($vs_tag, "^") !== false || strpos($vs_tag, "<") !== false) {
                     $this->view->setVar($vs_tag, $t_table->getWithTemplate($vs_tag, array('checkAccess' => $this->opa_access_values)));
                 } elseif (strpos($vs_tag, ".") !== false) {
                     $this->view->setVar($vs_tag, $t_table->get($vs_tag, array('checkAccess' => $this->opa_access_values)));
                 } else {
                     $this->view->setVar($vs_tag, "?{$vs_tag}");
                 }
             }
             $this->render($vs_path);
             break;
     }
 }
 /**
  * Generates detail detail. Will use a view named according to the following convention:
  *		<table_name>_<type_code>_detail_html.php
  *
  * So for example, the detail for objects of type 'artwork' (where 'artwork' is the type code for the artwork object type)
  * the view would be named "ca_objects_artwork_detail_html.php
  *
  * If the type specific view does not exist, then Show() will attemp to use a generic table-wide view name like this:
  *		<table_name>_detail_html.php
  *
  * For example: "ca_objects_detail_html.php"
  *
  * In general you should always have the table wide views defined. Then you can define type-specific views for your
  * application on an as-needed basis.
  */
 public function Show()
 {
     JavascriptLoadManager::register('browsable');
     JavascriptLoadManager::register('imageScroller');
     JavascriptLoadManager::register('maps3');
     $va_access_values = caGetUserAccessValues($this->request);
     $this->view->setVar('access_values', $va_access_values);
     if (!($t_item = $this->opo_datamodel->getInstanceByTableName($this->ops_tablename, true))) {
         die("Invalid table name " . $this->ops_tablename . " for detail");
     }
     if (!($vn_item_id = $this->request->getParameter($t_item->primaryKey(), pInteger))) {
         $this->notification->addNotification(_t("Invalid ID"), "message");
         $this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
         return;
     }
     if (!$t_item->load($vn_item_id)) {
         $this->notification->addNotification(_t("ID does not exist"), "message");
         $this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
         return;
     }
     #
     # Enforce access control
     #
     if (sizeof($va_access_values) && !in_array($t_item->get("access"), $va_access_values)) {
         $this->notification->addNotification(_t("This item is not available for view"), "message");
         $this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
         return;
     }
     //
     // In-detail browsing of objects - limited to object linked to the item being displayed
     //
     if ($this->request->config->get('allow_browse_within_detail_for_' . $this->ops_tablename) && is_object($this->opo_browse)) {
         // set browse context for controller
         $this->setContext($this->opo_browse->getContext());
         $t_table = $this->opo_datamodel->getTableInstance($this->ops_tablename);
         if ($this->request->session->getVar($this->ops_tablename . '_' . $this->ops_appname . '_detail_current_item_id') != $vn_item_id) {
             $this->opo_browse->removeAllCriteria();
         }
         // look for 'authority' facet for current detail table type so we can limit the object browse to the currently displayed item
         $vs_limit_facet_name = null;
         foreach ($this->opo_browse->getInfoForFacets() as $vs_facet_name => $va_facet_info) {
             if ($va_facet_info['type'] === 'authority' && $va_facet_info['table'] === $this->ops_tablename) {
                 $vs_limit_facet_name = $vs_facet_name;
                 break;
             }
         }
         if ($vs_limit_facet_name) {
             $this->opo_browse->addCriteria($vs_limit_facet_name, array($vn_item_id));
             $this->opo_browse->execute(array('checkAccess' => $va_access_values));
             $this->request->session->setVar($this->ops_tablename . '_' . $this->ops_appname . '_detail_current_browse_id', $this->opo_browse->getBrowseID());
             $this->view->setVar('show_browse', true);
             //
             // Browse paging
             //
             $vn_items_per_page = $this->request->config->get("objects_per_page_for_detail_pages");
             if (!$vn_items_per_page) {
                 $vn_items_per_page = 12;
             }
             $this->view->setVar('page', ($vn_p = $this->request->getParameter('page', pInteger)) ? $vn_p : 1);
             if ($this->opo_browse) {
                 $qr_hits = $this->opo_browse->getResults();
                 $vn_num_pages = ceil($qr_hits->numHits() / $vn_items_per_page);
                 $qr_hits->seek(($vn_p - 1) * $vn_items_per_page);
             } else {
                 $vn_num_pages = 0;
             }
             $this->view->setVar('browse_results', $qr_hits);
             $this->view->setVar('num_pages', $vn_num_pages);
             $this->view->setVar('items_per_page', $vn_items_per_page);
             $this->view->setVar('opo_browse', $this->opo_browse);
             $this->view->setVar('sorts', $this->opa_sorts);
             // supported sorts for the object browse
             // browse criteria in an easy-to-display format
             $va_browse_criteria = array();
             foreach ($this->opo_browse->getCriteriaWithLabels() as $vs_facet_code => $va_criteria) {
                 $va_facet_info = $this->opo_browse->getInfoForFacet($vs_facet_code);
                 $va_criteria_list = array();
                 foreach ($va_criteria as $vn_criteria_id => $vs_criteria_label) {
                     $va_criteria_list[] = $vs_criteria_label;
                 }
                 $va_browse_criteria[$va_facet_info['label_singular']] = join('; ', $va_criteria_list);
             }
             $this->view->setVar('browse_criteria', $va_browse_criteria);
         } else {
             // not configured for browse
             $this->request->session->setVar($this->ops_tablename . '_' . $this->ops_appname . '_detail_current_browse_id', null);
             $this->view->setVar('show_browse', false);
         }
     }
     $this->request->session->setVar($this->ops_tablename . '_' . $this->ops_appname . '_detail_current_item_id', $vn_item_id);
     # Next and previous navigation
     $opo_result_context = new ResultContext($this->request, $this->ops_tablename, ResultContext::getLastFind($this->request, $this->ops_tablename));
     $this->view->setVar('next_id', $opo_result_context->getNextID($vn_item_id));
     $this->view->setVar('previous_id', $opo_result_context->getPreviousID($vn_item_id));
     # Item instance and id
     $this->view->setVar('t_item', $t_item);
     $this->view->setVar($t_item->getPrimaryKey(), $vn_item_id);
     # Item  - preferred
     $this->view->setVar('label', $t_item->getLabelForDisplay());
     # Item  - nonpreferred
     $this->view->setVar('nonpreferred_labels', caExtractValuesByUserLocale($t_item->getNonPreferredLabels()));
     # Item timestamps (creation and last change)
     if ($va_entry_info = $t_item->getCreationTimestamp()) {
         $this->view->setVar('date_of_entry', date('m/d/Y', $va_entry_info['timestamp']));
     }
     if ($va_last_change_info = $t_item->getLastChangeTimestamp()) {
         $this->view->setVar('date_of_last_change', date('m/d/Y', $va_last_change_info['timestamp']));
     }
     # Media representations to display (objects only)
     if (method_exists($t_item, 'getPrimaryRepresentationInstance')) {
         if ($t_primary_rep = $t_item->getPrimaryRepresentationInstance()) {
             if (!sizeof($va_access_values) || in_array($t_primary_rep->get('access'), $va_access_values)) {
                 // check rep access
                 $va_info = $t_primary_rep->getMediaInfo('media', 'original');
                 $this->view->setVar('t_primary_rep', $t_primary_rep);
                 $va_rep_display_info = caGetMediaDisplayInfo('detail', $t_primary_rep->getMediaInfo('media', 'original', 'MIMETYPE'));
                 $this->view->setVar('primary_rep_display_version', $va_rep_display_info['display_version']);
                 unset($va_display_info['display_version']);
                 $va_rep_display_info['poster_frame_url'] = $t_primary_rep->getMediaUrl('media', $va_rep_display_info['poster_frame_version']);
                 unset($va_display_info['poster_frame_version']);
                 $this->view->setVar('primary_rep_display_options', $va_rep_display_info);
             }
         }
     }
     #
     # User-generated comments, tags and ratings
     #
     $va_user_comments = $t_item->getComments(null, true);
     $va_comments = array();
     if (is_array($va_user_comments)) {
         foreach ($va_user_comments as $va_user_comment) {
             $va_comment = array();
             if ($va_user_comment["comment"]) {
                 $va_comment["comment"] = $va_user_comment["comment"];
                 # TODO: format date based on local
                 $va_comment["date"] = date("n/j/Y", $va_user_comment["created_on"]);
                 $va_comment["created_on"] = $va_user_comment["created_on"];
                 # -- get name of commenter
                 $t_user = new ca_users($va_user_comment["user_id"]);
                 $va_comment["author"] = $t_user->getName();
                 $va_comment["email"] = $va_user_comment["email"];
                 $va_comment["name"] = $va_user_comment["name"];
                 $va_comments[] = $va_comment;
             }
         }
     }
     $this->view->setVar('comments', $va_comments);
     $va_user_tags = $t_item->getTags(null, true);
     $va_tags = array();
     if (is_array($va_user_tags)) {
         foreach ($va_user_tags as $va_user_tag) {
             if (!in_array($va_user_tag["tag"], $va_tags)) {
                 $va_tags[] = $va_user_tag["tag"];
             }
         }
     }
     $this->view->setVar('tags_array', $va_tags);
     $this->view->setVar('tags', implode(", ", $va_tags));
     # -- get average user ranking
     $this->view->setVar('ranking', $t_item->getAverageRating(null));
     // null makes it ignore moderation status
     # -- get number of user rankings
     $this->view->setVar('numRankings', $t_item->getNumRatings(null));
     // null makes it ignore moderation status
     # --- get related objects - explicit relationships
     $va_related_objects = array();
     if (method_exists($this, 'getRelatedObjects')) {
         $va_related_objects = $this->getRelatedObjects();
     }
     $this->view->setVar('related_objects', $va_related_objects);
     #
     # get suggested objects - you may be interested in
     #
     $va_suggested_objects = array();
     if (method_exists($this, 'getSuggestedItems')) {
         $va_suggested_objects = $this->getSuggestedItems();
     }
     $this->view->setVar('suggested_objects', $va_suggested_objects);
     #
     # Miscellaneous useful information
     #
     $this->view->setVar('t_relationship_types', new ca_relationship_types());
     // relationship types object - used for displaying relationship type of related authority information
     if (method_exists($t_item, 'getTypeName')) {
         $this->view->setVar('typename', $t_item->getTypeName());
     }
     # Hierarchy
     //  			if($t_occurrence->get("parent_id")){
     //  				$t_parent = new ca_occurrences($t_occurrence->get("parent_id"));
     //  				$this->view->setVar('parent_title', $t_parent->getLabelForDisplay());
     //  				$this->view->setVar('parent_id', $t_occurrence->get("parent_id"));
     //  			}
     // 	$va_occurrence_children = $t_occurrence->getHierarchyChildren();
     //  			if(is_array($va_occurrence_children) && (sizeof($va_occurrence_children) > 0)){
     //  				$this->view->setVar('num_children', sizeof($va_occurrence_children));
     //  			}
     // Record view
     $t_item->registerItemView($this->request->getUserID());
     //
     // Render view
     //
     if ($this->getView()->viewExists($this->ops_tablename . '_' . $t_item->getTypeCode() . '_detail_html.php')) {
         $this->render($this->ops_tablename . '_' . $t_item->getTypeCode() . '_detail_html.php');
     } else {
         $this->render($this->ops_tablename . '_detail_html.php');
     }
 }
    print "<HR/>";
}
#
# User-generated comments, tags and ratings
#
$va_user_comments = $t_object->getComments(null, true);
$va_comments = array();
if (is_array($va_user_comments)) {
    foreach ($va_user_comments as $va_user_comment) {
        if ($va_user_comment["comment"] || $va_user_comment["media1"] || $va_user_comment["media2"] || $va_user_comment["media3"] || $va_user_comment["media4"]) {
            # TODO: format date based on locale
            $va_user_comment["date"] = date("n/j/Y", $va_user_comment["created_on"]);
            # -- get name of commenter
            if ($va_user_comment["user_id"]) {
                $t_user = new ca_users($va_user_comment["user_id"]);
                $va_user_comment["author"] = $t_user->getName();
            } elseif ($va_user_comment["name"]) {
                $va_user_comment["author"] = $va_user_comment["name"];
            }
            $va_comments[] = $va_user_comment;
        }
    }
}
$va_user_tags = $t_object->getTags(null, true);
$va_tags = array();
if (is_array($va_user_tags)) {
    foreach ($va_user_tags as $va_user_tag) {
        if (!in_array($va_user_tag["tag"], $va_tags)) {
            $va_tags[] = $va_user_tag["tag"];
        }
    }