public function deactivate($contractor_id) { $criteria = new CDbCriteria(); $criteria->condition = "user_type='contractor' AND userid=" . $contractor_id; Affiliates::model()->deleteAll($criteria); Referral::model()->deleteAll($criteria); $criteria = new CDbCriteria(); $criteria->condition = "owner_user_type='contractor' AND owner_id=" . $contractor_id; Answers::model()->deleteAll($criteria); Questions::model()->deleteAll($criteria); $criteria = new CDbCriteria(); $criteria->condition = "user_type='contractor' AND deleted_by=" . $contractor_id; Messagedeleted::model()->deleteAll($criteria); $criteria = new CDbCriteria(); $criteria->condition = "from_user_type='contractor' AND from_id=" . $contractor_id; Messages::model()->deleteAll($criteria); $criteria = new CDbCriteria(); $criteria->condition = "to_user_type='contractor' AND to_id=" . $contractor_id; Messages::model()->deleteAll($criteria); $criteria = new CDbCriteria(); $criteria->condition = "viewed_user_type='contractor' AND viewed_by=" . $contractor_id; QuestionViews::model()->deleteAll($criteria); $criteria = new CDbCriteria(); $criteria->condition = "referred_by_type='contractor' AND referred_by=" . $contractor_id; Referral::model()->deleteAll($criteria); $criteria = new CDbCriteria(); $criteria->condition = "invited_id=" . $contractor_id; ContractorTeam::model()->deleteAll($criteria); $criteria = new CDbCriteria(); $criteria->condition = "contractor_id=" . $contractor_id; ContractorBond::model()->deleteAll($criteria); ContractorLicense::model()->deleteAll($criteria); ContractorPoints::model()->deleteAll($criteria); ContractorSocials::model()->deleteAll($criteria); ContractorTeam::model()->deleteAll($criteria); ContractorViews::model()->deleteAll($criteria); Contractorphotos::model()->deleteAll($criteria); Feedback::model()->deleteAll($criteria); $criteria = new CDbCriteria(); $criteria->condition = "ContractorId=" . $contractor_id; self::model()->deleteAll($criteria); return true; }
public function actionContractor() { if (!Yii::app()->user->isGuest) { if (Yii::app()->user->role == 'contractor') { $this->pageTitle = 'Handyman.com - Contractor Dashboard'; $this->cities = Cities::model()->findAll(array('order' => 'RAND()', 'limit' => 10)); $contractor_id = Yii::app()->user->getId(); $model = Contractors::model()->findByPk($contractor_id); $param['page'] = "dashboard"; $param['model'] = $model; $criteria = new CDbCriteria(); $criteria->condition = "to_id={$contractor_id} and to_user_type='contractor'"; $param['message_count'] = Messages::model()->count($criteria); $criteria2 = new CdbCriteria(); $criteria2->condition = "contractor_id = {$contractor_id}"; $param['views_count'] = ContractorViews::model()->count($criteria2); $oneWeekAgo = date("Y-m-d H:i:s", strtotime("-1 months")); $criteria3 = new CdbCriteria(); $criteria3->addBetweenCondition('date_added', $oneWeekAgo, date("Y-m-d H:i:s")); $param['latest_project_count'] = Projects::model()->count($criteria3); $param['from'] = $oneWeekAgo; $param['to'] = date("Y-m-d H:i:s"); $param['points'] = 0; $points = ContractorPoints::model()->findByAttributes(array('contractor_id' => $contractor_id)); if (count($points) > 0) { $param['points'] = $points->points; } $team_invites = ContractorTeam::model()->findbyAttributes(array('invited_id' => $contractor_id, 'confirmed' => 0)); $param['team_invites'] = $team_invites; $this->render('contractor', $param); } else { $this->redirect(Yii::app()->homeUrl); } } else { $this->redirect(Yii::app()->homeUrl); } }
public function actionProfile() { $username = Yii::app()->Ini->v('user'); $profile_details = Contractors::model()->findByAttributes(array('Username' => $username)); $current_userid = Yii::app()->user->getId(); $con_id = $profile_details->ContractorId; $criteria = new CDbCriteria(); $criteria->condition = "contractor_id = '{$con_id}'"; $feedback = Feedback::model()->findAll($criteria); $criteria_social = new CDbCriteria(); $criteria_social->condition = "contractor_id = '{$con_id}'"; $social_accounts = ContractorSocials::model()->findAll($criteria_social); $contractor_license = ContractorLicense::model()->findByAttributes(array('contractor_id' => $con_id)); $contractor_bond = ContractorBond::model()->findByAttributes(array('contractor_id' => $con_id)); $contractor_points = Contractors::model()->updatePoints($con_id); $team_members = new CDbCriteria(); $team_members->condition = "contractor_id = '{$con_id}' AND confirmed = '1' ORDER BY RAND() LIMIT 0,5"; $contractor_team = ContractorTeam::model()->findAll($team_members); if (count($profile_details) > 0) { $profile_details->updatePoints($profile_details->ContractorId); $contractor_id = $con_id; $company = $profile_details->Name; $contact_name = $profile_details->ContactName; $phone = $profile_details->Phone; $fax = $profile_details->Fax; $address1 = $profile_details->Address1; $address2 = $profile_details->Address2; $city = $profile_details->City; $state = $profile_details->State; $zipcode = $profile_details->Zip; $email = $profile_details->Email; $website = $profile_details->Website; $about = $profile_details->AboutBusiness; $services = $profile_details->Services; $date_created = $profile_details->Created; $username = $profile_details->Username; $project_type = $this->getProjectTypeName($profile_details->ProjectTypeId); $photo_cover = $this->getProfileCover($profile_details->ContractorId); $is_my_profile = false; $homeowner_projects = array(); if (!Yii::app()->user->isGuest) { if ($contractor_id == $current_userid) { $is_my_profile = true; } else { /* if homeowner can send message and attach project */ if (Yii::app()->user->role == 'homeowner') { $criteria = new CDbCriteria(); $criteria->condition = "homeowner_id = " . $current_userid; $homeowner_projects = Projects::model()->findAll($criteria); } } } //get map location $address = urlencode($address1 . ',' . $city . ',' . $state . "," . $zipcode . ",USA"); $l = explode(",", Yii::app()->Ini->GetMapLocation($address)); $point = array($address1 . ',' . $city . ',' . $state, floatval($l[0]), floatval($l[1]), 0); $this->pageTitle = 'Handyman.com - Contractor - ' . $company . ' Profile'; $this->render('contractor-profile', array('profile_exists' => true, 'contractor_id' => $contractor_id, 'company' => $company, 'contact_name' => $contact_name, 'phone' => $phone, 'fax' => $fax, 'address1' => $address1, 'address2' => $address2, 'city' => $city, 'state' => $state, 'zipcode' => $zipcode, 'email' => $email, 'website' => $website, 'about' => $about, 'services' => $services, 'date_created' => date('F j, Y', strtotime($date_created)), 'username' => $username, 'project_type' => $project_type, 'page' => 'profile', 'param' => "", 'logo' => $this->getContractorProfilePic($profile_details->ContractorId), 'is_my_profile' => $is_my_profile, 'contractor_license' => $contractor_license, 'contractor_bond' => $contractor_bond, 'social_accounts' => $social_accounts, 'contractor_points' => $contractor_points, 'feedback' => $feedback, 'photo_cover' => $photo_cover, 'my_gallery' => Contractorphotos::model()->findAllByAttributes(array('contractor_id' => $contractor_id, 'is_profile' => '0'), array('limit' => '6', 'order' => 'RAND()')), 'homeowner_projects' => $homeowner_projects, 'point' => $point, 'contractor_team' => $contractor_team, 'map_location' => $l)); //update views if (!Yii::app()->user->isGuest) { $userid = Yii::app()->user->getId(); $role = Yii::app()->user->role; $views = ContractorViews::model()->findByAttributes(array('viewed_by' => $userid, 'contractor_id' => $contractor_id, 'viewed_user_type' => $role)); if (count($views) > 0) { } else { $views = new ContractorViews(); $views->contractor_id = $contractor_id; $views->viewed_by = $userid; $views->viewed_user_type = $role; $views->save(); } } } else { $this->redirect(Yii::app()->homeUrl . 'home/error'); } }