Ejemplo n.º 1
0
 /**
  * Moderate guest comments and answer - make it publish
  * @param string $type
  * @param int $id
  * @return string
  * @throws NotFoundException
  * @throws \Ffcms\Core\Exception\SyntaxException
  * @throws \Ffcms\Core\Exception\NativeException
  */
 public function actionPublish($type, $id = 0)
 {
     // check if it multiple accept ids
     if ($id === 0 || (int) $id < 1) {
         $ids = $this->request->query->get('selected');
         if (Obj::isArray($ids) && Arr::onlyNumericValues($ids)) {
             $id = $ids;
         } else {
             throw new NotFoundException('Bad conditions');
         }
     } else {
         $id = [$id];
     }
     // build query
     $query = null;
     switch ($type) {
         case static::TYPE_COMMENT:
             $query = CommentPost::whereIn('id', $id)->where('moderate', '=', 1);
             break;
         case static::TYPE_ANSWER:
             $query = CommentAnswer::whereIn('id', $id)->where('moderate', '=', 1);
             break;
     }
     // check if result is not empty
     if ($query === null || $query->count() < 1) {
         throw new NotFoundException(__('No comments found for this condition'));
     }
     // initialize moderation model
     $model = new FormCommentModerate($query, $type);
     // check if form is submited
     if ($model->send()) {
         $model->make();
         App::$Session->getFlashBag()->add('success', __('Comments or answers are successful published'));
         $this->response->redirect('comments/' . ($type === 'answer' ? 'answerlist' : 'index'));
     }
     return $this->view->render('publish', ['model' => $model]);
 }