Example #1
0
 /**
  * @return array(['id' => 'fullname])
  */
 public static function getAuthorsForDropDownList()
 {
     $authorsModels = Authors::find()->all();
     $authors = ArrayHelper::toArray($authorsModels, ['app\\models\\Authors' => ['id', 'fullname' => function ($model) {
         return "{$model->firstname} {$model->lastname}";
     }]]);
     return ArrayHelper::map($authors, 'id', 'fullname');
 }
Example #2
0
 public static function getAuthorsName($id = null)
 {
     $results = ['' => 'Не указан'];
     foreach (Authors::find()->all() as $data) {
         $results[$data->id] = $data->lastname . ' ' . $data->firstname;
     }
     return !empty($id) ? $results[$id] : $results;
 }
Example #3
0
 public static function getAuthors()
 {
     $result = ['' => ''];
     $x = Authors::find()->all();
     foreach ($x as $author) {
         $result[$author->id] = "{$author->firstname} {$author->lastname}";
     }
     return $result;
 }
Example #4
0
 public static function map()
 {
     $authors = Authors::find()->all();
     $map = array();
     array_walk($authors, function ($val) use(&$map) {
         $map[$val->id] = $val->firstname . ' ' . $val->lastname;
     });
     return $map;
 }
Example #5
0
 public static function getList()
 {
     $list = [];
     $authors = Authors::find()->all();
     foreach ($authors as $author) {
         $list[$author->id] = $author->firstname . ' ' . $author->lastname;
     }
     return $list;
 }
