/** * Consolidates the "from" and "to" fields by filling in data model objects from database. * In student mode, "from" will be the student model and "to" will be the employer model. * In employer mode, it will be wise versa. * @return boolean - true if the models are set successfully * @throws CException -if from and to fields are not valid or type is not a valid type */ private function _setFromAndTo() { if (!$this->hasErrors($this->from) && !$this->hasErrors($this->to)) { $criteria = new CDbCriteria(); $criteria->with = array('user' => array('select' => 'email, first_name, last_name', 'joinType' => 'INNER JOIN')); $criteria->together = true; switch ($this->type) { case self::TYPE_STU: $this->fromObj = Student::model()->findByPk($this->from, $criteria); $this->toObj = Employer::model()->findByPk($this->to, $criteria); $this->interviewObj = InterviewStudentJobTitle::model()->findByAttributes(array('stu_job_id' => $this->stu_job_id, 'employer_id' => $this->to, 'active' => 1)); break; case self::TYPE_EMP: $this->fromObj = Employer::model()->findByPk($this->from, $criteria); $this->toObj = Student::model()->findByPk($this->to, $criteria); //stu_job_id //$this->interviewObj=InterviewStudentJobTitle::model()->findByAttributes(array('stu_job_id'=>$this->stu_job_id,'employer_id'=>$this->from,'active'=>1)); $this->interviewObj = InterviewStudentJobTitle::model()->findByAttributes(array('employer_id' => $this->employer_id, 'stu_job_id' => $this->to)); break; default: throw new CException('Invalid type.'); break; } if ($this->fromObj != null && $this->toObj != null && $this->interviewObj != null) { return true; } else { return false; } } else { throw new CException('Cannot set From and To fields.'); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new CertificationForm(); $model->certification->provider_id = Yii::app()->user->id; $model->certification->provider = Employer::model()->findByPk(Yii::app()->user->id, array('select' => 'company_name'))->company_name; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Certification']) && isset($_POST['PostItem'])) { $model->postItem->attributes = $_POST['PostItem']; $model->certification->attributes = $_POST['Certification']; $fileUpload = CUploadedFile::getInstance($model->certification, 'cert_image'); if ($fileUpload !== null) { //$model->certification->removeCertImage(); $model->certification->cert_image = $fileUpload; } if ($model->validate() && $model->save()) { if ($fileUpload !== null) { $model->certification->cert_image->saveAs($model->certification->getCertImagePath()); } Yii::app()->user->setFlash('success', Yii::t('app', 'msg.success.create_certificate')); $this->redirect(array('view', 'id' => $model->postItem->post_item_id)); } /* if($model->validate()&&$model->save()) $this->redirect(array('view','id'=>$model->postItem->post_item_id)); */ } $this->render('create', array('model' => $model)); }
/** @var $user User * @return bool */ public static function emailEmployerVerified($user) { $employer = Employer::model()->findByPk($user->user_id); $mail = new YiiMailer('employerVerified', array('employer' => $employer, 'user' => $user)); $mail->render(); $mail->From = Yii::app()->params['nonReplyEmail']; $mail->FromName = Yii::app()->name; $mail->Subject = Yii::app()->name . ' - Employer account verified'; $mail->AddAddress(YII_DEBUG ? Yii::app()->params['adminEmail'] : $user->email); if ($mail->Send()) { $mail->ClearAddresses(); Yii::log("Mail sent via " . Yii::app()->params['nonReplyEmail'], 'log'); Yii::log("Mail sent successfully to " . (YII_DEBUG ? Yii::app()->params['adminEmail'] : $user->email), 'log'); return true; } else { Yii::log("Email error: " . $mail->getError(), 'log'); return false; } }
public function save() { if (Yii::app()->user->isEmployer()) { $this->workshop->company = Employer::model()->findByPk(Yii::app()->user->id)->company_name; } //start a transaction $transaction = Yii::app()->db->beginTransaction(); try { if ($this->postItem->save()) { if ($this->workshop->save(false, null, $this->postItem)) { $transaction->commit(); return true; } } $transaction->rollback(); return false; } catch (Exception $e) { $transaction->rollback(); return false; } }
public function authenticate() { $username = strtolower($this->username); if ($this->userType == 'Employer') { $user = Employer::model()->find('LOWER(username)=?', array($username)); } else { $user = User::model()->find('LOWER(username)=?', array($username)); } if ($user === null) { $this->errorCode = self::ERROR_USERNAME_INVALID; } else { if (!$user->hashPassword($this->password)) { $this->errorCode = self::ERROR_PASSWORD_INVALID; } else { $this->_id = $user->id; $this->setState('userType', $this->userType); $this->username = $user->username; $this->errorCode = self::ERROR_NONE; } } return $this->errorCode == self::ERROR_NONE; }
public function actionProfile() { $id = Yii::app()->user->id; if (Yii::app()->user->userType == 'User') { $model = User::model()->findByPk($id); $table = 'User'; $img = 'photo'; $renderPath = 'registration'; } else { if (Yii::app()->user->userType == 'Employer') { $model = Employer::model()->findByPk($id); $table = 'Employer'; $img = 'logo'; $renderPath = 'employerRegistration'; } } if (isset($_POST[$table])) { $_POST[$table][$img] = $model[$img]; $model->attributes = $_POST[$table]; $uploadedFile = CUploadedFile::getInstance($model, $img); if ($model->save()) { if (!empty($uploadedFile)) { $uploadedFile->saveAs(Yii::app()->basePath . Yii::app()->params['uploadPath'] . strtolower(Yii::app()->user->userType) . '/' . $uploadedFile->getName()); $model[$img] = $uploadedFile->getName(); $model->save(false); } Yii::app()->user->setFlash('success', "Profile Updated !"); $this->render($renderPath, array('model' => $model)); Yii::app()->end(); } } $this->render($renderPath, array('model' => $model)); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Employer the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Employer::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionViewProfile($id) { $user = User::model()->findByPk($id); if ($user !== null) { $userGroupId = $user->user_group_id; $userGroupId = intval($userGroupId); $model = null; switch ($userGroupId) { case Student::USER_GROUP_ID: $model = Student::model()->findByPk($id); $this->renderPartial('viewStudentProfile', array('model' => $model)); break; case Employer::USER_GROUP_ID: $model = Employer::model()->findByPk($id); $this->renderPartial('viewEmployerProfile', array('model' => $model)); break; default: throw new CHttpException(404, 'Invalid User group found.'); break; } } else { throw new CHttpException(404, 'User is not found.'); } }
$form = $this->beginWidget('CActiveForm', array('id' => 'post-form', 'enableAjaxValidation' => false, 'enableAjaxValidation' => false, 'focus' => $model->hasErrors() ? '.error:first' : array($model, 'title'), 'htmlOptions' => array('class' => 'form-horizontal', 'enctype' => 'multipart/form-data'))); ?> <p class="note">Fields with <span class="required">*</span> are required.</p> <?php echo $form->errorSummary($model); ?> <div class="form-group"> <?php echo $form->labelEx($model, 'employer_id', array('class' => 'col-sm-offset-2 col-sm-2')); ?> <div class="col-sm-6"> <?php $list = CHtml::listData(Employer::model()->findAll(array('order' => 'username')), 'id', 'username'); ?> <?php echo $form->dropDownList($model, 'employer_id', $list, array('class' => 'form-control', 'empty' => 'Select Employer', 'style' => 'text-transform: capitalize')); ?> <?php echo $form->error($model, 'employer_id'); ?> </div> </div> <div class="form-group"> <?php echo $form->labelEx($model, 'title', array('class' => 'col-sm-offset-2 col-sm-2')); ?> <div class="col-sm-6">