Commit ea09d15d78f90c9a5bbc0ef407a0fb42026d12c6

Authored by Yarik
1 parent c1b01820

test

common/models/Gallery.php
... ... @@ -3,6 +3,9 @@
3 3 namespace common\models;
4 4  
5 5 use Yii;
  6 +use yii\behaviors\BlameableBehavior;
  7 +use yii\behaviors\TimestampBehavior;
  8 +use yii\db\Expression;
6 9  
7 10 /**
8 11 * This is the model class for table "gallery".
... ... @@ -29,12 +32,31 @@ class Gallery extends \yii\db\ActiveRecord
29 32 /**
30 33 * @inheritdoc
31 34 */
  35 + public function behaviors()
  36 + {
  37 + return [
  38 + [
  39 + 'class' => BlameableBehavior::className(),
  40 + 'createdByAttribute' => 'user_id',
  41 + 'updatedByAttribute' => false,
  42 + ],
  43 + [
  44 + 'class' => TimestampBehavior::className(),
  45 + 'createdAtAttribute' => 'date_add',
  46 + 'updatedAtAttribute' => false,
  47 + 'value' => new Expression('NOW()'),
  48 + ],
  49 + ];
  50 + }
  51 +
  52 + /**
  53 + * @inheritdoc
  54 + */
