/**
  * Signs user up.
  *
  * @return true|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->phone = $this->phone;
         $user->email = $this->email;
         $randLength = mt_rand(6, 9);
         $this->password = Yii::$app->security->generateRandomString($randLength);
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             $profile = new Profile();
             $profile->user_id = $user->id;
             $profile->name = $this->name;
             //если в куках есть id аффилиата, сохраняем его
             $affiliateId = (int) Yii::$app->request->cookies['affiliate'];
             if ($affiliateId > 0 && User::findIdentity($affiliateId)) {
                 $profile->user_affiliate_id = $affiliateId;
             }
             $profile->save();
             return $this->sendRegistrationEmail();
         }
     }
     return null;
 }
 public function up()
 {
     $data = (include Yii::getAlias('@common') . '/data/test-adverts.php');
     $i = 0;
     while ($i++ !== 3) {
         foreach ($data as $one) {
             $advert = new Advert();
             $advert->detachBehavior('timestamp');
             $advert->setAttributes($one);
             $advert->user_id = rand(1, 50);
             $advert->created_at = time() - 3600 * 24 * rand(1, 31) - 3600 * rand(1, 24) + rand(1, 3600);
             $advert->updated_at = $advert->created_at;
             $advert->term_at = $advert->created_at + 3600 * 24 * rand(1, 31);
             if ($advert->save()) {
                 echo "Advert for user №{$advert->user_id} created\n";
             } else {
                 print_r($advert->getErrors());
             }
         }
     }
     foreach (User::find()->all() as $user) {
         $profile = new Profile();
         $profile->user_id = $user->id;
         $profile->name = $user->username;
         if ($profile->save()) {
             echo "Profile of \"{$user->username}\" created\n";
         } else {
             print_r($profile->getErrors());
         }
     }
 }
Пример #3
0
 public function reg()
 {
     $user = new User();
     $user->phone = $this->phone;
     $user->email = $this->email;
     $user->status = $this->status;
     $user->setPassword($this->password);
     $user->generateAuthKey();
     if ($this->scenario === 'emailActivation') {
         $user->generateSecretKey();
     }
     $transaction = Yii::$app->db->beginTransaction();
     try {
         if ($user->save()) {
             $modelProfile = new Profile();
             $modelProfile->user_id = $user->id;
             if ($modelProfile->save()) {
                 $transaction->commit();
                 return RbacHelper::assignRole($user->getId()) ? $user : null;
             }
         } else {
             return false;
         }
     } catch (Exception $e) {
         $transaction->rollBack();
     }
 }
 /**
  * Create user profile after registration.
  */
 public function createProfile($event)
 {
     $user = $this->owner;
     $profile = new Profile();
     $profile->user_id = $user->id;
     $profile->save();
 }
 /**
  * Creates a new Pay model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @param integer $user_id
  * @return mixed
  */
 public function actionCreate($user_id = false)
 {
     if ($user_id) {
         $profile = Profile::findOne(['user_id' => $user_id]);
         if (!$profile) {
             throw new HttpException(404);
         }
         $model = new Pay();
         $model->setScenario('pay-create');
         $model->maxBonusBalance = $profile->bonus_balance;
         $tickets = SeasonTicket::getTicketArray();
         //ajax validation
         if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         }
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             $groups = Group::getGroupArray();
             return $this->render('create', ['model' => $model, 'profile' => $profile, 'tickets' => $tickets, 'groups' => $groups]);
         }
     } else {
         $searchModel = new UserSearch();
         $dataProvider = $searchModel->search(Yii::$app->request->get());
         return $this->render('listusers', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel]);
     }
 }
Пример #6
0
 public function actionProfile()
 {
     $model = Profile::findOne(['user_id' => Yii::$app->user->id]);
     if (!$model) {
         $model = new Profile();
         $model->user_id = Yii::$app->user->id;
     }
     if ($model->birthday) {
         $model->year = substr($model->birthday, 0, 4);
         $model->month = substr($model->birthday, 5, 2);
         $model->day = substr($model->birthday, 8, 2);
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->year = intval(Yii::$app->request->post()['Profile']['year']);
         $model->month = intval(Yii::$app->request->post()['Profile']['month']);
         $model->day = intval(Yii::$app->request->post()['Profile']['day']);
         if ($model->year || $model->month || $model->day) {
             $model->birthday = date('Y-m-d H:i:s', mktime(0, 0, 0, $model->month, $model->day, $model->year));
         }
         if ($model->save()) {
             Yii::$app->getSession()->setFlash('success', Yii::t('app', 'New profile was saved.'));
         }
     }
     return $this->render('profile', ['model' => $model]);
 }
