コード例 #1
0
ファイル: LibroSearch.php プロジェクト: ibergonzi/country
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Libro::find()->joinWith('userCreatedBy');
     $pageSize = isset($_GET['per-page']) ? $_GET['per-page'] : \Yii::$app->params['libro.defaultPageSize'];
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $pageSize], 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC], 'enableMultiSort' => true]]);
     // Agregado a mano, para que incluya el ordenamiento por descCliente
     $dataProvider->sort->attributes['descUsuario'] = ['asc' => ['user.username' => SORT_ASC], 'desc' => ['user.username' => SORT_DESC]];
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['libro.id' => $this->id, 'idporton' => $this->idporton]);
     $query->andFilterWhere(['like', 'texto', $this->texto])->andFilterWhere(['like', 'user.username', $this->descUsuario]);
     if (isset($params['resetFechas'])) {
         \Yii::$app->session->remove('libroFecDesde');
         \Yii::$app->session->remove('libroFecHasta');
         $this->fecdesde = null;
         $this->fechasta = null;
         unset($params['resetFechas']);
     }
     if (!empty($this->fecdesde) && !empty($this->fechasta)) {
         // cada vez que se envia el form con el rango de fechas se guardan las fechas en sesion
         \Yii::$app->session->set('libroFecDesde', $this->fecdesde);
         \Yii::$app->session->set('libroFecHasta', $this->fechasta);
         // para el between entre datetimes se debe agregar un dia mas a la fecha hasta
         $f = new \DateTime($this->fechasta);
         $f->add(new \DateInterval('P1D'));
         $query->andFilterWhere(['between', 'libro.created_at', $this->fecdesde, $f->format('Y-m-d')]);
         //unset($this->fecdesde);
     } else {
         $sfd = \Yii::$app->session->get('libroFecDesde') ? \Yii::$app->session->get('libroFecDesde') : '';
         $sfh = \Yii::$app->session->get('libroFecHasta') ? \Yii::$app->session->get('libroFecHasta') : '';
         // si todavia están en sesion las variables del rango de fechas se hace el between y se elimina created_at
         if ($sfd && $sfh) {
             // para el between entre datetimes se debe agregar un dia mas a la fecha hasta
             $f = new \DateTime(\Yii::$app->session->get('libroFecHasta'));
             $f->add(new \DateInterval('P1D'));
             $query->andFilterWhere(['between', 'libro.created_at', \Yii::$app->session->get('libroFecDesde'), $f->format('Y-m-d')]);
             $this->created_at = '';
         } else {
             $query->andFilterWhere(['like', 'libro.created_at', $this->fecSP2EN($this->created_at)]);
         }
     }
     return $dataProvider;
 }
コード例 #2
0
ファイル: LibroController.php プロジェクト: ibergonzi/country
 /**
  * Finds the Libro model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Libro the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Libro::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }