Esempio n. 1
0
 /**
  * Search users
  * @return string
  * @throws \Ffcms\Core\Exception\SyntaxException
  * @throws \Ffcms\Core\Exception\NativeException
  */
 public function actionSearch()
 {
     // create model object
     $model = new FormUserSearch();
     $model->setSubmitMethod('GET');
     // get app configs
     $cfgs = $this->getConfigs();
     $records = null;
     $pagination = null;
     // check if request is sended
     if ($model->send() && $model->validate()) {
         // get records from db
         $records = ProfileRecords::where('nick', 'like', '%' . $model->query . '%');
         $page = (int) $this->request->query->get('page');
         $userPerPage = (int) $cfgs['usersOnPage'];
         if ($userPerPage < 1) {
             $userPerPage = 1;
         }
         $offset = $page * $userPerPage;
         // build pagination
         $pagination = new SimplePagination(['url' => ['profile/search', null, null, [$model->getFormName() . '[query]' => $model->query, $model->getFormName() . '[submit]' => true]], 'page' => $page, 'step' => $userPerPage, 'total' => $records->count()]);
         // make query finally
         $records = $records->skip($offset)->take($userPerPage)->get();
     }
     // display response
     return $this->view->render('search', ['model' => $model, 'records' => $records, 'pagination' => $pagination, 'ratingOn' => (int) $cfgs['rating']]);
 }