Пример #7
0
 public function actionForm()
 {
     //vd(1);
     $model = Profile::find()->where(['user_id' => Yii::$app->user->id])->one();
     if (!$model) {
         $model = new Profile();
     }
     if ($model->load(Yii::$app->request->post())) {
         //vd($_POST);
         if ($model->validate()) {
             $model->gender = $_POST['gender'];
             $model->user_id = Yii::$app->user->id;
             $model->login = User::getLoginById(Yii::$app->user->id);
             $model->save();
             return $this->render('form', ['model' => $model]);
         } else {
             vd($model->getErrors());
         }
     }
     return $this->render('form', ['model' => $model]);
 }
 /**
  * Lists all PaidEmployment models.
  * @return mixed
  */
 public function actionIndex()
 {
     $groupsArray = ArrayHelper::map(Group::find()->asArray()->select('id, name')->orderBy('name')->all(), 'id', 'name');
     $searchModel = new EmploymentSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     if (!empty($searchModel->userFullName)) {
         $filterUserDataArray = [$searchModel->userFullName => \common\models\Profile::getFullNameByUserId($searchModel->userFullName)];
     } else {
         $filterUserDataArray = [];
     }
     return $this->render('index', compact(['searchModel', 'dataProvider', 'groupsArray', 'filterUserDataArray']));
 }
Пример #9
0
 public function updateProfile()
 {
     $profile = ($profile = Profile::findOne(Yii::$app->user->id)) ? $profile : new Profile();
     $profile->user_id = Yii::$app->user->id;
     $profile->first_name = $this->first_name;
     $profile->second_name = $this->second_name;
     $profile->middle_name = $this->middle_name;
     if ($profile->save()) {
         return $profile;
     }
     return false;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Profile::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['profile_id' => $this->profile_id, 'precinct_id' => $this->precinct_id, 'type_id' => $this->type_id, 'employee_id' => $this->employee_id]);
     $query->orFilterWhere(['like', 'profilenumber', $this->globalSearch])->orFilterWhere(['like', 'phonenumber', $this->globalSearch])->orFilterWhere(['like', 'profile_firstname', $this->globalSearch])->orFilterWhere(['like', 'profile_middlename', $this->globalSearch])->orFilterWhere(['like', 'profile_lastname', $this->globalSearch])->orFilterWhere(['like', 'profile_picture', $this->globalSearch])->orFilterWhere(['like', 'gsis', $this->globalSearch])->orFilterWhere(['like', 'sss', $this->sss])->orFilterWhere(['like', 'mothers_maiden_name', $this->globalSearch])->orFilterWhere(['like', 'sex', $this->globalSearch]);
     return $dataProvider;
 }
Пример #11
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Profile::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['user_id' => $this->user_id, 'dep_id' => $this->dep_id]);
     $query->andFilterWhere(['like', 'pxname', $this->pxname])->andFilterWhere(['like', 'firstname', $this->firstname])->andFilterWhere(['like', 'lastname', $this->lastname])->andFilterWhere(['like', 'photo', $this->photo])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'phone', $this->phone]);
     return $dataProvider;
 }
Пример #12
0
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             $profile = new Profile();
             $profile->loadDefaultValues();
             $profile->first_name = $this->first_name;
             $profile->last_name = $this->last_name;
             $profile->dob = $this->dob;
             $profile->address = $this->address;
             $profile->address2 = $this->address2;
             $profile->district = $this->district;
             $profile->state = $this->state;
             $profile->mobile = $this->mobile;
             $profile->ic = $this->ic;
             $profile->postcode = $this->postcode;
             $profile->name = $this->name;
             $profile->link('user', $user);
             if ($this->role == 'ENT') {
                 $ent = new Entrepreneur();
                 $ent->plkn = $this->plkn;
                 $ent->link('user', $user);
             } elseif ($this->role == 'MNT') {
                 $mnt = new Mentor();
                 $mnt->link('user', $user);
             }
             Yii::$app->mailer->compose()->setFrom('*****@*****.**')->setTo($user->email)->setSubject('SALEXES Registration')->setTextBody('Congratulations you have been succesfully registered with us !!!')->setHtmlBody('<b>Please contact admin@9teraju.com to make payment for account activation.</b>')->send();
             return $user;
         }
     }
     return null;
 }
