Commit eacb83cce1a9c46a0bfde2186302fac2f6a184d7

Authored by Yarik
1 parent e9013fc3

test

common/config/main-local.php
... ... @@ -3,9 +3,9 @@ return [
3 3 'components' => [
4 4 'db' => [
5 5 'class' => 'yii\db\Connection',
6   - 'dsn' => 'pgsql:host=195.248.225.149;port=5432;dbname=mfp',
7   - 'username' => 'test33',
8   - 'password' => 'E4q2N7i9',
  6 + 'dsn' => 'pgsql:host=127.0.0.1;port=5432;dbname=mfp_local',
  7 + 'username' => 'postgres',
  8 + 'password' => '',
9 9 'schemaMap' => [
10 10 'pgsql'=> [
11 11 'class'=>'yii\db\pgsql\Schema',
... ...
frontend/controllers/AccountsController.php
... ... @@ -170,16 +170,29 @@ class AccountsController extends Controller
170 170  
171 171 public function actionEmployment()
172 172 {
173   - $job = Job::find()->where(['user_id' => \Yii::$app->user->getId()])->orderBy(['current' => SORT_DESC])->all();
174   - if(empty($job)) {
175   - $job[] = new Job(['user_id' => \Yii::$app->user->getId(), 'current' => 0]);
176   - }
177   - if(!$job[0]->current) {
178   - array_unshift($job, new Job(['user_id' => \Yii::$app->user->getId(), 'current' => 1]));
179   - }
180   - if(!empty(\Yii::$app->request->post())) {
181   - var_dump(\Yii::$app->request->post());
182   - die();
  173 + $post = \Yii::$app->request->post();
  174 + if(!empty($post)) {
  175 + $job = [];
  176 + for($i = 0; $i < count($post['Job']); $i++) {
  177 + $job[$i] = new Job(['user_id' => \Yii::$app->user->getId(), 'current' => 0]);
  178 + }
  179 + if(Job::loadMultiple($job, $post)) {
  180 + $job[0]->current = 1;
  181 + if(Job::validateMultiple($job)) {
  182 + Job::deleteAll(['user_id' => \Yii::$app->user->getId()]);
  183 + foreach($job as $onejob) {
  184 + $onejob->save(false);
  185 + }
  186 + }
  187 + }
  188 + } else {
  189 + $job = Job::find()->where(['user_id' => \Yii::$app->user->getId()])->orderBy(['current' => SORT_DESC])->all();
  190 + if(empty($job)) {
  191 + $job[] = new Job(['user_id' => \Yii::$app->user->getId(), 'current' => 0]);
  192 + }
  193 + if(!$job[0]->current) {
  194 + array_unshift($job, new Job(['user_id' => \Yii::$app->user->getId(), 'current' => 1]));
  195 + }
183 196 }
184 197 return $this->render('employment', ['job' => $job]);
185 198 }
... ...
frontend/views/accounts/employment.php
... ... @@ -19,9 +19,6 @@
19 19 <p>Текущее место работы:</p>
20 20 <div class="current_job_inputs">
21 21 <?php
22   - echo $form->field ($current, '[0]current')
23   - ->label (false)
24   - ->hiddenInput (['value' => 1]);
25 22 echo $form->field ($current, '[0]name')
26 23 ->label ('Название')
27 24 ->textInput ();
... ... @@ -76,6 +73,7 @@
76 73 </div>
77 74 <?php
78 75 echo Html::button('Добавить место работы', ['id' => 'add_job_button']);
  76 + echo Html::submitButton('Обновить');
79 77 $form->end ();
80 78 ?>
81 79 <script>
... ...