From e715603324e229716251149802672f5bf43b7583 Mon Sep 17 00:00:00 2001 From: Yarik Date: Fri, 19 Feb 2016 18:21:16 +0200 Subject: [PATCH] test --- common/models/Portfolio.php | 2 +- frontend/controllers/PerformerController.php | 437 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- frontend/views/performer/portfolio-view.php | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------- 3 files changed, 336 insertions(+), 279 deletions(-) diff --git a/common/models/Portfolio.php b/common/models/Portfolio.php index 6f11514..c8f6f54 100644 --- a/common/models/Portfolio.php +++ b/common/models/Portfolio.php @@ -179,6 +179,6 @@ public function getGallery() { - $this->hasOne(Gallery::className(), ['gallery_id' => 'gallery_id']); + return $this->hasOne(Gallery::className(), ['gallery_id' => 'gallery_id']); } } diff --git a/frontend/controllers/PerformerController.php b/frontend/controllers/PerformerController.php index 849fae1..35bfc2a 100755 --- a/frontend/controllers/PerformerController.php +++ b/frontend/controllers/PerformerController.php @@ -1,266 +1,285 @@ controller->actionParams['performer_id'])) { - $performer_id = $action->controller->actionParams['performer_id']; - $user = User::findOne($performer_id); - if(!empty($user->userInfo)) { - $user->userInfo->updateCounters(['view_count' => 1]); - } - } - return parent::afterAction($action, $result); - } + namespace frontend\controllers; + + use common\models\Blog; + use common\models\Fields; + use common\models\Gallery; + use common\models\Portfolio; + use common\models\PortfolioSpecialization; + use Yii; + use yii\data\ArrayDataProvider; + use yii\data\Pagination; + use yii\helpers\ArrayHelper; + use yii\web\BadRequestHttpException; + use yii\web\Controller; + use common\models\User; /** - * @inheritdoc + * Site controller */ - public function actions() + class PerformerController extends Controller { - return [ - 'error' => [ - 'class' => 'yii\web\ErrorAction', - ], - 'captcha' => [ - 'class' => 'yii\captcha\CaptchaAction', - 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, - ], - ]; - } - public function actionCommon($performer_id) - { + public $layout = 'performer'; - $user = User::findOne($performer_id); + public $user; - if(!$user instanceof User){ - throw new BadRequestHttpException('Пользователь не найден'); - } - - $educations = Fields::getData($user->id,$user->className(),'education'); - $phones = Fields::getData($user->id,$user->className(),'phone'); - $sites = Fields::getData($user->id,$user->className(),'site'); - $soft = implode(', ',ArrayHelper::getColumn(Fields::getData($user->id,$user->className(),'soft'), 'soft')); - - return $this->render('common',[ - 'user' => $user, - 'educations' => $educations, - 'phones' => $phones, - 'sites' => $sites, - 'soft' => $soft - ]); - - - } - - public function actionPortfolio($performer_id) - { - $user = User::findOne($performer_id); + public $defaultAction = 'common'; - if(!$user instanceof User){ - throw new BadRequestHttpException('Пользователь не найден'); + public function afterAction($action, $result) + { + if(!empty( $action->controller->actionParams[ 'performer_id' ] )) { + $performer_id = $action->controller->actionParams[ 'performer_id' ]; + $user = User::findOne($performer_id); + if(!empty( $user->userInfo )) { + $user->userInfo->updateCounters([ 'view_count' => 1 ]); + } + } + return parent::afterAction($action, $result); } - $projects = ArrayHelper::getColumn($user->portfolios,'portfolio_id'); + /** + * @inheritdoc + */ + public function actions() + { + return [ + 'error' => [ + 'class' => 'yii\web\ErrorAction', + ], + 'captcha' => [ + 'class' => 'yii\captcha\CaptchaAction', + 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : NULL, + ], + ]; + } - $filters = PortfolioSpecialization::find()->select(["specialization_id","COUNT('specialization_id') AS count"]) - ->where(["portfolio_id"=>$projects ])->groupBy("specialization_id")->all(); + public function actionCommon($performer_id) + { - $portfolio = new ArrayDataProvider([ - 'allModels' => $user->portfolios, - 'pagination' => [ - 'pageSize' => 9, - ], - ]); + $user = User::findOne($performer_id); - return $this->render('portfolio',[ - 'user' => $user, - 'filters' => $filters, - 'portfolio' => $portfolio, - 'count' => count($user->portfolios) - ]); + if(!$user instanceof User) { + throw new BadRequestHttpException('Пользователь не найден'); + } - } + $educations = Fields::getData($user->id, $user->className(), 'education'); + $phones = Fields::getData($user->id, $user->className(), 'phone'); + $sites = Fields::getData($user->id, $user->className(), 'site'); + $soft = implode(', ', ArrayHelper::getColumn(Fields::getData($user->id, $user->className(), 'soft'), 'soft')); - public function actionPortfolioFilter($performer_id, $filter){ - $user = User::findOne($performer_id); + return $this->render('common', [ + 'user' => $user, + 'educations' => $educations, + 'phones' => $phones, + 'sites' => $sites, + 'soft' => $soft, + ]); - if(!$user instanceof User){ - throw new BadRequestHttpException('Пользователь не найден'); } - $portfolios = ArrayHelper::getColumn($user->portfolios,'portfolio_id'); - - - $filters = PortfolioSpecialization::find()->select(["specialization_id","COUNT('specialization_id') AS count"]) - ->where(["portfolio_id"=>$portfolios ])->groupBy("specialization_id")->all(); - - $filter_result = PortfolioSpecialization::find() - ->where(['specialization_id'=>$filter, - 'portfolio_id'=>$portfolios - ])->all(); - - - $portfolio = new ArrayDataProvider([ - 'allModels' => Portfolio::find()->where(['portfolio_id'=>ArrayHelper::getColumn($filter_result,'portfolio_id')])->all(), - 'pagination' => [ - 'pageSize' => 9, - ], - ]); + public function actionPortfolio($performer_id) + { + $user = User::findOne($performer_id); - return $this->render('portfolio',[ - 'user' => $user, - 'filters' => $filters, - 'portfolio' => $portfolio, - 'filter_id' => $filter, - 'count' => count($user->portfolios) - ]); - } + if(!$user instanceof User) { + throw new BadRequestHttpException('Пользователь не найден'); + } + $projects = ArrayHelper::getColumn($user->portfolios, 'portfolio_id'); + + $filters = PortfolioSpecialization::find() + ->select([ + "specialization_id", + "COUNT('specialization_id') AS count", + ]) + ->where([ "portfolio_id" => $projects ]) + ->groupBy("specialization_id") + ->all(); + + $portfolio = new ArrayDataProvider([ + 'allModels' => $user->portfolios, + 'pagination' => [ + 'pageSize' => 9, + ], + ]); + + return $this->render('portfolio', [ + 'user' => $user, + 'filters' => $filters, + 'portfolio' => $portfolio, + 'count' => count($user->portfolios), + ]); - public function actionPortfolioView($performer_id/*, $portfolio_id*/) - { - $user = User::findOne($performer_id); - return $this->render('portfolio-view', ['user' => $user]); - } + } - public function actionBlogList($performer_id) - { - $user = User::findOne($performer_id); + public function actionPortfolioFilter($performer_id, $filter) + { + $user = User::findOne($performer_id); - if(!$user instanceof User){ - throw new BadRequestHttpException('Пользователь не найден'); + if(!$user instanceof User) { + throw new BadRequestHttpException('Пользователь не найден'); + } + $portfolios = ArrayHelper::getColumn($user->portfolios, 'portfolio_id'); + + $filters = PortfolioSpecialization::find() + ->select([ + "specialization_id", + "COUNT('specialization_id') AS count", + ]) + ->where([ "portfolio_id" => $portfolios ]) + ->groupBy("specialization_id") + ->all(); + + $filter_result = PortfolioSpecialization::find() + ->where([ + 'specialization_id' => $filter, + 'portfolio_id' => $portfolios, + ]) + ->all(); + + $portfolio = new ArrayDataProvider([ + 'allModels' => Portfolio::find() + ->where([ 'portfolio_id' => ArrayHelper::getColumn($filter_result, 'portfolio_id') ]) + ->all(), + 'pagination' => [ + 'pageSize' => 9, + ], + ]); + + return $this->render('portfolio', [ + 'user' => $user, + 'filters' => $filters, + 'portfolio' => $portfolio, + 'filter_id' => $filter, + 'count' => count($user->portfolios), + ]); } + public function actionPortfolioView($performer_id, $portfolio_id) + { + $user = User::findOne($performer_id); + $portfolio = $user->getPortfolios() + ->where([ 'portfolio_id' => $portfolio_id ]) + ->one(); + $portfolio->updateCounters([ 'view_count' => 1 ]); + return $this->render('portfolio-view', [ + 'user' => $user, + 'portfolio' => $portfolio, + ]); + } - $query = $user->getBlog(); - - $countQuery = clone $query; + public function actionBlogList($performer_id) + { + $user = User::findOne($performer_id); - $pagination = new Pagination(['totalCount' => $countQuery->count(), - 'pageSize' => 5, - ]); + if(!$user instanceof User) { + throw new BadRequestHttpException('Пользователь не найден'); + } - $article = $query->offset($pagination->offset) - ->limit($pagination->limit) - ->all(); + $query = $user->getBlog(); - $blog = new ArrayDataProvider([ - 'allModels' => $article, - ]); + $countQuery = clone $query; + $pagination = new Pagination([ + 'totalCount' => $countQuery->count(), + 'pageSize' => 5, + ]); - return $this->render('blog-list',[ - 'user' => $user, - 'blog' => $blog, - 'pagination' => $pagination - ]); - } + $article = $query->offset($pagination->offset) + ->limit($pagination->limit) + ->all(); - public function actionBlogView($performer_id, $link) - { - $user = User::findOne($performer_id); + $blog = new ArrayDataProvider([ + 'allModels' => $article, + ]); - if(!$user instanceof User){ - throw new BadRequestHttpException('Пользователь не найден'); + return $this->render('blog-list', [ + 'user' => $user, + 'blog' => $blog, + 'pagination' => $pagination, + ]); } + public function actionBlogView($performer_id, $link) + { + $user = User::findOne($performer_id); - $article = Blog::findOne(['link'=>$link,'user_id'=>$performer_id]); - $article->updateCounters(['view_count' => 1]); - - - return $this->render('blog-view',[ - 'user' => $user, - 'article' =>$article, + if(!$user instanceof User) { + throw new BadRequestHttpException('Пользователь не найден'); + } - ]); - } + $article = Blog::findOne([ + 'link' => $link, + 'user_id' => $performer_id, + ]); + $article->updateCounters([ 'view_count' => 1 ]); - public function actionReview($performer_id) - { - $user = User::findOne($performer_id); + return $this->render('blog-view', [ + 'user' => $user, + 'article' => $article, - if(!$user instanceof User){ - throw new BadRequestHttpException('Пользователь не найден'); + ]); } + public function actionReview($performer_id) + { + $user = User::findOne($performer_id); - return $this->render('review',[ - 'user' => $user - ]); - } + if(!$user instanceof User) { + throw new BadRequestHttpException('Пользователь не найден'); + } - public function actionWorkplace($performer_id) - { - $user = User::findOne($performer_id); - if(!$user instanceof User){ - throw new BadRequestHttpException('Пользователь не найден'); + return $this->render('review', [ + 'user' => $user, + ]); } - return $this->render('workplace',[ - 'user' => $user - ]); - } - - public function actionGallery($performer_id) - { - $user = User::findOne($performer_id); + public function actionWorkplace($performer_id) + { + $user = User::findOne($performer_id); + if(!$user instanceof User) { + throw new BadRequestHttpException('Пользователь не найден'); + } - if(!$user instanceof User){ - throw new BadRequestHttpException('Пользователь не найден'); + return $this->render('workplace', [ + 'user' => $user, + ]); } + public function actionGallery($performer_id) + { + $user = User::findOne($performer_id); - $query = Gallery::find(['user_id'=>$performer_id]); + if(!$user instanceof User) { + throw new BadRequestHttpException('Пользователь не найден'); + } + + $query = Gallery::find([ 'user_id' => $performer_id ]); - $countQuery = clone $query; + $countQuery = clone $query; - $pagination = new Pagination(['totalCount' => $countQuery->count(), - 'pageSize' => 5, - ]); + $pagination = new Pagination([ + 'totalCount' => $countQuery->count(), + 'pageSize' => 5, + ]); - $gallery = $query->offset($pagination->offset) - ->limit($pagination->limit) - ->all(); + $gallery = $query->offset($pagination->offset) + ->limit($pagination->limit) + ->all(); - $gallery = new ArrayDataProvider([ - 'allModels' => $gallery, - ]); + $gallery = new ArrayDataProvider([ + 'allModels' => $gallery, + ]); - $videos = Fields::getData($user->id,Gallery::className(),'youtube'); + $videos = Fields::getData($user->id, Gallery::className(), 'youtube'); - $this->layout = 'gallery'; + $this->layout = 'gallery'; - return $this->render('gallery',[ - 'user' => $user, - 'gallery' =>$gallery, - 'pagination' => $pagination, - 'videos' => $videos - ]); + return $this->render('gallery', [ + 'user' => $user, + 'gallery' => $gallery, + 'pagination' => $pagination, + 'videos' => $videos, + ]); + } } -} diff --git a/frontend/views/performer/portfolio-view.php b/frontend/views/performer/portfolio-view.php index 8d27213..dadfdb4 100644 --- a/frontend/views/performer/portfolio-view.php +++ b/frontend/views/performer/portfolio-view.php @@ -1,37 +1,45 @@ params['user'] = $user; - -$this->title = 'My Yii Application'; + use common\models\Portfolio; + use common\models\User; + use yii\web\ViewAction; + + /** + * @var ViewAction $this + * @var User $user + * @var Portfolio $portfolio + */ + $this->params[ 'user' ] = $user; + + $this->title = 'My Yii Application'; ?>
-
+
+
-
+
+
-
127
+
view_count ?>
-
+
+
-
10.0
+
XX.X
-
+
+
-
14
+
XX
@@ -46,25 +54,32 @@ $this->title = 'My Yii Application';
-
Квартира - студия в современном стиле
-
-
-
-
    -
  • -
  • -
  • -
  • -
  • -
  • -
-
-
- - +
name ?>
+ gallery ) || !empty( $portfolio->gallery->photo )) { + ?> +
+
+
+
    + gallery->photo) as $one_photo) { + ?> +
  • + +
+
+
+ + +
+
-
-
+
@@ -167,7 +182,8 @@ $this->title = 'My Yii Application';
@@ -196,7 +212,8 @@ $this->title = 'My Yii Application';
-

22.09.2015

+ +

22.09.2015

@@ -225,7 +242,8 @@ $this->title = 'My Yii Application';
-

22.09.2015

+ +

22.09.2015

@@ -254,7 +272,8 @@ $this->title = 'My Yii Application';
-

22.09.2015

+ +

22.09.2015

@@ -282,7 +301,8 @@ $this->title = 'My Yii Application';
-

22.09.2015

+ +

22.09.2015

@@ -299,40 +319,58 @@ $this->title = 'My Yii Application'; \ No newline at end of file -- libgit2 0.21.4