aboutsummaryrefslogtreecommitdiff
path: root/ratatoeskr/sys
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2011-10-05 14:27:15 +0200
committerKevin Chabowski <kevin@kch42.de>2011-10-05 14:27:15 +0200
commit1141e8e9fe480b0407d4d7e247efadb4e12c7db6 (patch)
tree3dec0ff73468cb7d4fd490c6fba0f18702d67d23 /ratatoeskr/sys
parent2e0b96389928162d6fb7b524a7c5af5fc61faa6c (diff)
downloadratatoeskr-cms-1141e8e9fe480b0407d4d7e247efadb4e12c7db6.tar.gz
ratatoeskr-cms-1141e8e9fe480b0407d4d7e247efadb4e12c7db6.tar.bz2
ratatoeskr-cms-1141e8e9fe480b0407d4d7e247efadb4e12c7db6.zip
Fixed docu and added some features to models.php
* New NaturalDocs topics: STETag and STEVar. * Article::by_multi added. * Article::get_comments can nof filter comments.
Diffstat (limited to 'ratatoeskr/sys')
-rw-r--r--ratatoeskr/sys/models.php77
-rw-r--r--ratatoeskr/sys/translation.php2
2 files changed, 63 insertions, 16 deletions
diff --git a/ratatoeskr/sys/models.php b/ratatoeskr/sys/models.php
index 83fe748..eb8f26c 100644
--- a/ratatoeskr/sys/models.php
+++ b/ratatoeskr/sys/models.php
@@ -34,6 +34,18 @@ $imagetype_file_extensions = array(
$ratatoeskr_settings = NULL;
/*
+ * Constants: ARTICLE_STATUS_
+ * Possible <Article>::$status values.
+ *
+ * ARTICLE_STATUS_HIDDEN - Article is hidden (Numeric: 0)
+ * ARTICLE_STATUS_LIVE - Article is visible / live (Numeric: 1)
+ * ARTICLE_STATUS_STICKY - Article is sticky (Numeric: 2)
+ */
+define("ARTICLE_STATUS_HIDDEN", 0);
+define("ARTICLE_STATUS_LIVE", 1);
+define("ARTICLE_STATUS_STICKY", 2);
+
+/*
* Class: DoesNotExistError
* This Exception is thrown by an ::by_*-constructor or any array-like object if the desired object is not present in the database.
*/
@@ -1621,17 +1633,6 @@ class Image
}
/*
- * Constants: Possible <Article>::$status values.
- *
- * ARTICLE_STATUS_HIDDEN - Article is hidden
- * ARTICLE_STATUS_LIVE - Article is visible / live
- * ARTICLE_STATUS_STICKY - Article is sticky
- */
-define("ARTICLE_STATUS_HIDDEN", 0);
-define("ARTICLE_STATUS_LIVE", 1);
-define("ARTICLE_STATUS_STICKY", 2);
-
-/*
* Class: Article
* Representation of an article
*/
@@ -1753,12 +1754,12 @@ class Article
/*
* Constructor: by_urlname
- * Get by urlname
+ * Get by urltitle
*
* Parameters:
* $urlname - The urlname
*/
- public static function by_urlname($id)
+ public static function by_urlname($urlname)
{
$obj = new self;
$obj ->populate_by_sqlresult(qdb(
@@ -1768,6 +1769,41 @@ class Article
}
/*
+ * Constructor: by_multi
+ * Get Articles by multiple criterias
+ *
+ * Parameters:
+ * $criterias - Array that can have these keys: id, urltitle, section, status
+ *
+ * Returns:
+ * Array of Article objects
+ */
+ public function by_multi($criterias)
+ {
+ $subqueries = array();
+ foreach($criterias as $k => $v)
+ {
+ switch($k)
+ {
+ case "id": $subqueries[] = qdb_fmt("`id` = %d", $v); break;
+ case "urltitle": $subqueries[] = qdb_fmt("`urltitle` = '%s'", $v); break;
+ case "section": $subqueries[] = qdb_fmt("`section` = %d", $v->get_id()); break;
+ case "status": $subqueries[] = qdb_fmt("`status` = %d", $v); break;
+ default: continue;
+ }
+ }
+
+ if(empty($subqueries))
+ return self::all(); /* No limiting criterias, so we take them all... */
+
+ $result = qdb("SELECT `id` FROM `PREFIX_articles` WHERE " . implode(" AND ", $subqueries));
+ $rv = array();
+ while($sqlrow = mysql_fetch_assoc($result))
+ $rv[] = self::by_id($sqlrow["id"]);
+ return $rv;
+ }
+
+ /*
* Constructor: all
* Get all articles
*
@@ -1787,13 +1823,24 @@ class Article
* Function: get_comments
* Getting comments for this article.
*
+ * Parameters:
+ * $limit_lang - Get only comments in a language (empty string for no limitation, this is the default).
+ * $only_visible - Do you only want the visible comments? (Default: False)
+ *
* Returns:
* Array of <Comment> objects.
*/
- public function get_comments()
+ public function get_comments($limit_lang = "", $only_visible = false)
{
$rv = array();
- $result = qdb("SELECT `id` FROM `PREFIX_comments` WHERE `article` = %d", $this->id);
+
+ $conditions = array(qdb_fmt("`article` = %d", $this->id));
+ if($limit_lang != "")
+ $conditions[] = qdb_fmt("`language` = '%s'", $limit_lang);
+ if($only_visible)
+ $conditions[] = "`visible` = 1";
+
+ $result = qdb("SELECT `id` FROM `PREFIX_comments` WHERE " . implode(" AND ", $conditions));
while($sqlrow = mysql_fetch_assoc($result))
$rv[] = Comment::by_id($sqlrow["id"]);
return $rv;
diff --git a/ratatoeskr/sys/translation.php b/ratatoeskr/sys/translation.php
index 01f7c6d..cd40f85 100644
--- a/ratatoeskr/sys/translation.php
+++ b/ratatoeskr/sys/translation.php
@@ -1,6 +1,6 @@
<?php
/*
- * File: ratatoeskr/backend/main.php
+ * File: ratatoeskr/sys/translation.php
* Load translation.
*
* License: