Exemplo n.º 1
0
 /**
  * Find content items on database and return rows as object
  * @return mixed
  * @throws NotFoundException
  */
 private function findItems()
 {
     if (!Obj::isArray($this->_catIds) || count($this->_catIds) < 1) {
         throw new NotFoundException(__('Category is not founded'));
     }
     // calculate selection offset
     $itemPerPage = (int) $this->_configs['itemPerCategory'];
     // check if custom itemlimit defined over model api
     if ($this->_customItemLimit !== false) {
         $itemPerPage = (int) $this->_customItemLimit;
     }
     $offset = $this->_page * $itemPerPage;
     // get all items from categories
     $query = ContentRecord::whereIn('category_id', $this->_catIds)->where('display', '=', 1);
     // save count
     $this->_contentCount = $query->count();
     // apply sort by
     switch ($this->_sort) {
         case 'rating':
             $query = $query->orderBy('rating', 'DESC');
             break;
         case 'views':
             $query = $query->orderBy('views', 'DESC');
             break;
         default:
             $query = $query->orderBy('created_at', 'DESC');
             break;
     }
     // get all items if offset is negative
     if ($itemPerPage < 0) {
         return $query->get();
     }
     // make select based on offset
     return $query->skip($offset)->take($itemPerPage)->get();
 }
Exemplo n.º 2
0
 /**
  * Publish content on moderate stage
  * @return string
  * @throws NotFoundException
  * @throws SyntaxException
  * @throws NativeException
  */
 public function actionPublish()
 {
     // get ids as array from GET
     $ids = $this->request->query->get('selected');
     if (!Obj::isArray($ids) || count($ids) < 1) {
         throw new NotFoundException(__('Items to publish is not found'));
     }
     // try to find items in db
     $records = ContentEntity::whereIn('id', $ids)->where('display', '=', 0);
     if ($records->count() < 1) {
         throw new NotFoundException(__('Items to publish is not found'));
     }
     // initialize model and operate submit
     $model = new FormContentPublish($records);
     if ($model->send() && $model->validate()) {
         $model->make();
         App::$Session->getFlashBag()->add('success', __('Content is successful published'));
         $this->response->redirect('content/index');
     }
     // draw view output
     return $this->view->render('publish', ['records' => $records->get(), 'model' => $model]);
 }