32 55 public function rules()
33 56 {
34 57 return [
35   - [['user_id', 'name', 'date_add'], 'required'],
36   - [['user_id', 'user_add_id', 'type'], 'integer'],
37   - [['date_add'], 'safe'],
  58 + [['name'], 'required'],
  59 + [['type'], 'integer'],
38 60 [['photo'], 'string'],
39 61 [['name', 'cover'], 'string', 'max' => 255],
40 62 ];
... ... @@ -48,12 +70,12 @@ class Gallery extends \yii\db\ActiveRecord
48 70 return [
49 71 'gallery_id' => Yii::t('app', 'Gallery ID'),
50 72 'user_id' => Yii::t('app', 'User ID'),
51   - 'name' => Yii::t('app', 'Name'),
52   - 'date_add' => Yii::t('app', 'Date Add'),
  73 + 'name' => Yii::t('app', 'Название'),
  74 + 'date_add' => Yii::t('app', 'Дата добавления'),
53 75 'user_add_id' => Yii::t('app', 'User Add ID'),
54   - 'cover' => Yii::t('app', 'Cover'),
55   - 'type' => Yii::t('app', 'Type'),
56   - 'photo' => Yii::t('app', 'Photo'),
  76 + 'cover' => Yii::t('app', 'Фото главное'),
  77 + 'type' => Yii::t('app', 'Вид галереи'),
  78 + 'photo' => Yii::t('app', 'Фото галереи'),
57 79 ];
58 80 }
59 81 }
... ...
common/models/ImageSizerForm.php
... ... @@ -29,7 +29,7 @@ class ImageSizerForm extends Model
29 29 public function rules()
30 30 {
31 31 return [
32   - [['width', 'height'], 'integer'],
  32 + [['width', 'height', 'multi'], 'integer'],
33 33 [['field', 'multi','old_img'], 'string', 'max' => 255],
34 34 [['model', 'form',], 'string'],
35 35 [['file','img','price_list'], 'file'],
... ...
common/modules/file/controllers/UploaderController.php
... ... @@ -134,12 +134,14 @@ class UploaderController extends Controller {
134 134  
135 135 public function actionDownloadPhoto()
136 136 {
137   -
138 137 $model = new ImageSizerForm();
139 138  
140 139 $request = Yii::$app->request->post();
  140 +
141 141 if ($request) {
142 142  
  143 + $model->multi = $request['multi'];
  144 +
143 145 $model->file = UploadedFile::getInstance($model, 'file');
144 146  
145 147 $md5_file = md5_file($model->file->tempName).rand(1, 1000);
... ... @@ -167,13 +169,10 @@ class UploaderController extends Controller {
167 169 $imageLink = '/storage/'.$this->getUserPath().'/'.$md5_file.'/'.'original'.'.'.$model->file->extension;
168 170  
169 171 }
170   -
171   -
172 172 if($model->multi){
173   - $view = $this->renderPartial('@app/components/views/_gallery_item', [
  173 + $view = $this->renderPartial('@common/widgets/views/_gallery_item', [
174 174 'item' => ['image'=>$imageLink],
175 175 ]);
176   -
177 176 return json_encode(['link'=>$imageLink, 'view' =>$view]);
178 177  
179 178  
... ...
common/widgets/views/image_sizer.php
... ... @@ -101,7 +101,7 @@ $id = $model::tableName().'_id';
101 101 <?= Html::activeHiddenInput( $model,$field,['id' => "{$field}_picture_link"]) ?>
102 102  
103 103  
104   - <input type="hidden" name="ImageSizerForm[multi]" value="<?=$multi?>"/>
  104 + <input type="hidden" name="ImageSizerForm[multi]" value="true"/>
105 105  
106 106 <div id="<?= $field?>_img_block">
107 107 <?php
... ... @@ -116,9 +116,8 @@ $id = $model::tableName().&#39;_id&#39;;
116 116  
117 117 $("#<?= $field?>").fileupload({
118 118 dataType: 'json',
119   - formData: {width: <?=$width?>,height:<?=$height?>},
  119 + formData: {width: <?=$width?>,height:<?=$height?>, multi: 1},
120 120 done: function (e, data) {
121   -
122 121 var img = data.result.view;
123 122 var block = $("#<?= $field?>_img_block");
124 123 block.append(img);
... ...
common/widgets/views/requirements_field.php 0 → 100644
  1 +<?php
  2 + use yii\helpers\Html;
  3 +
  4 +?>
  5 +<fieldset>
  6 +
  7 + <legend>Требования</legend>
  8 +
  9 + <p class="btn btn-success add_field_<?= $this->context->id ?>">Добавить поле</p>
  10 +
  11 +
  12 + <?php $t = 0;
  13 + for($i = 1; $i <= count($model); $i++):
  14 + $row = $i;
  15 +
  16 + ?>
  17 +
  18 + <?= Html::beginTag('div', [
  19 + 'class' => 'form-group',
  20 + 'id' => isset( $model[ $i ][ 'parent_key' ] ) ? $model[ $i ][ 'parent_key' ] : 0,
  21 + ]) ?>
  22 + <input type="text" placeholder="Требование" class="form-control" value="<?= isset( $model[ $t ][ 'value' ] ) ? $model[ $t ][ 'value' ] : '' ?>" name="Fields[requirements][<?= $row ?>][0][requirements]"/>
  23 + <span data-id="<?= isset( $model[ $i ][ 'parent_key' ] ) ? $model[ $i ][ 'parent_key' ] : 0 ?>" title="удалить" class="glyphicon glyphicon-trash delete-field-item"></span>
  24 + <?= Html::endTag('div') ?>
  25 + <?php $i = ++$t; ?>
  26 + <?php endfor; ?>
  27 +
  28 +
  29 +</fieldset>
  30 +<script>
  31 + var start_i_<?=$this->context->id?> = <?=$i?>;
  32 + $ (document)
  33 + .ready (
  34 + function ()
  35 + {
  36 + $ ('.add_field_<?=$this->context->id?>')
  37 + .click (
  38 + function ()
  39 + {
  40 + var block = $ (this)
  41 + .parent ('fieldset');
  42 + var block_id = $ (this)
  43 + .parent ('fieldset');
  44 + var sub_block = '<div class="form-group" >' +
  45 + '<input type="text" placeholder="Требование" class="form-control" value="" name="Fields[requirements][' + start_i_<?=$this->context->id?>++ + '][0][requirements]" />' +
  46 + '<span title="удалить" class="glyphicon glyphicon-trash delete-field-item"></span>' +
  47 + '<div>';
  48 + console.log (block);
  49 + block.append (sub_block);
  50 + }
  51 + );
  52 + }
  53 + );
  54 +</script>
  55 +
  56 +
... ...
common/widgets/views/youtube_field.php 0 → 100644
  1 +<?php
  2 + use yii\helpers\Html;
  3 +
  4 +?>
  5 +<fieldset>
  6 +
  7 + <legend>Видео с Youtube</legend>
  8 +
  9 + <p class="btn btn-success add_field_<?= $this->context->id ?>">Добавить поле</p>
  10 +
  11 +
  12 + <?php $t = 0;
  13 + for($i = 1; $i <= count($model); $i++):
  14 + $row = $i;
  15 +
  16 + ?>
  17 +
  18 + <?= Html::beginTag('div', [
  19 + 'class' => 'form-group',
  20 + 'id' => isset( $model[ $i ][ 'parent_key' ] ) ? $model[ $i ][ 'parent_key' ] : 0,
  21 + ]) ?>
  22 + <input type="text" placeholder="Url видео" class="form-control" value="<?= isset( $model[ $t ][ 'value' ] ) ? $model[ $t ][ 'value' ] : '' ?>" name="Fields[youtube][<?= $row ?>][0][youtube]"/>
  23 + <span data-id="<?= isset( $model[ $i ][ 'parent_key' ] ) ? $model[ $i ][ 'parent_key' ] : 0 ?>" title="удалить" class="glyphicon glyphicon-trash delete-field-item"></span>
  24 + <?= Html::endTag('div') ?>
  25 + <?php $i = ++$t; ?>
  26 + <?php endfor; ?>
  27 +
  28 +
  29 +</fieldset>
  30 +<script>
  31 + var start_i_<?=$this->context->id?> = <?=$i?>;
  32 + $ (document)
  33 + .ready (
  34 + function ()
  35 + {
  36 + $ ('.add_field_<?=$this->context->id?>')
  37 + .click (
  38 + function ()
  39 + {
  40 + var block = $ (this)
  41 + .parent ('fieldset');
  42 + var block_id = $ (this)
  43 + .parent ('fieldset');
  44 + var sub_block = '<div class="form-group" >' +
  45 + '<input type="text" placeholder="Url видео" class="form-control" value="" name="Fields[youtube][' + start_i_<?=$this->context->id?>++ + '][0][youtube]" />' +
  46 + '<span title="удалить" class="glyphicon glyphicon-trash delete-field-item"></span>' +
  47 + '<div>';
  48 + console.log (block);
  49 + block.append (sub_block);
  50 + }
  51 + );
  52 + }
  53 + );
  54 +</script>
  55 +
  56 +
... ...
console/migrations/m160208_094102_add_project_specialization.php
... ... @@ -24,7 +24,7 @@ class m160208_094102_add_project_specialization extends Migration
24 24  
25 25 $this->createTable (
26 26 '{{%employment}}', [
27   - 'employment_id' => $this->primaryKey (), 'name' => $this->integer (),
  27 + 'employment_id' => $this->primaryKey (), 'name' => $this->string(),
28 28 ]
29 29 );
30 30 $this->createTable (
... ...
frontend/assets/AppAsset.php
... ... @@ -19,7 +19,7 @@ class AppAsset extends AssetBundle
19 19 public $css = [
20 20 'css/style.css',
21 21 '/admin/css/flags32.css',
22   - 'https://fonts.googleapis.com/css?family=Roboto:400,700&subset=cyrillic,latin',
  22 + //'https://fonts.googleapis.com/css?family=Roboto:400,700&subset=cyrillic,latin',
23 23 ];
24 24 public $js = [
25 25 '/js/script.js',
... ...
frontend/controllers/AccountsController.php
... ... @@ -3,7 +3,9 @@
3 3  
4 4 use common\models\Blog;
5 5 use common\models\CompanyInfo;
  6 + use common\models\Employment;
6 7 use common\models\Fields;
  8 + use common\models\Gallery;
7 9 use common\models\Job;
8 10 use common\models\Language;
9 11 use common\models\Payment;
... ... @@ -13,6 +15,7 @@
13 15 use common\models\Specialization;
14 16 use common\models\UserPayment;
15 17 use common\models\UserSpecialization;
  18 + use common\models\Vacancy;
16 19 use Yii;
17 20 use common\models\User;
18 21 use common\models\UserInfo;
... ... @@ -122,7 +125,10 @@
122 125 $blog = new Blog();
123 126 $post = \Yii::$app->request->post();
124 127 if($blog->load($post) && $blog->save()) {
125   - return $this->redirect(['blog-update', 'id' => $blog->blog_id]);
  128 + return $this->redirect([
  129 + 'blog-update',
  130 + [ 'id' => $blog->blog_id ],
  131 + ]);
126 132 } else {
127 133 return $this->render('_blog_form', [ 'blog' => $blog ]);
128 134 }
... ... @@ -437,7 +443,10 @@
437 443 foreach($project->paymentInput as $one_payment) {
438 444 $project->link('payments', Payment::findOne($one_payment));
439 445 }
440   - return $this->redirect(['projects-update', 'id' => $project->project_id]);
  446 + return $this->redirect([
  447 + 'projects-update',
  448 + 'id' => $project->project_id,
  449 + ]);
441 450 }
442 451 }
443 452 return $this->render('_projects_form', [
... ... @@ -516,6 +525,111 @@
516 525  
517 526 }
518 527  
  528 + public function actionGalleryCreate()
  529 + {
  530 + $gallery = new Gallery();
  531 + $user = \Yii::$app->user->identity;
  532 + $post = \Yii::$app->request->post();
  533 + if($gallery->load($post) && $gallery->save()) {
  534 + Fields::saveFieldData(Yii::$app->request->post('Fields'), \Yii::$app->user->identity->id, User::className(), 'ru');
  535 + return $this->redirect([
  536 + 'gallery-update',
  537 + 'id' => $gallery->gallery_id,
  538 + ]);
  539 + } else {
  540 + return $this->render('_gallery_form', [
  541 + 'gallery' => $gallery,
  542 + 'user' => $user,
  543 + ]);
  544 + }
  545 + }
  546 +
  547 + public function actionGalleryUpdate($id)
  548 + {
  549 + $gallery = Gallery::findOne($id);
  550 + $user = \Yii::$app->user->identity;
  551 + $post = \Yii::$app->request->post();
  552 + if($gallery->load($post) && $gallery->save()) {
  553 + Fields::saveFieldData(Yii::$app->request->post('Fields'), \Yii::$app->user->identity->id, User::className(), 'ru');
  554 + return $this->redirect([
  555 + 'gallery-update',
  556 + 'id' => $gallery->gallery_id,
  557 + ]);
  558 + } else {
  559 + return $this->render('_gallery_form', [
  560 + 'gallery' => $gallery,
  561 + 'user' => $user,
  562 + ]);
  563 + }
  564 + }
  565 +
  566 + public function actionVacancy()
  567 + {
  568 + $this->render('vacancy');
  569 + }
  570 +
  571 + public function actionVacancyCreate()
  572 + {
  573 + $vacancy = new Vacancy();
  574 + $employment = Employment::find()
  575 + ->select([
  576 + 'name',
  577 + 'employment_id',
  578 + ])
  579 + ->indexBy('employment_id')
  580 + ->asArray()
  581 + ->column();
  582 + $post = \Yii::$app->request->post();
  583 + if(!empty($post)) {
  584 + $vacancy->load($post);
  585 + $vacancy->validate();
  586 + if(!$vacancy->hasErrors()) {
  587 + $vacancy->save();
  588 + Fields::saveFieldData(Yii::$app->request->post('Fields'), $vacancy->vacancy_id, Vacancy::className(), 'ru');
  589 + $vacancy->unlinkAll('employments', true);
  590 + foreach($vacancy->employmentInput as $one_employment) {
  591 + $vacancy->link('employments', Employment::findOne($one_employment));
  592 + }
  593 + return $this->redirect(['vacancy-update', 'id' => $vacancy->vacancy_id]);
  594 + }
  595 + }
  596 + return $this->render('_vacancy_form', [
  597 + 'vacancy' => $vacancy,
  598 + 'employment' => $employment,
  599 + ]);
  600 + }
  601 +
  602 + public function actionVacancyUpdate($id)
  603 + {
  604 + $vacancy = Vacancy::findOne($id);
  605 + $employment = Employment::find()
  606 + ->select([
  607 + 'name',
  608 + 'employment_id',
  609 + ])
  610 + ->indexBy('employment_id')
  611 + ->asArray()
  612 + ->column();
  613 + $post = \Yii::$app->request->post();
  614 + if(!empty($post)) {
  615 + $vacancy->load($post);
  616 + $vacancy->validate();
  617 + if(!$vacancy->hasErrors()) {
  618 + $vacancy->save();
  619 + Fields::saveFieldData(Yii::$app->request->post('Fields'), $vacancy->vacancy_id, Vacancy::className(), 'ru');
  620 + $vacancy->unlinkAll('employments', true);
  621 + foreach($vacancy->employmentInput as $one_employment) {
  622 + $vacancy->link('employments', Employment::findOne($one_employment));
  623 + }
  624 + return $this->redirect(['vacancy-update', 'id' => $vacancy->vacancy_id]);
  625 + }
  626 + }
  627 + return $this->render('_vacancy_form', [
  628 + 'vacancy' => $vacancy,
  629 + 'employment' => $employment,
  630 + ]);
  631 + }
  632 +
519 633 public function actionGetForm($lastindex)
520 634 {
521 635 return $this->renderAjax('_job_form', [ 'index' => $lastindex + 1 ]);
... ...
frontend/views/accounts/_gallery_form.php 0 → 100644
  1 +<?php
  2 + /**
  3 + * @var Gallery $gallery
  4 + * @var User $user
  5 + */
  6 + use common\models\Gallery;
  7 + use common\models\User;
  8 + use common\widgets\FieldEditor;
  9 + use common\widgets\ImageUploader;
  10 + use mihaildev\ckeditor\CKEditor;
  11 + use yii\helpers\Html;
  12 + use yii\widgets\ActiveForm;
  13 +
  14 + $this->title = 'Мой профиль';
  15 + $this->params[ 'breadcrumbs' ][] = $this->title;
  16 +?>
  17 +<h1><?= $this->title ?></h1>
  18 +
  19 +<?php
  20 + $form = ActiveForm::begin();
  21 +?>
  22 +
  23 +<?= $gallery->date_add ?>
  24 +
  25 +<?= $form->field($gallery, 'name')
  26 + ->textInput() ?>
  27 +
  28 +<?= ImageUploader::widget([
  29 + 'model' => $gallery,
  30 + 'field' => 'cover',
  31 + 'width' => 100,
  32 + 'height' => 100,
  33 + 'multi' => false,
  34 + 'gallery' => $gallery->cover,
  35 + 'name' => 'Загрузить главное фото',
  36 +]); ?>
  37 +
  38 +<?= $form->field($gallery, 'type')
  39 + ->radioList([
  40 + 1 => 'Фото',
  41 + 2 => 'Видео',
  42 + ]) ?>
  43 +
  44 +<?= ImageUploader::widget([
  45 + 'model' => $gallery,
  46 + 'field' => 'photo',
  47 + 'width' => 100,
  48 + 'height' => 100,
  49 + 'multi' => true,
  50 + 'gallery' => $gallery->photo,
  51 + 'name' => 'Загрузить фото галереи',
  52 +]); ?>
  53 +
  54 +<?= FieldEditor::widget (
  55 + [
  56 + 'template' => 'youtube', 'item_id' => $user->id, 'model' => 'common\models\User', 'language' => 'ru',
  57 + ]
  58 +); ?>
  59 +
  60 +<?= Html::submitButton('Добавить') ?>
  61 +
  62 +<?php
  63 + $form->end();
  64 +?>
... ...
frontend/views/accounts/_vacancy_form.php 0 → 100644
  1 +<?php
  2 + /**
  3 + * @var Vacancy $vacancy
  4 + * @var Employment[] $employment
  5 + */
  6 + use common\models\Employment;
  7 + use common\models\Vacancy;
  8 + use common\widgets\FieldEditor;
  9 + use common\widgets\ImageUploader;
  10 + use mihaildev\ckeditor\CKEditor;
  11 + use yii\helpers\Html;
  12 + use yii\widgets\ActiveForm;
  13 +
  14 + $this->title = 'Мой профиль';
  15 + $this->params[ 'breadcrumbs' ][] = $this->title;
  16 +?>
  17 +<h1><?= $this->title ?></h1>
  18 +
  19 +<?php
  20 + $form = ActiveForm::begin();
  21 +?>
  22 +
  23 +<?= $form->field($vacancy, 'name')
  24 + ->textInput() ?>
  25 +
  26 +<?= $form->field($vacancy, 'link')
  27 + ->textInput() ?>
  28 +
  29 +<?= $form->field($vacancy, 'user_name')
  30 + ->textInput() ?>
  31 +
  32 +<?= $form->field($vacancy, 'city')
  33 + ->textInput() ?>
  34 +
  35 +<?= $form->field($vacancy, 'employmentInput')
  36 + ->checkboxList($employment) ?>
  37 +
  38 +<?= FieldEditor::widget (
  39 + [
  40 + 'template' => 'requirements', 'item_id' => $vacancy->vacancy_id, 'model' => 'common\models\Vacancy', 'language' => 'ru',
  41 + ]
  42 +); ?>
  43 +
  44 +<?= $form->field($vacancy, 'description')->widget(CKEditor::className()) ?>
  45 +
  46 +<?= Html::submitButton('Добавить') ?>
  47 +
  48 +<?php
  49 + $form->end();
  50 +?>
... ...