public function store() { $school = new School(); $school->city_id = Input::get('city'); $school->name = Input::get('name'); $school->address = Input::get('address'); $school->contact = Input::get('contact'); $school->contact_person = Input::get('contact_person'); $school->level = Input::get('level'); $school->save(); Session::flash('message', 'Sukses menambahkan Sekolah Baru!'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // $school = new School(); $school->name = $request->name; $school->address = $request->address; $school->state = $request->state; $school->zipcode = $request->zipcode; $school->country = $request->country; $school->save(); return $school->toJson(); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new School(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['School'])) { $model->attributes = $_POST['School']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->idschool)); } } $this->render('create', array('model' => $model)); }
public static function createSchool($domain, $schoolName, $contactName, $contactEmail, $password, $bgColor, $bgImg) { $newSchool = new School(); $newSchool->domain = $domain; $newSchool->schoolName = $schoolName; $newSchool->contactName = $contactName; $newSchool->contactEmail = $contactEmail; $newSchool->contactPassword = sha1($password); $newSchool->bgColor = $bgColor; $newSchool->bgImg = $bgImg; $newSchool->save(); return $newSchool; }
public function actionIndex() { $this->bodyId = 'page-school'; if (Yii::app()->request->isPostRequest) { $obj = array(); //图片不存在 if (!isset($_FILES['photo'])) { $obj['extra']['code'] = '400'; exit(json_encode($obj)); } //图片超过 2M $maxFileSize = Yii::app()->params['uploadMaxSize'] + 1; if ($_FILES['photo']['size'] > $maxFileSize) { $obj['extra']['code'] = '400'; $obj['extra']['errors'] = ['photo' => '最大2M']; exit(json_encode($obj)); } if (isset($_POST['project'])) { $_POST['project'] = json_encode($_POST['project']); } $school = new School(); $school->attributes = $_POST; $school->photo = EEH::moveUploadFile($_FILES['photo'], Yii::app()->params['uploadPathImage'] . 'school_photo/'); // 压缩图片 $info = pathinfo($school->photo); $smallFile = Yii::app()->params['uploadPathImage'] . 'school_photo/' . $school->photo; $bigFile = Yii::app()->params['uploadPathImage'] . 'school_photo/' . $info['filename'] . '_origin.' . $info['extension']; $image = Yii::app()->image->load($smallFile); $image->save($bigFile); // 保存原文件 $image->resize(Yii::app()->params['uploadMaxWidth'], Yii::app()->params['uploadMaxHeight'])->quality(Yii::app()->params['uploadQuality']); $image->save($smallFile); // 保存压缩后文件 if (!$school->save()) { $obj['extra']['code'] = '400'; foreach ($school->errors as $key => $value) { $obj['extra']['errors'][$key] = $value; } } else { $obj['extra']['desc'] = '报名成功。'; $obj['extra']['code'] = '200'; } exit(json_encode($obj)); } $this->render('index'); }
/** * Store a newly created resource in storage. * * @return Response */ public function storeKindergarten() { $data = Input::only('name', 'description', 'contacts', 'financing_id', 'district_id', 'city_id'); $school = new School(); $school->name = $data['name']; $school->type_id = '5'; $school->description = $data['description']; $school->contacts = $data['contacts']; $school->cover_photo = Input::file('cover_photo'); $school->financing_id = $data['financing_id']; $school->city_id = $data['city_id']; try { $school->save(); } catch (ValidationException $errors) { return Redirect::route('admin.kindergartens.create')->withErrors($errors->getErrors())->withInput(); } return Redirect::route('admin.kindergartens.create')->withErrors(array('mainSuccess' => 'Детската градина е успешно добавена.')); }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aSchool !== null) { if ($this->aSchool->isModified() || $this->aSchool->isNew()) { $affectedRows += $this->aSchool->save($con); } $this->setSchool($this->aSchool); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } if ($this->termsScheduledForDeletion !== null) { if (!$this->termsScheduledForDeletion->isEmpty()) { TermQuery::create()->filterByPrimaryKeys($this->termsScheduledForDeletion->getPrimaryKeys(false))->delete($con); $this->termsScheduledForDeletion = null; } } if ($this->collTerms !== null) { foreach ($this->collTerms as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { if ($this->CanAccess('create')) { $model = new School(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['School'])) { $model->attributes = $_POST['School']; if ($model->CanUpdate() && $model->save()) { // if AJAX request , we should not redirect the browser if (!Yii::app()->request->isAjaxRequest) { $this->redirect(array('view', 'id' => $model->id)); } else { // UNCOMMENT THIS IF YOU WANT TO RETURN ID OF THE NEWLY CREATED // OBJECT (USEFUL WHEN CREATING NEW OBJECTS VIA AJAX AND INFO ABOUT // THEN NEWLY CREATED OBJECT MUST BE SENT TO THE BROWSER) // echo CJSON::encode(array('error' => '', 'id' => $model->id)); // die(); } } else { throw new CHttpException(405, Yii::t('app', 'You do not have permissions to access this page.')); } } if (!Yii::app()->request->isAjaxRequest) { $this->render('create', array('model' => $model)); // IF YOU NEED DIFFERENT RENDERING FOR AJAX AND NON-AJAX CALLS, // USE THIS LINE AND DELETE THE LINE ABOVE // $this->render('create', array('model' => $model, 'ajaxRendering' => false)); } else { throw new CHttpException(400, Yii::t('app', 'Bad request. The request cannot be fulfilled.')); // IF YOU NEED DIFFERENT RENDERING FOR AJAX AND NON-AJAX CALLS, // USE THIS LINE AND DELETE THE LINE ABOVE // $this->renderPartial('create', array('model' => $model, 'ajaxRendering' => true)); } } else { throw new CHttpException(405, Yii::t('app', 'You do not have permissions to access this page.')); } }
/** * Execute the console command. * * @return mixed */ public function fire() { $school = new School(); $school->name = 'cool school'; $school->save(); $group = new Group(); $group->name = 'Admin'; $group->school_id = $school->id; $group->password = "******"; $group->save(); $user = new User(); $user->name = 'Alex Leung'; $user->email = '*****@*****.**'; $user->group_id = $group->id; $user->password = Hash::make("alexpass"); $user->save(); $user = new User(); $user->name = 'Krishang Swami'; $user->email = '*****@*****.**'; $user->group_id = $group->id; $user->password = Hash::make("krishpass"); $user->save(); }
public function addAction() { try { $name = Input::get('name'); $description = Input::get('description'); $address = Input::get('address'); $publish = Input::get('publish'); $school = new School(); $school->name = $name; $school->description = $description; $school->address = $address; $school->published = $publish; $school->save(); $id = DB::getPdo()->lastInsertId(); $schools = explode(',', $school); //Session::put('id', $id); Session::flash('status_success', 'Successfully Updated.'); return Redirect::route('admin/schoolEdit', array('id' => $id)); //return Redirect::route('admin/classEdit'); } catch (Exception $ex) { echo $ex; Session::flash('status_error', ''); } }
$app->get('/', function () use($app, $data) { $data['schools'] = School::with('User')->orderBy('name', 'ASC')->get()->toArray(); $app->render('schools/overview.html', $data); })->name('schools_overview'); $app->map('/delete/:id', function ($id) use($app, $data) { $data['school'] = School::find($id); if ($app->request->isPost()) { $data['school']->delete(); } $app->render('schools/delete.html', $data); })->via('GET', 'POST')->name('schools_delete'); $app->map('/new', function () use($app, $data) { if ($app->request->isPost()) { $school = new School(); $school->name = $app->request->post('name'); $school->save(); $data['new_school'] = $school; } $app->render('schools/new.html', $data); })->via('GET', 'POST')->name('schools_new'); $app->map('/edit/:id', function ($id) use($app, $data) { $data['request_method'] = $app->request->getMethod(); $school = School::find($id); if ($app->request->isGet()) { $data['school'] = $school->toArray(); } else { if ($app->request->isPost()) { $school->name = $app->request->post('name'); $school->save(); $data['new_school'] = $school->toArray(); }
public function postregister() { $rules = array('state' => 'required', 'city' => 'required', 'other_city' => 'required_if:city,other', 'centre' => 'required_if:city,other', 'school' => 'required', 'name' => "required_if:school,other|string", 'addr1' => 'required_if:school,other', 'pincode' => 'required_if:school,other|digits:6', 'contact' => 'required_if:school,other', 'squad' => 'required', 'language' => 'required', 'name1' => "required|Regex:/^[\\p{L} .'-]+\$/", 'email1' => 'required|email', 'contact1' => 'required|numeric', 'name2' => "required|Regex:/^[\\p{L} .'-]+\$/", 'email2' => 'required|email', 'contact2' => 'required|numeric'); $messages = array('name.regex' => 'School name can have words, commas, dashes, single quotes and dots.', 'pincode.digits' => 'Pincode can have exactly 6 digits.', 'contact.numeric' => 'School contact can have only digits.', 'name1.regex' => 'Name of Particpant 1 can have words, commas, dashes, single quotes and dots.', 'contact1.numeric' => 'Contact of Participant 1 can have only digits.', 'email1.email' => 'Email ID of Participant 1 has to be a valid email address.', 'name2.regex' => 'Name of Particpant 2 can have words, commas, dashes, single quotes and dots.', 'contact2.numeric' => 'Contact of Participant 2 can have only digits.', 'email2.email' => 'Email ID of Participant 2 has to be a valid email address.'); $validator = Validator::make(Input::all(), $rules, $messages); if ($validator->fails()) { Input::flash(); return Redirect::to('register')->withErrors($validator)->withInput(); } else { if (Input::get('city') === 'other') { $city = new City(); $city->name = ucwords(strtolower(Input::get('other_city'))); $city->state_id = Input::get('state'); $state = State::where('id', Input::get('state'))->first(); $city->region = $state->region; // $code=City::where('region', $state->region)->orderBy('code', 'desc')->first(); // $city->code=($code->code) + 1; $city->save(); $cities = City::where('name', Input::get('other_city'))->orderBy('id', 'desc')->first(); $city = $cities->id; } else { $city = Input::get('city'); } if (Input::get('centre') !== "") { $centre = Input::get('centre') * 10; } else { $centre = $city * 10; } if (Input::get('school') === 'other') { $school = new School(); $school->name = strtoupper(Input::get('name')); $school->address = strtoupper(Input::get('addr1') . ', ' . Input::get('addr2')); $school->pincode = Input::get('pincode'); $school->contact = Input::get('contact'); $school->email = Input::get('email'); $school->city_id = $city; $school->save(); $schools = School::where('name', Input::get('name'))->orderBy('id', 'desc')->first(); $school = $schools->id; } else { $school = Input::get('school'); } $user = new User(); $user->name1 = strtoupper(Input::get('name1')); $user->email1 = Input::get('email1'); $user->contact1 = Input::get('contact1'); $user->name2 = strtoupper(Input::get('name2')); $user->email2 = Input::get('email2'); $user->contact2 = Input::get('contact2'); $user->squad = Input::get('squad'); $user->school_id = $school; $user->language = Input::get('language'); $user->city_id = $city; $user->centre_id = $centre; $roll = ""; if (Input::get('squad') === 'JUNIOR') { $roll = "J"; } else { $roll = "H"; } if (Input::get('language') === 'en') { $roll .= "E"; } else { $roll .= "H"; } $centre_id = City::where('id', $centre / 10)->orderBy('id')->first(); // $code=$centre_id->id; $roll .= $centre_id->code; $roll .= 1; $lastroll = User::withTrashed()->where('roll', 'LIKE', "%{$roll}%")->count(); $roll .= str_pad(strval($lastroll + 1), 4, "0", STR_PAD_LEFT); $user->roll = $roll; $user->year = 2015; $password = str_random(6); $user->password = Hash::make($password); $user->save(); $school = School::find($user->school_id); $city = City::find($user->city_id); $state = State::find($city->state_id); Mail::send('emails.registered', array('user' => $user, 'school' => $school, 'city' => $city, 'state' => $state, 'password' => $password, 'name' => $user->name1), function ($message) use($user) { $message->to($user->email1, $user->name1)->subject('Technothlon Registration Details'); }); Mail::send('emails.registered', array('user' => $user, 'school' => $school, 'city' => $city, 'state' => $state, 'password' => $password, 'name' => $user->name2), function ($message) use($user) { $message->to($user->email2, $user->name2)->subject('Technothlon Registration Details'); }); Input::flush(); // return Redirect::route('home'); return View::make('layouts.registersuccess')->with('user', $user); } }
public function import($content) { $header_cols = array('name' => 0, 'school_category_id' => 1, 'level_of_education' => 2, 'post' => 3, 'postal_code' => 4, 'municipality_id' => 5, 'region_id' => 6, 'country_id' => 7); header('Content-Type: text/html; charset=utf-8'); $lines = explode("\n", $content); for ($i = 1; $i < count($lines); ++$i) { if (trim($lines[$i]) == '') { continue; } $cols = explode(";", $lines[$i]); // država $country_id = 0; $country = Country::model()->find('country=:country', array(':country' => trim($cols[$header_cols['country_id']]))); if ($country == null) { echo Yii::t('app', 'Country does not exist! Country: ') . trim($cols[$header_cols['country_id']]); die; } $country_id = $country->id; // regija $region = Region::model()->find('name=:name and country_id=:country_id', array(':name' => trim($cols[$header_cols['region_id']]), ':country_id' => $country_id)); if ($region == null) { $region = new Region(); $region->country_id = $country_id; $region->name = trim($cols[$header_cols['region_id']]); $region->save(); } $region_id = $region->id; // občina $municipality = Municipality::model()->find('name=:name and country_id=:country_id', array(':name' => trim($cols[$header_cols['municipality_id']]), ':country_id' => $country_id)); if ($municipality == null) { $municipality = new Municipality(); $municipality->country_id = $country_id; $municipality->name = trim($cols[$header_cols['municipality_id']]); $municipality->save(); } $municipality_id = $municipality->id; $school_name = trim($cols[$header_cols['name']]); if ($school_name[0] == '"') { $school_name = mb_substr($school_name, 1, mb_strlen($school_name, 'UTF-8') - 2, 'UTF-8'); } $school_name = str_replace('""', '"', $school_name); $school = School::model()->find('name=:name and country_id=:country_id', array(':name' => $school_name, ':country_id' => $country_id)); if ($school == null) { $school = new School(); $school->name = $school_name; $school->country_id = $country_id; $school->municipality_id = $municipality_id; $school->region_id = $region_id; $school->post = trim($cols[$header_cols['post']]); $school->postal_code = trim($cols[$header_cols['postal_code']]); $school->school_category_id = (int) trim($cols[$header_cols['school_category_id']]); $school->level_of_education = (int) trim($cols[$header_cols['level_of_education']]); $school->save(); echo 'Imported: ', $school_name, "<br />\n"; if (count($school->errors) > 0) { print_r($school->errors); die; } } else { echo 'Already imported: ', $school_name, "<br />\n"; } } }
public static function SyncZavodiWhereKategorijaActive() { $schoolCategories = SchoolCategory::model()->findAll('active=:active', array(':active' => 1)); $kategorije = array(); $kategorija_map = array(); foreach ($schoolCategories as $schoolCategory) { $kategorije[] = $schoolCategory->name; $kategorija_map[$schoolCategory->name] = $schoolCategory->id; } echo "Current categories for sync:<br />"; pre_print($kategorije); $list = self::GetRegZavod(); if (!isset($list['return'])) { return array(); } $list = $list['return']; echo "Current schools to sync:<br />"; $country = Country::model()->find('country=:country', array(':country' => 'Slovenija')); if ($country == null) { echo "Add country Slovenija!<br />\n"; die; } $country_id = $country->id; // cache all občine $municipalities = Municipality::model()->findAll('country_id=:country_id', array(':country_id' => $country_id)); $municipality_map = array(); foreach ($municipalities as $municipality) { $municipality_map[$municipality->name] = $municipality->id; } // cache all regije $regions = Region::model()->findAll('country_id=:country_id', array(':country_id' => $country_id)); $region_map = array(); foreach ($regions as $region) { $region_map[$region->name] = $region->id; } $counter = 0; $updated = 0; $inserted = 0; for ($i = 0; $i < count($list); ++$i) { if (in_array($list[$i]['KATEGORIJA'], $kategorije)) { $counter++; $el = $list[$i]; $school = School::model()->find('name=:name and country_id=:country_id', array(':name' => trim($el['ZAVOD_NAZIV']), ':country_id' => $country_id)); if ($school == null) { $school = new School(); $school->name = trim($el['ZAVOD_NAZIV']); $school->country_id = $country_id; $inserted++; } $school->school_category_id = $kategorija_map[trim($el['KATEGORIJA'])]; // občina if (!isset($municipality_map[trim($el['OBCINANAZIV'])])) { $municipality = new Municipality(); $municipality->name = trim($el['OBCINANAZIV']); $municipality->country_id = $country_id; $municipality->save(); $municipality_map[trim($el['OBCINANAZIV'])] = $municipality->id; } $school->municipality_id = $municipality_map[trim($el['OBCINANAZIV'])]; // regija if (!isset($region_map[trim($el['REGIJANAZIV'])])) { $region = new Region(); $region->name = trim($el['REGIJANAZIV']); $region->country_id = $country_id; $region->save(); $region_map[trim($el['REGIJANAZIV'])] = $region->id; } $school->region_id = $region_map[trim($el['REGIJANAZIV'])]; $school->post = trim($el['POSTANAZIV']); $school->postal_code = trim($el['POSTASIFRA']); $school->identifier = trim($el['ZAVPRS']); $school->headmaster = trim($el['ZAVRAVN']); if (isset($el['ZAVDAVST'])) { $school->tax_number = trim($el['ZAVDAVST']); } if ($school->save()) { $updated++; } } } echo 'Found schools to sync: ', $counter, "<br />\n"; echo 'New schools imported: ', $inserted, "<br />\n"; echo 'Updated schools: ', $updated - $inserted, "<br />\n"; }
/** * Assuming there exists an activerecord array */ public function updateSchoolDataArray($arObject, $collectionName, $collectionClassName, $itemCount, $arryUpdateFields, $req) { //$arryRecords=array(); // Loop once for each array item to be added for ($index = 1; $index < $itemCount + 1; $index++) { foreach ($arryUpdateFields as $fieldName) { $indexedFieldname = $fieldName . $index; $indexedValue = $req[$indexedFieldname]; //print("ADDing $fieldName => $indexedValue<p>"); $arryUpdates[$fieldName] = $indexedValue; //var_dump($indexedValue); } if (strlen($arryUpdates['school_name']) > 0) { $arryRecords[] = $arryUpdates; } } //print("Creating these records<p>"); //var_dump($arryRecords); // Delete all existing associations $colClass = new $collectionClassName(); $colClass->delete_all("user_id=" . $this->uid); //create and add new school items foreach ($arryRecords as $record) { $newArryRecords[] = new $collectionClassName($record); } // We can't save these school items unless they have school_id's // So we must either lookup or create new ones $count = 0; foreach ($newArryRecords as $userProfEduItem) { $schoolName = $userProfEduItem->school_name; $school = new School(); //print("Query For: "."name='$schoolName' and school_type='".$arryRecords[$count]['attended_for']."'"); $school = $school->find_first("name='{$schoolName}' and school_type='" . $arryRecords[$count]['attended_for'] . "'"); if ($school == null) { $school = new School(array('school_type' => $arryRecords[$count]['attended_for'], 'name' => $schoolName)); $school->save(); $school = $school->find_first("name='{$schoolName}' and school_type='" . $arryRecords[$count]['attended_for'] . "'"); } // Now a school exists and we can update the Edu Item $userProfEduItem->school_id = $school->id; $count++; } // Now save our user prof items $arObject->{$collectionName} = $newArryRecords; return $arObject->save(); }
public function changerequestAction() { $this->response->setHeader("Content-Type", "text/plain; charset=utf-8"); $id = $this->request->getQuery('id', 'int'); $agree = $this->request->getQuery('agree', 'int'); $req = Request::findFirst($id); if ($req != false) { $this->db->begin(); // 新建学校 if ($agree) { $school = new School(); $school->name = $req->name; $school->district = $req->district; if (!$school->save()) { foreach ($school->getMessages() as $message) { echo $message; } $this->db->rollback(); return; } } // 设定管理员和学校关联 $manager = $req->getManager(); $manager->school_id = $school->school_id; if (!$manager->save()) { foreach ($manager->getMessages() as $message) { echo $message; } $this->db->rollback(); return; } // 更新状态 $req->statue = $agree; if ($req->save()) { echo "1"; $this->db->commit(); $this->view->disable(); } else { foreach ($req->getMessages() as $message) { echo $message; } $this->db->rollback(); return; } } else { echo "0"; } }
private function newschool($name, $district, $manager) { // 新建学校 $school = new School(); $school->name = $name; $school->district = $district; if (!$school->save()) { foreach ($school->getMessages() as $message) { $this->db->rollback(); throw new PDOException($message); } } // 设定管理员和学校关联 $manager->school_id = $school->school_id; if (!$manager->save()) { foreach ($manager->getMessages() as $message) { $this->db->rollback(); throw new PDOException($message); } } }
public function actionRegisterLinkedIn() { // 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 $config['base_url'] = 'http://' . Yii::app()->request->getServerName() . '/JobFair/index.php/user/auth1.php'; $config['callback_url'] = 'http://' . Yii::app()->request->getServerName() . '/JobFair/index.php/user/RegisterLinkedIn'; $config['linkedin_access'] = '2rtmn93gu2m4'; $config['linkedin_secret'] = 'JV0fYG9ls3rclP8v'; include_once Yii::app()->basePath . "/views/user/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); // get user by linkedinid $model = new User(); $user = User::model()->findByAttributes(array('linkedinid' => $data->id)); // check if user exits in database, if so login if ($user != null) { if ($user->disable != 1) { $identity = new UserIdentity($user->username, ''); if ($identity->authenticateOutside()) { Yii::app()->user->login($identity); } $this->redirect("/JobFair/index.php/home/studenthome"); return; } else { $this->redirect("/JobFair/index.php/site/page?view=disableUser"); return; } // register } else { // print "<pre>"; print_r('user is null');print "</pre>"; // check that there is no duplicate user if so link to that account $duplicateUser = User::model()->findByAttributes(array('email' => $data->{'email-address'})); if ($duplicateUser != null) { // get username and link the accounts $username = $duplicateUser->username; $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; } } // ----------------------SKILLS---------------------- if ($duplicateUser->disable != 1) { $identity = new UserIdentity($duplicateUser->username, ''); if ($identity->authenticateOutside()) { Yii::app()->user->login($identity); } $mesg = "LinkedIn"; //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()); } $this->actionLinkTo($data->{'email-address'}, $data->{'first-name'}, $data->{'last-name'}, $picture, $mesg, $phone, $city, $state, $about_me); return; } else { $this->redirect("/JobFair/index.php/site/page?view=disableUser"); return; } } // Populate user attributes $model->FK_usertype = 1; $model->registration_date = new CDbExpression('NOW()'); $model->activation_string = 'linkedin'; $model->username = $data->{'email-address'}[0]; $model->first_name = $data->{'first-name'}; $model->last_name = $data->{'last-name'}; $model->email = $data->{'email-address'}; $model->image_url = $data->{'picture-urls'}->{'picture-url'}[0]; $model->linkedinid = $data->id; //Hash the password before storing it into the database $hasher = new PasswordHash(8, false); $model->password = $hasher->HashPassword('tester'); $model->activated = 1; $model->has_viewed_profile = 1; $model->save(false); // // ------------------BASIC INFO--------------- $basic_info = null; $basic_info = BasicInfo::model()->findByAttributes(array('userid' => $model->id)); if ($basic_info == null) { $basic_info = new BasicInfo(); } $basic_info->userid = $model->id; $basic_info->phone = $data->{'phone-numbers'}->{'phone-number'}->{'phone-number'}; $basic_info->city = $data->location->name; $basic_info->state = ''; $basic_info->about_me = $data->headline; $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' => $model->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 = $model->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' => $model->id)); foreach ($delete_pos as $de) { $de->delete(); } for ($i = 0; $i < $pos_count; $i++) { $new_pos = new Experience(); $new_pos->FK_userid = $model->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' => $model->id, 'skillid' => Skillset::model()->findByAttributes(array('name' => $data->skills->skill[$i]->skill->name))->id)) == null) { $new_sdnt_skill = new StudentSkillMap(); $new_sdnt_skill->userid = $model->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); } } // ----------------------SKILLS---------------------- // LOGIN $user = User::model()->find("username=:username", array(':username' => $model->username)); $identity = new UserIdentity($user->username, 'tester'); if ($identity->authenticate()) { Yii::app()->user->login($identity); } $this->redirect("/JobFair/index.php/user/ChangeFirstPassword"); } }
public function addschool() { $rules = array('name' => 'required|string|max:250', 'address' => 'required|string|max:250', 'pincode' => 'required|numeric|digits:6', 'contact' => 'required|string|max:250', 'email' => 'required|email'); $v = Validator::make(Input::all(), $rules); if ($v->fails()) { return 'There are errors in input. Please refresh and try again.'; } $school = new School(); $school->name = Input::get('name'); $school->address = Input::get('address'); $school->pincode = Input::get('pincode'); $school->email = Input::get('email'); $school->contact = Input::get('contact'); $school->verified = 1; $school->city_id = Auth::crep()->get()->city_id; $school->comments = 'Added by ' . Auth::crep()->get()->name . ' on ' . date('H:i:s d-m-Y', time()); $school->save(); return '<option value="' . $school->id . '">' . $school->name . '</option>'; }