Commit 28855799ed5b823274b201c2b51e56b1f31567d8

Authored by Yarik
2 parents b73541b6 fb0f9630

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	frontend/controllers/CabinetController.php
#	frontend/models/IntellectualProperty.php
frontend/controllers/CabinetController.php
@@ -51,9 +51,15 @@ @@ -51,9 +51,15 @@
51 if(!$userPassport = $user->userPassport) { 51 if(!$userPassport = $user->userPassport) {
52 $userPassport = new UserPassport(); 52 $userPassport = new UserPassport();
53 } 53 }
  54 +
  55 + $table = IntellectualProperty::find()->where([
  56 + 'user_id' => \Yii::$app->user->identity->id,
  57 + ])->all();
  58 +
54 return $this->render('index', [ 59 return $this->render('index', [
55 'userData' => $userData, 60 'userData' => $userData,
56 'userPassport' => $userPassport, 61 'userPassport' => $userPassport,
  62 + 'table' => $table,
57 ]); 63 ]);
58 } 64 }
59 65
@@ -128,6 +134,29 @@ @@ -128,6 +134,29 @@
128 ]; 134 ];
129 } 135 }
130 } 136 }
  137 +
  138 + public function actionAddIntProp()
  139 + {
  140 + $request = \Yii::$app->request;
  141 + $response = \Yii::$app->response;
  142 + $response->format = $response::FORMAT_JSON;
  143 +
  144 + $intProperty = new IntellectualProperty();
  145 +
  146 + $intProperty->user_id = \Yii::$app->user->identity->id;
  147 +
  148 + if($intProperty->load($request->post()) && $intProperty->save()) {
  149 + return [
  150 + 'success' => true,
  151 + 'message' => 'Данные успешно сохранены',
  152 + ];
  153 + } else {
  154 + return [
  155 + 'error' => true,
  156 + 'message' => 'Ошибка сохранения данных',
  157 + ];
  158 + }
  159 + }