Example #6
0
 /**
  * Updates an existing Books 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()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'authors' => $this->getAuthorsArray(Authors::find()->all())]);
     }
 }
Example #7
0
 public function getAuthors()
 {
     $authors = Authors::find()->orderBy('firstname')->all();
     $lastname = ArrayHelper::map($authors, 'id', 'lastname');
     $firstname = ArrayHelper::map($authors, 'id', 'firstname');
     foreach ($lastname as $key => $value) {
         $fullName[$key] = $firstname[$key] . ' ' . $lastname[$key];
     }
     return $fullName;
 }
Example #8
0
 public static function getAuthorList()
 {
     $list = array();
     $authors = Authors::find()->all();
     //Все авторы
     foreach ($authors as $value) {
         $list[$value->id] = $value->firstname . " " . $value->lastname;
     }
     return $list;
 }
Example #9
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Authors::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'firstname', $this->firstname])->andFilterWhere(['like', 'lastname', $this->lastname]);
     return $dataProvider;
 }
Example #10
0
 public static function getNameAuthor($id = NULL)
 {
     if ($id == NULL) {
         return NULL;
     }
     $author = Authors::find()->where(['id' => $id])->asArray()->one();
     if (!empty($author)) {
         return $author['firstname'] . ' ' . $author['lastname'];
     } else {
         return NULL;
     }
 }
Example #11
0
 /**
  * Updates an existing Books 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);
     $model_b_a_rel = BookAuthorRel::findOne(['b_id' => $id]);
     $authorsArr = Authors::authorArr();
     if ($model->load(Yii::$app->request->post()) && $model_b_a_rel->load(Yii::$app->request->post())) {
         $model->save();
         $model_b_a_rel->saveMultiple(1);
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'model_b_a_rel' => $model_b_a_rel, 'authorsArr' => $authorsArr]);
     }
 }
Example #12
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Authors::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, 'date_create' => $this->date_create, 'date_update' => $this->date_update]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Example #13
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Authors::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->setSort(['attributes' => ['id', 'fullName' => ['asc' => ['first_name' => SORT_ASC, 'last_name' => SORT_ASC], 'desc' => ['first_name' => SORT_DESC, 'last_name' => SORT_DESC], 'label' => 'Full Name', 'default' => SORT_ASC]]]);
     $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])->andWhere('first_name LIKE "%' . $this->fullName . '%" ' . 'OR last_name LIKE "%' . $this->fullName . '%"');
     return $dataProvider;
 }
Example #14
0
 public function search($params)
 {
     $query = Authors::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], 'default' => SORT_ASC], 'firstname', 'lastname']]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'firstname', $this->firstname]);
     $query->andFilterWhere(['like', 'lastname', $this->lastname]);
     $query->andWhere('firstname LIKE "%' . $this->fullName . '%" ' . 'OR lastname LIKE "%' . $this->fullName . '%"');
     return $dataProvider;
 }
Example #15
0
 /**
  * Updates an existing Books model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $authors = Authors::getAuthorsForDropDownList();
     $model = $this->findModel($id);
     //Request from form
     if (Yii::$app->request->isPost) {
         $model->load(Yii::$app->request->post());
         $model->cover = UploadedFile::getInstance($model, 'cover');
         if ($model->save()) {
             $absoluteUrl = Yii::$app->session->has('absoluteUrl') ? Yii::$app->session->get('absoluteUrl') : Yii::$app->urlManager->createUrl("books");
             return $this->redirect($absoluteUrl);
         }
     }
     //Render update form
     return $this->render('update', ['model' => $model, 'authors' => $authors]);
 }
Example #16
0
 public function actionEdit($id = null)
 {
     if (empty($id)) {
         $model = new Books();
     } else {
         $model = Books::find()->where(['id' => $id])->one();
     }
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $model->date_create = date('Y-m-d H:i:s');
         $model->save();
         return $this->redirect('index.php?r=site%2Fbooks');
     }
     $authors = Authors::find()->all();
     $selected_authors = array();
     foreach ($authors as $author) {
         $selected_authors[$author->id] = $author['firstname'] . " " . $author['lastname'];
     }
     return $this->render('edit', ['model' => $model, 'authors' => $selected_authors, 'book_id' => $id]);
 }
Example #17
0
 public function actionBooks()
 {
     $session = Yii::$app->session;
     $search = new SearchForm();
     if ($search->load(Yii::$app->request->post()) && $search->validate()) {
         $session['search'] = Yii::$app->request->post();
     } elseif (!empty($session['search']['SearchForm'])) {
         $search->load($session['search']);
     }
     if (empty($session['search']['SearchForm'])) {
         $books = Books::find()->all();
     } else {
         $books = Books::findWithFilters($session['search']['SearchForm']);
     }
     $authors = Authors::find()->all();
     $selected_authors = array();
     foreach ($authors as $author) {
         $selected_authors[$author->id] = $author['firstname'] . " " . $author['lastname'];
     }
     return $this->render('books', ['model' => $search, 'authors' => $selected_authors, 'books' => $books]);
 }
Example #18
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Books::find()->joinWith(['authors' => function (Query $query) {
         $query->from(Authors::tableName() . ' authors');
     }]);
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->sort->attributes['authors.fullname'] = ['asc' => ['authors.firstname' => SORT_ASC, 'authors.lastname' => SORT_ASC], 'desc' => ['authors.firstname' => SORT_DESC, 'authors.lastname' => 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;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'date_create' => $this->date_create, 'date_update' => $this->date_update, 'date' => $this->date, 'author_id' => $this->author_id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'preview', $this->preview])->andFilterWhere(['and', ['like', 'authors.firstname', $this->getAttribute('authors.fullname')], ['like', 'authors.lastname', $this->getAttribute('authors.fullname')]]);
     if (!is_null($this->from_date) && !is_null($this->to_date)) {
         $query->andFilterWhere(['between', 'date', date('Y-m-d', strtotime($this->from_date)), date('Y-m-d', strtotime($this->to_date))]);
     }
     return $dataProvider;
 }
Example #19
0
 /**
  * get Authors array for select box and other
  * @return array
  */
 public function getAuthors()
 {
     return ArrayHelper::map(Authors::find()->addSelect([Authors::tableName() . ".*", "CONCAT(firstname, ' ', lastname) AS author_fullname"])->all(), 'id', 'author_fullname');
 }
Example #20
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAuthor()
 {
     return $this->hasOne(Authors::className(), ['id' => 'author_id']);
 }
Example #21
0
use app\models\Authors;
use yii\jui\DatePicker;
/* @var $this yii\web\View */
/* @var $model app\models\BooksSearch */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="books-search">

    <?php 
