From b0477de58a7d8091f240b3a997d1ccd5f2a29b3d Mon Sep 17 00:00:00 2001 From: Phrlog Date: Mon, 17 Oct 2016 17:04:57 +0300 Subject: [PATCH 1/6] =?UTF-8?q?=D1=83=D0=BF=D1=80=D0=BE=D1=89=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=88=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/m161009_175734_user_roles.php | 19 ---- frontend/views/anek/feed.php | 104 ++++++------------ 2 files changed, 33 insertions(+), 90 deletions(-) delete mode 100644 console/migrations/m161009_175734_user_roles.php diff --git a/console/migrations/m161009_175734_user_roles.php b/console/migrations/m161009_175734_user_roles.php deleted file mode 100644 index 9b01400..0000000 --- a/console/migrations/m161009_175734_user_roles.php +++ /dev/null @@ -1,19 +0,0 @@ -addColumn("{{%user}}", "role", $this->integer()->notNull()->defaultValue(20). " AFTER username"); - $this->update("{{%user}}", ["role" => \common\models\User::ROLE_ADMIN], ['username' => 'admin']); - } - - public function safeDown() - { - $this->dropColumn("{{%user}}", "role"); - } - -} diff --git a/frontend/views/anek/feed.php b/frontend/views/anek/feed.php index 100c9e9..428e287 100644 --- a/frontend/views/anek/feed.php +++ b/frontend/views/anek/feed.php @@ -18,8 +18,7 @@ /* @var $users array */ - -$this->registerJsFile("/js/jquery.grid-a-licious.min.js",['depends' => [\yii\web\JqueryAsset::className()]]); +$this->registerJsFile("/js/jquery.grid-a-licious.min.js", ['depends' => [\yii\web\JqueryAsset::className()]]); $like_url = Url::to(['ajax/like']); $paginator_url = Url::to(['feed', 'page' => '']); @@ -233,14 +232,13 @@ function (msg) 'options' => ['class' => 'form-horizontal'], ]); -foreach ($aneks as $a) -{ +foreach ($aneks as $a) { if (!isset($users[$a->user->id])) { $users[$a->user->id] = $a->user->username; } } ?> -field($filter, 'user')->dropDownList($users,['prompt' => 'Все пользователи']) ?> +field($filter, 'user')->dropDownList($users, ['prompt' => 'Все пользователи']) ?> field($filter, 'mode')->checkboxList(Aneks::$modes) ?> 'btn btn-primary']) ?> -
- getContent(); - - $image_html = ''; - $text_html = ''; - if (($anek_content->mode === Aneks::MODE_BOTH)||($anek_content->mode === Aneks::MODE_IMAGE)) - { - $image_src = $a->getImage(); - + if (($anek_content->mode === Aneks::MODE_BOTH) || ($anek_content->mode === Aneks::MODE_IMAGE)) { $image_url = Url::to(['image/get', 'url' => $a->image]); - - $image_html = << -HTML; - } - if (($anek_content->mode === Aneks::MODE_BOTH)||($anek_content->mode === Aneks::MODE_TEXT)) - { - $text_html = <<{$anek_content->text}

-HTML; } ?> - -
-
- -
- -
- -

user->username ?>

-
- - Похожие - - - - - userLikes()) - { - $red = ' btn-danger'; - } - ?> - +
+
+
+ + + +
+ +
+ +

user->username ?>

