PageRenderTime 67ms CodeModel.GetById 36ms RepoModel.GetById 1ms app.codeStats 0ms

/app/lib/pawtucket/BaseDetailController.php

https://bitbucket.org/Sinfin/pawtucket
PHP | 683 lines | 479 code | 66 blank | 138 comment | 86 complexity | 436bdb5da0bddc7302bb4dbcac9816dd MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0
  1. <?php
  2. /* ----------------------------------------------------------------------
  3. * app/lib/ca/BaseBrowseController.php : base controller for search interface
  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_LIB_DIR__."/ca/ImportExport/DataExporter.php");
  29. require_once(__CA_APP_DIR__.'/helpers/accessHelpers.php');
  30. require_once(__CA_LIB_DIR__."/core/Datamodel.php");
  31. require_once(__CA_LIB_DIR__.'/ca/ResultContext.php');
  32. require_once(__CA_LIB_DIR__.'/core/GeographicMap.php');
  33. require_once(__CA_MODELS_DIR__."/ca_bundle_displays.php");
  34. require_once(__CA_MODELS_DIR__."/ca_bundle_mappings.php");
  35. require_once(__CA_MODELS_DIR__."/ca_relationship_types.php");
  36. require_once(__CA_MODELS_DIR__."/ca_collections.php");
  37. require_once(__CA_MODELS_DIR__."/ca_objects.php");
  38. require_once(__CA_MODELS_DIR__."/ca_sets.php");
  39. require_once(__CA_MODELS_DIR__."/ca_lists.php");
  40. class BaseDetailController extends ActionController {
  41. # -------------------------------------------------------
  42. protected $opo_datamodel;
  43. protected $ops_context = '';
  44. protected $opo_browse;
  45. protected $ops_tablename;
  46. # -------------------------------------------------------
  47. #
  48. # -------------------------------------------------------
  49. public function __construct(&$po_request, &$po_response, $pa_view_paths=null) {
  50. $this->opo_datamodel = Datamodel::load();
  51. $vs_browse_table_name = $po_request->config->get('allow_browse_within_detail_for_'.$this->ops_tablename);
  52. // create object browse for filtering objects on collection detail page
  53. $this->opo_browse = $this->getBrowseInstance($vs_browse_table_name, $po_request->session->getVar($this->ops_tablename.'_'.$this->ops_appname.'_detail_current_browse_id'), $this->ops_appname.'_detail');
  54. $this->opa_sorts = $this->getBrowseSorts($vs_browse_table_name);
  55. parent::__construct($po_request, $po_response, $pa_view_paths);
  56. JavascriptLoadManager::register('tabs');
  57. JavascriptLoadManager::register('maps');
  58. }
  59. # -------------------------------------------------------
  60. /**
  61. * Sets current browse context
  62. * Settings for the current browse are stored per-context. This means if you
  63. * have multiple interfaces in the same application using browse services
  64. * you can keep their settings (and caches) separate by varying the context.
  65. *
  66. * The browse engine and browse controller both have their own context settings
  67. * but the BaseDetailController is setup to make the browse engine's context its own.
  68. * Thus you only need set the context for the engine; the controller will inherit it.
  69. */
  70. public function setContext($ps_context) {
  71. $this->ops_context = $ps_context;
  72. }
  73. # -------------------------------------------------------
  74. /**
  75. * Returns the current browse context
  76. */
  77. public function getContext($ps_context) {
  78. return $this->ops_context;
  79. }
  80. # -------------------------------------------------------
  81. # Detail display
  82. # -------------------------------------------------------
  83. /**
  84. * Alias for show() method
  85. */
  86. public function Index() {
  87. $this->Show();
  88. }
  89. # -------------------------------------------------------
  90. /**
  91. * Generates detail detail. Will use a view named according to the following convention:
  92. * <table_name>_<type_code>_detail_html.php
  93. *
  94. * So for example, the detail for objects of type 'artwork' (where 'artwork' is the type code for the artwork object type)
  95. * the view would be named "ca_objects_artwork_detail_html.php
  96. *
  97. * If the type specific view does not exist, then Show() will attemp to use a generic table-wide view name like this:
  98. * <table_name>_detail_html.php
  99. *
  100. * For example: "ca_objects_detail_html.php"
  101. *
  102. * In general you should always have the table wide views defined. Then you can define type-specific views for your
  103. * application on an as-needed basis.
  104. */
  105. public function Show() {
  106. JavascriptLoadManager::register('browsable');
  107. // JavascriptLoadManager::register('docReader');
  108. // JavascriptLoadManager::register('jquery', 'expander');
  109. $va_access_values = caGetUserAccessValues($this->request);
  110. $this->view->setVar('access_values', $va_access_values);
  111. if(!$t_item = $this->opo_datamodel->getInstanceByTableName($this->ops_tablename, true)) {
  112. die("Invalid table name ".$this->ops_tablename." for detail"); // shouldn't happen
  113. }
  114. if(!($vn_item_id = $this->request->getParameter($t_item->primaryKey(), pInteger))){
  115. $this->notification->addNotification(_t("Invalid ID"), "message");
  116. $this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
  117. return;
  118. }
  119. if(!$t_item->load($vn_item_id)){
  120. $this->notification->addNotification(_t("ID does not exist"), "message");
  121. $this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
  122. return;
  123. }
  124. if($t_item->hasField('deleted') && $t_item->get('deleted')){
  125. $this->notification->addNotification(_t("ID has been deleted"), "message");
  126. $this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
  127. return;
  128. }
  129. #
  130. # Enforce access control
  131. #
  132. if(sizeof($va_access_values) && !in_array($t_item->get("access"), $va_access_values)){
  133. $this->notification->addNotification(_t("This item is not available for view"), "message");
  134. $this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
  135. return;
  136. }
  137. //
  138. // In-detail browsing of objects - limited to object linked to the item being displayed
  139. //
  140. if (($vs_browse_for_table = $this->request->config->get('allow_browse_within_detail_for_'.$this->ops_tablename)) && is_object($this->opo_browse)) {
  141. // set browse context for controller
  142. $this->setContext($this->opo_browse->getContext());
  143. //
  144. // Restrict facets to specific group for refine browse (if set in app.conf config)
  145. //
  146. if ($vs_facet_group = $this->request->config->get('ca_objects_refine_facet_group')) {
  147. $this->opo_browse->setFacetGroup($vs_facet_group);
  148. }
  149. $t_table = $this->opo_datamodel->getInstanceByTableName($this->ops_tablename, true);
  150. if ($this->request->session->getVar($this->ops_tablename.'_'.$this->ops_appname.'_detail_current_item_id') != $vn_item_id) {
  151. $this->opo_browse->removeAllCriteria();
  152. }
  153. // look for 'authority' facet for current detail table type so we can limit the object browse to the currently displayed item
  154. $vs_limit_facet_name = null;
  155. foreach($this->opo_browse->getInfoForFacets() as $vs_facet_name => $va_facet_info) {
  156. if (($va_facet_info['type'] === 'authority') && ($va_facet_info['table'] === $this->ops_tablename)) {
  157. $vs_limit_facet_name = $vs_facet_name;
  158. break;
  159. }
  160. }
  161. if ($vs_limit_facet_name) {
  162. $this->opo_browse->addCriteria($vs_limit_facet_name, array($vn_item_id));
  163. $this->opo_browse->execute(array('checkAccess' => $va_access_values));
  164. $this->request->session->setVar($this->ops_tablename.'_'.$this->ops_appname.'_detail_current_browse_id', $this->opo_browse->getBrowseID());
  165. $this->view->setVar('show_browse', true);
  166. //
  167. // Browse paging
  168. //
  169. $vn_items_per_page = $this->request->config->get("objects_per_page_for_detail_pages");
  170. if(!$vn_items_per_page){
  171. $vn_items_per_page = 12;
  172. }
  173. $this->view->setVar('page', ($vn_p = $this->request->getParameter('page', pInteger)) ? $vn_p : 1);
  174. if ($this->opo_browse) {
  175. $va_sort = array();
  176. if ($vs_sort = $this->request->config->get('sort_browse_within_detail_for_'.$this->ops_tablename)) {
  177. $va_sort = array('sort' => $vs_sort);
  178. }
  179. $qr_hits = $this->opo_browse->getResults($va_sort);
  180. $vn_num_pages = ceil($qr_hits->numHits()/$vn_items_per_page);
  181. $qr_hits->seek(($vn_p - 1) * $vn_items_per_page);
  182. } else {
  183. $vn_num_pages = 0;
  184. }
  185. $this->view->setVar('browse_results', $qr_hits);
  186. $this->view->setVar('num_pages', $vn_num_pages);
  187. $this->view->setVar('items_per_page', $vn_items_per_page);
  188. $this->view->setVar('opo_browse', $this->opo_browse);
  189. $this->view->setVar('sorts', $this->opa_sorts); // supported sorts for the object browse
  190. // browse criteria in an easy-to-display format
  191. $va_browse_criteria = array();
  192. foreach($this->opo_browse->getCriteriaWithLabels() as $vs_facet_code => $va_criteria) {
  193. $va_facet_info = $this->opo_browse->getInfoForFacet($vs_facet_code);
  194. $va_criteria_list = array();
  195. foreach($va_criteria as $vn_criteria_id => $vs_criteria_label) {
  196. $va_criteria_list[] = $vs_criteria_label;
  197. }
  198. $va_browse_criteria[$va_facet_info['label_singular']] = join('; ', $va_criteria_list);
  199. }
  200. $this->view->setVar('browse_criteria', $va_browse_criteria);
  201. } else {
  202. // not configured for browse
  203. $this->request->session->setVar($this->ops_tablename.'_'.$this->ops_appname.'_detail_current_browse_id', null);
  204. $this->view->setVar('show_browse', false);
  205. }
  206. }
  207. $this->request->session->setVar($this->ops_tablename.'_'.$this->ops_appname.'_detail_current_item_id', $vn_item_id);
  208. # Next and previous navigation
  209. $opo_result_context = new ResultContext($this->request, $this->ops_tablename, ResultContext::getLastFind($this->request, $this->ops_tablename));
  210. $this->view->setVar('next_id', $opo_result_context->getNextID($vn_item_id));
  211. $this->view->setVar('previous_id', $opo_result_context->getPreviousID($vn_item_id));
  212. # Is the item we're show details for in the result set?
  213. $this->view->setVar('is_in_result_list', ($opo_result_context->getIndexInResultList($vn_item_id) != '?'));
  214. # Item instance and id
  215. $this->view->setVar('t_item', $t_item);
  216. $this->view->setVar($t_item->getPrimaryKey(), $vn_item_id);
  217. # Item - preferred
  218. $this->view->setVar('label', $t_item->getLabelForDisplay());
  219. # Item - nonpreferred
  220. $this->view->setVar('nonpreferred_labels', caExtractValuesByUserLocale($t_item->getNonPreferredLabels()));
  221. # Item timestamps (creation and last change)
  222. if ($va_entry_info = $t_item->getCreationTimestamp()) {
  223. $this->view->setVar('date_of_entry', date('m/d/Y', $va_entry_info['timestamp']));
  224. }
  225. if ($va_last_change_info = $t_item->getLastChangeTimestamp()) {
  226. $this->view->setVar('date_of_last_change', date('m/d/Y', $va_last_change_info['timestamp']));
  227. }
  228. # Media representations to display (objects only)
  229. if (method_exists($t_item, 'getPrimaryRepresentationInstance')) {
  230. if ($t_primary_rep = $t_item->getPrimaryRepresentationInstance()) {
  231. if (!sizeof($va_access_values) || in_array($t_primary_rep->get('access'), $va_access_values)) { // check rep access
  232. $this->view->setVar('t_primary_rep', $t_primary_rep);
  233. $va_rep_display_info = caGetMediaDisplayInfo('detail', $t_primary_rep->getMediaInfo('media', 'INPUT', 'MIMETYPE'));
  234. $this->view->setVar('primary_rep_display_version', $va_rep_display_info['display_version']);
  235. unset($va_display_info['display_version']);
  236. $va_rep_display_info['poster_frame_url'] = $t_primary_rep->getMediaUrl('media', $va_rep_display_info['poster_frame_version']);
  237. unset($va_display_info['poster_frame_version']);
  238. $this->view->setVar('primary_rep_display_options', $va_rep_display_info);
  239. }
  240. }
  241. }
  242. #
  243. # User-generated comments, tags and ratings
  244. #
  245. $va_user_comments = $t_item->getComments(null, true);
  246. $va_comments = array();
  247. if (is_array($va_user_comments)) {
  248. foreach($va_user_comments as $va_user_comment){
  249. if($va_user_comment["comment"] || $va_user_comment["media1"] || $va_user_comment["media2"] || $va_user_comment["media3"] || $va_user_comment["media4"]){
  250. # TODO: format date based on locale
  251. $va_user_comment["date"] = date("n/j/Y", $va_user_comment["created_on"]);
  252. # -- get name of commenter
  253. $t_user = new ca_users($va_user_comment["user_id"]);
  254. $va_user_comment["author"] = $t_user->getName();
  255. $va_comments[] = $va_user_comment;
  256. }
  257. }
  258. }
  259. $this->view->setVar('comments', $va_comments);
  260. $va_user_tags = $t_item->getTags(null, true);
  261. $va_tags = array();
  262. if (is_array($va_user_tags)) {
  263. foreach($va_user_tags as $va_user_tag){
  264. if(!in_array($va_user_tag["tag"], $va_tags)){
  265. $va_tags[] = $va_user_tag["tag"];
  266. }
  267. }
  268. }
  269. $this->view->setVar('tags_array', $va_tags);
  270. $this->view->setVar('tags', implode(", ", $va_tags));
  271. $this->view->setVar('result_context', $opo_result_context);
  272. # -- get average user ranking
  273. $this->view->setVar('ranking', $t_item->getAverageRating(null)); // null makes it ignore moderation status
  274. # -- get number of user rankings
  275. $this->view->setVar('numRankings', $t_item->getNumRatings(null)); // null makes it ignore moderation status
  276. #
  277. # Miscellaneous useful information
  278. #
  279. $this->view->setVar('t_relationship_types', new ca_relationship_types()); // relationship types object - used for displaying relationship type of related authority information
  280. if (method_exists($t_item, 'getTypeName')) { $this->view->setVar('typename', $t_item->getTypeName()); }
  281. // Record view
  282. $t_item->registerItemView($this->request->getUserID());
  283. # Media representations to display (objects only)
  284. if (method_exists($t_item, 'getRepresentations')) {
  285. // Get all representations
  286. $size = array('large', 'original', 'fullscreen');
  287. $representations = $t_item->getRepresentations($size, null, array('checkAccess' => $va_access_values));
  288. $images = false;
  289. $audio = false;
  290. $video = false;
  291. $rewrite = $t_item->get('object_text');
  292. if (strlen($rewrite) == 0) $rewrite = false;
  293. foreach ($representations as $id => $repre) {
  294. $type = explode('/', $repre['info']['original']['MIMETYPE']);
  295. switch ($type[0]) {
  296. case 'audio':
  297. if (!$audio) $audio = array();
  298. $audio[$id] = $repre;
  299. break;
  300. case 'video':
  301. if (!$video) $video = array();
  302. $video[$id] = $repre;
  303. break;
  304. default: // image
  305. if (!$images) $images = array();
  306. $images[$id] = $repre;
  307. break;
  308. }
  309. }
  310. $this->view->setVar("representations_images", $images);
  311. $this->view->setVar("representations_audio", $audio);
  312. $this->view->setVar("representations_video", $video);
  313. $this->view->setVar("representations_rewrite", $rewrite);
  314. }
  315. //
  316. // Render view
  317. //
  318. if ($this->getView()->viewExists($this->ops_tablename.'_'.$t_item->getTypeCode().'_detail_html.php')) {
  319. $this->render($this->ops_tablename.'_'.$t_item->getTypeCode().'_detail_html.php');
  320. } else {
  321. $this->render($this->ops_tablename.'_detail_html.php');
  322. }
  323. }
  324. # -------------------------------------------------------
  325. # Tagging and commenting
  326. # -------------------------------------------------------
  327. public function saveCommentRanking() {
  328. if(!$t_item = $this->opo_datamodel->getInstanceByTableName($this->ops_tablename)) {
  329. die("Invalid table name ".$this->ops_tablename." for saving comment");
  330. }
  331. if(!($vn_item_id = $this->request->getParameter($t_item->primaryKey(), pInteger))){
  332. $this->notification->addNotification(_t("Invalid ID"), "message");
  333. $this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
  334. return;
  335. }
  336. if(!$t_item->load($vn_item_id)){
  337. $this->notification->addNotification(_t("ID does not exist"), "message");
  338. $this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
  339. return;
  340. }
  341. # --- get params from form
  342. $ps_comment = $this->request->getParameter('comment', pString);
  343. $pn_rank = $this->request->getParameter('rank', pInteger);
  344. $ps_tags = $this->request->getParameter('tags', pString);
  345. $ps_email = $this->request->getParameter('email', pString);
  346. $ps_name = $this->request->getParameter('name', pString);
  347. $ps_media1 = $_FILES['media1']['tmp_name'];
  348. $ps_media1_original_name = $_FILES['media1']['name'];
  349. if($ps_comment || $pn_rank || $ps_tags || $ps_media1){
  350. if(!(($pn_rank > 0) && ($pn_rank <= 5))){
  351. $pn_rank = null;
  352. }
  353. if($ps_comment || $pn_rank || $ps_media1){
  354. $t_item->addComment($ps_comment, $pn_rank, $this->request->getUserID(), null, $ps_name, $ps_email, ($this->request->config->get("dont_moderate_comments")) ? 1:0, null, array('media1_original_filename' => $ps_media1_original_name), $ps_media1);
  355. }
  356. if($ps_tags){
  357. $va_tags = array();
  358. $va_tags = explode(",", $ps_tags);
  359. foreach($va_tags as $vs_tag){
  360. $t_item->addTag(trim($vs_tag), $this->request->getUserID(), null, ($this->request->config->get("dont_moderate_comments")) ? 1:0, null);
  361. }
  362. }
  363. if($ps_comment || $ps_tags || $ps_media1){
  364. if($this->request->config->get("dont_moderate_comments")){
  365. $this->notification->addNotification(_t("Thank you for contributing."), "message");
  366. }else{
  367. $this->notification->addNotification(_t("Thank you for contributing. Your comments will be posted on this page after review by site staff."), "message");
  368. }
  369. # --- check if email notification should be sent to admin
  370. if(!$this->request->config->get("dont_email_notification_for_new_comments")){
  371. # --- send email confirmation
  372. # -- generate mail subject line
  373. ob_start();
  374. require($this->request->getViewsDirectoryPath()."/mailTemplates/admin_comment_notification_subject.tpl");
  375. $vs_subject_line = ob_get_contents();
  376. ob_end_clean();
  377. # -- generate mail text from template - get both html and text versions
  378. ob_start();
  379. require($this->request->getViewsDirectoryPath()."/mailTemplates/admin_comment_notification.tpl");
  380. $vs_mail_message_text = ob_get_contents();
  381. ob_end_clean();
  382. ob_start();
  383. require($this->request->getViewsDirectoryPath()."/mailTemplates/admin_comment_notification_html.tpl");
  384. $vs_mail_message_html = ob_get_contents();
  385. ob_end_clean();
  386. caSendmail($this->request->config->get("ca_admin_email"), $this->request->config->get("ca_admin_email"), $vs_subject_line, $vs_mail_message_text, $vs_mail_message_html);
  387. }
  388. }else{
  389. $this->notification->addNotification(_t("Thank you for your contribution."), "message");
  390. }
  391. }
  392. $this->Show();
  393. }
  394. # -------------------------------------------------------
  395. # Detail-based browsing
  396. # -------------------------------------------------------
  397. public function getFacet() {
  398. $ps_facet_name = $this->request->getParameter('facet', pString);
  399. if ($this->request->getParameter('clear', pInteger)) {
  400. $this->opo_browse->removeAllCriteria();
  401. $this->opo_browse->execute(array('checkAccess' => $va_access_values));
  402. $this->request->session->setVar($this->ops_tablename.'_'.$this->ops_context.'_current_browse_id', $this->opo_browse->getBrowseID());
  403. } else {
  404. if ($this->request->getParameter('modify', pString)) {
  405. $vm_id = $this->request->getParameter('id', pString);
  406. $this->opo_browse->removeCriteria($ps_facet_name, array($vm_id));
  407. $this->opo_browse->execute(array('checkAccess' => $va_access_values));
  408. $this->view->setVar('modify', $vm_id);
  409. }
  410. }
  411. $va_facet = $this->opo_browse->getFacet($ps_facet_name, array('sort' => 'name', 'checkAccess' => $va_access_values));
  412. $this->view->setVar('facet', $va_facet);
  413. $this->view->setVar('facet_info', $va_facet_info = $this->opo_browse->getInfoForFacet($ps_facet_name));
  414. $this->view->setVar('facet_name', $ps_facet_name);
  415. $this->view->setVar('browse_id', $pn_browse_id);
  416. $this->view->setVar('grouping', $this->request->getParameter('grouping', pString));
  417. // generate type menu and type value list for related authority table facet
  418. if ($va_facet_info['type'] === 'authority') {
  419. $t_model = $this->opo_datamodel->getTableInstance($va_facet_info['table']);
  420. if (method_exists($t_model, "getTypeList")) {
  421. $this->view->setVar('type_list', $t_model->getTypeList());
  422. }
  423. $t_rel_types = new ca_relationship_types();
  424. $this->view->setVar('relationship_type_list', $t_rel_types->getRelationshipInfo($va_facet_info['relationship_table']));
  425. }
  426. $t_table = $this->opo_datamodel->getTableInstance($this->ops_tablename);
  427. $this->view->setVar('other_parameters', array($t_table->primaryKey() => $this->request->getParameter($t_table->primaryKey(), pInteger)));
  428. $this->render('../Browse/ajax_browse_facet_html.php');
  429. }
  430. # -------------------------------------------------------
  431. public function addCriteria() {
  432. $ps_facet_name = $this->request->getParameter('facet', pString);
  433. $this->opo_browse->addCriteria($ps_facet_name, array($this->request->getParameter('id', pString)));
  434. $this->Show();
  435. }
  436. # -------------------------------------------------------
  437. public function modifyCriteria() {
  438. $ps_facet_name = $this->request->getParameter('facet', pString);
  439. $this->opo_browse->removeCriteria($ps_facet_name, array($this->request->getParameter('mod_id', pString)));
  440. $this->opo_browse->addCriteria($ps_facet_name, array($this->request->getParameter('id', pString)));
  441. $this->Show();
  442. }
  443. # -------------------------------------------------------
  444. public function removeCriteria() {
  445. $ps_facet_name = $this->request->getParameter('facet', pString);
  446. $this->opo_browse->removeCriteria($ps_facet_name, array($this->request->getParameter('id', pString)));
  447. $this->Show();
  448. }
  449. # -------------------------------------------------------
  450. public function clearCriteria() {
  451. $this->opo_browse->removeAllCriteria();
  452. $this->Show();
  453. }
  454. # ------------------------------------------------------------------
  455. /**
  456. * Export displayed item
  457. */
  458. public function exportItem() {
  459. if(!$t_item = $this->opo_datamodel->getInstanceByTableName($this->ops_tablename, true)) {
  460. die("Invalid table name ".$this->ops_tablename." for detail"); // shouldn't happen
  461. }
  462. if(!($vn_item_id = $this->request->getParameter($t_item->primaryKey(), pInteger))){
  463. $this->notification->addNotification(_t("Invalid ID"), "message");
  464. $this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
  465. return;
  466. }
  467. if(!$t_item->load($vn_item_id)){
  468. $this->notification->addNotification(_t("ID does not exist"), "message");
  469. $this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
  470. return;
  471. }
  472. $ps_mapping = $this->request->getParameter('mapping', pString);
  473. $t_mapping = new ca_bundle_mappings();
  474. if(!$t_mapping->load(array('mapping_code' => $ps_mapping))) {
  475. $this->notification->addNotification(_t("Mapping does not exist"), "message");
  476. $this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
  477. return;
  478. }
  479. if(!$t_mapping->get('access')) {
  480. $this->notification->addNotification(_t("Export format cannot be used"), "message");
  481. $this->response->setRedirect(caNavUrl($this->request, "", "", "", ""));
  482. return;
  483. }
  484. $vn_mapping_id = $t_mapping->getPrimaryKey();
  485. $o_export = new DataExporter();
  486. $this->view->setVar('export_mimetype', $o_export->exportMimetype($vn_mapping_id));
  487. $this->view->setVar('export_data', $o_export->export($vn_mapping_id, $t_item, null, array('returnOutput' => true, 'returnAsString' => true)));
  488. $this->view->setVar('export_filename', preg_replace('![\W]+!', '_', substr($t_item->getLabelForDisplay(), 0, 40).'_'.$o_export->exportTarget($vn_mapping_id)).'.'.$o_export->exportFileExtension($vn_mapping_id));
  489. $this->render('export_xml.php');
  490. }
  491. # -------------------------------------------------------
  492. /**
  493. *
  494. */
  495. protected function getBrowseInstance($pm_table_name_or_num, $pn_browse_id, $ps_context) {
  496. $vs_table = $this->opo_datamodel->getTableName($pm_table_name_or_num);
  497. switch($vs_table) {
  498. case 'ca_entities':
  499. require_once(__CA_LIB_DIR__.'/ca/Browse/EntityBrowse.php');
  500. return new EntityBrowse($pn_browse_id, $ps_context);
  501. break;
  502. case 'ca_places':
  503. require_once(__CA_LIB_DIR__.'/ca/Browse/PlaceBrowse.php');
  504. return new PlaceBrowse($pn_browse_id, $ps_context);
  505. break;
  506. case 'ca_occurrences':
  507. require_once(__CA_LIB_DIR__.'/ca/Browse/OccurrenceBrowse.php');
  508. return new OccurrenceBrowse($pn_browse_id, $ps_context);
  509. break;
  510. case 'ca_collections':
  511. require_once(__CA_LIB_DIR__.'/ca/Browse/CollectionBrowse.php');
  512. return new CollectionBrowse($pn_browse_id, $ps_context);
  513. break;
  514. case 'ca_object_lots':
  515. require_once(__CA_LIB_DIR__.'/ca/Browse/ObjectLotBrowse.php');
  516. return new ObjectLotBrowse($pn_browse_id, $ps_context);
  517. break;
  518. case 'ca_loans':
  519. require_once(__CA_LIB_DIR__.'/ca/Browse/LoanBrowse.php');
  520. return new LoanBrowse($pn_browse_id, $ps_context);
  521. break;
  522. case 'ca_movements':
  523. require_once(__CA_LIB_DIR__.'/ca/Browse/MovementBrowse.php');
  524. return new MovementBrowse($pn_browse_id, $ps_context);
  525. break;
  526. case 'ca_storage_locations':
  527. require_once(__CA_LIB_DIR__.'/ca/Browse/StorageLocationBrowse.php');
  528. return new StorageLocationBrowse($pn_browse_id, $ps_context);
  529. break;
  530. case 'ca_objects':
  531. default:
  532. if (($vs_table == 'ca_objects') || (int)$pm_table_name_or_num) {
  533. require_once(__CA_LIB_DIR__.'/ca/Browse/ObjectBrowse.php');
  534. return new ObjectBrowse($pn_browse_id, $ps_context);
  535. }
  536. break;
  537. }
  538. return null;
  539. }
  540. # -------------------------------------------------------
  541. /**
  542. *
  543. */
  544. protected function getBrowseSorts($pm_table_name_or_num) {
  545. $va_sorts = null;
  546. switch($vs_table) {
  547. case 'ca_entities':
  548. $va_sorts = array(
  549. 'ca_entity_labels.displayname' => _t('name'),
  550. 'ca_entities.type_id' => _t('type'),
  551. 'ca_entities.idno' => _t('idno')
  552. );
  553. break;
  554. case 'ca_places':
  555. $va_sorts = array(
  556. 'ca_place_labels.name' => _t('name'),
  557. 'ca_places.type_id' => _t('type'),
  558. 'ca_places.idno' => _t('idno')
  559. );
  560. break;
  561. case 'ca_occurrences':
  562. $va_sorts = array(
  563. 'ca_occurrence_labels.name' => _t('name'),
  564. 'ca_occurrences.type_id' => _t('type'),
  565. 'ca_occurrences.idno' => _t('idno')
  566. );
  567. break;
  568. case 'ca_collections':
  569. $va_sorts = array(
  570. 'ca_collection_labels.name' => _t('name'),
  571. 'ca_collections.type_id' => _t('type'),
  572. 'ca_collections.idno' => _t('idno')
  573. );
  574. break;
  575. case 'ca_object_lots':
  576. $va_sorts = array(
  577. 'ca_object_lot_labels.name' => _t('name'),
  578. 'ca_object_lots.type_id' => _t('type'),
  579. 'ca_object_lots.idno_stub' => _t('idno')
  580. );
  581. break;
  582. case 'ca_loans':
  583. $va_sorts = array(
  584. 'ca_loan_labels.name' => _t('short description'),
  585. 'ca_loans.type_id' => _t('type'),
  586. 'ca_loans.idno' => _t('idno')
  587. );
  588. break;
  589. case 'ca_movements':
  590. $va_sorts = array(
  591. 'ca_movement_labels.name' => _t('short description'),
  592. 'ca_movements.type_id' => _t('type'),
  593. 'ca_movements.idno' => _t('idno')
  594. );
  595. break;
  596. case 'ca_storage_locations':
  597. $va_sorts = array(
  598. 'ca_storage_location_labels.name' => _t('name'),
  599. 'ca_storage_locations.type_id' => _t('type')
  600. );
  601. break;
  602. case 'ca_objects':
  603. default:
  604. if (($vs_table == 'ca_objects') || (int)$pm_table_name_or_num) {
  605. $va_sorts = array(
  606. 'ca_object_labels.name' => _t('title'),
  607. 'ca_objects.type_id' => _t('type'),
  608. 'ca_objects.idno' => _t('idno')
  609. );
  610. }
  611. break;
  612. }
  613. return $va_sorts;
  614. }
  615. # -------------------------------------------------------
  616. }
  617. ?>