$form = ActiveForm::begin(['action' => ['index'], 'method' => 'get']);
?>
    <div class="row">
        <div class="col-md-4">
			<?php 
echo $form->field($model, 'author_id')->dropDownList(ArrayHelper::map(Authors::find()->all(), 'id', 'Name'), ['prompt' => '---']);
?>
		</div>
		<div class="col-md-4">
			<?php 
echo $form->field($model, 'name');
?>
		</div>
    </div>
    <div class="row">
        <div class="col-md-6">
			Дата выхода от: <?php 
echo DatePicker::widget(['model' => $model, 'attribute' => 'date_ot', 'language' => 'ru', 'dateFormat' => 'yyyy-MM-dd']);
?>
			до <?php 
echo DatePicker::widget(['model' => $model, 'attribute' => 'date_do', 'language' => 'ru', 'dateFormat' => 'yyyy-MM-dd']);
Example #22
0
<div class="books-search">

    <?php 
$form = ActiveForm::begin(['action' => ['index'], 'method' => 'get']);
?>

    <?php 
echo $form->field($model, 'name');
?>

    <?php 
echo $form->field($model, 'date')->widget(\kartik\daterange\DateRangePicker::classname(), ['convertFormat' => true, 'pluginOptions' => ['format' => 'Y-m-d']]);
?>

    <?php 
echo $form->field($model, 'author_id')->dropDownList(\yii\helpers\ArrayHelper::map(\app\models\Authors::find()->all(), 'id', function ($model) {
    return $model->firstname . ' ' . $model->lastname;
}), ['prompt' => '']);
?>

    <div class="form-group">
        <?php 
