From 1da17132715b1d23144ecedf48ca86fc03d91ff2 Mon Sep 17 00:00:00 2001 From: Ferenc Szekely Date: Fri, 23 Mar 2012 19:08:12 +0200 Subject: [PATCH] preparations to accept QA forms --- controllers/comments.php | 95 +++++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 41 deletions(-) diff --git a/controllers/comments.php b/controllers/comments.php index 033ddf2..c3147c9 100644 --- a/controllers/comments.php +++ b/controllers/comments.php @@ -165,9 +165,13 @@ public function post_add(array $args) return; } - if ($_POST['type'] != 1) + if ( $_POST['type'] != '1' + && $_POST['type'] != '8') { - throw new midgardmvc_exception_notfound("Only 'content' type ('1') is supported for now. Please set it."); + $ocs->writeError('Content type: ' . $_POST['type'] . ' is not supported.', 104); + $ocs->endDocument(); + self::output_xml($ocs); + return; } $primary = new com_meego_package(); @@ -178,49 +182,58 @@ public function post_add(array $args) throw new midgardmvc_exception_notfound("Content object not found"); } - $comment = new com_meego_comments_comment(); - - if ( isset($_POST['parent']) - && !empty($_POST['parent'])) - { - $parent = new com_meego_comments_comment(); - $parent->get_by_id((int) $_POST['parent']); - if ($parent->to != $primary->guid) - { - throw new midgardmvc_exception_notfound("Parent comment is not related to the content item"); - } - $comment->up = $parent->id; - } - - $comment->to = $primary->guid; - $comment->content = $_POST['message']; - - if ( isset($_POST['subject']) - && !empty($_POST['subject'])) - { - $comment->title = $_POST['subject']; - } - - $comment->create(); - - if ($comment->guid) + switch ($_POST['type']) { - $rating = new com_meego_ratings_rating(); - - $rating->to = $primary->guid; - // for comments we have no votes - $rating->rating = 0; - - $rating->comment = $comment->id; - - if (! $rating->create()) - { - throw new midgardmvc_exception_notfound("Could not create rating object"); - } + case 1: + $comment = new com_meego_comments_comment(); + + if ( isset($_POST['parent']) + && !empty($_POST['parent'])) + { + $parent = new com_meego_comments_comment(); + $parent->get_by_id((int) $_POST['parent']); + if ($parent->to != $primary->guid) + { + throw new midgardmvc_exception_notfound("Parent comment is not related to the content item"); + } + $comment->up = $parent->id; + } + + $comment->to = $primary->guid; + $comment->content = $_POST['message']; + + if ( isset($_POST['subject']) + && !empty($_POST['subject'])) + { + $comment->title = $_POST['subject']; + } + + $comment->create(); + + if ($comment->guid) + { + $rating = new com_meego_ratings_rating(); + + $rating->to = $primary->guid; + // for comments we have no votes + $rating->rating = 0; + + $rating->comment = $comment->id; + + if (! $rating->create()) + { + throw new midgardmvc_exception_notfound("Could not create rating object"); + } + } + break; + case 8: + break; } - $ocs->writeMeta(0); + // POST went fine + $ocs->writeMeta(null, null, 'Posting succeded.', 'ok', 100); $ocs->endDocument(); + self::output_xml($ocs); }