CMS  Version 3.9
document.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 
42 class Document extends DataItem implements Searchable
43 {
44  // Fields
45 
46  var $fields = array("document_id" => Number,
47  "title" => String,
48  "file" => String,
49  "url" => String,
50  "publication_date" => Date,
51  "keywords" => String,
52  "author" => String,
53  "publication" => String,
54  "image_id" => Image,
55  "notes" => HTML,
56  "public" => Boolean,
57  "last_modified" => Timestamp,
58  "document_library_id" => Number,
59  "owner_id" => Number,
60  "allow_access" => String
61  );
62 
63  // Relations
64 
65  var $relations = array( "Topics" => Topic,
66  "Owner" => "",
67  "DocumentLibrary" => DocumentLibrary,
68  "Comments" => Comment,
69  "Image" => ImageRecord
70  );
71 
72  var $fieldAliases = array("image_id" => "Image",
73  "url" => "External URL");
74 
75  function Topics($constraint = "")
76  {
77  return $this->crossReference(Topic, DocumentTopicXref, $constraint);
78  }
79 
80  function Comments($constraint = "")
81  {
82  return $this->crossReference(Comment, DocumentCommentXref, $constraint);
83  }
84 
85  function Image()
86  {
87  return $this->getRelated(ImageRecord);
88  }
89 
90  function Owner()
91  {
92  $mgr = new UserManager();
93  return $mgr->getUser($this->owner_id);
94  }
95 
96  function isOwner()
97  {
98  global $user;
99  $owner = $this->Owner();
100 
101  return ($owner->user_id == $user->user_id) ? true : false;
102  }
103 
104  /*
105  * For fileshare space, role-based permissions must be anything
106  * in addition or other than just "allow_access" to get edit
107  * details rights to a document.
108  */
110  {
111  global $user;
112 
113  $library = $this->DocumentLibrary();
114 
115  $member = $library->getFileshareUser($user->user_id);
116 
117  if($this->isOwner() || checkRole($library->manage_folders) ||
118  checkRole($library->upload_files) || checkRole($library->delete_files) || $member)
119  return true;
120  else
121  return false;
122  }
123 
125  {
126  $library = $this->DocumentLibrary();
127 
128  if($this->isOwner() || $library->isOwner() ||
129  checkRole($library->delete_files))
130  return true;
131  else
132  return false;
133  }
134 
135  function DocumentLibrary()
136  {
137  return $this->getRelated(DocumentLibrary);
138  }
139 
140  function Document()
141  {
142  $this->primary_key = "document_id";
143  $this->table = "document";
144 
145  // Patch in the user class, since this can be overridden by the application
146  $mgr = new UserManager();
147  $this->relations["Owner"] = $mgr->getUserClass();
148 
149  $this->default_format = "{title}";
150 
151  $this->DataItem(func_get_args());
152  }
153 
154  function search($params, $range = null)
155  {
156  trace("Searching Documents", 3);
157 
158 
159  if ($range)
160  {
161  $range = " AND {$this->primary_key} IN (".implode($range, ", ").")";
162  }
163 
164  if (is_object($params))
165  {
166  $search = clone $params;
167  $search->target = $this;
168 
169  if (!$range)
170  {
171  if (!$search->get("text", "like"))
172  {
173  $search->secondaryFields("author", "notes", "publication");
174  }
175  else
176  {
177  $search->remapField("text", "notes");
178  }
179  }
180 
181  $constraint = $search->generateConstraint();
182  $constraint .= $constraint ? " AND public=1" : " WHERE public=1";
183 
184  $constraint .= $range;
185 
186  $documents = Query::create(Document, $constraint)
187  ->execute();
188  }
189  else
190  {
191  $params = preg_replace('/[^\w]+/', ' ', $params);
192  $params = "%$params%";
193  $documents = Query::create(Document, "WHERE (title like :a OR keywords LIKE :b OR notes Like :c) and public=1 $range")
194  ->bind(":a", $params, ":b", $params, ":c", $params)
195  ->execute();
196  }
197 
199  }
200 }
201 
203 {
204  var $item;
205 
207  {
208  $this->item = $item;
209  }
210 
211  function getPrimaryKey() { return $this->item->getPrimaryKey(); }
212  function get($field) { return $this->item->get($field); }
213  function prettifyClassName($plural = false) { return $this->item->prettifyClassName($plural = false); }
214  function format($format) { return $this->item->format($format); }
215 
216  function relevance()
217  {
218  return 1;
219  }
220 
221  function title()
222  {
223  return $this->item->title;
224  }
225 
226  function date()
227  {
228  return $this->item->publication_date;
229  }
230 
231  function summary()
232  {
233  $file = $this->item->file;
234 
235  $library = $this->item->DocumentLibrary();
236  $size = $library->getFileSize($this->item);
237 
238  if (Settings::getValue("document", "link_to_details"))
239  {
240  $link = "/document_details";
241  $linkText = "View Details";
242  }
243  else
244  {
245  $link = "/action/document/download";
246  $linkText = "Download";
247  }
248 
249  $img = $this->formatIcon(getDocIcon($file), getDocType($file));
250  return $this->item->format("<h4>{title}</h4><p><em>{author} {publication_date:short}</em></p>{$img} <a href='{$link}?document_id={document_id}'>{$linkText}</a> $size");
251  }
252 }
253 
254 
255 
256 class DocumentCommentXref extends DataItem
257 {
258  var $table = "document_comment_xref";
259  var $primary_key = "document_comment_id";
260 
261  var $fields = array("document_comment_id" => Number,
262  "document_id" => Number,
263  "comment_id" => Number);
264 
265  var $relations = array( "Document" => Document,
266  "Comment" => Comment);
267 
269  {
270  if (!$document_id) return false;
271  checkNumeric($document_id);
272 
273  try
274  {
276  $library = $document->DocumentLibrary();
277  return $library->allow_comments;
278  }
279  catch(DataNotFoundException $e)
280  {
281  return false;
282  }
283  }
284 
285  function getURL()
286  {
287  if(!$this->document_id) return "";
288 
289  $url = "document_details?document_id={$this->document_id}";
290  return $url . $this->format("#comment{comment_id}");
291  }
292 
293  function Document()
294  {
295  return $this->getRelated(Document);
296  }
297 
298  function Comment()
299  {
300  return $this->getRelated(Comment);
301  }
302 
303 }
304 
305 
306 class DocumentSolrAdapter // Implements ISolrAdapter
307 {
308 
309  function getClass()
310  {
311  return Document;
312  }
313 
314  function getFilter()
315  {
316  return "WHERE public=1";
317  }
318 
319  function getTitleFormat()
320  {
321  return "{title:xml}";
322  }
323 
324  function getContentFormat()
325  {
326  return "";
327  }
328 
329  function getAuthorFormat()
330  {
331  return "{author:xml}";
332  }
333 
334  function getKeywordFormat()
335  {
336  return "{keywords:xml}";
337  }
338 
339  function wrap($item)
340  {
341  return new DocumentSearchResult($item);
342  }
343 }
344 ?>
$constraint
$calendar owner_id
if(! $document_library_id) $library
$range
Definition: error_log.inc:13
$file
Definition: delete.inc:47
$size
Definition: download.inc:47
formatIcon($icon, $alt)
Definition: searchable.inc:78
verifyEnabled($document_id)
Definition: document.inc:268
This class maps the publication table.
Definition: document.inc:43
$fieldAliases
Definition: document.inc:72
search($params, $range=null)
DataItems must implement this method to provide search functionality.
Definition: document.inc:154
Comments($constraint="")
Definition: document.inc:80
isOwner()
Definition: document.inc:96
DocumentLibrary()
Definition: document.inc:135
Topics($constraint="")
Definition: document.inc:75
fileshareAllowDelete()
Definition: document.inc:124
Document()
Definition: document.inc:140
fileshareAllowEdit()
Definition: document.inc:109
summary()
Display the item title and any other essential details for the item such as author and a create date.
Definition: document.inc:231
DocumentSearchResult($item)
Definition: document.inc:206
prettifyClassName($plural=false)
Definition: document.inc:213
static wrap($items, $resultClass)
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104
This class maps the topic table.
Definition: topic.inc:38
Provides the interface to the user model for the application.
global $user
$document_id
Definition: delete.inc:37
if(! $document_id) $document
Definition: delete.inc:43
$d document_id
Definition: download.inc:67
The Searchable interface must be implemented by any DataItem classes that want to be searchable via t...
Definition: searchable.inc:45
$documents
$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