summaryrefslogtreecommitdiff
path: root/modules/comment/controllers
diff options
context:
space:
mode:
authorJozef Selesi <jozefs@users.sourceforge.net>2008-11-15 16:52:23 +0000
committerJozef Selesi <jozefs@users.sourceforge.net>2008-11-15 16:52:23 +0000
commitf9eaa8c220630578664fb6b46d082fce42726ca5 (patch)
treea9bac48a58c68d575ef46eed149d9daf4f6a0093 /modules/comment/controllers
parent66bd9d85b3820df8e4393019754d6a11294d4d4e (diff)
Initial add comment implementation.
Diffstat (limited to 'modules/comment/controllers')
-rw-r--r--modules/comment/controllers/comment.php100
1 files changed, 99 insertions, 1 deletions
diff --git a/modules/comment/controllers/comment.php b/modules/comment/controllers/comment.php
index dd2b44f9..fab18498 100644
--- a/modules/comment/controllers/comment.php
+++ b/modules/comment/controllers/comment.php
@@ -17,6 +17,104 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class Comment_Controller extends Controller {
+class Comment_Controller extends REST_Controller {
+ protected $resource_type = "comment";
+ /**
+ * Return the form for adding comments.
+ */
+ public function _get_form($comment) {
+ $form = new Forge(url::current(true), "", "post", array("id" => "gComment"));
+ $group = $form->group(_("Add Comment"));
+ $group->input("author")
+ ->label(_("Author"))
+ ->id("gAuthor")
+ ->class(null)
+ ->value($comment->author);
+ $group->input("email")
+ ->label(_("Email"))
+ ->id("gEmail")
+ ->class(null)
+ ->value($comment->email);
+ $group->textarea("text")
+ ->label(_("Text"))
+ ->id("gText")
+ ->class(null)
+ ->value($comment->text);
+ $group->hidden("item_id")
+ ->value($comment->item_id);
+ $group->submit(_("Add"));
+
+ $this->_add_validation_rules(ORM::factory("comment")->validation_rules, $form);
+
+ return $form;
+ }
+
+ /**
+ * @todo Refactor this into a more generic location
+ */
+ private function _add_validation_rules($rules, $form) {
+ foreach ($form->inputs as $name => $input) {
+ if (isset($input->inputs)) {
+ $this->_add_validation_rules($rules, $input);
+ }
+ if (isset($rules[$name])) {
+ $input->rules($rules[$name]);
+ }
+ }
+ }
+
+ public function add($item_id) {
+ $comment = ORM::factory('comment');
+ $comment->item_id = $item_id;
+
+ $form = $this->_get_form($comment);
+ if ($form->validate()) {
+ $comment = ORM::factory('comment');
+ $comment->author = $this->input->post('author');
+ $comment->email = $this->input->post('email');
+ $comment->text = $this->input->post('text');
+ $comment->datetime = time();
+ $comment->item_id = $this->input->post('item_id');
+ $comment->save();
+ } else {
+ print $form->render("form.html");
+ }
+ }
+
+ public function get_item_comments($item_id) {
+ $v = comment::show_comment_list($item_id);
+ print $v;
+ }
+
+ /**
+ * Get an existing comment.
+ * @see Rest_Controller::_get($resource)
+ */
+ public function _get($user) {
+ throw new Exception("@todo Comment_Controller::_get NOT IMPLEMENTED");
+ }
+
+ /**
+ * Update existing comment.
+ * @see Rest_Controller::_put($resource)
+ */
+ public function _put($resource) {
+ throw new Exception("@todo Comment_Controller::_put NOT IMPLEMENTED");
+ }
+
+ /**
+ * @see Rest_Controller::_post($resource)
+ */
+ public function _post($user) {
+ throw new Exception("@todo Comment_Controller::_post NOT IMPLEMENTED");
+ }
+
+ /**
+ * Delete existing comment.
+ * @see Rest_Controller::_delete($resource)
+ */
+ public function _delete($resource) {
+ throw new Exception("@todo Comment_Controller::_delete NOT IMPLEMENTED");
+ }
}