CMS  Version 3.9
link_record.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 linkation
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 Fakoli::using("search");
40 
44 class LinkRecord extends DataItem // implements Searchable
45 {
46  var $table = "link_record";
47  var $primary_key = "link_id";
48  var $pretty_class_name = "Link";
49 
50  // Fields
51 
52  var $fields = array("link_id" => Number,
53  "title" => String,
54  "url" => String,
55  "description" => HTML,
56  "published" => Boolean,
57  "last_modified" => Timestamp,
58  "link_library_id" => Number,
59  "owner_id" => Number,
60  "sort_order" => Number);
61 
62  // Relations
63 
64  var $relations = array("Owner" => "",
65  "LinkLibrary" => LinkLibrary
66  );
67 
68  function Owner()
69  {
70  $mgr = new UserManager();
71  return $mgr->getUser($this->owner_id);
72  }
73 
74  function isOwner()
75  {
76  global $user;
77  $owner = $this->Owner();
78 
79  return ($owner->user_id == $user->user_id) ? true : false;
80  }
81 
82  function LinkLibrary()
83  {
84  return $this->getRelated(LinkLibrary);
85  }
86 
87  function search($params, $range = null)
88  {
89  trace("Searching Links", 3);
90 
91  if ($range)
92  {
93  $range = " AND {$this->primary_key} IN (".implode($range, ", ").")";
94  }
95 
96  if (is_object($params))
97  {
98  $search = clone $params;
99  $search->target = $this;
100 
101  if (!$range)
102  {
103  $search->remapField("text", "description");
104  }
105 
106  $constraint = $search->generateConstraint();
107  $constraint .= $constraint ? " AND published=1" : " WHERE published=1";
108 
109  $constraint .= $range;
110 
111  $links = Query::create(LinkRecord, $constraint)
112  ->execute();
113  }
114  else
115  {
116  $params = preg_replace('/[^\w]+/', ' ', $params);
117  $params = "%$params%";
118  $links = Query::create(LinkRecord, "WHERE (title like :a OR description Like :b) and published=1 $range")
119  ->bind(":a", $params, ":b", $params)
120  ->execute();
121  }
122 
124  }
125 }
126 
128 {
129  var $item;
130 
132  {
133  $this->item = $item;
134  }
135 
136  function getPrimaryKey() { return $this->item->getPrimaryKey(); }
137  function get($field) { return $this->item->get($field); }
138  function prettifyClassName($plural = false) { return $this->item->prettifyClassName($plural = false); }
139  function format($format) { return $this->item->format($format); }
140 
141  function relevance()
142  {
143  return 1;
144  }
145 
146  function title()
147  {
148  return $this->item->title;
149  }
150 
151  function date()
152  {
153  return $this->item->publication_date;
154  }
155 
156  function summary()
157  {
158  $url = $this->item->url;
159 
160  $img = $this->formatIcon(getDocIcon($url), getDocType($url));
161 
162  return $this->item->format("{$img}<h4><a href='{url}' target='_blank'>{title}</a></h4><p><em>{description}</em></p>");
163  }
164 }
165 ?>
$constraint
$calendar owner_id
$range
Definition: error_log.inc:13
formatIcon($icon, $alt)
Definition: searchable.inc:78
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
static wrap($items, $resultClass)
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
if(! $blog->published||! $blog->enable_rss_feed||!checkRole($blog->allow_read)) $url
Definition: rss.inc:58