Пример #13
0
 public function actionProfileEdit($id)
 {
     $model = new ProfileForm();
     $model->loadModel($id);
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             Yii::$app->session->setFlash('success', 'Успешно сохранено!');
             return Yii::$app->getResponse()->redirect(Url::to(['site/profile-view', 'id' => $model['id']]));
         } else {
             Yii::$app->session->setFlash('warning', 'Упс, что-то пошло не так. Проверте введенные данные, вдруг в них закралась ошибка!');
         }
     }
     $specitems = Profile::getSpecsAllWithChoice($model->edu_base);
     return $this->render('profileEdit', ['model' => $model, 'specitems' => $specitems]);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = PaidEmployment::find()->joinWith(['pay.profile', 'pay', 'timetable', 'timetable.group']);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['date' => SORT_DESC]]]);
     $dataProvider->sort->attributes['pay.profile.fullName'] = ['asc' => [Profile::tableName() . '.name' => SORT_ASC, Profile::tableName() . '.surname' => SORT_ASC], 'desc' => [Profile::tableName() . '.name' => SORT_DESC, Profile::tableName() . '.surname' => SORT_DESC]];
     $dataProvider->sort->attributes['timetable.group.name'] = ['asc' => [Group::tableName() . '.name' => SORT_ASC], 'desc' => [Group::tableName() . '.name' => SORT_DESC]];
     $dataProvider->sort->attributes['timetable.start'] = ['asc' => [Timetable::tableName() . '.start' => SORT_ASC], 'desc' => [Timetable::tableName() . '.start' => SORT_DESC]];
     $dataProvider->sort->attributes['timetable.end'] = ['asc' => [Timetable::tableName() . '.end' => SORT_ASC], 'desc' => [Timetable::tableName() . '.end' => SORT_DESC]];
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'date' => $this->date, 'pay_id' => $this->pay_id, 'pay.user_id' => $this->userFullName, 'timetable.group_id' => $this->timetableGroupId]);
     return $dataProvider;
 }
Пример #15
0
 /**
  * @return string
  */
 public function actionDeleteAvatar()
 {
     $imageData = Json::decode(Yii::$app->request->post('imageData'));
     $modelImageForm = new ImageForm();
     $modelImageForm->deleteImage();
     if (Yii::$app->session->get('error')) {
         echo $error = Yii::$app->session->get('error');
     } else {
         $error = false;
     }
     /* @var $model \common\models\Profile */
     if ($imageData['modelName'] == 'Profile') {
         $model = Profile::findOne($imageData['object_id']);
     }
     $imagesObject = $model->imagesOfObjects;
     return $this->render('@common/widgets/ImageLoad/views/_formAutoload', ['modelName' => $imageData['modelName'], 'id' => $imageData['id'], 'object_id' => $imageData['object_id'], 'images_num' => $imageData['images_num'], 'images_label' => $imageData['images_label'], 'images_temp' => $imageData['images_temp'], 'imagesObject' => $imagesObject, 'modelImageForm' => $modelImageForm, 'baseUrl' => $imageData['baseUrl'], 'imagePath' => $imageData['imagePath'], 'noImage' => $imageData['noImage'], 'imageClass' => $imageData['imageClass'], 'buttonDeleteClass' => $imageData['buttonDeleteClass'], 'imageContainerClass' => $imageData['imageContainerClass'], 'formImagesContainerClass' => $imageData['formImagesContainerClass'], 'error' => $error]);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = User::find()->joinWith(['profile']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->sort->attributes['profile.name'] = ['asc' => [Profile::tableName() . '.name' => SORT_ASC], 'desc' => [Profile::tableName() . '.name' => SORT_DESC]];
     $dataProvider->sort->attributes['profile.surname'] = ['asc' => [Profile::tableName() . '.surname' => SORT_ASC], 'desc' => [Profile::tableName() . '.surname' => SORT_DESC]];
     $dataProvider->sort->attributes['profile.middle_name'] = ['asc' => [Profile::tableName() . '.middle_name' => SORT_ASC], 'desc' => [Profile::tableName() . '.middle_name' => SORT_DESC]];
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status]);
     $query->andFilterWhere($this->getBetweenDatesFilterArray('created_at', ' - '))->andFilterWhere($this->getBetweenDatesFilterArray('updated_at', ' - '))->andFilterWhere(['LIKE', 'phone', $this->phone])->andFilterWhere(['LIKE', 'email', $this->email])->andFilterWhere(['LIKE', 'profile.name', $this->getAttribute('profile.name')])->andFilterWhere(['LIKE', 'profile.surname', $this->getAttribute('profile.surname')])->andFilterWhere(['LIKE', 'profile.middle_name', $this->getAttribute('profile.middle_name')]);
     return $dataProvider;
 }
