From f7089e23dfd1cede749bf5bae2a5eb7b641dd4f2 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 15 Feb 2016 17:09:30 +0200 Subject: [PATCH] 15.02.16 --- common/models/PortfolioSpecialization.php | 2 ++ frontend/controllers/AccountsController.php | 4 ++++ frontend/controllers/PerformerController.php | 17 ++++++++++++++++- frontend/views/accounts/_portfolio_form.php | 11 ++++++----- frontend/views/performer/portfolio.php | 221 +++++++++++++++++++---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- frontend/views/performer/portfolio_list_view.php | 39 +++++++++++++++++++++++++++++++++++++++ frontend/widgets/MyListView.php | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 195 insertions(+), 208 deletions(-) create mode 100644 frontend/views/performer/portfolio_list_view.php create mode 100644 frontend/widgets/MyListView.php diff --git a/common/models/PortfolioSpecialization.php b/common/models/PortfolioSpecialization.php index cb04527..6a373e0 100644 --- a/common/models/PortfolioSpecialization.php +++ b/common/models/PortfolioSpecialization.php @@ -16,6 +16,8 @@ use Yii; */ class PortfolioSpecialization extends \yii\db\ActiveRecord { + + public $count; /** * @inheritdoc */ diff --git a/frontend/controllers/AccountsController.php b/frontend/controllers/AccountsController.php index 76948ee..c1af09d 100755 --- a/frontend/controllers/AccountsController.php +++ b/frontend/controllers/AccountsController.php @@ -466,8 +466,11 @@ if(!$portfolio instanceof ActiveRecord) { throw new NotFoundHttpException('Запись не найдена'); } + $specializations = Specialization::find()->where(['specialization_pid' => 0])->orderBy('specialization_id')->all(); + $post = \Yii::$app->request->post(); + if(!empty( $post )) { $portfolio->load($post); $portfolio->validate(); @@ -483,6 +486,7 @@ return $this->redirect('portfolio'); } } + return $this->render('_portfolio_form', [ 'portfolio' => $portfolio, 'specializations' => $specializations, diff --git a/frontend/controllers/PerformerController.php b/frontend/controllers/PerformerController.php index 99c67ff..cc42f5f 100755 --- a/frontend/controllers/PerformerController.php +++ b/frontend/controllers/PerformerController.php @@ -4,6 +4,8 @@ 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; @@ -80,10 +82,23 @@ class PerformerController extends Controller 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 + 'user' => $user, + 'filters' => $filters, + 'portfolio' => $portfolio ]); } diff --git a/frontend/views/accounts/_portfolio_form.php b/frontend/views/accounts/_portfolio_form.php index 3fc0cda..a453696 100644 --- a/frontend/views/accounts/_portfolio_form.php +++ b/frontend/views/accounts/_portfolio_form.php @@ -7,7 +7,8 @@ use common\models\Specialization; use common\widgets\ImageUploader; use mihaildev\ckeditor\CKEditor; - use yii\helpers\Html; +use yii\helpers\ArrayHelper; +use yii\helpers\Html; use yii\widgets\ActiveForm; use \common\widgets\MultiLangForm; use kartik\select2\Select2; @@ -56,7 +57,7 @@ use yii\web\JsExpression; @@ -78,8 +79,8 @@ use yii\web\JsExpression; $portfolio, 'field'=>'cover', - 'width'=>100, - 'height'=>100, + 'width'=>210, + 'height'=>150, 'multi'=>false, 'gallery' =>$portfolio->cover, 'name' => 'Загрузить' @@ -166,4 +167,4 @@ use yii\web\JsExpression; $(document).ready(function(){ }) - \ No newline at end of file + diff --git a/frontend/views/performer/portfolio.php b/frontend/views/performer/portfolio.php index 0a35464..e28edf2 100755 --- a/frontend/views/performer/portfolio.php +++ b/frontend/views/performer/portfolio.php @@ -1,219 +1,36 @@ params['user'] = $user; $this->title = 'My Yii Application'; ?>
-
- -
-
-
-
-
-
127
-
-
-
-
-
-
10.0
-
-
-
-
-
-
14
-
-
- -
-
- -
-
-
-
-
-
127
-
-
-
-
-
-
10.0
-
-
-
-
-
-
14
-
-
- -
-
- -
-
-
-
-
-
127
-
-
-
-
-
-
10.0
-
-
-
-
-
-
14
-
-
- -
-
- -
-
-
-
-
-
127
-
-
-
-
-
-
10.0
-
-
-
-
-
-
14
-
-
- -
-
- -
-
-
-
-
-
127
-
-
-
-
-
-
10.0
-
-
-
-
-
-
14
-
-
- -
-
- -
-
-
-
-
-
127
-
-
-
-
-
-
10.0
-
-
-
-
-
-
14
-
-
- -
- - + $portfolio, + 'itemView'=>'portfolio_list_view', + 'layout' => "{items}\n" + ] ); + ?>
diff --git a/frontend/views/performer/portfolio_list_view.php b/frontend/views/performer/portfolio_list_view.php new file mode 100644 index 0000000..2088627 --- /dev/null +++ b/frontend/views/performer/portfolio_list_view.php @@ -0,0 +1,39 @@ + +
+
+
+ cover), '#');?> +
+
+
+ name?> +
+
+
+
+
+
+
+
+
127
+
+
+
+
+
+
10.0
+
+
+
+
+
+
14
+
+
+
specializations,'specialization_name'))?>
+
\ No newline at end of file diff --git a/frontend/widgets/MyListView.php b/frontend/widgets/MyListView.php new file mode 100644 index 0000000..4e0c235 --- /dev/null +++ b/frontend/widgets/MyListView.php @@ -0,0 +1,109 @@ + + * @since 2.0 + */ +class MyListView extends ListView +{ + /** + * @var array the HTML attributes for the container of the rendering result of each data model. + * The "tag" element specifies the tag name of the container element and defaults to "div". + * If "tag" is false, it means no container element will be rendered. + * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. + */ + public $itemOptions = []; + /** + * @var string|callable the name of the view for rendering each data item, or a callback (e.g. an anonymous function) + * for rendering each data item. If it specifies a view name, the following variables will + * be available in the view: + * + * - `$model`: mixed, the data model + * - `$key`: mixed, the key value associated with the data item + * - `$index`: integer, the zero-based index of the data item in the items array returned by [[dataProvider]]. + * - `$widget`: ListView, this widget instance + * + * Note that the view name is resolved into the view file by the current context of the [[view]] object. + * + * If this property is specified as a callback, it should have the following signature: + * + * ~~~ + * function ($model, $key, $index, $widget) + * ~~~ + */ + public $itemView; + /** + * @var array additional parameters to be passed to [[itemView]] when it is being rendered. + * This property is used only when [[itemView]] is a string representing a view name. + */ + public $viewParams = []; + /** + * @var string the HTML code to be displayed between any two consecutive items. + */ + public $separator = "\n"; + /** + * @var array the HTML attributes for the container tag of the list view. + * The "tag" element specifies the tag name of the container element and defaults to "div". + * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. + */ + public $options = ['class' => 'list-view']; + + + /** + * Renders all data models. + * @return string the rendering result + */ + public function renderItems() + { + $models = $this->dataProvider->getModels(); + $keys = $this->dataProvider->getKeys(); + $rows = []; + foreach (array_values($models) as $index => $model) { + $rows[] = $this->renderItem($model, $keys[$index], $index); + } + + return implode($this->separator, $rows); + } + + /** + * Renders a single data model. + * @param mixed $model the data model to be rendered + * @param mixed $key the key value associated with the data model + * @param integer $index the zero-based index of the data model in the model array returned by [[dataProvider]]. + * @return string the rendering result + */ + public function renderItem($model, $key, $index) + { + if ($this->itemView === null) { + $content = $key; + } elseif (is_string($this->itemView)) { + $content = $this->getView()->render($this->itemView, array_merge([ + 'model' => $model, + 'key' => $key, + 'index' => $index, + 'widget' => $this, + ], $this->viewParams)); + } else { + $content = call_user_func($this->itemView, $model, $key, $index, $this); + } + + return $content; + + } +} -- libgit2 0.21.4