131 160
132 public function findProperty($id) 161 public function findProperty($id)
133 { 162 {
frontend/models/IntellectualProperty.php
1 <?php 1 <?php
2 -  
3 -namespace frontend\models;  
4 -  
5 -use common\models\User;  
6 -  
7 -/**  
8 - * This is the model class for table "intellectual_property".  
9 - *  
10 - * @property integer $id  
11 - * @property integer $user_id  
12 - * @property string $title  
13 - * @property integer $creation_date  
14 - * @property string $code  
15 - * @property string $genre  
16 - * @property integer $registration_date  
17 - * @property string $contract  
18 - * @property string $type  
19 - *  
20 - * @property CreativeRole[] $creativeRoles  
21 - * @property User $user  
22 - * @property Report[] $reports  
23 - */  
24 -class IntellectualProperty extends \yii\db\ActiveRecord  
25 -{ 2 +
  3 + namespace frontend\models;
  4 +
  5 + use common\models\User;
  6 +
26 /** 7 /**
27 - * @inheritdoc 8 + * This is the model class for table "intellectual_property".
  9 + *
  10 + * @property integer $id
  11 + * @property integer $user_id
  12 + * @property string $title
  13 + * @property integer $creation_date
  14 + * @property string $code
  15 + * @property string $genre
  16 + * @property integer $registration_date
  17 + * @property string $contract
  18 + * @property string $type
  19 + * @property CreativeRole[] $creativeRoles
  20 + * @property User $user
  21 + * @property Report[] $reports
28 */ 22 */
29 - public static function tableName() 23 + class IntellectualProperty extends \yii\db\ActiveRecord
30 { 24 {
31 - return 'intellectual_property'; 25 + /**
  26 + * @inheritdoc
  27 + */
  28 + public static function tableName()
  29 + {
  30 + return 'intellectual_property';
  31 + }
  32 +
  33 + /**
  34 + * @inheritdoc
  35 + */
  36 + public function rules()
  37 + {
  38 + return [
  39 + [
  40 + [
  41 + 'user_id',
  42 + ],
  43 + 'integer',
  44 + ],
  45 + [
  46 + [
  47 + 'creation_date',
  48 + 'registration_date',
  49 + 'title',
  50 + 'code',
  51 + 'genre',
  52 + 'contract',
  53 + 'type',
  54 + 'author_role',
  55 + 'percent',
  56 + 'calculated',
  57 + 'play_count',
  58 + ],
  59 + 'string',
  60 + 'max' => 255,
  61 + ],
  62 + [
  63 + [ 'user_id' ],
  64 + 'exist',
  65 + 'skipOnError' => true,
  66 + 'targetClass' => User::className(),
  67 + 'targetAttribute' => [ 'user_id' => 'id' ],
  68 + ],
  69 + ];
  70 + }
  71 +
  72 + /**
  73 + * @inheritdoc
  74 + */
  75 + public function attributeLabels()
  76 + {
  77 + return [
  78 + 'id' => 'ID',
  79 + 'user_id' => 'User ID',
  80 + 'title' => 'Назва',
  81 + 'creation_date' => 'Дата створення',
  82 + 'code' => 'Шифр',
  83 + 'genre' => 'Жанр',
  84 + 'registration_date' => 'Дата реєстрації',
  85 + 'contract' => 'Договір',
  86 + 'type' => 'Тип',
  87 + 'author_role' => 'Роль автора',
  88 + 'percent' => 'Процент долі автора',
  89 + 'calculated' => 'Нараховано',
  90 + 'play_count' => 'К-ть відтворень',
  91 + ];
  92 + }
  93 +
  94 + /**
  95 + * @return \yii\db\ActiveQuery
  96 + */
  97 + public function getCreativeRoles()
  98 + {
  99 + return $this->hasMany(CreativeRole::className(), [ 'intellectual_property_id' => 'id' ]);
  100 + }
  101 +
  102 + /**
  103 + * @return \yii\db\ActiveQuery
  104 + */
  105 + public function getUser()
  106 + {
  107 + return $this->hasOne(User::className(), [ 'id' => 'user_id' ]);
  108 + }
  109 +
  110 + /**
  111 + * @return \yii\db\ActiveQuery
  112 + */
  113 + public function getReports()
  114 + {
  115 + return $this->hasMany(Report::className(), [ 'intellectual_property_id' => 'id' ]);
  116 + }
32 } 117 }
33 -  
34 - /**  
35 - * @inheritdoc  
36 - */  
37 - public function rules()  
38 - {  
39 - return [  
40 - [['user_id', 'creation_date', 'registration_date'], 'integer'],  
41 - [['title', 'code', 'genre', 'contract', 'type'], 'string', 'max' => 255],  
42 - [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],  
43 - ];  
44 - }  
45 -  
46 - /**  
47 - * @inheritdoc  
48 - */  
49 - public function attributeLabels()  
50 - {  
51 - return [  
52 - 'id' => 'ID',  
53 - 'user_id' => 'User ID',  
54 - 'title' => 'Назва',  
55 - 'creation_date' => 'Дата створення',  
56 - 'code' => 'Шифр',  
57 - 'genre' => 'Жанр',  
58 - 'registration_date' => 'Дата реєстрації',  
59 - 'contract' => 'Договір',  
60 - 'type' => 'Тип',  
61 - ];  
62 - }  
63 -  
64 - /**  
65 - * @return \yii\db\ActiveQuery  
66 - */  
67 - public function getCreativeRoles()  
68 - {  
69 - return $this->hasMany(CreativeRole::className(), ['intellectual_property_id' => 'id']);  
70 - }  
71 -  
72 - /**  
73 - * @return \yii\db\ActiveQuery  
74 - */  
75 - public function getUser()  
76 - {  
77 - return $this->hasOne(User::className(), ['id' => 'user_id']);  
78 - }  
79 -  
80 - /**  
81 - * @return \yii\db\ActiveQuery  
82 - */  
83 - public function getReports()  
84 - {  
85 - return $this->hasMany(Report::className(), ['intellectual_property_id' => 'id']);  
86 - }  
87 -}  
frontend/views/cabinet/index.php
@@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
4 * @var UserData $userData 4 * @var UserData $userData
5 * @var UserPassport $userPassport 5 * @var UserPassport $userPassport
6 * @var yii\web\View $this 6 * @var yii\web\View $this
  7 + * @var IntellectualProperty[] $table
7 */ 8 */
8 9
9 use frontend\models\UserData; 10 use frontend\models\UserData;
@@ -11,6 +12,7 @@ @@ -11,6 +12,7 @@
11 use frontend\models\IntellectualProperty; 12 use frontend\models\IntellectualProperty;
12 use yii\helpers\Html; 13 use yii\helpers\Html;
13 use yii\widgets\ActiveForm; 14 use yii\widgets\ActiveForm;
  15 + use yii\widgets\Pjax;
14 16
15 $this->title = 'My Yii Application'; 17 $this->title = 'My Yii Application';
16 ?> 18 ?>
@@ -44,6 +46,11 @@ @@ -44,6 +46,11 @@
44 ) ?> 46 ) ?>
45 </div> 47 </div>
46 <div class="style table-forms-wrapp"> 48 <div class="style table-forms-wrapp">
  49 + <?php
  50 + Pjax::begin([
  51 + 'id' => 'int-prop-greed',
  52 + ]);
  53 + ?>
