Пример #1
0
 /**
  * Delete user row from database
  * @param int $id
  * @return string
  * @throws \Ffcms\Core\Exception\SyntaxException
  * @throws \Ffcms\Core\Exception\NativeException
  * @throws NotFoundException
  */
 public function actionDelete($id = null)
 {
     // check if id is passed or get data from GET as array 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];
     }
     // initialize delete model
     $model = new FormUserDelete($id);
     // check if users is found
     if ($model->users === null) {
         throw new NotFoundException(__('Users are not found'));
     }
     // check if delete is submited
     if ($model->send() && $model->validate()) {
         $model->delete();
         App::$Session->getFlashBag()->add('success', __('Users and them data are successful removed'));
         $this->response->redirect('user/index');
     }
     // set view response
     return $this->view->render('user_delete', ['model' => $model]);
 }
Пример #2
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]);
 }