/** * List content items * @return string * @throws \Ffcms\Core\Exception\SyntaxException * @throws \Ffcms\Core\Exception\NativeException */ public function actionIndex() { // set current page and offset $page = (int) $this->request->query->get('page'); $offset = $page * self::ITEM_PER_PAGE; $query = null; // get query type (trash, category, all) $type = $this->request->query->get('type'); if ($type === 'trash') { $query = ContentEntity::onlyTrashed(); } elseif ($type === 'moderate') { // only items on moderate $query = ContentEntity::where('display', '=', 0); } elseif (Obj::isLikeInt($type)) { // sounds like category id ;) $query = ContentEntity::where('category_id', '=', (int) $type); } else { $query = new ContentEntity(); $type = 'all'; } // build pagination $pagination = new SimplePagination(['url' => ['content/index', null, null, ['type' => $type]], 'page' => $page, 'step' => self::ITEM_PER_PAGE, 'total' => $query->count()]); // build listing objects $records = $query->orderBy('id', 'desc')->skip($offset)->take(self::ITEM_PER_PAGE)->get(); return $this->view->render('index', ['records' => $records, 'pagination' => $pagination, 'type' => $type]); }
/** * FormContentClear constructor. Pass content records collection object inside (can be empty collection) * @param Content|Collection $records */ public function __construct($records) { $this->_records = $records; $this->count = $this->_records->count(); parent::__construct(); }