+
+ text) { ?> +

text ?>

+ + Похожие + + + + +
-
-
- - -
- - - - - - + + + From a6940643444d49771c78dca6e32f3eabd30e3b5e Mon Sep 17 00:00:00 2001 From: Phrlog Date: Mon, 17 Oct 2016 17:06:00 +0300 Subject: [PATCH 2/6] =?UTF-8?q?=D0=BD=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/controllers/AjaxController.php | 84 ++++++++++--------------- 1 file changed, 34 insertions(+), 50 deletions(-) diff --git a/frontend/controllers/AjaxController.php b/frontend/controllers/AjaxController.php index 1f6e1e6..ea6d152 100644 --- a/frontend/controllers/AjaxController.php +++ b/frontend/controllers/AjaxController.php @@ -41,59 +41,43 @@ public function actionLike() { $id = Yii::$app->request->post("id"); - if ($id !== null) - { - $id = (int) $id; - $anek = Aneks::findOne($id); - /* @var $anek Aneks */ - - if ($anek) - { - $likes = count($anek->likes); - - if ($anek->userLikes()) - { - Likes::deleteAll(["user_id" => Yii::$app->user->id, "anek_id" => $anek->id]); - $like = false; - $likes--; - } - else - { - $like = new Likes(); - - $like->user_id = Yii::$app->user->id; - $like->anek_id = $anek->id; - - if (!$like->save()) - { - throw new ErrorException("Не удалось сохранить лайк"); - } - else - { - $like = true; - $likes++; - } - } - $result = new \stdClass; - - $result->like = $like; - $result->likes = $likes; - - Yii::$app->response->format = Response::FORMAT_JSON; - - return $result; + if (!$id) { + throw new BadRequestHttpException("Данные не переданы"); + } - } - else - { - throw new ErrorException("Анекдот не найден"); - } + $anek = Aneks::findOne($id); + + if (!$anek) { + throw new ErrorException("Анекдот не найден"); } - else - { - throw new BadRequestHttpException("Данные не переданы"); + + $likes = count($anek->likes); + + if ($anek->userLikes()) { + Likes::deleteAll(["user_id" => Yii::$app->user->id, "anek_id" => $anek->id]); + $like = false; + $likes--; + } else { + $like = new Likes(); + + $like->user_id = Yii::$app->user->id; + $like->anek_id = $anek->id; + + if (!$like->save()) { + throw new ErrorException("Не удалось сохранить лайк"); + } + + $like = true; + $likes++; } - } + $result = new \stdClass; + + $result->like = $like; + $result->likes = $likes; + Yii::$app->response->format = Response::FORMAT_JSON; + return $result; + } + } From 9de96f79c04c1f976779f43197803d7beda7e528 Mon Sep 17 00:00:00 2001 From: Phrlog Date: Mon, 17 Oct 2016 17:06:59 +0300 Subject: [PATCH 3/6] =?UTF-8?q?=D1=83=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=87=D0=B8=D1=82=D0=B0=D0=B5=D0=BC=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/controllers/ImageController.php | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/frontend/controllers/ImageController.php b/frontend/controllers/ImageController.php index 2a7493c..61e7bda 100644 --- a/frontend/controllers/ImageController.php +++ b/frontend/controllers/ImageController.php @@ -51,25 +51,21 @@ public function actions() */ public function actionGet($url = null) { - $image = AnekPicture::readPicture($url); - - if ($url === null) - { + if ($url === null) { throw new BadRequestHttpException("Картинка не запрошена"); } - if ($image) - { - $response = Yii::$app->getResponse(); - $response->headers->set('Content-Type', 'image/jpeg'); - $response->format = Response::FORMAT_RAW; - - return $image; + $image = AnekPicture::readPicture($url); - } - else - { + if (!$image) { throw new NotFoundHttpException("Картинка не найдена"); } + + $response = Yii::$app->getResponse(); + $response->headers->set('Content-Type', 'image/jpeg'); + $response->format = Response::FORMAT_RAW; + + return $image; + } } From 97055bca1c152887eeae93a893135e93a39ed45f Mon Sep 17 00:00:00 2001 From: Phrlog Date: Mon, 17 Oct 2016 17:07:54 +0300 Subject: [PATCH 4/6] =?UTF-8?q?=D0=BD=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BF=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/controllers/UserController.php | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/frontend/controllers/UserController.php b/frontend/controllers/UserController.php index 0507851..caf26f0 100644 --- a/frontend/controllers/UserController.php +++ b/frontend/controllers/UserController.php @@ -179,15 +179,13 @@ public function actionPostAnek() if (count($post)) { $picture = UploadedFile::getInstance($anek_form,'image'); - $image = null; if ($picture) { - $image = AnekPicture::uploadImage($picture); + $anek_form->image = AnekPicture::uploadImage($picture); } $anek_form->text = $post['text']; - $anek_form->image = $image; $anek_form->category_id = $post['category_id']; if ($anek_form->createAnek()) @@ -205,17 +203,14 @@ public function actionUploadAnek() { $upload_form = new ExcelForm(); - if (Yii::$app->request->isPost) { $file = UploadedFile::getInstance($upload_form,'word'); - $content = null; if ($file) { $content = ExcelForm::getContent($file); - $anek = new Aneks(); $anek->text = $content; @@ -223,13 +218,7 @@ public function actionUploadAnek() { return $this->redirect(["feed"]); } - else - { - //var_dump($anek->errors);die(); - } - } - //die($content); } return $this->render("upload-anek",[ From 01f38e22c4dd3486e3c2052031363c702f27b581 Mon Sep 17 00:00:00 2001 From: Phrlog Date: Mon, 17 Oct 2016 17:09:05 +0300 Subject: [PATCH 5/6] =?UTF-8?q?=D1=83=D0=B1=D1=80=D0=B0=D0=BD=20=D0=BB?= =?UTF-8?q?=D0=B8=D1=88=D0=BD=D0=B8=D0=B9=20=D0=BA=D0=BE=D0=B4,=20=D1=83?= =?UTF-8?q?=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD=D0=B0=20=D1=87=D0=B8=D1=82?= =?UTF-8?q?=D0=B0=D0=B5=D0=BC=D0=BE=D1=81=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/views/anek/one.php | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/frontend/views/anek/one.php b/frontend/views/anek/one.php index fd6d322..e4482fc 100644 --- a/frontend/views/anek/one.php +++ b/frontend/views/anek/one.php @@ -24,27 +24,16 @@
getContent(); - - $image_html = ''; - $text_html = ''; - if (($anek_content->mode === Aneks::MODE_BOTH)||($anek_content->mode === Aneks::MODE_IMAGE)) - { - $image_src = $anek->getImage(); - $image_html = <<" -HTML; - } - if (($anek_content->mode === Aneks::MODE_BOTH)||($anek_content->mode === Aneks::MODE_TEXT)) - { - $text_html = <<{$anek_content->text}

-HTML; - } + $image_src = ($anek_content->mode === Aneks::MODE_BOTH)||($anek_content->mode === Aneks::MODE_IMAGE) ? + $anek->getImage(): + null; ?>
- + + " +
-
- - From c29335ee0abd7c3d2ef149f875e89b1e2bbf8e3b Mon Sep 17 00:00:00 2001 From: Phrlog Date: Mon, 17 Oct 2016 17:12:44 +0300 Subject: [PATCH 6/6] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D0=B8=D0=BB=20=D0=BF=D0=BE=D0=BB=D0=B5=20role=20=D0=B2?= =?UTF-8?q?=20init?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- console/migrations/m130524_201442_init.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/console/migrations/m130524_201442_init.php b/console/migrations/m130524_201442_init.php index 93a09d7..652ffa5 100644 --- a/console/migrations/m130524_201442_init.php +++ b/console/migrations/m130524_201442_init.php @@ -20,7 +20,7 @@ public function up() 'password_hash' => $this->string()->notNull(), 'password_reset_token' => $this->string()->unique(), 'email' => $this->string()->notNull()->unique(), - + 'role' => $this->integer()->notNull()->defaultValue(20), 'status' => $this->smallInteger()->notNull()->defaultValue(10), 'created_at' => $this->integer()->notNull(), 'updated_at' => $this->integer()->notNull(), @@ -30,6 +30,7 @@ public function up() $user->username = 'admin'; $user->email = 'admin@localhost'; $user->setPassword('admin'); + $user->role = \common\models\User::ROLE_ADMIN; $user->generateAuthKey(); $user->save();