CMS  Version 3.9
Blog Class Reference

Inherits DataItem.

Public Member Functions

 Owner ()
 
 getOwnerName ()
 
 Image ()
 
 Subscribers ($constraint="")
 
 allowDelete ()
 
 getSortOrderConstraint ()
 
 Articles ($constraint="")
 
 countArticles ()
 
 getURL ()
 Determines the URL for the blog. More...
 
 enumerateContentLinks ()
 
 Blog ()
 
 search ($params, $range=null)
 

Static Public Member Functions

static findByIdentifier ($identifier)
 
static findByTitle ($title)
 
static getArticleTypeOptions ()
 

Public Attributes

 $fields
 
 $versioned_fields = array("title", "description", "image_id")
 
 $relations
 

Detailed Description

Definition at line 40 of file blog.inc.

Member Function Documentation

◆ allowDelete()

Blog::allowDelete ( )

Definition at line 94 of file blog.inc.

95  {
96  if(!checkRole("admin"))
97  {
98  return false;
99  }
100 
101  $articles = Query::create(Article, "WHERE article_type=:article_type")
102  ->bind(":article_type", $this->title)
103  ->executeValue("COUNT(1)");
104 
105  return $articles > 0 ? false : true;
106  }
return false
$bookmark title
Defines the Article class.
Definition: article.inc:45
$articles
Definition: rss.inc:62

◆ Articles()

Blog::Articles (   $constraint = "")

Definition at line 130 of file blog.inc.

131  {
132  if (!$constraint || stripos($constraint, "ORDER") === false)
133  {
135  }
136 
137  $constraint = preg_replace("/^\s*WHERE\s+/i", "AND ", $constraint);
138 
139  $constraint = "WHERE article_type=:a $constraint";
140 
141  $articles = Query::create(Article, $constraint)
142  ->bind(":a", $this->title)
143  ->execute();
144 
145  return $articles;
146  }
$constraint
getSortOrderConstraint()
Definition: blog.inc:108

◆ Blog()

Blog::Blog ( )

Definition at line 222 of file blog.inc.

223  {
224  $this->primary_key = "blog_id";
225  $this->table = "blog";
226 
227  $this->default_format = "{title}";
228 
229  // Patch in the user class, since this can be overridden by the application
230  $mgr = new UserManager();
231  $this->relations["Owner"] = $mgr->getUserClass();
232 
233  $this->DataItem(func_get_args());
234  }
Provides the interface to the user model for the application.

◆ countArticles()

Blog::countArticles ( )

Definition at line 148 of file blog.inc.

149  {
150  return Query::create(Article, "WHERE article_type=:a")
151  ->bind(":a", $this->title)
152  ->executeValue("COUNT(1)");
153  }

◆ enumerateContentLinks()

Blog::enumerateContentLinks ( )

Definition at line 210 of file blog.inc.

211  {
212  $articles = $this->Articles("WHERE published=1 ORDER BY sort_order, title");
213  $links = array();
214  foreach($articles as $article)
215  {
216  $links[$article->title] = $this->identifier."?article_id=".$article->article_id;
217  }
218 
219  return $links;
220  }
$article
Articles($constraint="")
Definition: blog.inc:130

◆ findByIdentifier()

static Blog::findByIdentifier (   $identifier)
static

Definition at line 155 of file blog.inc.

156  {
157  $match = Query::create(Blog, "WHERE identifier=:id")
158  ->bind(":id", $identifier)
159  ->executeSingle();
160 
161  return $match;
162  }
Definition: blog.inc:41
$identifier
Definition: rss.inc:37

◆ findByTitle()

static Blog::findByTitle (   $title)
static

Definition at line 164 of file blog.inc.

165  {
166  $match = Query::create(Blog, "WHERE title=:title")
167  ->bind(":title", $title)
168  ->executeSingle();
169 
170  return $match;
171  }

◆ getArticleTypeOptions()

static Blog::getArticleTypeOptions ( )
static

Definition at line 197 of file blog.inc.

198  {
199  $blogs = Query::create(Blog, "ORDER BY title")->execute();
200  $options = array();
201  foreach($blogs as $blog)
202  {
203  $options[$blog->title] = $blog->title;
204  }
205 
206  return $options;
207  }
$blog
Definition: blog.inc:44

