Beispiel #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');
 }
Beispiel #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;
 }
Beispiel #3
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;
 }
Beispiel #4
0
 public static function getAuthors()
 {
     $result = ['' => ''];
     $x = Authors::find()->all();
     foreach ($x as $author) {
         $result[$author->id] = "{$author->firstname} {$author->lastname}";
     }
     return $result;
 }
Beispiel #5
0
 public static function getList()
 {
     $list = [];
     $authors = Authors::find()->all();
     foreach ($authors as $author) {
         $list[$author->id] = $author->firstname . ' ' . $author->lastname;
     }
     return $list;
 }
Beispiel #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())]);
     }
 }
Beispiel #7
0
 public static function getAuthorList()
 {
     $list = array();
     $authors = Authors::find()->all();
     //Все авторы
     foreach ($authors as $value) {
         $list[$value->id] = $value->firstname . " " . $value->lastname;
     }
     return $list;
 }
Beispiel #8
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;
 }
Beispiel #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;
 }
Beispiel #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;
     }
 }
Beispiel #11
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;
 }
Beispiel #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]);
     $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;
 }
Beispiel #13
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;
 }
Beispiel #14
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]);
 }
Beispiel #15
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]);
 }
Beispiel #16
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>
Beispiel #17
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 = isset($_REQUEST['id']) ? $_REQUEST['id'] : '';
     $model = $this->findModel($id);
     $searchModel = new BooksSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     if ($model->load(Yii::$app->request->post()) && $model->upload()) {
         if ($model->save()) {
             return $this->success();
         } else {
             return $this->errors();
         }
     } else {
         return $this->renderAjax('update', ['authors' => Authors::find()->all(), 'model' => $model]);
     }
 }
Beispiel #18
0
echo $form->field($model, 'date_create')->textInput();
?>

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

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

    <?php 
echo $form->field($model, 'date')->textInput(array('type' => 'date'));
?>

    <?php 
echo $form->field($model, 'author_id')->dropDownList(ArrayHelper::map(\app\models\Authors::find()->all(), 'id', ['name' => 'lastname']), ['prompt' => 'Select Author']);
?>

    <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>
Beispiel #19
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>
 public function edit()
 {
     // Check Author authentication Session
     if (!Auth::check('default')) {
         return $this->redirect('Authors::login');
     }
     // Retrieve current Author id
     $author_id = Auth::check('default')->data['id'];
     $author = Authors::find($this->request->id);
     if ($this->request->data) {
         if (strlen($this->request->data['password'])) {
             $this->request->data['password'] = \lithium\util\String::hash($this->request->data['password']);
         } else {
             unset($this->request->data['password']);
         }
         if ($author->save($this->request->data)) {
             Session::write('message', 'Your author account has been edit');
             $this->redirect(array('Authors::dashboard'));
         } else {
             Session::write('message', 'Your author account can not be edited');
         }
     }
     return compact('author', 'author_id');
 }
Beispiel #21
0
use app\models\Authors;
/* @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', 'options' => ['class' => 'form-inline']]);
?>

    <div class="row">
        <div class="col-md-4">
            <?php 
echo $form->field($model, 'author_id')->DropDownList(ArrayHelper::map(Authors::find()->all(), 'id', 'fullName'), ['prompt' => $model->getAttributeLabel('author_id'), 'class' => 'form-control input-sm'])->label(false);
?>
            <?php 
echo $form->field($model, 'name')->textInput(['placeholder' => $model->getAttributeLabel('name'), 'class' => 'form-control input-sm'])->label(false);
?>
        </div>
    </div>
    <div class="row">
        <div class="col-md-11">
            <?php 
echo $form->field($model, 'dateFrom')->widget(\yii\jui\DatePicker::className(), ['dateFormat' => 'yyyy-MM-dd', 'class' => 'form-control', 'options' => ['class' => 'form-control input-sm']]);
?>
            <?php 
echo $form->field($model, 'dateTo')->widget(\yii\jui\DatePicker::className(), ['dateFormat' => 'yyyy-MM-dd', 'options' => ['class' => 'form-control input-sm']]);
?>
        </div>
Beispiel #22
0
use app\models\Authors;
use yii\helpers\ArrayHelper;
/* @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-3">
                <?php 
echo $form->field($model, 'author_id')->dropDownList(ArrayHelper::map(Authors::find()->all(), 'id', 'firstname', 'lastname'), ['prompt' => 'Выберите автора...']);
?>
            </div>
            <div class="col-md-3"><?php 
echo $form->field($model, 'name');
?>
</div>
            <div class="col-md-6"></div>
        </div>
        <div class="row">
            <div class="col-md-8">
                <?php 
echo $form->field($model, 'date_from')->widget(DateRangePicker::className(), ['attributeTo' => 'date_to', 'form' => $form, 'language' => 'ru', 'size' => 'md', 'labelTo' => 'до', 'clientOptions' => ['autoclose' => true, 'format' => 'yyyy-m-d']]);
?>
            </div>
            <div class="col-md-4 text-right"><?php 
Beispiel #23
0
        <?php 
echo $form->field($model, BooksForm::FIELD_DATE_UPDATE)->textInput(['readonly' => true]);
?>

        <?php 
echo $form->field($model, BooksForm::FIELD_NAME);
?>

        <?php 
echo $form->field($model, BooksForm::FIELD_PREVIEW)->fileInput();
?>


        <?php 
echo $form->field($model, BooksForm::FIELD_AUTHOR_ID)->dropDownList(ArrayHelper::map(Authors::find()->all(), Authors::FIELD_ID, Authors::FULLNAME));
?>

        <?php 
echo $form->field($model, BooksForm::FIELD_DATE)->widget(DatePicker::className(), ['language' => 'ru', 'clientOptions' => ['autoclose' => true, 'format' => 'dd/mm/yyyy']]);
?>

        <?php 
echo Html::submitButton('Сохранить', ['class' => 'btn btn-default pull-right']);
?>

    <?php 
$form->end();
?>
    </div>
</div>
Beispiel #24
0
    <?php 
echo $form->field($model, 'date')->textInput();
?>

    <?php 
if (\file_exists($model->preview)) {
    echo Html::img($model->getImgSrc(), ['width' => '100', 'class' => 'books-img']);
}
?>

    <?php 
echo $form->field($model, 'image')->fileInput(["accept" => "image/x-png, image/gif, image/jpeg"]);
?>

    <?php 
echo $form->field($model, 'author_id')->dropDownList(ArrayHelper::map(Authors::find()->all(), 'id', 'fullname'), ['options' => [$model->author_id => ['selected' => true]]]);
?>

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

    <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();
?>
Beispiel #25
0
use yii\widgets\ActiveForm;
use app\models\Authors;
?>

<div class="books-form">

     <?php 
$form = ActiveForm::begin();
?>

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

    <?php 
echo $form->field($model, 'author_id')->dropDownList(yii\helpers\ArrayHelper::map(Authors::find()->all(), 'id', 'fullname'));
?>

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

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

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

    <?php 
Beispiel #26
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]]]);
Beispiel #27
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>
Beispiel #28
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');
 }
Beispiel #29
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']);
Beispiel #30
0
/* @var $model app\models\Books */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="books-form">

    <?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>

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

    <?php 
echo $form->field($model, 'author_id')->DropDownList(ArrayHelper::map(Authors::find()->all(), 'id', 'fullName'));
?>

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

    <?php 
echo $form->field($model, 'date')->widget(\yii\jui\DatePicker::className(), ['dateFormat' => 'yyyy-MM-dd']);
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>