/
wizard.php
161 lines (140 loc) · 3.86 KB
/
wizard.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
/**
* @version $Id: admin.menus.php 3504 2006-05-15 05:25:43Z eddieajau $
* @package Joomla
* @subpackage Menus
* @copyright Copyright (C) 2005 - 2006 Open Source Matters. All rights
* reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant to the
* GNU General Public License, and as distributed it includes or is derivative
* of works licensed under the GNU General Public License or other free or open
* source software licenses. See COPYRIGHT.php for copyright notices and
* details.
*/
jimport( 'joomla.application.model' );
/**
* @package Joomla
* @subpackage Menus
* @author Andrew Eddie
*/
class JMenuModelWizard extends JModel
{
var $_wizard = null;
var $_helper = null;
/** @var object JRegistry object */
var $_item = null;
function init($type='component')
{
global $mainframe;
// Create the JWizard object
jimport('joomla.presentation.wizard');
$type = $mainframe->getUserStateFromRequest('menuwizard.type', 'type', $type);
$menutype = $mainframe->getUserStateFromRequest('menuwizard.menutype', 'menutype');
$id = $mainframe->getUserStateFromRequest('menuwizard.id', 'id', false);
// Include and create the helper object
if ($type) {
require_once(COM_MENUS.'helpers'.DS.$type.'.php');
$class = 'JMenuHelper'.ucfirst($type);
$this->_helper = new $class($this);
$this->_helper->setXmlPath( COM_MENUS.'helpers'.DS.'xml' );
$name = $this->_helper->getWizardName();
} else {
$name = 'menu';
}
// Instantiate wizard
$this->_wizard = new JWizard($mainframe, $name);
// Load the XML if helper is set
if (isset($this->_helper)) {
$this->_helper->init($this->_wizard);
}
// Lets load the defaults if we are at the beginning and have an item to load them from
if (!$this->_wizard->isStarted() && $id) {
$item = & JTable::getInstance('menu', $this->getDBO());
$item->load($id);
if ($cid = $item->componentid) {
$db =& $this->getDBO();
$query = "SELECT `option`" .
"\n FROM `#__components`" .
"\n WHERE `id` = $cid";
$db->setQuery($query);
$option = $db->loadResult();
} else {
$option = 'com_content';
}
$mainframe->setUserState('request.menuwizard.type', $item->type);
$mainframe->setUserState('request.menuwizard.component', $option);
// Clear the wizard and load the default values
$this->_wizard->clear();
$this->_wizard->loadDefault($item->control);
}
}
function &getForm()
{
return $this->_wizard->getForm();
}
function getMessage()
{
return $this->_wizard->getMessage();
}
function &getConfirmation()
{
global $mainframe;
$return = &$this->_helper->getConfirmation();
$id = $mainframe->getUserStateFromRequest('menuwizard.id', 'id', false);
if ($id) {
$return['cid'] = array($id);
}
return $return;
}
function getStep()
{
return $this->_wizard->getStep();
}
function getStepName()
{
return $this->_wizard->getStepName();
}
function getSteps()
{
return $this->_wizard->getSteps();
}
/**
* Get a list of the menu_types records
* @return array An array of records as objects
*/
function getMenuTypeList()
{
$db = $this->getDBO();
$query = 'SELECT * FROM #__menu_types';
$db->setQuery( $query );
return $db->loadObjectList();
}
/**
* Get a list of the menutypes
* @return array An array of menu type names
*/
function getMenuTypes()
{
$db = $this->getDBO();
$query = 'SELECT menutype FROM #__menu_types';
$db->setQuery( $query );
return $db->loadResultArray();
}
/**
* Gets a list of components that can link to the menu
*/
function getComponentList()
{
$db = $this->getDBO();
$query = "SELECT c.id, c.name, c.link, c.option"
. "\n FROM #__components AS c"
. "\n WHERE c.link <> '' AND parent = 0"
. "\n ORDER BY c.name"
;
$db->setQuery( $query );
$result = $db->loadObjectList( );
return $result;
}
}
?>