PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/app/plugins/simpleGallery/controllers/ShowController.php

https://bitbucket.org/Sinfin/pawtucket
PHP | 204 lines | 127 code | 36 blank | 41 comment | 8 complexity | 62a376ffc3264ba0c03447d4e1644084 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0
  1. <?php
  2. /* ----------------------------------------------------------------------
  3. * includes/ShowController.php
  4. * ----------------------------------------------------------------------
  5. * CollectiveAccess
  6. * Open-source collections management software
  7. * ----------------------------------------------------------------------
  8. *
  9. * Software by Whirl-i-Gig (http://www.whirl-i-gig.com)
  10. * Copyright 2009-2011 Whirl-i-Gig
  11. *
  12. * For more information visit http://www.CollectiveAccess.org
  13. *
  14. * This program is free software; you may redistribute it and/or modify it under
  15. * the terms of the provided license as published by Whirl-i-Gig
  16. *
  17. * CollectiveAccess is distributed in the hope that it will be useful, but
  18. * WITHOUT ANY WARRANTIES whatsoever, including any implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  20. *
  21. * This source code is free and modifiable under the terms of
  22. * GNU General Public License. (http://www.gnu.org/copyleft/gpl.html). See
  23. * the "license.txt" file for details, or visit the CollectiveAccess web site at
  24. * http://www.CollectiveAccess.org
  25. *
  26. * ----------------------------------------------------------------------
  27. */
  28. require_once(__CA_MODELS_DIR__.'/ca_sets.php');
  29. require_once(__CA_MODELS_DIR__.'/ca_objects.php');
  30. require_once(__CA_MODELS_DIR__.'/ca_set_items.php');
  31. require_once(__CA_MODELS_DIR__.'/ca_collections.php');
  32. require_once(__CA_MODELS_DIR__.'/ca_lists.php');
  33. // require_once(__CA_HELPERS_DIR__.'/displayHelpers.php');
  34. require_once(__CA_APP_DIR__.'/helpers/accessHelpers.php');
  35. require_once(__CA_LIB_DIR__.'/ca/ResultContext.php');
  36. class ShowController extends ActionController {
  37. # -------------------------------------------------------
  38. private $opo_plugin_config; // plugin config file
  39. private $ops_theme; // current theme
  40. private $opo_result_context; // current result context
  41. # -------------------------------------------------------
  42. public function __construct(&$po_request, &$po_response, $pa_view_paths=null) {
  43. // JavascriptLoadManager::register('panel');
  44. JavascriptLoadManager::register('onlineExhibition');
  45. JavascriptLoadManager::register('jquery', 'expander');
  46. JavascriptLoadManager::register('jquery', 'swipe');
  47. parent::__construct($po_request, $po_response, $pa_view_paths);
  48. $this->opo_plugin_config = Configuration::load($this->request->getAppConfig()->get('application_plugins').'/simpleGallery/conf/simpleGallery.conf');
  49. if (!(bool)$this->opo_plugin_config->get('enabled')) { die(_t('simpleGallery plugin is not enabled')); }
  50. $this->ops_theme = __CA_THEME__; // get current theme
  51. if(!is_dir(__CA_APP_DIR__.'/plugins/simpleGallery/views/'.$this->ops_theme)) { // if theme is not defined for this plugin, try to use "default" theme
  52. $this->ops_theme = 'default';
  53. }
  54. $this->opo_result_context = new ResultContext($po_request, 'ca_objects', 'simple_gallery');
  55. }
  56. # -------------------------------------------------------
  57. public function Index() {
  58. $va_access_values = caGetUserAccessValues($this->request);
  59. // get sets for public display
  60. $t_list = new ca_lists();
  61. $vn_public_set_type_id = $t_list->getItemIDFromList('set_types', $t_list->getAppConfig()->get('simpleGallery_set_type'));
  62. $t_set = new ca_sets();
  63. $va_sets = caExtractValuesByUserLocale($t_set->getSets(array('table' => 'ca_objects', 'checkAccess' => $va_access_values, 'setType' => $vn_public_set_type_id)));
  64. $va_set_descriptions = $t_set->getAttributeFromSets($this->opo_plugin_config->get('set_description_element_code'), array_keys($va_sets), array("checkAccess" => $va_access_values));
  65. $images = $t_set->getAttributeFromSets('exhibition_cover_small', array_keys($va_sets), array("checkAccess" => $va_access_values, "version" => "thumbnail"));
  66. $this->view->setVar('images', $images);
  67. $this->view->setVar('sets', $va_sets);
  68. $this->view->setVar('first_items_from_sets', $va_set_first_items);
  69. $this->view->setVar('set_descriptions', $va_set_descriptions);
  70. $this->render($this->ops_theme.'/landing_html.php');
  71. }
  72. # -------------------------------------------------------
  73. public function displaySet() {
  74. # --- set info
  75. $pn_set_id = $this->request->getParameter('set_id', pInteger);
  76. $t_set = new ca_sets($pn_set_id);
  77. $va_access_values = caGetUserAccessValues($this->request);
  78. # Enforce access control
  79. if(sizeof($va_access_values) && !in_array($t_set->get("access"), $va_access_values)){
  80. $this->notification->addNotification(_t("This set is not available for view"), "message");
  81. $this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
  82. return;
  83. }
  84. $this->view->setVar('t_set', $t_set);
  85. $va_items = caExtractValuesByUserLocale($t_set->getItems(array('thumbnailVersions' => array('large', 'mediumlarge', 'small'), "checkAccess" => $va_access_values, 'returnItemAttributes' => array('exhibition_size'))));
  86. $this->view->setVar('main_item', array_slice($va_items, 0, 1));
  87. $this->view->setVar('items', $va_items);
  88. $va_row_ids = array();
  89. foreach($va_items as $vn_item_id => $va_item_info) {
  90. $va_row_ids[] = $va_item_info['row_id'];
  91. }
  92. # --- all featured sets - for display in right hand column
  93. // get sets for public display
  94. $t_list = new ca_lists();
  95. $vn_public_set_type_id = $t_list->getItemIDFromList('set_types', $t_list->getAppConfig()->get('simpleGallery_set_type'));
  96. $va_sets = caExtractValuesByUserLocale($t_set->getSets(array('table' => 'ca_objects', 'checkAccess' => $va_access_values, 'setType' => $vn_public_set_type_id)));
  97. $va_set_first_items = array();
  98. $va_set_first_items = $t_set->getFirstItemsFromSets(array_keys($va_sets), array("version" => "icon", "checkAccess" => $va_access_values));
  99. $this->view->setVar('sets', $va_sets);
  100. $this->view->setVar('first_items_from_sets', $va_set_first_items);
  101. $this->view->setVar('set_title', $t_set->getLabelForDisplay());
  102. $this->view->setVar('set_description', $t_set->get($this->opo_plugin_config->get('set_description_element_code'), array('convertLinkBreaks' => true)));
  103. $obj = new ca_objects();
  104. $periodizations = $obj->getAttributeForIDs('periodization', $va_row_ids);
  105. $ids = $va_row_ids;
  106. $object_texts = $obj->getAttributeForIDs('object_text', $va_row_ids);
  107. $this->view->setVar('periodizations', $periodizations);
  108. $this->view->setVar('object_texts', $object_texts);
  109. $col = new ca_collections();
  110. $idnos = $t_set->get('exhibition_collection_idno', array('returnAsArray' => true, 'checkAccess' => $va_access_values));
  111. $arr = array();
  112. foreach ($idnos as $idno) {
  113. $arr[] = $idno['exhibition_collection_idno'];
  114. }
  115. $collections = $col->getCollectionIDsByIdnos($arr);
  116. $labels = $col->getPreferredDisplayLabelsForIDs($collections);
  117. $this->view->setVar('collections', $labels);
  118. // Needed to figure out what result context to use on details
  119. $this->opo_result_context->setParameter('set_id', $pn_set_id);
  120. $this->opo_result_context->setResultList($va_row_ids);
  121. $this->opo_result_context->setAsLastFind();
  122. $this->opo_result_context->saveContext();
  123. $this->render($this->ops_theme.'/set_info_html.php');
  124. }
  125. # -------------------------------------------------------
  126. # --- returns set item info in panel - used with small image list results
  127. public function setItemInfo(){
  128. $va_access_values = caGetUserAccessValues($this->request);
  129. $pn_set_id = $this->request->getParameter('set_id', pInteger);
  130. $t_set = new ca_sets($pn_set_id);
  131. $this->view->setVar('set_id', $pn_set_id);
  132. $pn_set_item_id = $this->request->getParameter('set_item_id', pInteger);
  133. $t_set_item = new ca_set_items($pn_set_item_id);
  134. $va_set_item_info = array();
  135. $va_items = $t_set->getItemIDs(array("checkAccess" => $va_access_values));
  136. $pn_previous_id = "";
  137. foreach($va_items as $vn_item_id => $va_item_info){
  138. if($va_set_item_info["item_id"]){
  139. $va_set_item_info["next_id"] = $vn_item_id;
  140. break;
  141. }
  142. if($pn_set_item_id == $vn_item_id){
  143. $va_set_item_info["previous_id"] = $pn_previous_id;
  144. $va_set_item_info["item_id"] = $vn_item_id;
  145. }
  146. $pn_previous_id = $vn_item_id;
  147. }
  148. $va_set_item_info["item_id"] = $t_set_item->get("item_id");
  149. $va_rep = $t_set_item->getRepresentations(array("mediumlarge", "small"), null, array("return_with_access" => $va_access_values));
  150. $this->view->setVar('t_object_representation', $t_rep = new ca_object_representations($va_rep[0]['representation_id']));
  151. $va_rep_display_info = caGetMediaDisplayInfo('cropped_gallery_media_overlay', $t_rep->getMediaInfo('media', 'INPUT', 'MIMETYPE'));
  152. $this->view->setVar('rep_display_version', $va_rep_display_info['display_version']);
  153. unset($va_display_info['display_version']);
  154. $va_rep_display_info['poster_frame_url'] = $t_rep->getMediaUrl('media', $va_rep_display_info['poster_frame_version']);
  155. unset($va_display_info['poster_frame_version']);
  156. $this->view->setVar('rep_display_options', $va_rep_display_info);
  157. $va_set_item_info["info"] = $va_rep[0]['info'];
  158. $va_set_item_info["label"] = $t_set_item->getLabelForDisplay();
  159. $va_set_item_info["description"] = $t_set_item->get($this->opo_plugin_config->get('set_description_element_code'), array('convertLineBreaks' => true));
  160. $va_set_item_info["row_id"] = $t_set_item->get("row_id");
  161. $t_object = new ca_objects($t_set_item->get("row_id"));
  162. $va_set_item_info["object_label"] = $t_object->getLabelForDisplay();
  163. $this->view->setVar('item_info', $va_set_item_info);
  164. $this->render($this->ops_theme.'/ajax_item_info_html.php');
  165. }
  166. # -------------------------------------------------------
  167. }
  168. ?>