CMS  Version 3.9
menus.inc
Go to the documentation of this file.
1 <?php
7 /**************************************************************
8 
9  Copyright (c) 2010 Sonjara, Inc
10 
11  Permission is hereby granted, free of charge, to any person
12  obtaining a copy of this software and associated documentation
13  files (the "Software"), to deal in the Software without
14  restriction, including without limitation the rights to use,
15  copy, modify, merge, publish, distribute, sublicense, and/or sell
16  copies of the Software, and to permit persons to whom the
17  Software is furnished to do so, subject to the following
18  conditions:
19 
20  The above copyright notice and this permission notice shall be
21  included in all copies or substantial portions of the Software.
22 
23  Except as contained in this notice, the name(s) of the above
24  copyright holders shall not be used in advertising or otherwise
25  to promote the sale, use or other dealings in this Software
26  without prior written authorization.
27 
28  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
30  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
32  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
33  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35  OTHER DEALINGS IN THE SOFTWARE.
36 
37 *****************************************************************/
38 
39 
40 class Menu extends DataItem
41 {
42  var $primary_key = "menu_id";
43  var $table = "menu";
44 
45  var $default_format = "{name}";
46  var $pretty_class_name = "Menu";
47 
48  // Fields
49  var $fields = array("menu_id" => Number,
50  "site_id" => Number,
51  "name" => String,
52  "identifier" => String,
53  "description" => Text,
54  "css_class" => String,
55  "container_css_class" => String,
56  "wrap_menu_items" => Boolean,
57  "highlight_current_item" => Boolean,
58  "highlight_current_section" => Boolean);
59 
60  // Relations
61  var $relations = array( "Site" => Site,
62  "MenuItems" => MenuItem);
63 
64  function Site()
65  {
66  return $this->getRelated(Site);
67  }
68 
69  function MenuItems($constraint = "")
70  {
71  return $this->getRelatedList(MenuItem, "", $constraint);
72  }
73 
80  static function findByIdentifier($identifier)
81  {
82  return Query::create(Menu, "WHERE identifier=:i")
83  ->bind(":i", $identifier)
84  ->executeSingle();
85  }
86 
92  function getMenuItem($title)
93  {
94  return Query::create(MenuItem, "WHERE menu_id=:m AND title=:t")
95  ->bind(":m", $this->menu_id, ":t", $title)
96  ->executeSingle();
97  }
98 
105  {
106  return Query::create(MenuItem, "WHERE menu_id=:m AND title=:t")
107  ->bind(":m", $this->menu_id, ":t", $title)
108  ->exists();
109  }
110 }
111 
112 class MenuItem extends DataItem
113 {
114  var $primary_key = "menu_item_id";
115  var $table = "menu_item";
116 
117  var $default_format = "{title}";
118  var $pretty_class_name = "Menu Item";
119 
120  // Fields
121  var $fields = array("menu_item_id" => Number,
122  "title" => String,
123  "custom_format" => String,
124  "menu_id" => Number,
125  "parent_id" => Number,
126  "identifier" => String,
127  "page_id" => Number,
128  "url" => String,
129  "css_class" => String,
130  "sort_order" => Number,
131  "role" => String,
132  "permissions" => String,
133  "published" => Boolean,
134  "required_parameters" => String,
135  "display_flags" => String);
136 
137  var $fieldAliases = array("css_class" => "CSS Class");
138 
139  // Relations
140 
141  var $relations = array( "Page" => Page,
142  "Menu" => Menu,
143  "Parent" => MenuItem,
144  "Children" => MenuItem);
145 
146  function Page()
147  {
148  $pages = Query::create(Page, "WHERE identifier=:i")
149  ->bind(":i", $this->identifier)
150  ->execute();
151  if (count($pages) > 0)
152  {
153  return $pages[0];
154  }
155 
156  $pages = Query::create(ComponentPage, "WHERE identifier=:i")
157  ->bind(":i", $this->identifier)
158  ->execute();
159  if (count($pages) > 0)
160  {
161  return $pages[0];
162  }
163 
164  return null;
165  }
166 
167  function Menu()
168  {
169  return $this->getRelated(Menu);
170  }
171 
172  function Parent()
173  {
174  if (!$this->parent_id) return null;
175 
176  return $this->getRelated(MenuItem, "parent_id");
177  }
178 
179  function Children($constraint = "ORDER BY sort_order, title")
180  {
181  return query(MenuItem, "WHERE parent_id={$this->menu_item_id} $constraint");
182  }
183 }?>
$constraint
$menuItem menu_id
$title
Definition: menus.inc:44
Definition: menus.inc:41
$default_format
Definition: menus.inc:45
$primary_key
Definition: menus.inc:42
$relations
Definition: menus.inc:61
Site()
Definition: menus.inc:64
getMenuItem($title)
Finds the specified MenuItem within the menu, by title.
Definition: menus.inc:92
$fields
Definition: menus.inc:49
$pretty_class_name
Definition: menus.inc:46
menuItemExists($title)
Checks whether the specified menu item exists within the menu.
Definition: menus.inc:104
static findByIdentifier($identifier)
Returns the Menu object that matches the specified identifier.
Definition: menus.inc:80
MenuItems($constraint="")
Definition: menus.inc:69
$table
Definition: menus.inc:43
Menu()
Definition: menus.inc:167
Page()
Definition: menus.inc:146
$fieldAliases
Definition: menus.inc:137
Children($constraint="ORDER BY sort_order, title")
Definition: menus.inc:179
$primary_key
Definition: menus.inc:114
$default_format
Definition: menus.inc:117
Parent()
Definition: menus.inc:172
$pretty_class_name
Definition: menus.inc:118
$relations
Definition: menus.inc:141
Definition: page.inc:43
Definition: site.inc:40
$pages
Definition: export.inc:38
$identifier
Definition: rss.inc:37