Пример #17
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Pay::find()->joinWith(['profile', 'ticket']);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['create_at' => SORT_DESC]]]);
     /**
      * Настройка параметров сортировки
      * Важно: должна быть выполнена раньше $this->load($params)
      * statement below
      */
     $dataProvider->sort->attributes['userFullName'] = ['asc' => [Profile::tableName() . '.name' => SORT_ASC, Profile::tableName() . '.surname' => SORT_ASC], 'desc' => [Profile::tableName() . '.name' => SORT_DESC, Profile::tableName() . '.surname' => SORT_DESC]];
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, Pay::tableName() . '.user_id' => $this->user_id, 'ticket_id' => $this->ticket_id, 'current_cost' => $this->current_cost, 'cash' => $this->cash, 'bonus_cash' => $this->bonus_cash]);
     $query->andFilterWhere($this->getBetweenDatesFilterArray('create_at', ' - ', 'Y-m-d H:i:s'))->andFilterWhere(['like', 'comment', $this->comment]);
     $query->andFilterWhere(['like', 'CONCAT(" ", ' . Profile::tableName() . '.name, ' . Profile::tableName() . '.surname) ', $this->userFullName]);
     return $dataProvider;
 }
Пример #18
0
 public function loadModel($id)
 {
     $profile = Profile::findById($id);
     if (!empty($profile)) {
         $this->id = $profile->id;
         $this->status = $profile->status;
         $this->created_at = $profile->created_at;
         $this->updated_at = $profile->updated_at;
         $this->attributes = $profile->attributes;
         return true;
     } else {
         return false;
     }
 }
 public function actionProfile()
 {
     $model = Profile::findOne(['user_id' => Yii::$app->user->id]);
     if (!$model) {
         $model = new Profile();
         $model->user_id = Yii::$app->user->id;
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->getSession()->setFlash('success', Yii::t('app', 'New password was saved.'));
         return $this->goHome();
     }
     return $this->render('profile', ['model' => $model]);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProfiles()
 {
     return $this->hasMany(Profile::className(), ['employee_id' => 'employee_id']);
 }
Пример #21
0
 public function actionActiveRecordJoin()
 {
     // Работа с Active Record используя Join
     // SELECT `customer`.* FROM `customer`
     // LEFT JOIN `order` ON `order`.`customer_id` = `customer`.`id`
     // WHERE `order`.`status` = 1
     //
     // SELECT * FROM `order` WHERE `customer_id` IN (...)
     /*$model = Profile::find()
       ->select('profile.*')
       ->leftJoin('auth_assignment', '`auth_assignment`.`user_id` = `profile`.`user_id`')                          // условие, достать только с ролью "Пользователь"
       ->where(['auth_assignment.item_name' => 'Создатель'])                                                       // условие, достать только с ролью "Пользователь"
       ->with(['user', 'imagesOfObjects'])                                                                         // здесь дополнительная связь к таблицам, которые нужно вытащить
       ->all();*/
     // Лучше так
     /*$model = Profile::find()
       ->select('profile.*')
       ->innerJoinWith('user', '`user`.`id` = `profile`.`user_id`')                          // условие, достать только с ролью "Пользователь"
       ->where(['user.email' => '*****@*****.**'])                                                  // условие, достать только с ролью "Пользователь"
       ->with(['imagesOfObjects.image'])                                                     // здесь дополнительная связь к таблицам, которые нужно вытащить
       ->all();*/
     // или так
     /*$model = Profile::find()->joinWith([
           'user' => function ($query) {
               $query->andWhere(['<', 'id', 5])
               ->select(['user.id', 'user.email', 'user.phone']);                                 // выборочные поля из user
           },
       ])->with(['imagesOfObjects.image'])
           ->all();*/
     // или так
     /*$model = Profile::find()->innerJoinWith([
           'user' => function ($query) {
               $query->andWhere(['<', 'id', 5])
                   ->select(['user.id', 'user.email', 'user.phone']);                                 // выборочные поля из user
           },
       ])->all();*/
     // получить данные много ко многим через модель см getImages() которая использует getImagesOfObjects() в модели Profile
     /*$model = Profile::find()
           ->where(['user_id' => 1])
           //->innerJoinWith([                         // если найдет images, тогда достанет пользователя
           ->joinWith([                                // достанет пользователя, даже если не найдет images
           'images' => function ($query) {
           },
       ])->one();*/
     // или
     //$model = Profile::findOne(1);
     // получить данные много ко многим через модель см getImages() которая использует getImagesOfObjects() в модели Profile
     //d($model->images);
     // Join с дополнительным условием CONDITION (возвращает true, если условие истинно)
     /*$model = Profile::find()->innerJoinWith([
           'user' => function ($query) {
               $query->onCondition(['user.status' => User::STATUS_NOT_ACTIVE]);
           },
       ])->all();*/
     // или так
     /*$model = Profile::find()->joinWith([
           'user' => function ($query) {
               $query->onCondition(['user.status' => User::STATUS_NOT_ACTIVE]);        // если условие верно, таблицы объединяются. Отличается от where, который возвращает только
                                                                                       // один профили с верным условием, тем, что возвращает все профили, а где условие верно
                                                                                       // добавляет связанную таблицу. Если использовать innerJoinWith(), будет работать как where()
           },
       ])->all();*/
     // Обратные связи. Смотри модель User inverseOf() Например есть код:
     // SELECT * FROM `user` WHERE `id` = 1
     //$model = User::findOne(1);
     // SELECT * FROM `profile` WHERE `user_id` = 1
     //$profile = $model->profile2[0];
     // SQL-запрос не выполняется
     //$model2 = $profile->user;
     // выведет "одинаковы"
     //echo ($model === $model2) ? 'одинаковы' : 'НЕ одинаковы';
     $model = Profile::find()->joinWith(['user' => function ($query) {
         $query->onCondition(['user.status' => User::STATUS_NOT_ACTIVE]);
     }])->all();
     return $this->render('index', ['model' => $model]);
 }
Пример #22
0
 /**
  * Удаляет бонусные балы аффилиатов, при удалении (отмене) платежа
  * @param integer $affiliateId
  * @param float $cashOfPay
  * @return bool
  */
 public static function deleteAffiliatePercent($affiliateId, $cashOfPay)
 {
     if (!self::isActiveAffiliateProgram() || self::getMinSum() > $cashOfPay) {
         return true;
     }
     $model = Profile::findOne(['user_id' => $affiliateId]);
     if (!$model) {
         return true;
     }
     $percent = intval($cashOfPay * self::getDecimalPercent());
     $model->bonus_balance -= $percent;
     if (!$model->save()) {
         return false;
     }
     // аффилиат второго уровня
     if (0 < self::getPercentSecondLevel() && 0 < $model->user_affiliate_id) {
         $modelSecondLevel = Profile::findOne(['user_id' => $model->user_affiliate_id]);
         if (!$modelSecondLevel) {
             return true;
         }
         $percentSecondLevel = intval($cashOfPay * self::getDecimalPercentSecondLevel());
         $modelSecondLevel->bonus_balance -= $percentSecondLevel;
         if (!$modelSecondLevel->save()) {
             return false;
         }
     }
     return true;
 }
 /**
  * Finds the Profile model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Profile the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Profile::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #24
0
 /**
  * Save application form.
  *
  * @return Profile|null the saved model or null if saving fails
  */
 public function save()
 {
     if ($this->validate()) {
         $person = Person::findById($this->id_person);
         if (empty($person)) {
             $person = new Person();
         }
         if (trim($this->parent1_type) != '') {
             $parent1 = Person::findById($person->id_parent1);
             if (empty($parent1)) {
                 $parent1 = new Person();
             }
             $parent1->attributes = $this->getMyAttributes('parent1_');
             $parent1->save();
             $person->id_parent1 = $parent1->id;
         } else {
             $parent1 = Person::findById($person->id_parent1);
             if (!empty($parent1)) {
                 $parent1->delete();
             }
             $person->id_parent1 = null;
         }
         if (trim($this->parent2_type) != '') {
             $parent2 = Person::findById($person->id_parent2);
             if (empty($parent2)) {
                 $parent2 = new Person();
             }
             $parent2->attributes = $this->getMyAttributes('parent2_');
             $parent2->save();
             $person->id_parent2 = $parent2->id;
         } else {
             $parent2 = Person::findById($person->id_parent2);
             if (!empty($parent2)) {
                 $parent2->delete();
             }
             $person->id_parent2 = null;
         }
         $person->attributes = $this->attributes;
         if ($person->save()) {
             $this->id_person = $person->id;
             $profile = Profile::findById($this->id);
             if (empty($profile)) {
                 $profile = new Profile();
             }
             $profile->attributes = $this->attributes;
             $profile->id_person = $person->id;
             $profile->status = $this->status;
             if ($profile->validate()) {
                 $profile->save();
                 $this->id = $profile->id;
                 $specs = Yii::$app->request->post('spec');
                 $SpecArray = array();
                 $i = 0;
                 if (!empty($specs)) {
                     foreach ($specs as $id => $spec) {
                         if ($spec != 'none') {
                             $SpecArray[$i]['id_profile'] = $profile->id;
                             $SpecArray[$i]['id_spec'] = $id;
                             $spec == 'form_fulltime' ? $SpecArray[$i]['form_fulltime'] = 1 : ($SpecArray[$i]['form_fulltime'] = 0);
                             $spec == 'form_extramural' ? $SpecArray[$i]['form_extramural'] = 1 : ($SpecArray[$i]['form_extramural'] = 0);
                             $SpecArray[$i]['priority'] = $i + 1;
                             $i++;
                         }
                     }
                 }
                 Yii::$app->db->createCommand()->delete('profile_spec', 'id_profile=:id', [':id' => $profile->id])->execute();
                 if (!empty($SpecArray)) {
                     Yii::$app->db->createCommand()->batchInsert('profile_spec', ['id_profile', 'id_spec', 'form_fulltime', 'form_extramural', 'priority'], $SpecArray)->execute();
                 }
                 return true;
             } else {
                 return false;
             }
         }
     }
     return false;
 }
Пример #25
0
 /**
  * Get enrollee application.
  * @return Profile
  */
 public function getApplication()
 {
     return $this->hasOne(Profile::className(), ['id_person' => 'id']);
 }
Пример #26
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProfile()
 {
     return $this->hasOne(Profile::className(), ['user_id' => 'id']);
 }
Пример #27
0
 protected function findProfile($entrepreneur_user_id)
 {
     if (($model = Profile::findOne(['user_id' => $entrepreneur_user_id])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #28
0
 public function save()
 {
     $user = User::findOne(Yii::$app->user->id);
     $model = new Profile();
     $model->loadDefaultValues();
     $model->attributes = $this->attributes;
     try {
         return $model->link('user', $user);
     } catch (ErrorException $e) {
         echo $e->getMessage();
     }
 }
Пример #29
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getObject1()
 {
     return $this->hasOne(Profile::className(), ['user_id' => 'object_id']);
 }
Пример #30
0
 /**
  * Spec items.
  *
  * @return mixed
  * @throws BadRequestHttpException
  */
 public function actionSpecItems($base = null)
 {
     $specitems = Profile::getSpecsAllWithChoice($base);
     return $this->renderAjax('_specitems', ['specitems' => $specitems]);
 }