/
list.php
executable file
·137 lines (114 loc) · 3.81 KB
/
list.php
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
/**
* @package DOCman
* @copyright Copyright (C) 2011 - 2014 Timble CVBA (http://www.timble.net)
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
* @link http://www.joomlatools.com
*/
class ComDocmanControllerList extends ComKoowaControllerView implements KControllerModellable
{
/**
* Model object or identifier (com://APP/COMPONENT.model.NAME)
*
* @var string|object
*/
protected $_model;
public function __construct(KObjectConfig $config)
{
parent::__construct($config);
// Set the model identifier
$this->_model = $config->model;
if ($this->isDispatched())
{
$this->addBehavior('com://site/docman.controller.behavior.filterable', array(
'vars' => array(
'sort' => 'sort_documents'
)
));
}
}
protected function _initialize(KObjectConfig $config)
{
$config->append(array(
'formats' => array('json', 'rss'),
'model' => 'com://site/docman.model.categories',
'behaviors' => array('persistable')
));
parent::_initialize($config);
}
public function getRequest()
{
$request = parent::getRequest();
$query = $request->query;
if (!isset($query->slug) && isset($query->path)) {
$query->slug = array_pop(explode('/', $query->path));
}
return $request;
}
public function getView()
{
if(!$this->_view instanceof KViewInterface)
{
//Get the view
$view = parent::getView();
//Set the model in the view
$view->setModel($this->getModel());
}
return parent::getView();
}
/**
* Get the model object attached to the controller
*
* @throws \UnexpectedValueException If the model doesn't implement the ModelInterface
* @return KModelInterface
*/
public function getModel()
{
if(!$this->_model instanceof KModelInterface)
{
//Make sure we have a model identifier
if(!($this->_model instanceof KObjectIdentifier)) {
$this->setModel($this->_model);
}
$this->_model = $this->getObject($this->_model);
if(!$this->_model instanceof KModelInterface)
{
throw new UnexpectedValueException(
'Model: '.get_class($this->_model).' does not implement KModelInterface'
);
}
//Inject the request into the model state
$this->_model->getState()->insert('status', 'cmd');
$this->_model->setState($this->getRequest()->query->toArray());
}
return $this->_model;
}
/**
* Method to set a model object attached to the controller
*
* @param mixed $model An object that implements KObjectInterface, KObjectIdentifier object
* or valid identifier string
* @return KControllerView
*/
public function setModel($model)
{
if(!($model instanceof KModelInterface))
{
if(is_string($model) && strpos($model, '.') === false )
{
// Model names are always plural
if(KStringInflector::isSingular($model)) {
$model = KStringInflector::pluralize($model);
}
$identifier = $this->getIdentifier()->toArray();
$identifier['path'] = array('model');
$identifier['name'] = $model;
$identifier = $this->getIdentifier($identifier);
}
else $identifier = $this->getIdentifier($model);
$model = $identifier;
}
$this->_model = $model;
return $this->_model;
}
}