/** * Показывает контент * @return string * @TODO Нужно предусмотреть возможность вывода разного контента, привязаного к одной категории * */ public function actionShow() { $this->cat_id = Yii::$app->getRequest()->getQueryParam('id') ? Yii::$app->getRequest()->getQueryParam('id') : null; $cat_obg = Categories::find()->where('id = ' . $this->cat_id)->one(); $allContent = Articles::find()->where('cat_id = ' . $this->cat_id)->all(); $allArticlesForPager = Articles::find()->where(['cat_id' => $this->cat_id]); $countQueryCont = clone $allArticlesForPager; $pagesGlobal = new Pagination(['totalCount' => $countQueryCont->count(), 'pageSize' => 1, 'forcePageParam' => false, 'pageSizeParam' => false]); $artPages = $allArticlesForPager->offset($pagesGlobal->offset)->limit($pagesGlobal->limit)->all(); foreach ($allContent as $article) { //var_dump($this->cat_id); $this->article_id = $article->id; $article = Articles::findOne($this->article_id); $allArticles = ArticlesContent::find()->where(['articles_id' => $this->article_id])->orderBy(['id' => SORT_DESC]); //var_dump($allArticles); exit; $countQuery = clone $allArticles; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => isset($article->onepages) ? $article->onepages : 0, 'forcePageParam' => false, 'pageSizeParam' => false]); $models = $allArticles->offset($pages->offset)->limit($pages->limit)->all(); $this->source = Source::find()->where(['id' => $models[0]->source_id])->one()->title; $this->author = Author::find()->where(['id' => Source::find()->where(['id' => $models[0]->source_id])->one()->author_id])->one()->name; $this->articles[] = ['article' => $article, 'contents' => $models, 'pages' => $pages, 'source' => $this->source, 'author' => $this->author]; } //var_dump($this->articles); exit; return $this->renderPartial($cat_obg->action, ['articles' => $this->articles, 'cat' => $this->cat_id, 'pagesGlobal' => $pagesGlobal, 'artPages' => $artPages, 'cat_obg' => $cat_obg]); }
public function search($params) { $query = Author::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * @param string $q * @return array */ public function actionIndex($q = null) { Yii::$app->getResponse()->format = Response::FORMAT_JSON; $model = Author::find()->limit(10); if (!is_null($q)) { $model->where(['or', ['like', 'firstname', $q], ['like', 'lastname', $q]]); } return ['results' => $model->all()]; }
public function actionIndex() { $searchModel = new SearchBook(); $author = new Author(); $author->surname = ''; $authors_data = $author->find()->select(['id', "name"])->all(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'author' => $author, 'authors_data' => $authors_data]); }
/** * Updates an existing Book model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $authors = \app\models\Author::find()->all(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index']); } else { return $this->render('update', ['model' => $model, 'authors' => $authors]); } }
public function runComplexQuery($i) { Author::find()->from('Author a')->where('a.id > :id OR (a.firstName || a.lastName) = :name', ['id' => $this->authors[array_rand($this->authors)]->id, 'name' => 'John Doe'])->count('a.id'); // $authors = $this->em->createQuery( // 'SELECT count(a.id) AS num FROM Author a WHERE a.id > ?1 OR CONCAT(a.firstName, a.lastName) = ?2' // )->setParameter(1, $this->authors[array_rand($this->authors)]->id) // ->setParameter(2, 'John Doe') // ->setMaxResults(1) // ->getSingleScalarResult(); }
public function actionUpdate($id) { $book = Book::findOne(['id' => $id]); $filtredModel = Yii::$app->request->get('filtredModel'); if (Yii::$app->request->isPost) { $book->load(Yii::$app->request->post()); $book->save(); $this->redirect(Url::to(array_merge(['books/index'], $filtredModel))); } return $this->render('update', ['book' => $book, 'authors' => Author::find()->all(), 'Book' => $filtredModel]); }
/** * Updates an existing Book model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { $file = UploadedFile::getInstance($model, 'preview'); if ($model->upload($file) && $model->save()) { return $this->redirect(Url::previous()); } } return $this->render('update', ['model' => $model, 'authors' => Author::find()->all()]); }
/** * Возвращает массив авторов вида: [id=>{firsname lastname},...] * * @return array */ public static function getListAuthor() { $authors = Author::find()->select(['id', 'firstname', 'lastname'])->all(); $result = []; /** * @var Author $author */ foreach ($authors as $author) { $result[$author->id] = $author->getFullName(); } return $result; }
/** * Updates an existing Book model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $authors = Author::find()->asArray()->all(); for ($i = 1; $i <= Author::find()->count(); $i++) { $authors_array[$i] = $authors[$i - 1]['firstname'] . ' ' . $authors[$i - 1]['lastname']; } if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'authors_array' => $authors_array]); } }
/** * Updates an existing Book model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); if (Yii::$app->request->isPost) { $model->load(Yii::$app->request->post()); $model->imageFile = UploadedFile::getInstance($model, 'preview'); $model->uploadFile(); $model->save(false); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'authors' => (new AuthorCollection())->createEntity(Author::find()->all(), true)]); } }
/** * Показываем контент * @param $id * @return string */ public function actionShow($id) { $article = Articles::findOne($id); $comment = new Comments(); $this->title = $article->title; $allArticles = ArticlesContent::find()->where(['articles_id' => $id]); //var_dump($allArticles); exit; $countQuery = clone $allArticles; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => isset($article->onepages) ? $article->onepages : 0, 'forcePageParam' => false, 'pageSizeParam' => false]); $models = $allArticles->offset($pages->offset)->limit($pages->limit)->all(); $this->source = Source::find()->where(['id' => $models[0]->source_id])->one()->title; $this->author = Author::find()->where(['id' => Source::find()->where(['id' => $models[0]->source_id])->one()->author_id])->one()->name; return $this->render('view', ['articles' => $allArticles, 'contents' => $models, 'pages' => $pages, 'title' => $this->title, 'source' => $this->source, 'author' => $this->author, 'comment' => $comment]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Author::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $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(['id' => $this->id]); $query->andFilterWhere(['like', 'firstname', $this->firstname])->andFilterWhere(['like', 'lastname', $this->lastname]); return $dataProvider; }
/** * Создание автораа * @return string */ public function actionCreate() { $model = new Author(); if ($model->load(Yii::$app->request->post())) { $model->name = Yii::$app->request->post('Author')['name']; $model->status = Yii::$app->request->post('Author')['status']; $model->description = Yii::$app->request->post('Author')['description']; $model->country_id = Yii::$app->request->post('Author')['country_id']; $model->save(false); $authors = Author::find(); $dataProvider = new ActiveDataProvider(['query' => $authors]); return $this->redirect(Url::toRoute('author/index')); } else { return $this->render('_form', ['model' => $model]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Author::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $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; } // grid filtering conditions $query->andFilterWhere(['author_id' => $this->author_id, 'birth' => $this->birth]); $query->andFilterWhere(['like', 'first_name', $this->first_name])->andFilterWhere(['like', 'last_name', $this->last_name]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Author::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->setSort(['attributes' => ['id', 'fullName' => ['asc' => ['firstname' => SORT_ASC, 'lastname' => SORT_ASC], 'desc' => ['firstname' => SORT_DESC, 'lastname' => SORT_DESC], 'label' => 'Автор', 'default' => SORT_ASC], 'author_id']]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $this->addCondition($query, 'id'); $this->addCondition($query, 'firstname', true); $this->addCondition($query, 'lastname', true); $this->addCondition($query, 'author_id'); $query->andFilterWhere(['id' => $this->id]); //$query->andFilterWhere(['like', 'firstname', $this->firstname]) // ->andFilterWhere(['like', 'lastname', $this->lastname]); $query->andWhere('firstname LIKE "%' . $this->fullName . '%" ' . 'OR lastname LIKE "%' . $this->fullName . '%"'); return $dataProvider; }
public function actionUpdate($id) { $model = $this->findModel($id); $model->isNewRecord = 0; $back_url = Url::toRoute('index'); $get_parameters = ''; if (Yii::$app->request->get('BookSearch')) { foreach (Yii::$app->request->get('BookSearch') as $key => $val) { $get_parameters .= '&BookSearch[' . $key . ']=' . $val; } } if (Yii::$app->request->get('sort')) { $get_parameters .= ($get_parameters ? '&' : '') . 'sort=' . Yii::$app->request->get('sort'); } if ($model->load(Yii::$app->request->post()) && $model->update()) { return $this->redirect($back_url . $get_parameters); } else { return $this->render('update', ['model' => $model, 'authors' => Author::find()->all(), 'back_url' => $back_url . $get_parameters]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Author::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); /** * Setup your sorting attributes * Note: This is setup before the $this->load($params) * statement below */ $dataProvider->setSort(['attributes' => ['id', 'firstname', 'lastname', 'fullname' => ['asc' => ['firstname' => SORT_ASC, 'lastname' => SORT_ASC], 'desc' => ['firstname' => SORT_DESC, 'lastname' => SORT_DESC], 'label' => 'Full Name', 'default' => SORT_ASC], 'author_id']]); $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(['id' => $this->id]); $query->andFilterWhere(['like', 'firstname', $this->firstname])->andFilterWhere(['like', 'lastname', $this->lastname]); // filter by person full name $query->andWhere('firstname LIKE "%' . $this->fullname . '%" ' . 'OR lastname LIKE "%' . $this->fullname . '%"'); return $dataProvider; }
?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'preview')->fileInput(); ?> <?php echo $form->field($model, 'date')->widget(DatePicker::className(), ['inline' => true, 'template' => '<div class="well well-sm" style="background-color: #fff; width:250px">{input}</div>', 'clientOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd']]); ?> <?php $authors = \app\models\Author::find()->all(); foreach ($authors as $author) { $data[$author->id] = $author->lastname . ' ' . $author->firstname; } echo $form->field($model, 'author_id')->widget(\kartik\select2\Select2::className(), ['data' => $data, 'options' => ['placeholder' => 'Выберите автора']]); ?> <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(); ?>
/** * Returns query to provide information for authors select * * @return ActiveQuery */ public function getAuthors() { $query = Author::find(); $query->select(['{{authors}}.id', "CONCAT({{authors}}.firstname, ' ', {{authors}}.lastname) as fullname"])->orderBy('fullname')->asArray(); return $query; }
use yii\widgets\ActiveForm; /* @var $this yii\web\View */ /* @var $model app\models\BookSearch */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="book-search"> <?php $form = ActiveForm::begin(['action' => ['index'], 'method' => 'get']); ?> <div class="row"> <div class="col-md-3"> <?php echo $form->field($model, 'author_id', ['template' => '{input}{error}'])->dropDownList(ArrayHelper::map(Author::find()->all(), 'id', 'fullname'), ['prompt' => Yii::t('app', 'Choose author')]); ?> </div> <div class="col-md-3"> <?php echo $form->field($model, 'name', ['template' => '{input}{error}'])->textInput(['placeholder' => Yii::t('app', 'Book name')]); ?> </div> </div> <div class="row"> <div class="col-md-6"> <div class="row"> <div class="col-md-4"> <?php echo Yii::t('app', 'Published date');
<?php use app\models\Author; use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\helpers\ArrayHelper; use dosamigos\datepicker\DatePicker; /* @var $this yii\web\View */ /* @var $model app\models\BookSearch */ /* @var $form yii\widgets\ActiveForm */ ?> <?php $authors = ArrayHelper::map(Author::find()->orderBy('lastname')->all(), 'id', 'fullname'); ?> <div class="book-search"> <?php $form = ActiveForm::begin(['action' => ['index'], 'method' => 'get']); ?> <div class="row"> <div class="col col-sm-4"> <?php echo $form->field($model, 'author_id')->dropDownList($authors, array('label' => 'Author', 'class' => 'form-control')); ?> </div> <div class="col col-sm-4"> <?php
<?php use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\helpers\ArrayHelper; use app\models\Author; use yii\jui\DatePicker; ?> <div class="site-index"> <?php $form = ActiveForm::begin(['id' => 'update-form', 'enableClientValidation' => true, 'options' => ['enctype' => 'multipart/form-data']]); ?> <div class="form-group"> <?php echo $form->field($model, 'author_id')->dropDownList(ArrayHelper::map(Author::find()->all(), 'id', 'lastname'), ['prompt' => 'писатель'])->label(false); ?> </div> <?php echo $form->errorSummary($model); ?> <div class="form-group"> <?php echo $form->field($model, 'name')->textInput(['placeholder' => $model->getAttributeLabel('name')])->label(false); ?> </div> <div class="form-group"> <?php echo $form->field($model, 'previewFile')->fileInput(); ?> <?php
<div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-default"> <div class="panel-heading">Поиск</div> <div class="panel-body"> <?php $form = ActiveForm::begin(['method' => 'get']); ?> <?php echo $form->field($searchModel, 'name'); ?> <?php echo $form->field($searchModel, 'author.last_name')->dropDownList(ArrayHelper::map(Author::find()->all(), 'last_name', 'last_name')); ?> <?php echo $form->field($searchModel, 'date')->widget(DatePicker::className(), ['language' => 'ru', 'name' => 'date', 'dateFormat' => 'php:d F Y']); ?> <?php echo $form->field($searchModel, 'after_date')->widget(DatePicker::className(), ['language' => 'ru', 'name' => 'after_date', 'dateFormat' => 'php:d F Y']); ?> <div class="form-group"> <?php echo Html::submitButton('Искать', ['class' => 'btn btn-info']); ?> </div>
<div class="book-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'title')->textInput(['maxlength' => 64]); ?> <?php echo $form->field($model, 'description')->textInput(['maxlength' => 1024]); ?> <?php echo $form->field($model, 'author_id')->dropDownList(ArrayHelper::map(Author::find()->select(['firstname', 'surname', 'id'])->all(), 'id', 'displayName'), ['class' => 'form-control inline-block']); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div>
$dtConf = ['language' => 'ru', 'dateFormat' => 'dd-MM-yyyy']; ?> <div class="book-search col-md-8"> <?php $form = ActiveForm::begin(['action' => ['index'], 'method' => 'get', 'options' => ['class' => 'form-inline']]); ?> <div class="form-group"> <?php echo $form->field($model, 'name'); ?> </div> <div class="form-group"> <?php echo $form->field($model, 'author_id')->dropdownList(\yii\helpers\ArrayHelper::map(\app\models\Author::find()->all(), 'id', 'fullName'), ['prompt' => 'выберите автора']); ?> </div> <div class="form-group"> <?php echo $form->field($model, 'date_from')->widget(\yii\jui\DatePicker::className(), $dtConf); ?> <?php echo $form->field($model, 'date_to')->widget(\yii\jui\DatePicker::className(), $dtConf); ?> </div> <div> <?php echo Html::submitButton('Искать', ['class' => 'btn btn-primary']); ?>
<div class="book-form"> <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'date')->textInput(); ?> <?php echo $form->field($model, 'author_id')->dropDownList(ArrayHelper::map(Author::find()->all(), 'id', 'fullname'), ['prompt' => 'Выберите автора']); ?> <?php echo $form->field($model, 'bookImage')->fileInput(); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Создать' : 'Обновить', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?>
class="btn btn-link add-new"> Add new </button> </div> </div> <div class="form-group"> <label for="author" class="col-lg-2 control-label">Authors</label> <div class="col-lg-8"> <select id="authors" class="selectpicker form-control" name="authors[]" data-live-search="true" multiple data-selected-text-format="count>4"> <?php $rows = Author::find()->all(); $authors = !empty($model->bookAuthors) ? array_column($model->getBookAuthors()->asArray()->all(), 'id') : array(); ?> <?php foreach ($rows as $row) { ?> <?php if (!empty($authors)) { ?> <?php $selectedRow = in_array($row->id, $authors); ?> <?php } elseif (!empty($formData['authors'])) { ?> <?php
/* @var $this yii\web\View */ /* @var $model app\models\BookSearch */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="book-search"> <?php $form = ActiveForm::begin(['action' => ['index'], 'method' => 'get']); ?> <div class="form-group"> <div class="col-md-12"> <div class="form-group row"> <div class="col-md-6"> <?php $authors = Author::find()->orderBy('firstname, lastname')->all(); $authorsList = ArrayHelper::map($authors, 'id', function ($model, $defaultValue) { return $model->firstname . ' ' . $model->lastname; }); echo $form->field($model, 'author')->dropDownList($authorsList, ['prompt' => 'Select author of the book...']); ?> </div> <div class="col-md-6"> <?php echo $form->field($model, 'title'); ?> </div> </div> </div> </div> <div class="form-group">
<div class="book-form"> <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'date_release')->widget(DatePicker::className(), []); ?> <?php echo $form->field($model, 'author_id')->dropDownList(\yii\helpers\ArrayHelper::map(\app\models\Author::find()->all(), 'id', 'last_name')); ?> <?php echo $form->field($model, 'imageFile')->fileInput(); ?> <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();