CMS  Version 3.9
site_map.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  * Description: data model classes for site hierarchy page
41  * chart. Site map or chart can be used for breadcrumbs
42  * and site help.
43  *
44  * author Janice Gallant for Sonjara, Inc.
45  *
46  * date: 9/30/10
47  *
48  */
49 
50 class SiteMap extends DataItem
51 {
52  var $fields = array(
53  "site_map_id" => Number,
54  "url" => String,
55  "page_title" => String,
56  "sort_order" => String,
57  "role" => String,
58  "parent_url" => String,
59  "published" => Boolean
60  );
61 
62  function Parent()
63  {
64  $parents = Query::create(SiteMap, "WHERE url=:parent_url")
65  ->bind("parent_url", $this->parent_url)
66  ->execute();
67 
68  return count($parents) ? $parents[0] : null;
69  }
70 
71  function Children($constraint = "")
72  {
73  $query = "WHERE parent_url=:url";
74  if($constraint)
75  {
76  $query .= preg_replace("/^WHERE/i", " AND", $constraint);
77  }
78  return Query::create(SiteMap, $query)
79  ->bind(":url", $this->url)
80  ->execute();
81  }
82 
83 
90  function isSibling($url)
91  {
92  $sibling = false;
93 
94  $siteMap = SiteMap::findSiteMapPage($url);
95 
96  $sibling = ($siteMap AND ($siteMap->parent_url == $this->parent_url)) ? true : false;
97 
98  return $sibling;
99  }
100 
101  static function findSiteMapPage($url)
102  {
103  if(!$url) return null;
104  $siteMaps = Query::create(SiteMap, "WHERE url=:url")
105  ->bind(":url", $url)
106  ->execute();
107 
108  return count($siteMaps) ? $siteMaps[0] : null;
109  }
110 
111  // allow delete if the page has no sub or child pages
112  function allowDelete()
113  {
114  $count = Query::create(SiteMap, "WHERE parent_url=:url")
115  ->bind(":url", $this->url)
116  ->executeValue("COUNT(1)");
117 
118  return ($count > 0) ? false : true;
119  }
120 
121  function isLeaf()
122  {
123  return $this->allowDelete();
124  }
125 
126  /*
127  * For select field renderer
128  */
129  static function getSiteMapPageList()
130  {
131  $siteMapPages = query(SiteMap, "ORDER BY url");
132 
133  if(count($siteMapPages) > 0)
134  {
135  foreach($siteMapPages as $sPage)
136  {
137  $pageList[$sPage->url] = $sPage->url . ": " . $sPage->page_title;
138  }
139  }
140 
141  $pageList[""] = "";
142  return $pageList;
143  }
144 
145  function SiteMap()
146  {
147  $this->table = "site_map";
148  $this->primary_key = "site_map_id";
149 
150  $this->DataItem(func_get_args());
151  }
152 }
153 ?>
$constraint
return false
$siteMapPages
Definition: site_map.inc:51
Children($constraint="")
Definition: site_map.inc:71
static getSiteMapPageList()
Definition: site_map.inc:129
Parent()
Definition: site_map.inc:62
static findSiteMapPage($url)
Definition: site_map.inc:101
isLeaf()
Definition: site_map.inc:121
SiteMap()
Definition: site_map.inc:145
isSibling($url)
Is the given url a sibling of this SiteMap obj.
Definition: site_map.inc:90
allowDelete()
Definition: site_map.inc:112
if(! $blog->published||! $blog->enable_rss_feed||!checkRole($blog->allow_read)) $url
Definition: rss.inc:58