ActivityController::comment PHP Метод

comment() публичный Метод

Comment on an activity item.
С версии: 2.0.0
public comment ( )
    public function comment()
    {
        $this->permission('Garden.Profiles.Edit');
        $Session = Gdn::session();
        $this->Form->setModel($this->ActivityModel);
        $NewActivityID = 0;
        // Form submitted
        if ($this->Form->authenticatedPostBack()) {
            $Body = $this->Form->getValue('Body', '');
            $ActivityID = $this->Form->getValue('ActivityID', '');
            if (is_numeric($ActivityID) && $ActivityID > 0) {
                $activity = $this->ActivityModel->getID($ActivityID);
                if ($activity) {
                    if ($activity['NotifyUserID'] == ActivityModel::NOTIFY_ADMINS) {
                        $this->permission('Garden.Settings.Manage');
                    } elseif ($activity['NotifyUserID'] == ActivityModel::NOTIFY_MODS) {
                        $this->permission('Garden.Moderation.Manage');
                    }
                } else {
                    throw new Exception(t('Invalid activity'));
                }
                $ActivityComment = array('ActivityID' => $ActivityID, 'Body' => $Body, 'Format' => 'Text');
                $ID = $this->ActivityModel->comment($ActivityComment);
                if ($ID == SPAM || $ID == UNAPPROVED) {
                    $this->StatusMessage = t('ActivityCommentRequiresApproval', 'Your comment will appear after it is approved.');
                    $this->render('Blank', 'Utility');
                    return;
                }
                $this->Form->setValidationResults($this->ActivityModel->validationResults());
                if ($this->Form->errorCount() > 0) {
                    throw new Exception($this->ActivityModel->Validation->resultsText());
                    $this->errorMessage($this->Form->errors());
                }
            }
        }
        // Redirect back to the sending location if this isn't an ajax request
        if ($this->_DeliveryType === DELIVERY_TYPE_ALL) {
            $Target = $this->Form->getValue('Return');
            if (!$Target) {
                $Target = '/activity';
            }
            redirect($Target);
        } else {
            // Load the newly added comment.
            $this->setData('Comment', $this->ActivityModel->getComment($ID));
            // Set it in the appropriate view.
            $this->View = 'comment';
        }
        // And render
        $this->render();
    }