/** * Key-value pairs of all experiences * @return array [category_id => category_name] */ public static function all() { static $result; if (!is_null($result)) { return $result; } $command = Yii::app()->db; /* @var CDbConnection $command */ $rows = $command->createCommand()->select('id, name')->from(Experience::model()->tableName())->queryAll(); $result = []; foreach ($rows as $row) { $result[$row['id']] = $row['name']; } return $result; }
<a href="#" onclick="document.forms['search-form-kids'].submit(); return false;"> <img src='<?php echo Yii::app()->params['siteBase']; ?> /images/icon_homepage_kids.gif' /><h5>Find classes & activities for kids</h5> </a> </div> </div> </div> <h3>Staff Picks in <span id='city'>Los Angeles</span></h3> <!----------- 1 row of tiles----> <div class="row"> <?php $experiences = Experience::model()->active()->current()->findAll(array('select' => '*, rand() as rand', 'limit' => 4, 'order' => 'rand')); $count = count($experiences); foreach ($experiences as $i => $experience) { $imageHTML = '<img src="' . ($experience->picture ? $experience->picture : 'http://placehold.it/400x300') . '" />'; $imageLink = CHtml::link($imageHTML, array('/experience/view', 'id' => $experience->Experience_ID)); $hostName = $experience->createUser->display; if (strlen($hostName) > 25) { $hostName = substr($hostName, 0, 25); $hostName .= ' ...'; } $hostLink = CHtml::link($hostName, array('/user/view', 'id' => $experience->Create_User_ID)); $enrollees = ''; foreach ($experience->enrolled as $enrollee) { $picLink = 'http://placeskull.com/100/100/868686'; if ($enrollee->profilePic != null) { $picLink = $enrollee->profilePic;
/** * 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 the ID of the model to be loaded */ public function loadModel($id) { $model = Experience::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function search() { $requestCriteria = new CDbCriteria(); $experienceCriteria = new CDbCriteria(); $requestCriteria->with = array('category', 'tags', 'createUser'); $experienceCriteria->with = array('location', 'category', 'tags', 'createUser'); $keywords = explode(' ', $this->keywords); if (isset($this->includedResults)) { $included = json_decode($this->includedResults); $experiences = array(); $requests = array(); foreach ($included as $item) { if ($item->type == 'experience') { $experiences[] = $item->id; } else { $requests[] = $item->id; } } $experienceCriteria->addInCondition('t.Experience_ID', $experiences); $requestCriteria->addInCondition('t.Request_ID', $requests); } else { foreach ($keywords as $keyword) { $requestCriteria->compare('t.Name', $keyword, true, 'OR'); $requestCriteria->compare('t.Description', $keyword, true, 'OR'); $requestCriteria->compare('category.Name', $keyword, true, 'OR'); $requestCriteria->compare('tags.Name', $keyword, true, 'OR'); $requestCriteria->compare('createUser.First_name', $keyword, true, 'OR'); $requestCriteria->compare('createUser.Last_name', $keyword, true, 'OR'); $requestCriteria->compare('createUser.DisplayName', $keyword, true, 'OR'); $experienceCriteria->compare('t.Name', $keyword, true, 'OR'); $experienceCriteria->compare('t.Description', $keyword, true, 'OR'); $experienceCriteria->compare('category.Name', $keyword, true, 'OR'); $experienceCriteria->compare('tags.Name', $keyword, true, 'OR'); $experienceCriteria->compare('createUser.First_name', $keyword, true, 'OR'); $experienceCriteria->compare('createUser.Last_name', $keyword, true, 'OR'); $experienceCriteria->compare('createUser.DisplayName', $keyword, true, 'OR'); } } $requestCriteria->addCondition('t.Created_Experience_ID is NULL'); if (isset($this->category) && is_numeric($this->category) && $this->category > 0) { $requestCriteria->compare('t.Category_ID', $this->category); $experienceCriteria->compare('t.Category_ID', $this->category); } if ($this->minPrice != null && $this->minPrice > 0) { $experienceCriteria->compare('t.Price', '>=' . $this->minPrice); } if ($this->maxPrice != null && $this->maxPrice > 0) { $experienceCriteria->compare('t.Price', '<=' . $this->maxPrice); } if ($this->start != null && strlen($this->start) > 0) { $experienceCriteria->compare('t.End', '>' . date('Y-m-d', strtotime($this->start))); } if ($this->end != null && strlen($this->end) > 0) { $experienceCriteria->compare('t.Start', '<' . date('Y-m-d', strtotime($this->end))); } if ($this->posterType != null && $this->posterType > 0) { $experienceCriteria->compare('createUser.PosterType', '=' . $this->posterType); } if ($this->experienceType != null && $this->experienceType > 0) { $experienceCriteria->compare('t.ExperienceType', '=' . $this->experienceType); } if ($this->ageRanges != null && !in_array(0, $this->ageRanges)) { $ageRange = 0; foreach ($this->ageRanges as $item) { $ageRange += $item; } $experienceCriteria->addCondition('t.AppropriateAges | ' . $ageRange . ' = ' . $ageRange); $experienceCriteria->compare('t.AppropriateAges', '>' . 0); } $experiences = Experience::model()->active()->current()->findAll($experienceCriteria); $requests = Request::model()->findAll($requestCriteria); foreach ($requests as $i => $request) { if (count($request->requestors) == 0) { unset($requests[$i]); } } if (isset($this->location) && strlen($this->location) > 0) { foreach ($experiences as $i => $experience) { if (!stristr($experience->location->fullAddress, $this->location)) { unset($experiences[$i]); } } foreach ($requests as $i => $request) { if ($request->Zip != $this->location) { unset($requests[$i]); } } } $experiences = array_values($experiences); $items = array_merge($experiences, $requests); $scores = array(); foreach ($items as $item) { $score = 1; $locationFound = false; foreach ($keywords as $keyword) { if (strlen($keyword) == 0) { continue; } if (stristr($item->Name, $keyword)) { $score += ExperienceSearchForm::NameValue; } if (stristr($item->Description, $keyword)) { $score += ExperienceSearchForm::NameValue; } if (stristr($item->category->Name, $keyword)) { $score += ExperienceSearchForm::CategoryValue; } if (stristr($item->tagstring, $keyword)) { $score += ExperienceSearchForm::TagValue; } if ($item instanceof Experience && $item->location != null && !$locationFound) { if (stristr($item->location->fulladdress, $keyword)) { $score *= ExperienceSearchForm::LocationMultiplier; $locationFound = true; } } } array_push($scores, $score); } arsort($scores); $sortedItems = array(); foreach ($scores as $i => $score) { $sortedItems[] = $items[$i]; } $this->totalResults = count($sortedItems); $this->totalPages = ceil($this->totalResults / ExperienceSearchForm::PageSize); if (isset($this->disablePaging) && $this->disablePaging != null) { return $sortedItems; } if (!isset($this->page)) { $this->page = 1; } $offset = ($this->page - 1) * ExperienceSearchForm::PageSize; $sortedItems = array_slice($sortedItems, $offset, ExperienceSearchForm::PageSize); return $sortedItems; }
public function actionMergeAccounts() { $model = new LinkTooForm(); $error = ''; if (isset($_POST['LinkTooForm'])) { $model = new LinkTooForm(); $model->attributes = $_POST['LinkTooForm']; $username = $model->email; $password = $model->password; $login = new LoginForm(); $login->username = $username; $login->password = $password; $user1 = User::model()->findByAttributes(array('username' => $username)); $user2 = User::getCurrentUser(); if ($user1 == null || !$login->validate()) { $error = "Username or password was incorrect."; $this->render('MergeAccounts', array('model' => $model, 'error' => $error)); } elseif ($user1->disable == 1) { $error = "User's account is disable."; $this->render('MergeAccounts', array('model' => $model, 'error' => $error)); } else { $basic_info = BasicInfo::model()->findByAttributes(array('userid' => $user1->id)); //link the third party accounts; $linkedinid = $user1->linkedinid; $googleid = $user1->googleid; $fiucsid = $user1->fiucsid; $fiu_account_id = $user1->fiu_account_id; if ($user2->linkedinid == null && $linkedinid != null) { $user2->linkedinid = $linkedinid; $user1->linkedinid = null; $user2->save(false); } if ($user2->googleid == null && $googleid != null) { $user2->googleid = $googleid; $user1->googleid = null; $user2->save(false); } if ($user2->fiucsid == null && $fiucsid != null) { $user2->fiucsid = $fiucsid; $user1->fiucsid = null; $user2->save(false); } if ($user2->fiu_account_id == null && $fiu_account_id != null) { $user2->fiu_account_id = $fiu_account_id; $user1->fiu_account_id = null; $user2->save(false); } //disable user $user1->disable = 1; $user1->save(false); //get basic info $first_name = $user1->first_name; $last_name = $user1->last_name; $email = $user1->email; $picture = $user1->image_url; $mesg = "Virtual Job Fair"; $phone = $basic_info->phone; $city = $basic_info->city; $state = $basic_info->state; $about_me = $basic_info->about_me; //get education $education1 = Education::model()->find('FK_user_id=:id', array(':id' => $user1->id)); $education2 = Education::model()->find('FK_user_id=:id', array(':id' => $user2->id)); if ($education1 != null && $education2 == null) { $education1->FK_user_id = $user2->id; $education1->save(false); } if ($education1 != null && $education2 != null) { if ($education1->FK_school_id != $education2->FK_school_id) { $education1->FK_user_id = $user2->id; $education1->save(false); } } //get experience $experience1 = Experience::model()->find('FK_userid=:id', array(':id' => $user1->id)); $experience2 = Experience::model()->find('FK_userid=:id', array(':id' => $user2->id)); if ($experience1 != null && $experience2 == null) { $experience1->FK_userid = $user2->id; $experience1->save(false); } if ($experience1 != null && $experience2 != null) { if ($experience1->company_name != $experience2->company_name) { $experience1->FK_userid = $user2->id; $experience1->save(false); } } //get skill $this->actionLinkTo($email, $first_name, $last_name, $picture, $mesg, $phone, $city, $state, $about_me); return; } // } else { $this->render('MergeAccounts', array('model' => $model, 'error' => $error)); } }
public function actionDemo() { // if user canceled, redirect to home page if (isset($_GET['oauth_problem'])) { $problem = $_GET['oauth_problem']; if ($problem == 'user_refused') { $this->redirect('/JobFair/index.php'); } } if (!isset($_SESSION)) { session_start(); } //edit by Manuel making the link dynamic, using Yii. and changing how the account will be link so if the student //decide to login with his linkedIn account it will be taken to the account that it is link to. $config['base_url'] = 'http://' . Yii::app()->request->getServerName() . '/JobFair/index.php/profile/auth.php'; $config['callback_url'] = 'http://' . Yii::app()->request->getServerName() . '/JobFair/index.php/profile/demo'; $config['linkedin_access'] = '2rtmn93gu2m4'; $config['linkedin_secret'] = 'JV0fYG9ls3rclP8v'; include_once Yii::app()->basePath . "/views/profile/linkedin.php"; # First step is to initialize with your consumer key and secret. We'll use an out-of-band oauth_callback $linkedin = new LinkedIn($config['linkedin_access'], $config['linkedin_secret'], $config['callback_url']); //$linkedin->debug = true; if (isset($_REQUEST['oauth_verifier'])) { $_SESSION['oauth_verifier'] = $_REQUEST['oauth_verifier']; $linkedin->request_token = unserialize($_SESSION['requestToken']); $linkedin->oauth_verifier = $_SESSION['oauth_verifier']; $linkedin->getAccessToken($_REQUEST['oauth_verifier']); $_SESSION['oauth_access_token'] = serialize($linkedin->access_token); header("Location: " . $config['callback_url']); exit; } else { $linkedin->request_token = unserialize($_SESSION['requestToken']); $linkedin->oauth_verifier = $_SESSION['oauth_verifier']; $linkedin->access_token = unserialize($_SESSION['oauth_access_token']); } # You now have a $linkedin->access_token and can make calls on behalf of the current member $xml_response = $linkedin->getProfile("~:(id,first-name,last-name,headline,picture-url,industry,email-address,languages,phone-numbers,skills,educations,location:(name),positions,picture-urls::(original))"); $data = simplexml_load_string($xml_response); // print "<pre>"; print_r($xml_response);print "</pre>"; //print "<pre>"; print_r($data->{'picture-urls'}->{'picture-url'}[0]);print "</pre>"; // print "<pre>"; print_r($data->{'id'});print "</pre>"; //return; // check that there is no duplicate id $duplicateUser = User::model()->findByAttributes(array('linkedinid' => $data->{'id'})); if ($duplicateUser != null) { $this->actionDuplicationError(); return; } // get username and link the accounts $username = Yii::app()->user->name; $user = User::model()->find("username=:username", array(':username' => $username)); $user->linkedinid = $data->{'id'}; $user->save(false); $user_id = $user->id; // ------------------BASIC INFO--------------- $basic_info = null; $basic_info = BasicInfo::model()->findByAttributes(array('userid' => $user_id)); if ($basic_info == null) { $basic_info = new BasicInfo(); } $basic_info->userid = $user_id; $basic_info->save(false); // ------------------BASIC INFO ----------------- // -----------------EDUCATION ---------------------- // get number of educations to add $educ_count = $data->educations['total']; // delete current educations $delete_educs = Education::model()->findAllByAttributes(array('FK_user_id' => $user_id)); foreach ($delete_educs as $de) { $de->delete(); } // add educations for ($i = 0; $i < $educ_count; $i++) { // first check if current education is in school table. if not, add it $current_school_name = $data->educations->education[$i]->{'school-name'}; $school_exists = School::model()->findByAttributes(array('name' => $current_school_name)); if ($school_exists == null) { $new_school = new School(); $new_school->name = $current_school_name; $new_school->save(); $school_id = School::model()->findByAttributes(array('name' => $current_school_name))->id; } else { $school_id = $school_exists->id; } // now ready to add new education $new_educ = new Education(); $new_educ->degree = $data->educations->education[$i]->degree; $new_educ->major = $data->educations->education[$i]->{'field-of-study'}; // $model->admission_date=date('Y-m-d',strtotime($model->admission_date)); $new_educ->graduation_date = date('Y-m-d', strtotime($data->educations->education[$i]->{'end-date'}->year)); // print "<pre>"; print_r($new_educ->graduation_date);print "</pre>";return; $new_educ->FK_school_id = $school_id; $new_educ->FK_user_id = $user_id; $new_educ->additional_info = $data->educations->education[$i]->notes; $new_educ->save(false); } // -----------------EDUCATION ---------------------- // -----------------EXPERIENCE ------------------- // get number of educations to add $pos_count = $data->positions['total']; // delete current positions $delete_pos = Experience::model()->findAllByAttributes(array('FK_userid' => $user_id)); foreach ($delete_pos as $de) { $de->delete(); } for ($i = 0; $i < $pos_count; $i++) { $new_pos = new Experience(); $new_pos->FK_userid = $user_id; $new_pos->company_name = $data->positions->position[$i]->company->name; $new_pos->job_title = $data->positions->position[$i]->title; $new_pos->job_description = $data->positions->position[$i]->summary; $temp_start_date = $data->positions->position[$i]->{'start-date'}->month . '/01/' . $data->positions->position[$i]->{'start-date'}->year; $new_pos->startdate = date('Y-m-d', strtotime($temp_start_date)); if ($data->positions->position[$i]->{'is-current'} == 'true') { $new_pos->enddate = ''; } else { $temp_end_date = $data->positions->position[$i]->{'end-date'}->month . '/01/' . $data->positions->position[$i]->{'end-date'}->year; $new_pos->enddate = date('Y-m-d', strtotime($temp_end_date)); } $new_pos->city = ''; $new_pos->state = ''; $new_pos->save(false); } // -----------------EXPERIENCE ------------------- // ----------------------SKILLS---------------------- // get number of educations to add $linkedin_skill_count = $data->skills['total']; for ($i = 0; $i < $linkedin_skill_count; $i++) { // check if skill exists in skill set table, if not, add it to skill set table if (Skillset::model()->findByAttributes(array('name' => $data->skills->skill[$i]->skill->name)) == null) { $new_skill = new Skillset(); $new_skill->name = $data->skills->skill[$i]->skill->name; $new_skill->save(false); //echo 'New Skill ' . $new_skill->attributes; } // check if student has that skill, if not add it to student-skill-map table if (StudentSkillMap::model()->findByAttributes(array('userid' => $user_id, 'skillid' => Skillset::model()->findByAttributes(array('name' => $data->skills->skill[$i]->skill->name))->id)) == null) { $new_sdnt_skill = new StudentSkillMap(); $new_sdnt_skill->userid = $user_id; $new_sdnt_skill->skillid = Skillset::model()->findByAttributes(array('name' => $data->skills->skill[$i]->skill->name))->id; $new_sdnt_skill->ordering = $i + 1; $new_sdnt_skill->save(false); //echo 'New Skill for student' . $new_sdnt_skill->attributes; } } // ----------------------end SKILLS---------------------- //get variables $mesg = "LinkedIn"; $phone = $data->{'phone-numbers'}->{'phone-number'}->{'phone-number'}; if ($phone != null) { $phone = strip_tags($data->{'phone-numbers'}->{'phone-number'}->{'phone-number'}->asXML()); } $city = $data->location->name; if ($city != null) { $city = strip_tags($data->location->name->asXML()); } $state = ''; $about_me = $data->headline; if ($about_me != null) { $about_me = strip_tags($data->headline->asXML()); } $picture = $data->{'picture-urls'}->{'picture-url'}[0]; if ($picture != null) { $picture = strip_tags($data->{'picture-urls'}->{'picture-url'}[0]->asXML()); } $xemail = $data->{'email-address'}; if ($xemail != null) { $xemail = strip_tags($data->{'email-address'}->asXML()); } $fname = $data->{'first-name'}; if ($fname != null) { $fname = strip_tags($data->{'first-name'}->asXML()); } $lname = $data->{'last-name'}; if ($lname != null) { $lname = strip_tags($data->{'last-name'}->asXML()); } $this->actionLinkToo($xemail, $fname, $lname, $picture, $mesg, $phone, $city, $state, $about_me); // return; }
public static function GetExperienceFromCode($code) { $id = intval($code, Experience::CODE_BASE) - Experience::CODE_OFFSET; $experience = Experience::model()->findByPk($id); return $experience; }