public function saveDegree(Degree $degree) { try { $degree->save(); } catch (Exception $e) { throw new DaoException($e->getMessage(), $e->getCode(), $e); } }
public static function degreeArray() { $degreeObject = new Degree(); $arr = $degreeObject->model()->findAll(); $degreeArray = array(); foreach ($arr as $object) { $degreeArray[$object->id] = $object->title; } return $degreeArray; }
public static function addDegree($name, $abbreviation = null) { $name = trim($name); $abbreviation = trim($abbreviation); if (self::getByText($name) || self::getByText($abbreviation)) { return false; } $degree = new Degree(); $degree->name = $name; $degree->abbreviation = $abbreviation; $degree->save(); return self::getByText($name); }
public static function home() { $degrees = Degree::all(); $degree1 = $degrees['0']; $degree2 = $degrees['1']; $degree3 = $degrees['2']; $degree1->institution = $degree1->institutions['0']; $degree2->institution = $degree2->institutions['0']; $degree3->institution = $degree3->institutions['0']; View::make('home.html', array('degree1' => $degree1, 'degree2' => $degree2, 'degree3' => $degree3)); }
public static function delete($id) { if (self::get_user_admin() == null) { Redirect::to('/home'); } $degrees = Degree::findByInstitution($id); if (!empty($degrees)) { Redirect::to('/institutions', array('error' => 'Institution could not be deleted, because it is linked to one or more degrees. First delete related degrees under Manage->Degrees.')); } $institution = Institution::find($id); $institution->delete(); Redirect::to('/institutions', array('message' => 'Institution deleted!')); }
public function search() { // Pick up parameters $params = $_POST; $keyword = $params['keyword']; $city = $params['city']; $institutions = $params['institutions']; $accepted_max = $params['accepted_max']; $accepted_min = $params['accepted_min']; $extent_max = $params['extent_max']; $extent_min = $params['extent_min']; //check number values are valid if (!is_numeric($accepted_max) || !is_numeric($accepted_min) || !is_numeric($extent_min) || !is_numeric($extent_max)) { View::make('search.html', array('error' => 'Some search parameters were weird, try again!')); } //Convert percentages to decimal $accepted_max = $accepted_max / 100; $accepted_min = $accepted_min / 100; //Find degrees that match the city and numeric parameters $degrees = Degree::search($city, $accepted_max, $accepted_min, $extent_max, $extent_min); $institutionCorrectDegrees = array(); //filter the results that contain correct institution foreach ($degrees as $degree) { foreach ($degree->institutions as $degreeInstitution) { if (in_array($degreeInstitution->id, $institutions)) { $institutionCorrectDegrees[] = $degree; break; } } } //filter the results that match the keyword $keywordMatchingDegrees = array(); if (strlen($keyword) > 0) { $keywordMatchingDegrees = $this->filterByKeyword($institutionCorrectDegrees, $keyword); } else { $keywordMatchingDegrees = $institutionCorrectDegrees; } self::makeInstitutionsStrings($keywordMatchingDegrees); $allInstitutions = Institution::all(); //add favorites $favorites = FavoriteController::getUserFavorites(); //return view if (empty($keywordMatchingDegrees)) { $error = 'No results were found, sorry!'; View::make('search.html', array('institutions' => $allInstitutions, 'error' => $error, 'degrees' => $keywordMatchingDegrees)); } View::make('search.html', array('institutions' => $allInstitutions, 'degrees' => $keywordMatchingDegrees, 'favorites' => $favorites)); }
public function actionSearch($q) { $result = array(); $term = trim(addcslashes($q, '%_')); // escape LIKE's special characters if (!empty($term)) { if (isset($_SESSION['uid'])) { $param = new CDbCriteria(array('condition' => "name LIKE :match AND university_id=" . $_SESSION['uid'], 'params' => array(':match' => "%{$term}%"))); } else { $param = new CDbCriteria(array('condition' => "name LIKE :match", 'params' => array(':match' => "%{$term}%"))); } $cursor = Degree::model()->findAll($param); if (!empty($cursor)) { foreach ($cursor as $id => $value) { $result[] = array('id' => $value['did'], 'name' => $value['name']); } } } echo json_encode($result); Yii::app()->end(); }
public function saveDegreeGroupInfo($data, $degree_id) { $group = DegreeGroup::model()->findByPk($data->getProperty('id')); if ($group == null) { $group = new DegreeGroup(); } $degree = new Degree(); $degree = Degree::model()->findByPk($degree_id); $group->cid = $data->getProperty('id'); $group->name = $data->getProperty('name'); //$datetime->add(new DateInterval('PT1H')); $group->email = $data->getProperty('email'); if (null != $data->getProperty('owner')) { $group->owner_id = $data->getProperty('owner')->getProperty('id'); $this->saveMemberInfo($data->getProperty('owner')); $this->saveGroupMember($data->getProperty('owner'), $data->getProperty('id'), 'Degree'); } $group->description = $data->getProperty('description'); $group->degree_id = $degree_id; $group->save(); }
public function executeBulkupload() { if ($this->getRequest()->getFileName('csvfile')) { $fileName = md5($this->getRequest()->getFileName('csvfile') . time() . rand(0, 99999)); $ext = $this->getRequest()->getFileExtension('csvfile'); $this->getRequest()->moveFile('csvfile', sfConfig::get('sf_upload_dir') . "//csvfiles//" . $fileName . ".csv"); $fullname = $fileName . ".csv"; //$fullpath = '/uploads/csvfiles/'.$fullname; $fp = sfConfig::get('sf_upload_dir') . "//csvfiles//" . $fileName . ".csv"; $reader = new sfCsvReader($fp, ',', '"'); $reader->open(); $i = 1; $exist; $ignore; $log; $ignoreflag = 0; $success = 0; while ($data = $reader->read()) { $name[] = array(); $name = explode(' ', $data[0]); $roll = $data[1]; $enrol = $data[2]; $branch = $data[3]; $degree = $data[4]; $year = $data[5]; $c = new Criteria(); $c->add(UserPeer::ENROLMENT, $enrol); $user = UserPeer::doSelectOne($c); if (!$user) { $c = new Criteria(); $c->add(BranchPeer::CODE, $branch); $br = BranchPeer::doSelectOne($c); if (!$br) { $br = new Branch(); $br->setName($branch); $br->setCode($branch); $br->save(); } $c = new Criteria(); $c->add(DegreePeer::NAME, $degree); $dg = DegreePeer::doSelectOne($c); if (!$dg) { $dg = new Degree(); $dg->setName($degree); $dg->save(); } $user = new User(); if ($roll) { $user->setRoll($roll); $user->setRollflag(sfConfig::get('app_defaultprivacy_roll')); } if ($enrol) { $user->setEnrolment($enrol); $user->setEnrolflag(sfConfig::get('app_defaultprivacy_enrol')); } else { $ignoreflag = 1; } if ($year) { $user->setGraduationyear($year); $user->setGraduationyearflag(sfConfig::get('app_defaultprivacy_year')); } $user->setBranchId($br->getId()); $user->setBranchflag(sfConfig::get('app_defaultprivacy_branch')); $user->setDegreeId($dg->getId()); $user->setDegreeflag(sfConfig::get('app_defaultprivacy_degree')); $user->setIslocked(sfConfig::get('app_islocked_unclaimed')); $user->setUsertype(sfConfig::get('app_usertypecode_Alumni')); $lastname = ''; $personal = new Personal(); $name[0] = str_replace('.', '', $name[0]); $personal->setFirstname($name[0]); if ($name[3]) { $name[1] = str_replace('.', '', $name[1]); $name[2] = str_replace('.', '', $name[2]); $name[3] = str_replace('.', '', $name[3]); $midname = $name[1] . " " . $name[2]; $personal->setMiddlename($midname); $personal->setLastname($name[3]); $lastname = $name[3]; } elseif ($name[2]) { $name[1] = str_replace('.', '', $name[1]); $name[2] = str_replace('.', '', $name[2]); $personal->setMiddlename($name[1]); $personal->setLastname($name[2]); $lastname = $name[2]; } elseif ($name[1]) { $name[1] = str_replace('.', '', $name[1]); $personal->setLastname($name[1]); $lastname = $name[1]; } $uname_suffix = $branch . substr($year, -2); if ($lastname) { $username = $name[0] . '.' . $lastname . '@'; } else { $username = $name[0] . '@'; } $temp = 1; $tempusername = $username; while ($this->uniqueuser($tempusername . $uname_suffix)) { $tempusername = $username . $temp; $temp++; } $tempusername = $tempusername . $uname_suffix; $user->setUsername($tempusername); if ($ignoreflag == 0) { $e = $user->save(); $personal->setUserId($user->getId()); $personal->save(); $success++; $log[$i][0] = $e == 1 ? "{$i}) Uploaded Successfully" : $e; $log[$i][1] = $data[0]; } else { $ignore[] = $i; $ignoreflag = 0; $log[$i][0] = "{$i}) NO enrolment number"; $log[$i][1] = $data[0]; } } else { $exist[] = $i; $log[$i][0] = "{$i}) In Database as " . $user->getFullname() . ", " . $user->getBranchname() . " " . $user->getGraduationyear(); $log[$i][1] = $data[0]; } $i++; } // while ($data = $reader->read()) ends here $reader->close(); $this->log = $log; $this->success = $success; $this->ignored = $ignore; $this->exists = $exist; } }
public function degrees() { return $this->belongsToMany(Degree::getClass(), 'degree_school')->withPivot('id')->withTimestamps(); }
echo "Degrees data folder does not exist.<br/>"; echo "Creating degrees data folder...<br/>"; mkdir("../data/uq/degrees", 0777, true); echo "Folder created.<br/><br/>"; } //Iterate through each given degree foreach ($degrees as $code) { //Format the urls for information about the given degree $site = "http://www.uq.edu.au/study/program.html?acad_prog=" . $code; $courseurl = "http://www.uq.edu.au/study/program_list.html?acad_prog=" . $code; //Collects the title abbreviation from the UQ website $html = new simple_html_dom(); $html->load_file($site); $title = $html->find('span[id=program-abbreviation]', 0)->innertext; //Creates a new Degree object from the information collected $degree = new Degree($code, $site, $title, $courseurl); //Indexes the degree $degree->index(); //Saves the degree $degree->save(); } //Degree object which provides functions which index and save information collected given degree information class Degree { //Initializes the class and stores local variables function Degree($code, $website, $title, $coursesite) { $this->code = $code; $this->website = $website; $this->coursesite = $coursesite; $this->title = $title;
public function setSecondLevelCategory($degree_group_id, $type) { if ($type) { $degree_group = DegreeGroup::model()->findByPk($degree_group_id); //$first_level_id = $this->setFirstLevelCategory($degree_group->city); $first_level_id = $this->setFirstLevelCategory($degree_group->degree_id); $degree = Degree::model()->findByPk($degree_group->degree_id); } else { $first_level_id = $this->setFirstLevelCategory($degree_group_id); $degree = Degree::model()->findByPk($degree_group_id); } $category_id = qa_db_category_slug_to_id($first_level_id, $degree->name); if (!isset($category_id)) { $category_id = qa_db_category_create($first_level_id, $degree->name, $degree->name); } return $category_id; }
public static function myDegrees() { $user = self::get_user_logged_in(); if ($user) { $userid = $user->id; $favorites = Favorite::findByUser($userid); $degrees = array(); foreach ($favorites as $favorite) { $degrees[] = Degree::find($favorite->degree_id); } foreach ($degrees as $degree) { $institutions = $degree->institutions; $institutionList = ""; foreach ($institutions as $institution) { $institutionList = $institutionList . $institution->name; $institutionList = $institutionList . "\n"; } $degree->institutions = $institutionList; } } View::make('mydegrees.html', array('degrees' => $degrees)); }