echo Html::submitButton('Поиск', ['class' => 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>

</div>
Example #23
0
 /**
  * Finds the Authors model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Authors the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Authors::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #24
0
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>

    <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'preview')->widget(FileInput::classname(), ['options' => ['accept' => 'image/*'], 'pluginOptions' => ['showPreview' => true, 'showCaption' => true, 'showRemove' => true, 'showUpload' => false]]);
?>

    <?php 
echo $form->field($model, 'date')->widget(DatePicker::classname(), ['value' => date('Y-m-d', strtotime('today')), 'options' => ['placeholder' => Yii::t('books', 'select Date')], 'pluginOptions' => ['hideInput' => true, 'format' => 'yyyy-mm-dd', 'todayHighlight' => true]]);
?>

    <?php 
echo $form->field($model, 'author_id')->dropDownList(ArrayHelper::map(Authors::find()->all(), 'id', 'fullName'), ['prompt' => Yii::t('books', 'select Author')]);
?>

    <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>
Example #25
0
use app\models\Authors;
/* @var $this yii\web\View */
/* @var $model app\models\BooksSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<br>
<div class="books-search clearfix">

    <?php 
$form = ActiveForm::begin(['action' => ['index'], 'method' => 'get']);
?>
    <div class="col-xs-6">
        <div class="form-group">
            <div class="col-xs-6">
                <?php 
echo $form->field($model, 'author_id')->dropDownList(array_merge([0 => 'Выберите автора'], Authors::getItems()))->label(false);
?>
            </div>
            <div class="col-xs-6">
                <?php 
echo $form->field($model, 'name')->textInput(['placeholder' => $model->getAttributeLabel('name')])->label(false);
?>
            </div>
        </div>
        <div class="form-group">
            <div class="col-xs-12 align-fd-inputs">
                Дата выхода книги:
                <?php 
echo $form->field($model, 'date_start', ['template' => '{input}'])->textInput(['class' => 'form-control datepicker'])->label(false);
?>
                до
 public function actionAjax()
 {
     $request = Yii::$app->request;
     $post = $request->post();
     $returnArray = [];
     if ($model = $this->findModel($post['id'])) {
         $returnArray['author'] = \app\models\Authors::getAuthorsName($model->author_id);
         $returnArray['name'] = $model->name;
         $returnArray['preview'] = $model->preview;
         $returnArray['date_create'] = $model->date_create;
         $returnArray['date_update'] = $model->date_update;
         $returnArray['date'] = $model->date;
     }
     echo json_encode($returnArray);
     exit;
 }
Example #27
0
    echo $model->preview;
    ?>
" width="100" height="150" />
    <?php 
} else {
    ?>
        <div class="clearfix"></div>
    <?php 
}
?>

    <?php 
echo $form->field($model, 'date')->widget(DatePicker::className(), ['model' => $model, 'attribute' => 'date', 'language' => 'ru', 'dateFormat' => 'dd.MM.yyyy', 'options' => ['class' => 'form-control'], 'clientOptions' => ['changeMonth' => true, 'changeYear' => true]]);
?>

    <?php 
echo $form->field($model, 'author_id')->dropDownList(Authors::find()->select(['name', 'id'])->indexBy('id')->column(), ['prompt' => 'выберите автора']);
?>

    <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>
Example #28
0
?>
<div class="books-index">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    <?php 
echo $this->render('_search', ['model' => $searchModel]);
?>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => ['id', 'name', ['attribute' => 'preview', 'content' => function ($model, $key, $index, $column) {
    if (!empty($model->preview)) {
        return Html::a('<img src="img/' . $model->preview . '" style="max-width: 100px; max-height: 100px;">', 'img/' . $model->preview, ['class' => 'view_image']);
    } else {
        return NULL;
    }
}], ['attribute' => 'author_id', 'value' => function ($data) {
    return Authors::getNameAuthor($data->id);
}], 'date', 'date_create', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{edit} {view} {delete}', 'buttons' => ['edit' => function ($url, $data) {
    Url::remember(Url::current());
    return Html::a('<span class="glyphicon glyphicon-pencil"></span>', Url::toRoute(['/books/update', 'id' => $data->id]), ['target' => '_blank']);
}, 'view' => function ($url, $data) {
    return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', Url::toRoute(['/books/view', 'id' => $data->id]), ['class' => 'fancybox.ajax', 'id' => 'view_modal']);
}, 'delete' => function ($url, $data) {
    return Html::a('<span class="glyphicon glyphicon-trash"></span>', Url::toRoute(['/books/delete', 'id' => $data->id]), ['data-confirm' => Yii::t('app', 'Вы действительно хотите удалить эту книгу?')]);
}]]]]);
?>

</div>
Example #29
0
use yii\widgets\ActiveForm;
use yii\helpers\Url;
use app\models\Authors;
use yii\helpers\ArrayHelper;
use kartik\datecontrol\DateControl;
?>

<div>

    <?php 
$form = ActiveForm::begin(['method' => 'get', 'options' => ['class' => 'form-inline']]);
?>

    <div class="form-group">
        <?php 
echo $form->field($searchModel, 'author_id')->dropDownList(ArrayHelper::merge([0 => 'Автор'], ArrayHelper::map(Authors::find()->all(), 'id', 'fullname')), ['options' => ['class' => 'form-control', $searchModel->author_id => ['selected' => true]]])->label(false);
?>
    </div>

    <div class="form-group">
        <?php 
echo $form->field($searchModel, 'name')->textInput(['placeholder' => Yii::t('app', 'Book Name')])->label(false);
?>
    </div>
<div class="row" style="padding-left:15px;">
    <?php 
echo $form->field($searchModel, 'date_from')->widget(DateControl::classname(), ['saveFormat' => 'php:Y-m-d H:i:s', 'ajaxConversion' => true, 'options' => ['pluginOptions' => ['autoclose' => true]]]);
?>

    <?php 
echo $form->field($searchModel, 'date_to')->widget(DateControl::classname(), ['saveFormat' => 'php:Y-m-d H:i:s', 'ajaxConversion' => false, 'options' => ['pluginOptions' => ['autoclose' => true]]]);
Example #30
0
 /**
  * @return $this
  */
 public function getAuthors()
 {
     return $this->hasMany(Authors::className(), ['id' => 'id_author'])->viaTable(AuthorsBooksRelation::tableName(), ['id_book' => 'id']);
 }