diff --git a/frontend/controllers/BookController.php b/frontend/controllers/BookController.php index 64296ba..6d52755 100644 --- a/frontend/controllers/BookController.php +++ b/frontend/controllers/BookController.php @@ -9,9 +9,10 @@ namespace frontend\controllers; use common\models\Book; + use yii\data\ActiveDataProvider; use yii\web\Controller; use yii\web\UploadedFile; - + class BookController extends Controller { /** @@ -22,13 +23,14 @@ if ($action->id == 'add' or $action->id == 'edit') { $this->enableCsrfValidation = false; } - + return parent::beforeAction($action); } - - public function actionAdd(){ + + public function actionAdd() + { /** - * @var \common\models\Author $user; + * @var \common\models\Author $user ; */ $user = \Yii::$app->user->identity; if (\Yii::$app->user->isGuest) { @@ -36,41 +38,69 @@ } $model = new Book(); if (\Yii::$app->request->isPost) { - + if ($model->load(\Yii::$app->request->post(), '') and $model->validate()) { $model->author_id = $user->id; $model->status = $model::STATUS_MODERATION; - return($model->save() && $model->saveImage(UploadedFile::getInstanceByName('file'))); + return ( $model->save() && $model->saveImage(UploadedFile::getInstanceByName('file')) ); } else { return false; } - + } - return $this->render('add', [ - 'book' => array() - ]); + return $this->render( + 'add', + [ + 'book' => [], + ] + ); } - public function actionEdit($id){ + public function actionEdit($id) + { $model = Book::findOne($id); - if ($model->author_id !== \Yii::$app->user->getId()){ - return $this->redirect(['site/index']); + if ($model->author_id !== \Yii::$app->user->getId()) { + return $this->redirect([ 'site/index' ]); } if (\Yii::$app->request->isPost) { - + if ($model->load(\Yii::$app->request->post(), '') and $model->validate()) { - return($model->save() && $model->saveImage(UploadedFile::getInstanceByName('file'))); + return ( $model->save() && $model->saveImage(UploadedFile::getInstanceByName('file')) ); } else { return false; } - + } - return $this->render('add', [ - 'book' => $model->attributes - ]); + return $this->render( + 'add', + [ + 'book' => $model->attributes, + ] + ); } - public function actionIndex(){ + public function actionIndex() + { + $dataProvider = new ActiveDataProvider( + [ + 'query' => Book::find() + ->with('author') + ->where([ 'status' => Book::STATUS_ACTIVE ]), + 'pagination' => [ + 'pageSize' => 10, + ], + ] + ); + return $this->render( + 'index', + [ + 'dataProvider' => $dataProvider, + ] + ); + } + public function actionView($id){ + $model = Book::find()->with('author') ->where(['id' => $id])->one(); + return $this->render('view', ['model' => $model]); } } \ No newline at end of file diff --git a/frontend/views/book/_book.php b/frontend/views/book/_book.php new file mode 100644 index 0000000..1f9d1e6 --- /dev/null +++ b/frontend/views/book/_book.php @@ -0,0 +1,32 @@ + +
+
+ image !== null){?> + + +
+
+ +
Автор: author->name?> author->secondname?>
+
+ preview?> +
+ price == null){?> + + +
вартість price?> грн.
+ + + +
+
diff --git a/frontend/views/book/index.php b/frontend/views/book/index.php new file mode 100644 index 0000000..ef6c860 --- /dev/null +++ b/frontend/views/book/index.php @@ -0,0 +1,41 @@ +params['breadcrumbs'][] = 'Книги'; + +?> +
+
+
+
+
Книги
+
+
+ $dataProvider, + 'itemView' => '_book', + 'options' => [ + 'class' => 'row', + + ], + 'itemOptions' => [ + 'class' => 'col-xs-12 col-sm-12 col-md-6 books-wrapp', + ], + 'layout' => '{items}', + ] + ); ?> + +
+ $dataProvider->pagination, + 'maxButtonCount' => 5, + ] + ); ?> +
+
+
diff --git a/frontend/views/book/view.php b/frontend/views/book/view.php new file mode 100644 index 0000000..810fa3e --- /dev/null +++ b/frontend/views/book/view.php @@ -0,0 +1,195 @@ +params[ 'breadrumbs'][] = [ + 'label' => 'Книги', + 'url' => Url::to(['book/index']) + ]; + + $this->params['breadcrumbs'][] = $model->title; + ?> + +
+
+
+ +
+ image !== null){?> +
+ id.'/'.$model->image)->cropResize(262, 390)->renderImage()?> +
+ +
+
+
title?>
+
+
+
+
+
author->name?> author->secondname?>
+
+
+ price == null){ ?> +
+
+ + +

37620 грн. зібрано

+

460 підтримувачів

+
+ +
+ +
+
вартість 150 грн.
+ +
+ +
+
+

поділитися в соціальних мережах

+ +
    +
  • +
  • +
  • +
+
+
+
+
+ preview?> +
+
+
+
+
+description != null){?> +
+
+
+
+
Опис
+
+
+ description; ?> +
+ + +
+
+
+ +
+
+
+
+
коментарі
+
+
+
+
+ +
+
+
Ольга Ващенко
+
Скоріше відкривайте, чекатиму з нетерпінням! Неймовірне вам спасибі за видання цього автора українською!
+
+ відповісти +
+
+ +
+
Олександр Кармаш
+
Скоріше відкривайте, чекатиму з нетерпінням! Неймовірне вам спасибі за видання цього автора українською!Це вже остаточний варіант обкладинки? Бо це мені вперше не сподобалась обкладинка книжки вашого видавництва...(як на мене фраза про розчинний убік збоку псує всю картину і видається зайвою)..
+
+ відповісти +
+
+
Андрій
+
+ Доброго дня! Це не обкладинка, а просто футуристична картинка "для ілюстрації". Обкладинку ми зараз готуємо і незабаром додамо її на сайт. +
+
+ відповісти +
+
+
+ +
+
Вікторія
+
Дочекався. Перша книжка Діка яку я прочитав (російською), тепер й українською. Неймовірно захоплива, і з (спойлер). + Але, шановні, змініть обкладинку, це ж обкладинка бразильського видання "Нейромант" Вільяма Гібсона
+
+ відповісти +
+
+ +
+
Руслан Ковтун
+
Дочекався. Перша книжка Діка яку я прочитав (російською), тепер й українською. Неймовірно захоплива, і з (спойлер). + Але, шановні, змініть обкладинку, це ж обкладинка бразильського видання "Нейромант" Вільяма Гібсона
+
+ відповісти +
+
+
+
+ +
+
+
+
Додати коментар
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+
+
+
diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index a48007c..638e6ee 100755 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -88,7 +88,7 @@ @@ -98,11 +98,17 @@ user->isGuest){?> - + + + diff --git a/frontend/views/site/index.php b/frontend/views/site/index.php index 8da72cf..adf302b 100755 --- a/frontend/views/site/index.php +++ b/frontend/views/site/index.php @@ -34,48 +34,22 @@
-
Книги
+
Книги
-
-
- -
-
-
title?>
-
Автор: author->name?> author->secondname?>
-
- preview?> -
-
-
-
34
-
-
-
-

110000 грн. необхідно

-

37620 грн. зібрано

-
-
-

20 дн. лишилось

-
-
-
- -
-
+ render('@frontend/views/book/_book', [ + 'model' => $book + ])?>
diff --git a/frontend/web/js/book.js b/frontend/web/js/book.js index 4618c2f..8fca295 100644 --- a/frontend/web/js/book.js +++ b/frontend/web/js/book.js @@ -38,11 +38,15 @@ .replace(/\r/g, "\\\\r") .replace(/\t/g, "\\\\t"); data = JSON.parse(st); - title = data.title; - description = data.description; - preview = data.preview; - image = data.image; - id = data.id; + console.log(data); + if (data.length > 0){ + title = data.title; + description = data.description; + preview = data.preview; + image = data.image; + id = data.id; + } + } titleSelector.addEventListener('blur', function(e) { e.preventDefault(); @@ -156,7 +160,7 @@ function sendData() { var xhr = new XMLHttpRequest(); var url = '/book/add'; - if (id !== 0){ + if (id != 0){ url = '/book/edit?id='+id; } xhr.open('POST', url, true); diff --git a/frontend/widgets/FrontendPager.php b/frontend/widgets/FrontendPager.php new file mode 100755 index 0000000..41d96a5 --- /dev/null +++ b/frontend/widgets/FrontendPager.php @@ -0,0 +1,175 @@ +pagination->getPageCount(); + if ($pageCount < 2 && $this->hideOnSinglePage) { + return ''; + } + + $buttons = []; + $currentPage = $this->pagination->getPage(); + + // first page +// $firstPageLabel = $this->firstPageLabel === true ? '1' : $this->firstPageLabel; +// if ($firstPageLabel !== false) { +// $buttons[] = $this->renderPageButton($firstPageLabel, 0, $this->firstPageCssClass, $currentPage <= 0, false); +// } + // prev page + if ($this->prevPageLabel !== false) { + if (( $page = $currentPage - 1 ) < 0) { + $page = 0; + } + $buttons[] = $this->renderPageButton( + $this->prevPageLabel, + $page, + $this->prevPageCssClass, + $currentPage <= 0, + false + ); + } + $firstPageLabel = '1'; + list($beginPage, $endPage) = $this->getPageRange(); + if ($beginPage !== 0) { + $buttons[] = $this->renderPageButton( + $firstPageLabel, + 0, + $this->firstPageCssClass, + $currentPage <= 0, + false + ); + } + // internal pages + + for ($i = $beginPage; $i <= $endPage; ++$i) { + $buttons[] = $this->renderPageButton( + $i + 1, + $i, + null, + $this->disableCurrentPageButton && $i == $currentPage, + $i == $currentPage + ); + } + // last page + $lastPageLabel = $this->lastPageLabel === true ? $pageCount : $this->lastPageLabel; + if ($lastPageLabel !== false and $endPage !== $pageCount - 1) { + if ($endPage + 1 < $pageCount - 1 and $this->dots) { + $buttons[] = $this->renderPageButton('...', $endPage + 1, $this->dotsClass, true, false); + } + if ($lastPageLabel == 'last_number') { + $lastPageLabel = $pageCount; + } + $buttons[] = $this->renderPageButton( + $lastPageLabel, + $pageCount - 1, + $this->lastPageCssClass, + $currentPage >= $pageCount - 1, + false + ); + } + // next page + if ($this->nextPageLabel !== false) { + if (( $page = $currentPage + 1 ) >= $pageCount - 1) { + $page = $pageCount - 1; + } + $buttons[] = $this->renderPageButton( + $this->nextPageLabel, + $page, + $this->nextPageCssClass, + $currentPage >= $pageCount - 1, + false + ); + } + + return Html::tag('ul', implode("\n", $buttons), $this->options); + } + + protected function renderPageButton($label, $page, $class, $disabled, $active) + { + $options = [ 'class' => empty($class) ? $this->pageCssClass : $class ]; + if ($active) { + Html::addCssClass($options, $this->activePageCssClass); + } + if ($disabled) { + Html::addCssClass($options, $this->disabledPageCssClass); + $tag = ArrayHelper::remove($this->disabledListItemSubTagOptions, 'tag', 'span'); + + return Html::tag('li', Html::tag($tag, $label, $this->disabledListItemSubTagOptions), $options); + } + $linkOptions = $this->linkOptions; + $linkOptions[ 'data-page' ] = $page; + if ($page == 0 and !$active) { + + $link = trim( + Url::current( + [ + 'page' => null, + 'per-page' => null, + ] + ), + '?' + ); + /** + * @var \artbox\catalog\models\Filter $filter + */ + $filter = \Yii::$app->get('filter')->filterObj; + if (key_exists($link, $filter->getReplacedFilters())) { + $link = $filter->getReplacedFilters()[ $link ]; + } + return Html::tag( + 'li', + Html::a($label, $link, $linkOptions), + $options + ); + } + + + if ($active) { + return Html::tag('li', Html::a($label, null, $linkOptions), $options); + } else { + $link = $this->pagination->createUrl($page); + $query = parse_url($link); + parse_str($query[ 'query' ], $params); + unset($query[ 'query' ]); + ksort($params); + $link = $query[ 'path' ] . '?' . http_build_query($params); + return Html::tag('li', Html::a($label, $link, $linkOptions), $options); + } + + } + + } \ No newline at end of file -- libgit2 0.21.4