From ea09d15d78f90c9a5bbc0ef407a0fb42026d12c6 Mon Sep 17 00:00:00 2001 From: Yarik Date: Tue, 9 Feb 2016 18:03:42 +0200 Subject: [PATCH] test --- common/models/Gallery.php | 38 ++++++++++++++++++++++++++++++-------- common/models/ImageSizerForm.php | 2 +- common/modules/file/controllers/UploaderController.php | 9 ++++----- common/widgets/views/image_sizer.php | 5 ++--- common/widgets/views/requirements_field.php | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/widgets/views/youtube_field.php | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ console/migrations/m160208_094102_add_project_specialization.php | 2 +- frontend/assets/AppAsset.php | 2 +- frontend/controllers/AccountsController.php | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- frontend/views/accounts/_gallery_form.php | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ frontend/views/accounts/_vacancy_form.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 381 insertions(+), 21 deletions(-) create mode 100644 common/widgets/views/requirements_field.php create mode 100644 common/widgets/views/youtube_field.php create mode 100644 frontend/views/accounts/_gallery_form.php create mode 100644 frontend/views/accounts/_vacancy_form.php diff --git a/common/models/Gallery.php b/common/models/Gallery.php index 6203ae2..88f1fd8 100644 --- a/common/models/Gallery.php +++ b/common/models/Gallery.php @@ -3,6 +3,9 @@ namespace common\models; use Yii; +use yii\behaviors\BlameableBehavior; +use yii\behaviors\TimestampBehavior; +use yii\db\Expression; /** * This is the model class for table "gallery". @@ -29,12 +32,31 @@ class Gallery extends \yii\db\ActiveRecord /** * @inheritdoc */ + public function behaviors() + { + return [ + [ + 'class' => BlameableBehavior::className(), + 'createdByAttribute' => 'user_id', + 'updatedByAttribute' => false, + ], + [ + 'class' => TimestampBehavior::className(), + 'createdAtAttribute' => 'date_add', + 'updatedAtAttribute' => false, + 'value' => new Expression('NOW()'), + ], + ]; + } + + /** + * @inheritdoc + */ public function rules() { return [ - [['user_id', 'name', 'date_add'], 'required'], - [['user_id', 'user_add_id', 'type'], 'integer'], - [['date_add'], 'safe'], + [['name'], 'required'], + [['type'], 'integer'], [['photo'], 'string'], [['name', 'cover'], 'string', 'max' => 255], ]; @@ -48,12 +70,12 @@ class Gallery extends \yii\db\ActiveRecord return [ 'gallery_id' => Yii::t('app', 'Gallery ID'), 'user_id' => Yii::t('app', 'User ID'), - 'name' => Yii::t('app', 'Name'), - 'date_add' => Yii::t('app', 'Date Add'), + 'name' => Yii::t('app', 'Название'), + 'date_add' => Yii::t('app', 'Дата добавления'), 'user_add_id' => Yii::t('app', 'User Add ID'), - 'cover' => Yii::t('app', 'Cover'), - 'type' => Yii::t('app', 'Type'), - 'photo' => Yii::t('app', 'Photo'), + 'cover' => Yii::t('app', 'Фото главное'), + 'type' => Yii::t('app', 'Вид галереи'), + 'photo' => Yii::t('app', 'Фото галереи'), ]; } } diff --git a/common/models/ImageSizerForm.php b/common/models/ImageSizerForm.php index 3856034..87dd988 100755 --- a/common/models/ImageSizerForm.php +++ b/common/models/ImageSizerForm.php @@ -29,7 +29,7 @@ class ImageSizerForm extends Model public function rules() { return [ - [['width', 'height'], 'integer'], + [['width', 'height', 'multi'], 'integer'], [['field', 'multi','old_img'], 'string', 'max' => 255], [['model', 'form',], 'string'], [['file','img','price_list'], 'file'], diff --git a/common/modules/file/controllers/UploaderController.php b/common/modules/file/controllers/UploaderController.php index 502e086..8e06bd7 100755 --- a/common/modules/file/controllers/UploaderController.php +++ b/common/modules/file/controllers/UploaderController.php @@ -134,12 +134,14 @@ class UploaderController extends Controller { public function actionDownloadPhoto() { - $model = new ImageSizerForm(); $request = Yii::$app->request->post(); + if ($request) { + $model->multi = $request['multi']; + $model->file = UploadedFile::getInstance($model, 'file'); $md5_file = md5_file($model->file->tempName).rand(1, 1000); @@ -167,13 +169,10 @@ class UploaderController extends Controller { $imageLink = '/storage/'.$this->getUserPath().'/'.$md5_file.'/'.'original'.'.'.$model->file->extension; } - - if($model->multi){ - $view = $this->renderPartial('@app/components/views/_gallery_item', [ + $view = $this->renderPartial('@common/widgets/views/_gallery_item', [ 'item' => ['image'=>$imageLink], ]); - return json_encode(['link'=>$imageLink, 'view' =>$view]); diff --git a/common/widgets/views/image_sizer.php b/common/widgets/views/image_sizer.php index e89030c..6c0f63f 100755 --- a/common/widgets/views/image_sizer.php +++ b/common/widgets/views/image_sizer.php @@ -101,7 +101,7 @@ $id = $model::tableName().'_id'; "{$field}_picture_link"]) ?> - +
").fileupload({ dataType: 'json', - formData: {width: ,height:}, + formData: {width: ,height:, multi: 1}, done: function (e, data) { - var img = data.result.view; var block = $("#_img_block"); block.append(img); diff --git a/common/widgets/views/requirements_field.php b/common/widgets/views/requirements_field.php new file mode 100644 index 0000000..6100bdb --- /dev/null +++ b/common/widgets/views/requirements_field.php @@ -0,0 +1,56 @@ + +
+ + Требования + +

Добавить поле

+ + + + + 'form-group', + 'id' => isset( $model[ $i ][ 'parent_key' ] ) ? $model[ $i ][ 'parent_key' ] : 0, + ]) ?> + + + + + + + +
+ + + diff --git a/common/widgets/views/youtube_field.php b/common/widgets/views/youtube_field.php new file mode 100644 index 0000000..102e92b --- /dev/null +++ b/common/widgets/views/youtube_field.php @@ -0,0 +1,56 @@ + +
+ + Видео с Youtube + +

Добавить поле

+ + + + + 'form-group', + 'id' => isset( $model[ $i ][ 'parent_key' ] ) ? $model[ $i ][ 'parent_key' ] : 0, + ]) ?> + + + + + + + +
+ + + diff --git a/console/migrations/m160208_094102_add_project_specialization.php b/console/migrations/m160208_094102_add_project_specialization.php index 464fc5a..de0b714 100644 --- a/console/migrations/m160208_094102_add_project_specialization.php +++ b/console/migrations/m160208_094102_add_project_specialization.php @@ -24,7 +24,7 @@ class m160208_094102_add_project_specialization extends Migration $this->createTable ( '{{%employment}}', [ - 'employment_id' => $this->primaryKey (), 'name' => $this->integer (), + 'employment_id' => $this->primaryKey (), 'name' => $this->string(), ] ); $this->createTable ( diff --git a/frontend/assets/AppAsset.php b/frontend/assets/AppAsset.php index 11d3f2c..6c5924b 100755 --- a/frontend/assets/AppAsset.php +++ b/frontend/assets/AppAsset.php @@ -19,7 +19,7 @@ class AppAsset extends AssetBundle public $css = [ 'css/style.css', '/admin/css/flags32.css', - 'https://fonts.googleapis.com/css?family=Roboto:400,700&subset=cyrillic,latin', + //'https://fonts.googleapis.com/css?family=Roboto:400,700&subset=cyrillic,latin', ]; public $js = [ '/js/script.js', diff --git a/frontend/controllers/AccountsController.php b/frontend/controllers/AccountsController.php index b586367..e5ea2c1 100755 --- a/frontend/controllers/AccountsController.php +++ b/frontend/controllers/AccountsController.php @@ -3,7 +3,9 @@ use common\models\Blog; use common\models\CompanyInfo; + use common\models\Employment; use common\models\Fields; + use common\models\Gallery; use common\models\Job; use common\models\Language; use common\models\Payment; @@ -13,6 +15,7 @@ use common\models\Specialization; use common\models\UserPayment; use common\models\UserSpecialization; + use common\models\Vacancy; use Yii; use common\models\User; use common\models\UserInfo; @@ -122,7 +125,10 @@ $blog = new Blog(); $post = \Yii::$app->request->post(); if($blog->load($post) && $blog->save()) { - return $this->redirect(['blog-update', 'id' => $blog->blog_id]); + return $this->redirect([ + 'blog-update', + [ 'id' => $blog->blog_id ], + ]); } else { return $this->render('_blog_form', [ 'blog' => $blog ]); } @@ -437,7 +443,10 @@ foreach($project->paymentInput as $one_payment) { $project->link('payments', Payment::findOne($one_payment)); } - return $this->redirect(['projects-update', 'id' => $project->project_id]); + return $this->redirect([ + 'projects-update', + 'id' => $project->project_id, + ]); } } return $this->render('_projects_form', [ @@ -516,6 +525,111 @@ } + public function actionGalleryCreate() + { + $gallery = new Gallery(); + $user = \Yii::$app->user->identity; + $post = \Yii::$app->request->post(); + if($gallery->load($post) && $gallery->save()) { + Fields::saveFieldData(Yii::$app->request->post('Fields'), \Yii::$app->user->identity->id, User::className(), 'ru'); + return $this->redirect([ + 'gallery-update', + 'id' => $gallery->gallery_id, + ]); + } else { + return $this->render('_gallery_form', [ + 'gallery' => $gallery, + 'user' => $user, + ]); + } + } + + public function actionGalleryUpdate($id) + { + $gallery = Gallery::findOne($id); + $user = \Yii::$app->user->identity; + $post = \Yii::$app->request->post(); + if($gallery->load($post) && $gallery->save()) { + Fields::saveFieldData(Yii::$app->request->post('Fields'), \Yii::$app->user->identity->id, User::className(), 'ru'); + return $this->redirect([ + 'gallery-update', + 'id' => $gallery->gallery_id, + ]); + } else { + return $this->render('_gallery_form', [ + 'gallery' => $gallery, + 'user' => $user, + ]); + } + } + + public function actionVacancy() + { + $this->render('vacancy'); + } + + public function actionVacancyCreate() + { + $vacancy = new Vacancy(); + $employment = Employment::find() + ->select([ + 'name', + 'employment_id', + ]) + ->indexBy('employment_id') + ->asArray() + ->column(); + $post = \Yii::$app->request->post(); + if(!empty($post)) { + $vacancy->load($post); + $vacancy->validate(); + if(!$vacancy->hasErrors()) { + $vacancy->save(); + Fields::saveFieldData(Yii::$app->request->post('Fields'), $vacancy->vacancy_id, Vacancy::className(), 'ru'); + $vacancy->unlinkAll('employments', true); + foreach($vacancy->employmentInput as $one_employment) { + $vacancy->link('employments', Employment::findOne($one_employment)); + } + return $this->redirect(['vacancy-update', 'id' => $vacancy->vacancy_id]); + } + } + return $this->render('_vacancy_form', [ + 'vacancy' => $vacancy, + 'employment' => $employment, + ]); + } + + public function actionVacancyUpdate($id) + { + $vacancy = Vacancy::findOne($id); + $employment = Employment::find() + ->select([ + 'name', + 'employment_id', + ]) + ->indexBy('employment_id') + ->asArray() + ->column(); + $post = \Yii::$app->request->post(); + if(!empty($post)) { + $vacancy->load($post); + $vacancy->validate(); + if(!$vacancy->hasErrors()) { + $vacancy->save(); + Fields::saveFieldData(Yii::$app->request->post('Fields'), $vacancy->vacancy_id, Vacancy::className(), 'ru'); + $vacancy->unlinkAll('employments', true); + foreach($vacancy->employmentInput as $one_employment) { + $vacancy->link('employments', Employment::findOne($one_employment)); + } + return $this->redirect(['vacancy-update', 'id' => $vacancy->vacancy_id]); + } + } + return $this->render('_vacancy_form', [ + 'vacancy' => $vacancy, + 'employment' => $employment, + ]); + } + public function actionGetForm($lastindex) { return $this->renderAjax('_job_form', [ 'index' => $lastindex + 1 ]); diff --git a/frontend/views/accounts/_gallery_form.php b/frontend/views/accounts/_gallery_form.php new file mode 100644 index 0000000..d8f8730 --- /dev/null +++ b/frontend/views/accounts/_gallery_form.php @@ -0,0 +1,64 @@ +title = 'Мой профиль'; + $this->params[ 'breadcrumbs' ][] = $this->title; +?> +

title ?>

+ + + +date_add ?> + +field($gallery, 'name') + ->textInput() ?> + + $gallery, + 'field' => 'cover', + 'width' => 100, + 'height' => 100, + 'multi' => false, + 'gallery' => $gallery->cover, + 'name' => 'Загрузить главное фото', +]); ?> + +field($gallery, 'type') + ->radioList([ + 1 => 'Фото', + 2 => 'Видео', + ]) ?> + + $gallery, + 'field' => 'photo', + 'width' => 100, + 'height' => 100, + 'multi' => true, + 'gallery' => $gallery->photo, + 'name' => 'Загрузить фото галереи', +]); ?> + + 'youtube', 'item_id' => $user->id, 'model' => 'common\models\User', 'language' => 'ru', + ] +); ?> + + + +end(); +?> diff --git a/frontend/views/accounts/_vacancy_form.php b/frontend/views/accounts/_vacancy_form.php new file mode 100644 index 0000000..ed85dc4 --- /dev/null +++ b/frontend/views/accounts/_vacancy_form.php @@ -0,0 +1,50 @@ +title = 'Мой профиль'; + $this->params[ 'breadcrumbs' ][] = $this->title; +?> +

title ?>

+ + + +field($vacancy, 'name') + ->textInput() ?> + +field($vacancy, 'link') + ->textInput() ?> + +field($vacancy, 'user_name') + ->textInput() ?> + +field($vacancy, 'city') + ->textInput() ?> + +field($vacancy, 'employmentInput') + ->checkboxList($employment) ?> + + 'requirements', 'item_id' => $vacancy->vacancy_id, 'model' => 'common\models\Vacancy', 'language' => 'ru', + ] +); ?> + +field($vacancy, 'description')->widget(CKEditor::className()) ?> + + + +end(); +?> -- libgit2 0.21.4