public function updatecontractorsocial($post) { $contractor_id = Yii::app()->user->getId(); $socials = Socials::model()->findAll(array('order' => 'social ASC')); $return['error_message'] = ""; $status = false; foreach ($socials as $k => $v) { $csocials = ContractorSocials::model()->findbyAttributes(array('contractor_id' => $contractor_id, 'social_id' => $v->social_id)); $var = 'social_' . $v->social_id; if (count($csocials)) { $csocials->value = $post[$var]; } else { $csocials = new ContractorSocials(); $csocials->value = $post[$var]; $csocials->contractor_id = $contractor_id; $csocials->social_id = $v->social_id; } if ($csocials->save()) { $status = true; } else { $return['error_message'] = "unable to save social update."; } } $return['status'] = $status; $this->renderJSON($return, $status); }
public function actionMy_account() { if (!Yii::app()->user->isGuest) { if (Yii::app()->user->role == 'contractor') { $contractor_id = Yii::app()->user->getId(); $this->pageTitle = 'Handyman.com - My Account'; $param['city'] = Cities::model()->findAll(array('order' => 'Name ASC')); $param['state'] = States::model()->findAll(array('order' => 'Name ASC')); $param['page'] = "account"; $param['cmodel'] = Contractors::model()->findByPk($contractor_id); //$param['csocials'] = ContractorSocials::model()->findbyAttributes(array('contractor_id' => $contractor_id)); $socials = Socials::model()->findAll(array('order' => 'social ASC')); $user_socials = array(); foreach ($socials as $k => $v) { $value = ContractorSocials::model()->findbyAttributes(array('contractor_id' => $contractor_id, 'social_id' => $v->social_id)); if (count($value) > 0) { $user_socials[$v->social_id] = $value->value; } else { $user_socials[$v->social_id] = ""; } } $param['socials'] = $socials; $param['user_socials'] = $user_socials; $param['clicense'] = ContractorLicense::model()->findbyAttributes(array('contractor_id' => $contractor_id)); $param['cbond'] = ContractorBond::model()->findbyAttributes(array('contractor_id' => $contractor_id)); $param['projects'] = Projecttypes::model()->findAll(array('order' => 'Name ASC')); $param['logo'] = $this->getContractorProfilePic($contractor_id); $this->render('my-account', $param); } else { $this->redirect(Yii::app()->homeUrl); } } else { $this->redirect(Yii::app()->homeUrl); } }