-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathCollectionsController.php
More file actions
137 lines (121 loc) · 4.73 KB
/
CollectionsController.php
File metadata and controls
137 lines (121 loc) · 4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/**
* Omeka
*
* @copyright Copyright 2007-2012 Roy Rosenzweig Center for History and New Media
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU GPLv3
*/
/**
* @package Omeka\Controller
*/
class CollectionsController extends Omeka_Controller_AbstractActionController
{
protected $_autoCsrfProtection = true;
public $contexts = array('show' => array('omeka-xml'));
protected $_browseRecordsPerPage = self::RECORDS_PER_PAGE_SETTING;
public function init()
{
$this->_helper->db->setDefaultModelName('Collection');
}
/**
* The show collection action.
*
* Note -- this also includes aspects of a browseAction in that in showing
* a single collection the action is also browsing items within that collection.
*/
public function showAction()
{
parent::showAction();
$recordsPerPage = $this->_getBrowseRecordsPerPage();
$currentPage = $this->getParam('page', 1);
$params = array('collection' => $this->view->collection->id);
$records = $this->_helper->db->getTable('Item')->findBy(
$params, $recordsPerPage, $currentPage);
$totalRecords = $this->_helper->db->getTable('Item')->count($params);
// Add pagination data to the registry. Used by pagination_links().
if ($recordsPerPage) {
Zend_Registry::set('pagination', array(
'page' => $currentPage,
'per_page' => $recordsPerPage,
'total_results' => $totalRecords,
));
$this->view->assign(array('items' => $records, 'total_results' => $totalRecords));
}
}
/**
* The add collection action
*/
public function addAction()
{
// Get all the element sets that apply to the item.
$this->view->elementSets = $this->_getCollectionElementSets();
parent::addAction();
}
/**
* The edit collection action
*/
public function editAction()
{
// Get all the element sets that apply to the item.
$this->view->elementSets = $this->_getCollectionElementSets();
parent::editAction();
}
protected function _getAddSuccessMessage($collection)
{
$collectionTitle = $this->_getElementMetadata($collection, 'Dublin Core', 'Title');
if ($collectionTitle != '') {
return __('The collection "%s" was successfully added!', $collectionTitle);
} else {
return __('The collection #%s was successfully added!', strval($collection->id));
}
}
protected function _getEditSuccessMessage($collection)
{
$collectionTitle = $this->_getElementMetadata($collection, 'Dublin Core', 'Title');
if ($collectionTitle != '') {
return __('The collection "%s" was successfully changed!', $collectionTitle);
} else {
return __('The collection #%s was successfully changed!', strval($collection->id));
}
}
protected function _getDeleteSuccessMessage($collection)
{
$collectionTitle = $this->_getElementMetadata($collection, 'Dublin Core', 'Title');
if ($collectionTitle != '') {
return __('The collection "%s" was successfully deleted!', $collectionTitle);
} else {
return __('The collection #%s was successfully deleted!', strval($collection->id));
}
}
protected function _getDeleteConfirmMessage($collection)
{
$collectionTitle = $this->_getElementMetadata($collection, 'Dublin Core', 'Title');
if ($collectionTitle != '') {
return __('This will delete the collection "%s" and its associated metadata. '
. 'This will not delete any items in this collection, but will '
. 'delete the reference to this collection in each item.', $collectionTitle);
} else {
return __('This will delete the collection #%s and its associated metadata. '
. 'This will not delete any items in this collection, but will '
. 'delete the reference to this collection in each item.', strval($collection->id));
}
}
protected function _getElementMetadata($collection, $elementSetName, $elementName)
{
$m = new Omeka_View_Helper_Metadata;
return strip_formatting($m->metadata($collection, array($elementSetName, $elementName)));
}
/**
* Gets the element sets for the 'Collection' record type.
*
* @return array The element sets for the 'Collection' record type
*/
protected function _getCollectionElementSets()
{
return $this->_helper->db->getTable('ElementSet')->findByRecordType('Collection');
}
protected function _getBrowseDefaultSort()
{
return array('added', 'd');
}
}