예제 #1
0
 public function actionStudentlist($id)
 {
     // "Response content must not be an array."
     /*$students = \app\models\Studentmodule::find()->where(['Module_id' => $id])->orderBy('id')->all();
       return $students;
        */
     // "Response content must be a string or an object implementing __toString()"
     $DataProvider = new ActiveDataProvider(['query' => Studentmodule::find()->where(['Module_id' => $id])->orderBy('id')->all()]);
     // When use this and return $Model instead of $DataProvider
     // http://stackoverflow.com/questions/27746984/criteria-active-data-provider-in-yii-2
     $Model = $DataProvider->getModels();
     return $Model;
 }
예제 #2
0
 public static function getMenuTree()
 {
     if (empty(self::$menuTree)) {
         $criteria = new CDbCriteria();
         $criteria->condition = '`t`.`parent_id`= :root';
         $criteria->params = array(':root' => 0);
         $criteria->order = '`t`.`id` ASC';
         $criteria->scopes = 'module';
         $rows = new ActiveDataProvider('CategoriesModel', array('criteria' => $criteria));
         foreach ($rows->getData() as $key => $item) {
             self::$menuTree[] = self::getMenuItems($item);
         }
     }
     return self::$menuTree;
 }
예제 #3
0
 public function actionList()
 {
     // Autenticacion
     // $this->_checkAuth();
     $modelo = array_key_exists('model', $_GET) ? $_GET['model'] : '';
     if ($modelo != '') {
         $dataProvider = new ActiveDataProvider($modelo);
         // Almacenamiento Log de sincronizacion
         $this->almacenarHistoriaSincOnline('list', $_GET, 'GET');
         $this->_sendResponse(200, CJSON::encode($dataProvider->getData()));
     } else {
         $this->_sendResponse(501, sprintf('Error: Modo <b>List</b> no esta implementado en el modelo <b>%s</b>', $modelo));
         Yii::app()->end();
     }
 }
예제 #4
0
 /**
  * getFromDataProvider
  * @return []Sitemap
  */
 private function getFromDataProvider()
 {
     $pagination = $this->dataProvider->getPagination();
     $pageCount = $pagination->pageCount;
     $pageParam = $pagination->pageParam;
     $indexModels = [];
     for ($i = 0; $i < $pageCount; ++$i) {
         $currentPage = $i + 1;
         if ($this->isClosure) {
             $indexModels[] = call_user_func($this->remap, $currentPage, $pageParam);
         } else {
             $indexModels[] = $this->getModel($currentPage, $this->route, $pageParam);
         }
     }
     return $indexModels;
 }
 /**
  * getFromDataProvider
  * @return Sitemap[]
  */
 protected function getFromDataProvider()
 {
     $pagination = $this->dataProvider->getPagination();
     $pageCount = $pagination->pageCount;
     $pageParam = $pagination->pageParam;
     $outModels = [];
     $hasRemap = $this->remap !== null;
     for ($i = 0; $i < $pageCount; ++$i) {
         $currentPage = $i + 1;
         if ($hasRemap) {
             $outModels[] = call_user_func($this->remap, $currentPage, $pageParam);
         } else {
             $outModels[] = $this->getModel($currentPage, $this->route, $pageParam);
         }
     }
     return $outModels;
 }
 public function actionSearch()
 {
     $GET = \Yii::$app->request->get();
     if (!empty($GET)) {
         $model = new $this->modelClass();
         foreach ($GET as $key => $value) {
             if (!$model->hasAttribute($key)) {
                 throw new \yii\web\HttpException(404, 'Invalid attribute:' . $key);
             }
         }
         try {
             $provider = new ActiveDataProvider(['query' => $model->find()->where($GET), 'pagination' => false]);
         } catch (Exception $ex) {
             throw new \yii\web\HttpException(500, 'Internal server error');
         }
         if ($provider->getCount() <= 0) {
             throw new \yii\web\HttpException(404, 'No entries found with this query string');
         } else {
             return $provider;
         }
     } else {
         throw new \yii\web\HttpException(400, 'There are no query string');
     }
 }
예제 #7
0
 public static function listData($model, $keyName, $valueName)
 {
     $data = [];
     $provider = new ActiveDataProvider(['query' => $model::find(), 'pagination' => false]);
     foreach ($provider->getModels() as $model) {
         $data[$model->{$keyName}] = $model->{$valueName};
     }
     return $data;
 }
 public function initDataProvider()
 {
     $this->search = new Search(Comments2Message::className());
     $this->dataProvider = $this->search->getDataProvider();
     if ($this->enabledPaging == Cms::BOOL_Y) {
         $this->dataProvider->getPagination()->defaultPageSize = $this->pageSize;
         $this->dataProvider->getPagination()->pageParam = $this->pageParamName;
     } else {
         $this->dataProvider->pagination = false;
     }
     if ($this->orderBy) {
         $this->dataProvider->getSort()->defaultOrder = [$this->orderBy => (int) $this->order];
     }
     return $this;
 }
예제 #9
0
 public function run()
 {
     $file = new MediaFile();
     $dp = new ActiveDataProvider($file, ['criteria' => $file->parentModel(Yii::app()->controller->user, true)->type(MediaFile::TYPE_VIDEO)->getDbCriteria(), 'pagination' => false]);
     $this->render('_videoPlayList', ['data' => $dp->getData()]);
 }