public function schoolClicked($id) { $schools = School::all(); $programs = Program::where('school_id', '=', $id)->get(); $books = Book::where('school_id', '=', $id)->get(); return view('home')->with('programs', $programs)->with('schools', $schools); }
/** * Display a listing of the resource. * * @return Response */ public function index() { // get all the schools from the database $schools = School::all(); // call the view by passing in all the schools as a variable called schools return view('schools.schoolshome', ['schools' => $schools]); }
public function profile() { $user = Auth::User(); $sections = null; $school = null; $teachingSections = null; $allSchools = School::all()->orderBy('id'); $allSections = Section::all(); $i = 0; if ($user->role == 1) { $studentSection = TeachingSection::getTeachingsectionByStudent($user); if ($studentSection === null) { } else { $school = School::getSchoolBySection($studentSection); } return view('users.profile', compact('school', 'user', 'studentSection')); } elseif ($user->role == 2) { $teacherTeachingSections = TeachingSection::getTeachingsectionsByTeacher($user); //$teacherSections有多个teachingSection if ($teacherTeachingSections === null) { } else { $teachedSections = []; foreach ($teacherTeachingSections as $teacherTeachingSection) { $section = Section::find($teacherTeachingSection->sections_id); $teachedSections[i] = $section; $i++; } $school = School::getSchoolBySection($teachedSections[0]); return view('users.profile', compact('school', 'user', 'teachedSections')); } } else { return view('users.newUserProfile', compact('user')); } //如果这个学生没有关联任何班级 $teachingSections = TeachingSection::getTeachingsectionsByUser($user); if ($teachingSections) { $sections = Section::getSectionByteachingSections($teachingSections); $school = School::getSchoolBySection($sections); return view('users.profile', compact('school', 'user', 'sections')); } else { return view('users.profile', compact('school', 'user', 'sections')); } // $sections_id = $teachingSections->id; // print_r($sections_id); // $sections = Section::getSectionByteachingSections($teachingSections); // $school = School::getSchoolBySection($sections); // 容错设计 // echo '--------------------------'; // echo '--------------------------'; // print_r($schoolName); // print_r($teachingSections->id); // print_r($teachingSections->sections_id); // print_r($teachingSections); // return view('users.profile', compact('user')); }
public function ajaxGetSchools(Request $request) { // if(Request::ajax()) { $schools = School::all(); $schools_array = array(); foreach ($schools as $key => $value) { $schools_array[] = $value; } return response()->json($schools_array); // } }
public function postAdd(Request $request) { $rules = ['school' => 'required']; $input = Input::only('school'); $validator = Validator::make($input, $rules); if ($validator->fails()) { return Redirect::back()->withInput()->withErrors($validator); } $school = new School(); $school->school_name = $request->school; $school->save(); $schools = School::all(); return redirect()->route('schools')->with('schools', $schools); }
public function getUsers(Request $request) { $lat = $request->get('lat'); $long = $request->get('long'); $schools = School::all(); $users = new \Illuminate\Database\Eloquent\Collection(); for ($i = 0; $i < $schools->count(); $i++) { $schoolLat = $schools->get($i)->latitude; $schoolLong = $schools->get($i)->longitude; if ($this->haversine($lat, $long, $schoolLat, $schoolLong) < 50) { $users->push($schools->get($i)->usersNotVoted($request->get('CurrentUser')->id)); } } return Response::json(['users' => $users->collapse()], 200); }
public function index() { return School::all(); }
/** * Output table data as csv. */ public function csv() { // grab data $data = School::all(); // create empty file $csv = Writer::createFromFileObject(new \SplTempFileObject()); // create header $csv->insertOne(\Schema::getColumnListing('schools')); // insert rows as associative array $csv->insertAll($data->toArray()); $csv->output('schools_' . \Carbon\Carbon::now()->timestamp . '.csv'); }
public function getSchools() { $schools = School::all(); return view("admin/schools")->with("schools", $schools); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { // $schools = School::all(); return view('schools.index', compact('schools')); }
public function test() { // this url below contains 200 programs. // it could be a huge performance concern if crawl it. // so I just choose the "I" category of all programs insteaded. // $url_main = "http://www.humber.ca/program"; set_time_limit(1000); // $url_main = "http://www.humber.ca/program/listings/b?school=All&credential=All&campus=All&field_program_name_value_1="; $html_main = file_get_contents($url_main); $crawler = new Crawler($html_main); $links = array(); // Simple XPath for this element, so I did not use CssSelector. $crawler->filterXPath('//tbody/tr/td/a')->each(function ($node, $i) use(&$links) { // the links in website are relative path, so I need to add a prefix to make it absolute. $prefix = "http://humber.ca"; $existed_programs = Program::all(); $existed_program_names = array(); foreach ($existed_programs as $key => $value) { $existed_program_names[] = $value['program_name']; } // get rid of the duplicated links, no idea why Humber make the program list a mess if (strpos($node->text(), ',') === false) { // get the full link $link = $prefix . $node->attr('href'); $link = trim($link); // get the text which is the program name $text = trim($node->text()); // put associate name & link to key/value pair array if (!in_array($text, $existed_program_names)) { $links["{$text}"] = $link; } } }); // an array to store all programs $programs = array(); // use a loop to crawl individual program webpage by accessing its link in $links array foreach ($links as $key => $value) { $program_url = $value; // use curl to get the webpage content // it seems file_get_contents() has some issues for these webpage // or it's just I made some mistakes $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, $program_url); curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Humber College'); $program_html = curl_exec($curl_handle); curl_close($curl_handle); if ($program_html) { $program_crawler = new Crawler($program_html); } // $program is an array to store the program's information with key/value pair $program = array(); // here I used CssSelector to help me translate the XPath. // It made me address it without headache. $program['program_name'] = trim($key); $Code = $program_crawler->filterXPath(CssSelector::toXPath('div.container.clearfix>section>div.field-items>div.field-item.even'))->text(); $program['program_code'] = trim($Code); $Credential = $program_crawler->filterXPath(CssSelector::toXPath('section.field-name-field-credential>div.field-item>a'))->text(); $program['program_credential'] = trim($Credential); $School = $program_crawler->filterXPath(CssSelector::toXPath('section.field-name-field-school>div.field-item>a'))->text(); $program['program_school'] = trim($School); // get all the schools from database $schools = School::all(); // Because I used School table's id as the foreign key in Program table. foreach ($schools as $key1 => $value1) { if ($program['program_school'] == $value1['school_name']) { $program['program_school_id'] = $value1['id']; } } // getting each courses' name/code $courses = array(); $courses = $program_crawler->filterXPath(CssSelector::toXPath('div.course'))->each(function ($node, $i) { $course = array(); $course_code = $node->children()->first()->text(); $course_name = $node->children()->last()->text(); $course['course_code'] = $course_code; $course['course_name'] = $course_name; return $course; }); $program['program_courses'] = $courses; $programs[] = $program; } // store the information from array to database through loops // just in case of accidents, I commented the inserting database code below. foreach ($programs as $key => $value) { $one_program = new Program(); $one_program->program_name = $value['program_name']; $one_program->program_code = $value['program_code']; $one_program->school_id = $value['program_school_id']; $one_program->credential = $value['program_credential']; $one_program->save(); echo "a program is saved to db" . "<br>"; foreach ($value['program_courses'] as $key2 => $value2) { // Same reason as above, I used Program table's id as foreign key in Course table $stored_programs = Program::all(); // $stored_programs = $programs; $course_belongs_id = 0; foreach ($stored_programs as $key3 => $value3) { if ($value['program_name'] == $value3['program_name']) { $course_belongs_id = $value3['id']; } } $existed_courses = Course::where('program_name', '=', $value['program_name']); $existed_course_name = array(); foreach ($existed_courses as $key => $value) { $existed_course_name[] = $value['course_name']; } if (!in_array($value2['course_name'], $existed_course_name)) { $one_course = new Course(); $one_course->course_name = $value2['course_name']; $one_course->course_code = $value2['course_code']; $one_course->program_id = $course_belongs_id; $one_course->save(); echo "a course is saved to db ---- " . $one_course->program_id . "<br>"; } } echo "<br>======<br>"; } }