/
categories.php
125 lines (110 loc) · 2.97 KB
/
categories.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
<?php
/**
* @version $Id: categories.php
* @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die;
jimport('joomla.application.component.model');
/**
* This models supports retrieving lists of contact categories.
*
* @package Joomla.Administrator
* @subpackage com_contact
* @since 1.6
*/
class ContactModelCategories extends JModel
{
/**
* Model context string.
*
* @var string
*/
public $_context = 'com_contact.categories';
/**
* The category context (allows other extensions to derived from this model).
*
* @var string
*/
protected $_extension = 'com_contact';
private $_parent = null;
private $_items = null;
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @since 1.6
*/
protected function populateState()
{
$app = &JFactory::getApplication();
$this->setState('filter.extension', $this->_extension);
// Get the parent id if defined.
$parentId = JRequest::getInt('id');
$this->setState('filter.parentId', $parentId);
$params = $app->getParams();
$this->setState('params', $params);
$this->setState('filter.published', 1);
$this->setState('filter.access', true);
}
/**
* Method to get a store id based on model configuration state.
*
* This is necessary because the model is used by the component and
* different modules that might need different sets of data or different
* ordering requirements.
*
* @param string $id A prefix for the store id.
*
* @return string A store id.
*/
protected function getStoreId($id = '')
{
// Compile the store id.
$id .= ':'.$this->getState('filter.extension');
$id .= ':'.$this->getState('filter.published');
$id .= ':'.$this->getState('filter.access');
$id .= ':'.$this->getState('filter.parentId');
return parent::getStoreId($id);
}
/**
* redefine the function an add some properties to make the styling more easy
*
* @return mixed An array of data items on success, false on failure.
*/
public function getItems()
{
if(!count($this->_items))
{
$app = JFactory::getApplication();
$menu = $app->getMenu();
$active = $menu->getActive();
$params = new JRegistry();
if($active)
{
$params->loadJSON($active->params);
}
$options = array();
$options['countItems'] = $params->get('show_item_count', 0) || !$params->get('show_empty_categories', 0);
$categories = JCategories::getInstance('Contact', $options);
$this->_parent = $categories->get($this->getState('filter.parentId', 'root'));
if(is_object($this->_parent))
{
$this->_items = $this->_parent->getChildren();
} else {
$this->_items = false;
}
}
return $this->_items;
}
public function getParent()
{
if(!is_object($this->_parent))
{
$this->getItems();
}
return $this->_parent;
}
}