◆ getOwnerName()

Blog::getOwnerName ( )

Definition at line 79 of file blog.inc.

80  {
81  return $this->Owner()->getFullName();
82  }
Owner()
Definition: blog.inc:73

◆ getSortOrderConstraint()

Blog::getSortOrderConstraint ( )

Definition at line 108 of file blog.inc.

109  {
110  $constraint = "";
111  switch($this->default_article_order)
112  {
113  case "DESC":
114  $constraint = " ORDER BY publish_date DESC";
115  break;
116 
117  case "ASC":
118  $constraint = " ORDER BY publish_date ASC";
119  break;
120 
121  case "SORT":
122  default:
123  $constraint = " ORDER BY sort_order";
124  break;
125  }
126 
127  return $constraint;
128  }

◆ getURL()

Blog::getURL ( )

Determines the URL for the blog.

Definition at line 177 of file blog.inc.

178  {
179  global $config;
180 
181  $url = "";
182 
183  if ($this->identifier)
184  {
185  $contents = SectionContent::getMappedContent($this->identifier);
186  if (count($contents))
187  {
188  $section = $contents[0]->Section();
189 
190  $url = $section->getSectionURL() . $this->identifier;
191  }
192  }
193 
194  return $url;
195  }
$section
Definition: event_form.inc:44
static getMappedContent($identifier)
Definition: section.inc:324
global $config
Definition: import.inc:4
if(! $blog->published||! $blog->enable_rss_feed||!checkRole($blog->allow_read)) $url
Definition: rss.inc:58

◆ Image()

Blog::Image ( )

Definition at line 84 of file blog.inc.

85  {
86  return $this->getRelated(ImageRecord);
87  }

◆ Owner()

Blog::Owner ( )

Definition at line 73 of file blog.inc.

74  {
75  $mgr = new UserManager();
76  return $mgr->getUser($this->owner_id);
77  }
$calendar owner_id

◆ search()

Blog::search (   $params,
  $range = null 
)

Definition at line 238 of file blog.inc.

239  {
240  trace("Searching Blogs", 3);
241 
242  if ($range)
243  {
244  $range = " AND {$this->primary_key} IN (".implode($range, ", ").")";
245  }
246 
247  if (is_object($params))
248  {
249  $search = clone $params;
250  $search->target = $this;
251 
252  $search->remapField("text", "description");
253 
254  $constraint = $search->generateConstraint();
255  $constraint .= $constraint ? " AND published=1" : " WHERE published=1";
256 
257  $constraint .= $range;
258 
259  $blogs = Query::create(Blog, $constraint)->execute();
260  }
261  else
262  {
263  $params = "%$params%";
264  $blogs = Query::create(Blog, "WHERE (title like :a OR description LIKE :b) AND published=1 $range")
265  ->bind(":a", $params, ":b", $params)
266  ->execute();
267  }
268 
270  }
$range
Definition: error_log.inc:13
static wrap($items, $resultClass)

◆ Subscribers()

Blog::Subscribers (   $constraint = "")

Definition at line 89 of file blog.inc.

90  {
91  return $this->getRelatedList(BlogSubscriber, "", $constraint);
92  }

Member Data Documentation

◆ $fields

Blog::$fields
Initial value:
= array("blog_id" => Number,
"title" => String,
"identifier" => String,
"image_id" => Number,
"description" => HTML,
"owner_id" => Number,
"read_access" => String,
"write_access" => String,
"default_article_order" => String,
"articles_per_page" => Number,
"blog_type" => String,
"allow_comments" => Boolean,
"comment_moderators" => String,
"published" => Boolean,
"created_date" => DateTime,
"allow_subscriptions" => Boolean,
"enable_rss_feed" => Boolean,
"max_rss_articles" => Number)

Definition at line 43 of file blog.inc.

◆ $relations

Blog::$relations
Initial value:
= array(
"Owner" => "",
"Articles" => Article,
"Image" => ImageRecord,
"Subscribers" => BlogSubscriber
)

Definition at line 66 of file blog.inc.

◆ $versioned_fields

Blog::$versioned_fields = array("title", "description", "image_id")

Definition at line 62 of file blog.inc.


The documentation for this class was generated from the following file: