public function actionIndex($start = false) { $session = Yii::$app->session; // first time save way back if (!$start) { $session->set('back_action', 'google/index'); $session->close(); $this->redirect(['google/oauth']); } $access_token = $session->get('access_token'); $model = new Book(); $xml = $model->getXml(self::SCOPE . 'spreadsheets/private/full', $access_token); $dataProvider = new ArrayDataProvider(['allModels' => $model->getSpreadsheets($xml), 'pagination' => ['pageSize' => 5], 'sort' => ['attributes' => ['updated_at']]]); if (isset($xml->title)) { list($title, $email) = explode('-', $xml->title); return $this->render('index', ['dataProvider' => $dataProvider, 'title' => $title, 'owner' => $email]); } else { throw new NotFoundHttpException('The requested model does not exist.'); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Book::find(); $query->joinWith(['author']); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 5], 'sort' => ['defaultOrder' => ['date_create' => SORT_DESC, 'title' => SORT_ASC]]]); $dataProvider->setSort(['attributes' => ['id', 'name' => ['asc' => ['name' => SORT_ASC], 'desc' => ['name' => SORT_DESC], 'label' => "Book's Title"], 'authorName' => ['asc' => ['authors.id' => SORT_ASC], 'desc' => ['authors.id' => SORT_DESC], 'label' => 'Author'], 'date' => ['asc' => ['date' => SORT_ASC], 'desc' => ['date' => SORT_DESC], 'label' => 'Date published'], 'date_create' => ['asc' => ['date_create' => SORT_ASC], 'desc' => ['date_create' => SORT_DESC], 'label' => 'Date create']]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'date_create' => $this->date_create, 'date_update' => $this->date_update, 'date' => $this->date]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'author_id', $this->author_id])->andFilterWhere(['>', 'date', $this->date_begin])->andFilterWhere(['<', 'date', $this->date_end]); return $dataProvider; }
/** * Логика поиска * @param $params * @return ActiveDataProvider */ public function search($params) { $query = Book::find()->joinWith('author'); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => self::PAGE_SIZE], 'sort' => ['attributes' => ['name', 'author_id' => ['asc' => ['firstname' => SORT_ASC, 'lastname' => SORT_ASC], 'desc' => ['firstname' => SORT_DESC, 'lastname' => SORT_DESC], 'default' => SORT_DESC]]]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $this->addCondition($query, 'name', true); $this->addCondition($query, 'author_id'); if ($this->date_from && $this->date_to) { $query->andFilterWhere(['between', 'date', $this->date_from, $this->date_to]); } elseif ($this->date_from && !$this->date_to) { $query->andFilterWhere(['>=', 'date', $this->date_from]); } elseif (!$this->date_from && $this->date_to) { $query->andFilterWhere(['<=', 'date', $this->date_to]); } if ($this->date_from || $this->date_to) { $query->addOrderBy('date'); } return $dataProvider; }
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'fileImage')->fileInput(); ?> <?php echo $form->field($model, 'date')->widget(DatePicker::className(), ['clientOptions' => ['dateFormat' => 'yy-mm-dd']]); ?> <?php echo $form->field($model, 'author_id')->dropDownList(Book::getAuthorsList(), ['prompt' => 'Please select One']); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div>
/** * Finds the Books model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Books the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Book::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getBooks() { return $this->hasMany(Book::className(), ['author_id' => 'id']); }