47 <table class="table-1" cellpadding="0" cellspacing="0" border="0"> 54 <table class="table-1" cellpadding="0" cellspacing="0" border="0">
48 <tr> 55 <tr>
49 <td>№<br/>п/п</td> 56 <td>№<br/>п/п</td>
@@ -55,148 +62,28 @@ @@ -55,148 +62,28 @@
55 <td>Нараховано</td> 62 <td>Нараховано</td>
56 <td>К-ть відтворень</td> 63 <td>К-ть відтворень</td>
57 </tr> 64 </tr>
58 -  
59 - <tr>  
60 - <td></td>  
61 - <td></td>  
62 - <td></td>  
63 - <td></td>  
64 - <td></td>  
65 - <td></td>  
66 - <td></td>  
67 - <td></td>  
68 - </tr>  
69 - <tr>  
70 - <td></td>  
71 - <td></td>  
72 - <td></td>  
73 - <td></td>  
74 - <td></td>  
75 - <td></td>  
76 - <td></td>  
77 - <td></td>  
78 - </tr>  
79 - <tr>  
80 - <td></td>  
81 - <td></td>  
82 - <td></td>  
83 - <td></td>  
84 - <td></td>  
85 - <td></td>  
86 - <td></td>  
87 - <td></td>  
88 - </tr>  
89 - <tr>  
90 - <td></td>  
91 - <td></td>  
92 - <td></td>  
93 - <td></td>  
94 - <td></td>  
95 - <td></td>  
96 - <td></td>  
97 - <td></td>  
98 - </tr>  
99 - <tr>  
100 - <td></td>  
101 - <td></td>  
102 - <td></td>  
103 - <td></td>  
104 - <td></td>  
105 - <td></td>  
106 - <td></td>  
107 - <td></td>  
108 - </tr>  
109 - <tr>  
110 - <td></td>  
111 - <td></td>  
112 - <td></td>  
113 - <td></td>  
114 - <td></td>  
115 - <td></td>  
116 - <td></td>  
117 - <td></td>  
118 - </tr>  
119 - <tr>  
120 - <td></td>  
121 - <td></td>  
122 - <td></td>  
123 - <td></td>  
124 - <td></td>  
125 - <td></td>  
126 - <td></td>  
127 - <td></td>  
128 - </tr>  
129 - <tr>  
130 - <td></td>  
131 - <td></td>  
132 - <td></td>  
133 - <td></td>  
134 - <td></td>  
135 - <td></td>  
136 - <td></td>  
137 - <td></td>  
138 - </tr>  
139 - <tr>  
140 - <td></td>  
141 - <td></td>  
142 - <td></td>  
143 - <td></td>  
144 - <td></td>  
145 - <td></td>  
146 - <td></td>  
147 - <td></td>  
148 - </tr>  
149 - <tr>  
150 - <td></td>  
151 - <td></td>  
152 - <td></td>  
153 - <td></td>  
154 - <td></td>  
155 - <td></td>  
156 - <td></td>  
157 - <td></td>  
158 - </tr>  
159 - <tr>  
160 - <td></td>  
161 - <td></td>  
162 - <td></td>  
163 - <td></td>  
164 - <td></td>  
165 - <td></td>  
166 - <td></td>  
167 - <td></td>  
168 - </tr>  
169 - <tr>  
170 - <td></td>  
171 - <td></td>  
172 - <td></td>  
173 - <td></td>  
174 - <td></td>  
175 - <td></td>  
176 - <td></td>  
177 - <td></td>  
178 - </tr>  
179 - <tr>  
180 - <td></td>  
181 - <td></td>  
182 - <td></td>  
183 - <td></td>  
184 - <td></td>  
185 - <td></td>  
186 - <td></td>  
187 - <td></td>  
188 - </tr> 65 + <?php
  66 + $i = 1;
  67 + foreach ($table as $row) {
  68 + ?>
189 <tr> 69 <tr>
190 - <td></td>  
191 - <td></td>  
192 - <td></td>  
193 - <td></td>  
194 - <td></td>  
195 - <td></td>  
196 - <td></td>  
197 - <td></td> 70 + <td><?= $i; ?></td>
  71 + <td><?= $row->title ?></td>
  72 + <td><?= $row->registration_date ?></td>
  73 + <td><?= $row->genre ?></td>
  74 + <td><?= $row->author_role ?></td>
  75 + <td><?= $row->percent ?></td>
  76 + <td><?= $row->calculated ?></td>
  77 + <td><?= $row->play_count ?></td>
198 </tr> 78 </tr>
  79 + <?php
  80 + $i++;
  81 + }
  82 + ?>
199 </table> 83 </table>
  84 + <?php
  85 + Pjax::end();
  86 + ?>
