updateComment() public static method

Update an existing comment
public static updateComment ( array $item ) : integer
$item array The new data.
return integer
Example #1
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('author')->isFilled(BL::err('AuthorIsRequired'));
         $this->frm->getField('email')->isEmail(BL::err('EmailIsInvalid'));
         $this->frm->getField('text')->isFilled(BL::err('FieldIsRequired'));
         if ($this->frm->getField('website')->isFilled()) {
             $this->frm->getField('website')->isURL(BL::err('InvalidURL'));
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = $this->id;
             $item['status'] = $this->record['status'];
             $item['author'] = $this->frm->getField('author')->getValue();
             $item['email'] = $this->frm->getField('email')->getValue();
             $item['website'] = $this->frm->getField('website')->isFilled() ? $this->frm->getField('website')->getValue() : null;
             $item['text'] = $this->frm->getField('text')->getValue();
             // insert the item
             BackendBlogModel::updateComment($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit_comment', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('Comments') . '&report=edited-comment&id=' . $item['id'] . '&highlight=row-' . $item['id'] . '#tab' . \SpoonFilter::toCamelCase($item['status']));
         }
     }
 }
Example #2
0
 /**
  * Update a comment
  *
  * @param int    $id            The id of the comment.
  * @param string $status        The new status for the comment. Possible values are: published, moderation, spam.
  * @param string $text          The new text for the comment.
  * @param string $authorName    The new author for the comment.
  * @param string $authorEmail   The new email for the comment.
  * @param string $authorWebsite The new website for the comment.
  *
  * @return null|bool
  */
 public static function commentsUpdate($id, $status = null, $text = null, $authorName = null, $authorEmail = null, $authorWebsite = null)
 {
     // authorize
     if (BaseAPI::isAuthorized() && BaseAPI::isValidRequestMethod('POST')) {
         // redefine
         $id = (int) $id;
         if ($status !== null) {
             $status = (string) $status;
         }
         if ($text !== null) {
             $text = (string) $text;
         }
         if ($authorName !== null) {
             $authorName = (string) $authorName;
         }
         if ($authorEmail !== null) {
             $authorEmail = (string) $authorEmail;
         }
         if ($authorWebsite !== null) {
             $authorWebsite = (string) $authorWebsite;
         }
         // validate
         if ($status === null && $text === null && $authorName === null && $authorEmail === null && $authorWebsite === null) {
             return BaseAPI::output(BaseAPI::ERROR, array('message' => 'No data provided.'));
         }
         // update
         if ($text !== null || $authorName !== null || $authorEmail != null || $authorWebsite !== null) {
             $item['id'] = (int) $id;
             if ($text !== null) {
                 $item['text'] = $text;
             }
             if ($authorName !== null) {
                 $item['author'] = $authorName;
             }
             if ($authorEmail !== null) {
                 $item['email'] = $authorEmail;
             }
             if ($authorWebsite !== null) {
                 $item['website'] = $authorWebsite;
             }
             // update the comment
             BackendBlogModel::updateComment($item);
         }
         // change the status if needed
         if ($status !== null) {
             BackendBlogModel::updateCommentStatuses(array($id), $status);
         }
     }
 }