public function process($get, $post) { $this->pageData["Title"] = "Home"; // Select all of the courses that this user is already added or ignored $query = new Query('action'); $result = $query->select('*', array(array('session_id', '=', $_COOKIE['sessionId']))); $idsAlreadyAdded = array(); foreach ($result as $action) { array_push($idsAlreadyAdded, $action->get('course_id')); } // Generate all of the courses (for testing) $allCourses = array(); $query = new Query('courses'); $result = $query->select('*', '', array('number', 'ASC'), 20, false); while ($row = mysqli_fetch_array($result)) { try { $course = new Course(); $course->findById($row['id']); if (!in_array($course->get('id'), $idsAlreadyAdded)) { // Check that this course has not been added by the user yet array_push($allCourses, array('id' => $course->get('id'), 'name' => ucwords(strtolower($course->get('name'))), 'department_id' => $course->get('department_id'), 'number' => $course->get('number'), 'description' => strlen($course->get('description')) == 0 ? 'No description' : $course->get('description'))); } } catch (Exception $e) { } } $this->pageData['allCourses'] = $allCourses; // Select all of the courses that this user is already added $query = new Query('action'); $result = $query->select('*', array(array('session_id', '=', $_COOKIE['sessionId']), array('choice', '=', 0))); $idsAlreadyAdded = array(); foreach ($result as $action) { array_push($idsAlreadyAdded, $action->get('course_id')); } // Get all of the courses in this user's session $usersCourses = array(); foreach ($idsAlreadyAdded as $courseId) { try { $course = new Course(); $course->findById($courseId); array_push($usersCourses, array('id' => $course->get('id'), 'name' => ucwords(strtolower($course->get('name'))), 'department_id' => $course->get('department_id'), 'number' => $course->get('number'))); } catch (Exception $e) { } } $this->pageData['usersCourses'] = $usersCourses; }
<?php $id = isset($vars[1]) ? $vars[1] : null; $object = Course::findById($id); if (is_null($object)) { HTML::forward('core/404'); } // handle form submission if (isset($_POST['submit'])) { $error_flag = false; /// validation // validation for $title $title = isset($_POST["title"]) ? strip_tags($_POST["title"]) : null; if (empty($title)) { Message::register(new Message(Message::DANGER, i18n(array("en" => "title is required.", "zh" => "请填写title")))); $error_flag = true; } // validation for $country_id $country_id = isset($_POST["country_id"]) ? strip_tags($_POST["country_id"]) : null; if (empty($country_id)) { Message::register(new Message(Message::DANGER, i18n(array("en" => "country_id is required.", "zh" => "请填写country_id")))); $error_flag = true; } // validation for $content $content = isset($_POST["content"]) ? $_POST["content"] : null; if (empty($content)) { Message::register(new Message(Message::DANGER, i18n(array("en" => "content is required.", "zh" => "请填写content")))); $error_flag = true; } // validation for $url $url = isset($_POST["url"]) ? strip_tags($_POST["url"]) : null;
function getClassNameById($id) { $result = new Course(); $result->findById($id); return $result->get('name'); }
<?php $id = isset($vars[1]) ? $vars[1] : null; $course = Course::findById($id); $country = $course->getCountry(); if (is_null($course)) { dispatch('site/404'); exit; } $html = new HTML(); $html->renderOut('site/components/html_header', array('title' => 'Course - ' . $course->getTitle(), 'body_class' => 'single single-ib_educator_course has-toolbar')); $html->output('<div id="page-container">'); //$html->renderOut('site/components/toptoolbar'); $html->renderOut('site/components/header'); $html->renderOut('site/course', array('breadcrumb' => $html->render('site/components/breadcrumb', array('items' => array('Home' => uri(''), $country->getName() => uri('country/' . $country->getId()), $course->getTitle() => false))), 'course' => $course, 'sidebar_right' => $html->render('site/components/sidebar_right', array('blocks' => array($html->render('site/components/sidebar_block_courses', array('course' => $course)), $html->render('site/components/sidebar_block_recent_news'), $html->render('site/components/sidebar_block_apply')))))); $html->renderOut('site/components/footer'); $html->output('</div>'); $html->renderOut('site/components/page_footer'); $html->renderOut('site/components/html_footer');
public function process($get, $post) { $this->pageData["Title"] = "Home"; //Generate the data from mysql. //NEED TO FIGURE OUT WHY COOKIE IS NOT WORKING. HERE I SET IT manually. $_COOKIE['sessionId'] = rand(880, 925); //Something wrong when no classes are taken by a given session. //I'll try to fix that someday. $Data = new Database(); //Setting up student //Replace with $session_id. The cookie doesn't work for me(Lucien) though... //$session = 912;//intval($_COOKIE['sessionId']); //echo "num: ".$session; $student = $Data->getStudent($_COOKIE['sessionId']); $studentCourses = $student->getTaken(); //echo " Session: ".$student->getId()." major: ".$student->getMajor()." year: ".$student->getYear(); foreach ($studentCourses as $course) { $result = new Course(); $result->findById($course); //echo "<h4>".$result->get('name')."<h4>"; } //Here's the array of courses generated by the Jaccard index. $JaccardCourses = $Data->getSuggestedCourses($studentCourses); // Select all of the courses that this user is already added or ignored $query = new Query('action'); $result = $query->select('*', array(array('session_id', '=', $_COOKIE['sessionId']))); $idsAlreadyAdded = array(); foreach ($result as $action) { array_push($idsAlreadyAdded, $action->get('course_id')); } // Generate all of the courses (for testing) //Get list of predicted courses from Python. $predClasses = $this->predictClasses(); $allCourses = array(); $query = new Query('courses'); //Adding predicted courses to the $allCourses array. /*foreach($predClasses as $class){ $result = new Course(); $result->findById($class['id']); array_push($allCourses,$result); }*/ //Grabs the Id's from the Jaccard Array and foreach ($JaccardCourses as $class => $score) { $result = new Course(); $result->findById($class); array_push($allCourses, $result); } //$allcourses only contains the course id's //Create new array containing all the course details based on what is in Allcourses. $allNewCourses = array(); foreach ($allCourses as $course) { try { if (!in_array($course->get('id'), $idsAlreadyAdded)) { // Check that this course has not been added by the user yet array_push($allNewCourses, array('id' => $course->get('id'), 'name' => ucwords(strtolower($course->get('name'))), 'department_id' => $course->get('department_id'), 'number' => $course->get('number'), 'description' => strlen($course->get('description')) == 0 ? 'No description' : $course->get('description'))); } } catch (Exception $e) { } } //Populate webpage with all the different courses that were predicted. $this->pageData['allCourses'] = $allNewCourses; /* IMPORTANT NODE */ ////////// // Select all of the courses that this user is already added $query = new Query('action'); $result = $query->select('*', array(array('session_id', '=', $_COOKIE['sessionId']), array('choice', '=', 1))); ///is 0 in leo's version, 1 in my old database. we need to sort that shit. $idsAlreadyAdded = array(); foreach ($result as $action) { array_push($idsAlreadyAdded, $action->get('course_id')); } // Get all of the courses in this user's session $usersCourses = array(); foreach ($idsAlreadyAdded as $courseId) { try { $course = new Course(); $course->findById($courseId); array_push($usersCourses, array('id' => $course->get('id'), 'name' => ucwords(strtolower($course->get('name'))), 'department_id' => $course->get('department_id'), 'number' => $course->get('number'))); } catch (Exception $e) { } } $this->pageData['usersCourses'] = $usersCourses; //Pushes all the new courses to the view. }