200 </div> 87 </div>
201 </div> 88 </div>
202 </div> 89 </div>
@@ -807,65 +694,68 @@ @@ -807,65 +694,68 @@
807 </div> 694 </div>
808 <!-- Modal --> 695 <!-- Modal -->
809 <div class="modal fade" id="add-composition-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> 696 <div class="modal fade" id="add-composition-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
810 - <div class="modal-dialog" role="document">  
811 - <div class="modal-content">  
812 - <div class="modal-header">  
813 - <button type="button" class="close" data-dismiss="modal" aria-label="Close">  
814 - <span aria-hidden="true">&times;</span></button>  
815 - <h4 class="modal-title" id="myModalLabel">Додати твір</h4>  
816 - </div>  
817 - <?php  
818 - $form = ActiveForm::begin(  
819 - [  
820 - 'action' => 'som-act',  
821 - 'id' => 'add-int-prop-form',  
822 - ]  
823 - );  
824 - $addIntProp = new IntellectualProperty();  
825 - ?>  
826 - <div class="modal-body forms-cabinet forms-2">  
827 -  
828 -  
829 - <?php  
830 - echo $form->field($addIntProp, 'title');  
831 - ?>  
832 -  
833 - <?php  
834 - echo $form->field($addIntProp, 'registration_date');  
835 - ?>  
836 -  
837 - <?php  
838 - echo $form->field($addIntProp, 'genre');  
839 - ?>  
840 -  
841 - <?php  
842 - echo $form->field($addIntProp, 'author_role');  
843 - ?>  
844 -  
845 - <?php  
846 - echo $form->field($addIntProp, 'percent');  
847 - ?>  
848 -  
849 - <?php  
850 - echo $form->field($addIntProp, 'calculated');  
851 - ?>  
852 -  
853 - <?php  
854 - echo $form->field($addIntProp, 'play_count');  
855 - ?>  
856 -  
857 - </div>  
858 - <div class="modal-footer btn-submit-blue">  
859 - <?php  
860 - echo Html::submitButton(  
861 - 'OK'  
862 - );  
863 - ?>  
864 - </div>  
865 - <?php  
866 - $form::end();  
867 - ?>  
868 - </div> 697 + <div class="modal-dialog" role="document">
  698 + <div class="modal-content">
  699 + <div class="modal-header">
  700 + <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  701 + <span aria-hidden="true">&times;</span></button>
  702 + <h4 class="modal-title" id="myModalLabel">Додати твір</h4>
  703 + </div>
  704 + <?php
  705 + $form = ActiveForm::begin(
  706 + [
  707 + 'action' => 'add-int-prop',
  708 + 'id' => 'add-int-prop-form',
  709 + ]
  710 + );
  711 + $addIntProp = new IntellectualProperty();
  712 + ?>
  713 + <div class="modal-body forms-cabinet forms-2">
  714 +
  715 +
  716 +
  717 + <?php
  718 + echo $form->field($addIntProp, 'title');
  719 + ?>
  720 +
  721 + <?php
  722 + echo $form->field($addIntProp, 'registration_date')->textInput([
  723 + 'class' => '_datepicker form-control',
  724 + ]);
  725 + ?>
  726 +
  727 + <?php
  728 + echo $form->field($addIntProp, 'genre');
  729 + ?>
  730 +
  731 + <?php
  732 + echo $form->field($addIntProp, 'author_role');
  733 + ?>
  734 +
  735 + <?php
  736 + echo $form->field($addIntProp, 'percent');
  737 + ?>
  738 +
  739 + <?php
  740 + echo $form->field($addIntProp, 'calculated');
  741 + ?>
  742 +
  743 + <?php
  744 + echo $form->field($addIntProp, 'play_count');
  745 + ?>
  746 +
  747 + </div>
  748 + <div class="modal-footer btn-submit-blue">
  749 + <?php
  750 + echo Html::submitButton(
  751 + 'OK'
  752 + );
  753 + ?>
  754 + </div>
  755 + <?php
  756 + $form::end();
  757 + ?>
869 </div> 758 </div>
  759 + </div>
870 </div> 760 </div>
871 761
frontend/web/js/script.js
@@ -251,6 +251,23 @@ $(document).ready(function(){ @@ -251,6 +251,23 @@ $(document).ready(function(){
251 $('#'+id).prepend('<div class="preloader"></div>'); 251 $('#'+id).prepend('<div class="preloader"></div>');
252 $.pjax.reload('#'+id); 252 $.pjax.reload('#'+id);
253 } 253 }
  254 +
  255 + $(document).on('beforeSubmit', '#add-int-prop-form', function() {
  256 + $.post($(this).attr('action'), $(this).serialize(), function(data) {
  257 + var type;
  258 + if(data.error) {
  259 + type = 'danger';
  260 + } else {
  261 + type = 'success';
  262 + }
  263 + $('#add-composition-modal').modal('hide');
  264 + showStatus(data.message, type);
  265 + $.pjax.reload('#int-prop-greed');
  266 + document.getElementById('add-int-prop-form').reset();
  267 + });
  268 +
  269 + return false;
  270 + });
254 }); 271 });
255 272
256 273