author = $author; $comment->email = $email; $comment->text = $text; $comment->datetime = $datetime; $comment->item_id = $item_id; return $comment->save(); } static function get_add_form($item) { $form = new Forge(url::site("comments/{$item->id}"), "", "post", array("id" => "gCommentForm")); $group = $form->group(_("Add Comment")); $group->input("author") ->label(_("Author")) ->id("gAuthor"); $group->input("email") ->label(_("Email")) ->id("gEmail"); $group->textarea("text")->label(_("Text")) ->id("gText"); $group->submit(_("Add")); $form->add_rules_from(ORM::factory("comment")); return $form; } static function get_edit_form($comment) { $form = new Forge( url::site("comment/{$comment->id}?_method=put"), "", "post", array("id" => "gCommentForm")); $group = $form->group(_("Edit Comment")); $group->input("author") ->label(_("Author")) ->id("gAuthor") ->value($comment->author); $group->input("email") ->label(_("Email")) ->id("gEmail") ->value($comment->email); $group->textarea("text")->label(_("Text")) ->id("gText") ->value($comment->text); $group->submit(_("Edit")); $form->add_rules_from($comment); return $form; } /** * @todo Refactor this into a more generic location */ private static function _add_validation_rules($model_name, $form) { $rules = ORM::factory($model_name)->validation_rules; foreach ($form->inputs as $name => $input) { if (isset($input->inputs)) { comment::_add_validation_rules($model_name, $input); } if (isset($rules[$name])) { $input->rules($rules[$name]); } } } static function block($theme, $show_add_form=true) { $block = new Block; $block->id = "gComment"; $block->title = _("Comments"); $block->content = comment::get_comments($theme->item()); if ($show_add_form) { $block->content .= comment::get_add_form($theme->item())->render("form.html"); } return $block; } static function get_comments($item) { $comments = array("