CMS  Version 3.9
link_library.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 LinkLibrary extends DataItem
41 {
42  var $table = "link_library";
43  var $primary_key = "link_library_id";
44  var $default_format = "{name}";
45 
46  // Fields
47 
48  var $fields = array("link_library_id" => Number,
49  "name" => String,
50  "identifier" => String,
51  "description" => HTML,
52  "hidden" => Boolean,
53  "owner_id" => Number,
54  "read_access" => String,
55  "write_access" => String,
56  "create_date" => DateTime,
57  "last_modified" => Timestamp,
58  "enabled" => Boolean);
59 
60  var $relations = array( "Owner" => "",
61  "Links" => LinkRecord);
62 
63 
64  function Owner()
65  {
66  if(!$this->owner_id)
67  return null;
68 
69  $mgr = new UserManager();
70  return $mgr->getUser($this->owner_id);
71  }
72 
73  function isOwner()
74  {
75  global $user;
76 
77  if(!$user)
78  return false;
79 
80  $owner = $this->Owner();
81 
82  return ($owner->user_id == $user->user_id) ? true : false;
83  }
84 
85 
86  function Links($constraint = "")
87  {
88  return $this->getRelatedList(LinkRecord, "", $constraint);
89  }
90 
91  function getOwnerName()
92  {
93  $owner = $this->Owner();
94 
95  return ($owner) ? $owner->getFullName() : "";
96  }
97 
98  function countLinks($published = false)
99  {
100  $constraint = $published ? " AND published=1" : "";
101 
102  return queryValue(LinkRecord, "COUNT(1)", "WHERE link_library_id={$this->link_library_id}$constraint");
103  }
104 
105  static function findByIdentifier($identifier)
106  {
107  $match = Query::create(LinkLibrary, "WHERE identifier=:id")
108  ->bind(":id", $identifier)
109  ->executeSingle();
110 
111  return $match;
112  }
113 
114  /*
115  * Check user-level access
116  */
117  function allowReadAccess()
118  {
119  global $user;
120 
121  if(!$user)
122  $user = FileshareManager::setVisitor();
123 
124  if($this->isOwner() || checkRole($this->read_access))
125  {
126  return true;
127  }
128  return false;
129  }
130 
131  function allowWriteAccess()
132  {
133  global $user;
134 
135  if(!$user)
136  return false;
137 
138  if($this->isOwner() || checkRole($this->write_access))
139  {
140  return true;
141  }
142  return false;
143 
144  }
145 }?>
$constraint
$calendar owner_id
$published
Definition: update.inc:38
Provides the interface to the user model for the application.
global $user
$table column("Redirect From", "<a href='redirect_form?redirect_id={redirect_id}'>{redirect_from}</a>", true, "width: 30%") -> column("Redirect To", "<a href='{redirect_to}' target='_blank'>{redirect_to}</a>", true, "width: 30%") ->column("Last Modified", "{last_modified}", true, "width: 20%; text-align: center") ->column("Override", "{ override true
Definition: redirects.inc:9
$identifier
Definition: rss.inc:37