PageRenderTime 46ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/app/plugins/bristol/controllers/ShowController.php

https://bitbucket.org/Sinfin/pawtucket
PHP | 210 lines | 131 code | 39 blank | 40 comment | 13 complexity | 855994bd28ffa8289213039c9b6411b1 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_lists.php');
  32. require_once(__CA_APP_DIR__.'/helpers/accessHelpers.php');
  33. require_once(__CA_LIB_DIR__.'/ca/ResultContext.php');
  34. class ShowController extends ActionController {
  35. # -------------------------------------------------------
  36. private $opo_plugin_config; // plugin config file
  37. private $ops_theme; // current theme
  38. private $opo_result_context; // current result context
  39. # -------------------------------------------------------
  40. public function __construct(&$po_request, &$po_response, $pa_view_paths=null) {
  41. JavascriptLoadManager::register('panel');
  42. JavascriptLoadManager::register('jquery', 'expander');
  43. JavascriptLoadManager::register('jquery', 'swipe');
  44. parent::__construct($po_request, $po_response, $pa_view_paths);
  45. // redirect user if not logged in
  46. if (($this->request->config->get('pawtucket_requires_login') && !($this->request->isLoggedIn()))||($this->request->config->get('show_bristol_only'))&&!($this->request->isLoggedIn())) {
  47. $this->response->setRedirect(caNavUrl($this->request, "", "LoginReg", "form"));
  48. }
  49. $this->opo_plugin_config = Configuration::load($this->request->getAppConfig()->get('application_plugins').'/bristol/conf/bristol.conf');
  50. if (!(bool)$this->opo_plugin_config->get('enabled')) { die(_t('bristol plugin is not enabled')); }
  51. $this->ops_theme = __CA_THEME__; // get current theme
  52. if(!is_dir(__CA_APP_DIR__.'/plugins/bristol/views/'.$this->ops_theme)) { // if theme is not defined for this plugin, try to use "default" theme
  53. $this->ops_theme = 'default';
  54. }
  55. $this->opo_result_context = new ResultContext($po_request, 'ca_objects', 'simple_gallery');
  56. }
  57. # -------------------------------------------------------
  58. public function Index() {
  59. $va_access_values = caGetUserAccessValues($this->request);
  60. // get sets for public display
  61. $t_list = new ca_lists();
  62. $vn_public_set_type_id = $t_list->getItemIDFromList('set_types', $t_list->getAppConfig()->get('simpleGallery_set_type'));
  63. $t_set = new ca_sets();
  64. $va_sets = caExtractValuesByUserLocale($t_set->getSets(array('table' => 'ca_objects', 'access' => __CA_SET_READ_ACCESS__, 'user_id' => $this->request->getUserID())));
  65. $va_set_first_items = $t_set->getFirstItemsFromSets(array_keys($va_sets), array("version" => "widepreview", "checkAccess" => $va_access_values));
  66. $va_set_descriptions = $t_set->getAttributeFromSets($this->opo_plugin_config->get('set_description_element_code'), array_keys($va_sets), array("checkAccess" => $va_access_values));
  67. $va_set_date = $t_set->getAttributeFromSets('setdate', array_keys($va_sets), array("checkAccess" => $va_access_values));
  68. $va_set_creator = $t_set->getAttributeFromSets('setcreator', array_keys($va_sets), array("checkAccess" => $va_access_values));
  69. $this->view->setVar('sets', $va_sets);
  70. $this->view->setVar('first_items_from_sets', $va_set_first_items);
  71. $this->view->setVar('set_descriptions', $va_set_descriptions);
  72. $this->view->setVar('set_date', $va_set_date);
  73. $this->view->setVar('set_creator', $va_set_creator);
  74. $this->render($this->ops_theme.'/landing_html.php');
  75. }
  76. # -------------------------------------------------------
  77. public function displaySet() {
  78. # --- set info
  79. $t_set = new ca_sets($pn_set_id = $this->request->getParameter('set_id', pInteger));
  80. if (!$t_set->getPrimaryKey()) {
  81. $this->notification->addNotification(_t("This set does not exist"), "message");
  82. $this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
  83. return;
  84. }
  85. $va_access_values = caGetUserAccessValues($this->request);
  86. # Enforce access control
  87. if(sizeof($va_access_values) && !in_array($t_set->get("access"), $va_access_values)){
  88. $this->notification->addNotification(_t("This set is not available for view"), "message");
  89. $this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
  90. return;
  91. }
  92. if(!$t_set->haveAccessToSet($this->request->getUserID(), __CA_SET_READ_ACCESS__)){
  93. $this->notification->addNotification(_t("This set is not available for view"), "message");
  94. $this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
  95. return;
  96. }
  97. $this->view->setVar('t_set', $t_set);
  98. $va_items = caExtractValuesByUserLocale($t_set->getItems(array('thumbnailVersions' => array('widepreview', 'medium'), 'access' => __CA_SET_READ_ACCESS__, "checkAccess" => $va_access_values, 'user_id' => $this->request->getUserID())));
  99. $this->view->setVar('items', $va_items);
  100. $va_row_ids = array();
  101. foreach($va_items as $vn_item_id => $va_item_info) {
  102. $va_row_ids[] = $va_item_info['row_id'];
  103. }
  104. # --- all featured sets - for display in right hand column
  105. // get sets for public display
  106. $t_list = new ca_lists();
  107. $vn_public_set_type_id = $t_list->getItemIDFromList('set_types', $t_list->getAppConfig()->get('bristol_set_type'));
  108. $t_set = new ca_sets($pn_set_id);
  109. $va_sets = caExtractValuesByUserLocale($t_set->getSets(array('table' => 'ca_objects', 'access' => __CA_SET_READ_ACCESS__, 'setType' => $vn_public_set_type_id, 'user_id' => $this->request->getUserID())));
  110. $va_set_first_items = array();
  111. $va_set_first_items = $t_set->getFirstItemsFromSets(array_keys($va_sets), array("version" => "icon", "checkAccess" => $va_access_values));
  112. $this->view->setVar('sets', $va_sets);
  113. $this->view->setVar('first_items_from_sets', $va_set_first_items);
  114. $this->view->setVar('set_title', $t_set->getLabelForDisplay());
  115. $this->view->setVar('set_description', $t_set->get($this->opo_plugin_config->get('set_description_element_code'), array('convertLinkBreaks' => true)));
  116. $this->view->setVar('set_creator', $t_set->get('setcreator', array('convertLinkBreaks' => true)));
  117. $this->view->setVar('set_date', $t_set->get('setdate', array('convertLinkBreaks' => true)));
  118. $va_exp_dates = $t_set->getAccessExpirationDates($this->request->getUserID(), __CA_SET_READ_ACCESS__, $pn_set_id);
  119. $this->view->setVar('set_expiration_date', $va_exp_dates[$pn_set_id]);
  120. // Needed to figure out what result context to use on details
  121. $this->opo_result_context->setParameter('set_id', $pn_set_id);
  122. $this->opo_result_context->setResultList($va_row_ids);
  123. $this->opo_result_context->setAsLastFind();
  124. $this->opo_result_context->saveContext();
  125. $this->render($this->ops_theme.'/set_info_html.php');
  126. }
  127. # -------------------------------------------------------
  128. # --- returns set item info in panel - used with small image list results
  129. public function setItemInfo(){
  130. $va_access_values = caGetUserAccessValues($this->request);
  131. $pn_set_id = $this->request->getParameter('set_id', pInteger);
  132. $t_set = new ca_sets($pn_set_id);
  133. $this->view->setVar('set_id', $pn_set_id);
  134. $pn_set_item_id = $this->request->getParameter('set_item_id', pInteger);
  135. $t_set_item = new ca_set_items($pn_set_item_id);
  136. $va_set_item_info = array();
  137. $va_items = $t_set->getItemIDs(array("checkAccess" => $va_access_values, 'access' => __CA_SET_READ_ACCESS__, 'user_id' => $this->request->getUserID()));
  138. $pn_previous_id = "";
  139. foreach($va_items as $vn_item_id => $va_item_info){
  140. if($va_set_item_info["item_id"]){
  141. $va_set_item_info["next_id"] = $vn_item_id;
  142. break;
  143. }
  144. if($pn_set_item_id == $vn_item_id){
  145. $va_set_item_info["previous_id"] = $pn_previous_id;
  146. $va_set_item_info["item_id"] = $vn_item_id;
  147. }
  148. $pn_previous_id = $vn_item_id;
  149. }
  150. $va_set_item_info["item_id"] = $t_set_item->get("item_id");
  151. $va_rep = $t_set_item->getRepresentations(array("mediumlarge", "small"), null, array("return_with_access" => $va_access_values));
  152. $this->view->setVar('t_object_representation', $t_rep = new ca_object_representations($va_rep[0]['representation_id']));
  153. $va_rep_display_info = caGetMediaDisplayInfo('cropped_gallery_media_overlay', $t_rep->getMediaInfo('media', 'INPUT', 'MIMETYPE'));
  154. $this->view->setVar('rep_display_version', $va_rep_display_info['display_version']);
  155. unset($va_display_info['display_version']);
  156. $va_rep_display_info['poster_frame_url'] = $t_rep->getMediaUrl('media', $va_rep_display_info['poster_frame_version']);
  157. unset($va_display_info['poster_frame_version']);
  158. $this->view->setVar('rep_display_options', $va_rep_display_info);
  159. $va_set_item_info["info"] = $va_rep[0]['info'];
  160. $va_set_item_info["label"] = $t_set_item->getLabelForDisplay();
  161. $va_set_item_info["description"] = $t_set_item->get($this->opo_plugin_config->get('set_description_element_code'), array('convertLineBreaks' => true));
  162. $va_set_item_info["row_id"] = $t_set_item->get("row_id");
  163. $t_object = new ca_objects($t_set_item->get("row_id"));
  164. $va_set_item_info["object_label"] = $t_object->getLabelForDisplay();
  165. $this->view->setVar('item_info', $va_set_item_info);
  166. $this->view->setVar('t_object', $t_object);
  167. $this->render($this->ops_theme.'/ajax_item_info_html.php');
  168. }
  169. # -------------------------------------------------------
  170. }
  171. ?>