From 1141e8e9fe480b0407d4d7e247efadb4e12c7db6 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Wed, 5 Oct 2011 14:27:15 +0200 Subject: 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. --- make_docu.sh | 9 +++-- ratatoeskr/sys/models.php | 77 ++++++++++++++++++++++++++++++++++-------- ratatoeskr/sys/translation.php | 2 +- 3 files changed, 70 insertions(+), 18 deletions(-) diff --git a/make_docu.sh b/make_docu.sh index 8d64d10..9ffe508 100755 --- a/make_docu.sh +++ b/make_docu.sh @@ -1,4 +1,9 @@ #!/usr/bin/env bash -if ! [ -d docu ]; then mkdir docu; fi -if ! [ -d naturaldocs_dir ]; then mkdir naturaldocs_dir; fi +if ! [ -d docu ]; then + mkdir docu +fi +if ! [ -d naturaldocs_dir ]; then + mkdir naturaldocs_dir + echo -e "Format: 1.4\n\nTopic Type: STE Tag\n\n Plural: STE Tags\n Scope: Always global\n\n Keywords:\n stetag, stetags\n\nTopic Type: STE Variable\n\n Plural: STE Variables\n Scope: Always global\n\n Keywords:\n stevar, stevars\n stevariable, stevariables" > naturaldocs_dir/Topics.txt +fi NaturalDocs -i . -xi ./ratatoeskr/libs/ -o HTML docu -p naturaldocs_dir/ 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 @@ -33,6 +33,18 @@ $imagetype_file_extensions = array( */ $ratatoeskr_settings = NULL; +/* + * Constants: ARTICLE_STATUS_ + * Possible
::$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. @@ -1620,17 +1632,6 @@ class Image } } -/* - * Constants: Possible
::$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( @@ -1767,6 +1768,41 @@ class Article return $obj; } + /* + * 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 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 @@