Habari\Comments::moderate_these PHP Method

moderate_these() public static method

Changes the status of comments
public static moderate_these ( array | Comments $comments, integer | string $status = null ) : boolean
$comments array | Comments Comments to be moderated
$status integer | string The new status for the provided array of comments, "unapproved" if not provided
return boolean True if all the comments were successfully changed
    public static function moderate_these($comments, $status = null)
    {
        if (empty($status)) {
            $status = Comment::status('unapproved');
        }
        // Ensure we have an id, not a string
        $status = Comment::status($status);
        $comments = Utils::single_array($comments);
        if (count($comments) == 0) {
            return false;
        }
        if ($comments[0] instanceof Comment) {
            // We were passed an array of comment objects. Use them directly.
            $result = true;
            /** @var Comment $comment */
            foreach ($comments as $comment) {
                $comment->status = $status;
                $result &= $comment->update();
                EventLog::log(_t('Comment %1$s moderated from %2$s', array($comment->id, $comment->post->title)), 'info', 'comment', 'habari');
            }
        } else {
            if (is_numeric($comments[0])) {
                $result = true;
                foreach ($comments as $commentid) {
                    $result &= DB::update(DB::table('comments'), array('status' => $status), array('id' => $commentid));
                    EventLog::log(_t('Comment %1$d moderated', array($commentid)), 'info', 'comment', 'habari');
                }
            } else {
                // We were passed a type we could not understand.
                return false;
            }
        }
        return $result;
    }