public static function store() { $params = $_POST; $course_params = array('name' => $params['name'], 'city' => $params['city']); $course = new Course($course_params); $errors = $course->errors(); $number_of_holes = count($params) - count($course_params) - 1; // one hidden input for hole_count // Check hole validity before saving anything $holes = array(); for ($hole_num = 1; $hole_num <= $number_of_holes; $hole_num++) { $par = $params['hole' . $hole_num]; $hole = new Hole(array('hole_num' => $hole_num, 'par' => $par)); $holes[] = $hole; $errors = array_merge($errors, $hole->errors()); } if (count($errors) == 0) { // Course and holes were all valid $courseid = $course->save(); $course->number_of_holes = count($holes); foreach ($holes as $hole) { $hole->courseid = $courseid; $hole->save(); } Redirect::to('/course/' . $courseid, array('message' => 'Rata ja sen väylät lisätty.')); } else { View::make('course/new.html', array('errors' => $errors, 'attributes' => $params, 'hole_count' => $params['hole_count'])); } }
/** * 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->aCourse !== null) { if ($this->aCourse->isModified() || $this->aCourse->isNew()) { $affectedRows += $this->aCourse->save($con); } $this->setCourse($this->aCourse); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } $this->alreadyInSave = false; } return $affectedRows; }
/** * 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->aInstructor !== null) { if ($this->aInstructor->isModified() || $this->aInstructor->isNew()) { $affectedRows += $this->aInstructor->save($con); } $this->setInstructor($this->aInstructor); } if ($this->aCourse !== null) { if ($this->aCourse->isModified() || $this->aCourse->isNew()) { $affectedRows += $this->aCourse->save($con); } $this->setCourse($this->aCourse); } if ($this->isNew()) { $this->modifiedColumns[] = CourseInstructorAssociationPeer::ID; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = CourseInstructorAssociationPeer::doInsert($this, $con); $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which // should always be true here (even though technically // BasePeer::doInsert() can insert multiple rows). $this->setId($pk); //[IMV] update autoincrement primary key $this->setNew(false); } else { $affectedRows += CourseInstructorAssociationPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } if ($this->collCourseRatings !== null) { foreach ($this->collCourseRatings as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collAutoCourseRatings !== null) { foreach ($this->collAutoCourseRatings 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() { $model = new Course(); $batch = new Batch(); // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation(array($model, $batch)); if (isset($_POST['Course'])) { $model->attributes = $_POST['Course']; $model->created_by = Yii::app()->user->id; $model->created_date = new CDbExpression('NOW()'); if ($model->save()) { if (isset($_POST['Batch'])) { $batch->batch_name = $_POST['Batch']['batch_name']; $batch->batch_fees = $_POST['Batch']['batch_fees']; $batch->course_id = $model->course_id; $batch->batch_start_date = ''; $batch->batch_end_date = ''; $batch->batch_created_by = Yii::app()->user->id; $batch->batch_creation_date = new CDbExpression('NOW()'); $batch->save(false); } $this->redirect(array('view', 'id' => $model->course_id)); } } $this->render('create', array('model' => $model, 'batch' => $batch)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Course(); $model->scenario = 'create'; if (isset($_POST['Course'])) { $model->attributes = $_POST['Course']; if ($model->save()) { $this->redirect(array('index')); } } $this->render('create', array('model' => $model)); }
function test_save() { //Arrange $course_name = "Monster Literature"; $course_number = "ENG304"; $test_course = new Course($course_name, $course_number); $test_course->save(); //Act $result = Course::getAll(); //Assert $this->assertEquals($test_course, $result[0]); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Course(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Course'])) { $model->attributes = $_POST['Course']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
function testSave() { //Arrange $course_name = "HISTORY"; $number = 101; $test_course = new Course($course_name, $number); //var_dump($test_course); //Act $test_course->save(); //Assert $result = Course::getAll(); $this->assertEquals($test_course, $result[0]); }
function testCreate_OneToMany() { $this->_createModelAndIncludeThem('lecture', 'Lecture'); $this->_createModelAndIncludeThem('course', 'Course'); $course = new Course(); $course->setTitle($course_title = 'bar'); $course->save(); $lecture = new Lecture(); $lecture->setTitle($lecture_title = 'foo'); $lecture->setCourse($course); $lecture->save(); $loaded_lecture = lmbActiveRecord::findById('Lecture', $lecture->getId()); $this->assertEqual($loaded_lecture->getTitle(), $lecture_title); $this->assertEqual($loaded_lecture->getCourse()->getId(), $course->getId()); $loaded_course = lmbActiveRecord::findById('Course', $course->getId()); $this->assertEqual($loaded_course->getLectures()->at(0)->getId(), $lecture->getId()); }
function test_addStudent_and_getStudents() { $name = "Western Civ"; $number = "HST 101"; $test_course = new Course($name, $number); $test_course->save(); $name = "Chris"; $date = "1111-11-11"; $test_student = new Student($name, $date); $test_student->save(); $name2 = "Dillon"; $test_student2 = new Student($name2, $date); $test_student2->save(); $test_course->addStudent($test_student); $test_course->addStudent($test_student2); $this->assertEquals($test_course->getStudents(), [$test_student, $test_student2]); }
function test_addCourse_and_getCourses() { $name = "Western Civ"; $number = "HST 101"; $test_course = new Course($name, $number); $test_course->save(); $name2 = "Remedial Math"; $number2 = "MTH 64"; $test_course2 = new Course($name2, $number2); $test_course2->save(); $name = "Chris"; $date = "1111-11-11"; $test_student = new Student($name, $date); $test_student->save(); $test_student->addCourse($test_course); $test_student->addCourse($test_course2); $this->assertEquals($test_student->getCourses(), [$test_course, $test_course2]); }
public function save() { $adminId = Session::get('admin_id'); if (!isset($adminId)) { return json_encode(array('message' => 'not logged')); } $instituteId = Session::get('institute_id'); if (!isset($instituteId)) { return json_encode(array('message' => 'invalid')); } $course = new Course(); $course->institute_id = $instituteId; $course->name = Input::get('name'); $course->description = Input::get('description'); $course->status = 'active'; $course->created_at = date('Y-m-d h:i:s'); $course->save(); return json_encode(array('message' => 'done')); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model=new Course; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if(isset($_POST['Course'])) { $_POST['Course']['course_img']=$_FILES['Course']['name']['course_img']; $model->attributes=$_POST['Course']; $model->logo=$_FILES['Course']; if($model->save()) $this->redirect(array('view','id'=>$model->course_ID)); } $this->render('create',array( 'model'=>$model, )); }
/** * Attempts to save new course and redirect to the newly created course. */ public static function store() { $player = self::get_user_logged_in(); if (!$player) { View::make('player/login.html', array('error' => 'Vain kirjautuneet käyttäjät voivat lisätä ratoja.')); } $params = $_POST; $params['url'] = self::fix_url($params['url']); $params['mapLink'] = self::fix_url($params['mapLink']); $attributes = array('name' => $params['name'], 'description' => $params['description'], 'address' => $params['address'], 'mapLink' => $params['mapLink'], 'url' => $params['url']); $course = new Course($attributes); $errors = $course->errors(); if (count($errors) == 0) { $course->save(); Hole::create_holes($params['holes'], $course->id); Moderator::add_as_moderator($course->id, $player->id); Redirect::to('/course/' . $course->id . '/edit', array('message' => 'Rata lisätty, täydennä vielä väylien tiedot.')); } else { View::make('course/new.html', array('errors' => $errors, 'attributes' => $attributes)); } }
public function actionCreate() { if (!Yii::app()->user->getId()) { Yii::app()->user->loginRequired(); } $model = new Course(); if ($_POST['Course']) { $time_area = ''; if ($_POST['Course']['time_area']) { $time_area = serialize($_POST['Course']['time_area']); } $_POST['Course']['time_area'] = $time_area; $model->attributes = $_POST['Course']; if ($model->validate() && $model->save()) { Yii::app()->user->setFlash('course', '创建成功'); $this->redirect(array('course/index')); } } $stores = Store::model()->getName(); $this->render('create', ['model' => $model, 'stores' => $stores]); }
public function store() { $course = new Course(); $days = implode(",", Input::get('days')); $costs = Input::get('costs'); $costs = str_replace(",", ".", $costs); $costs = str_replace(".", "", $costs); $costs = substr($costs, 0, -2); $course->project_id = Auth::user()->curr_project_id; $course->location_id = Auth::user()->location_id; $course->classification_id = Input::get('classification'); $course->program_id = Input::get('program'); $course->generation_id = Input::get('generation'); $course->name = Input::get('name'); $course->description = Input::get('description'); $course->course_days = $days; $course->costs = $costs; $course->capacity = Input::get('capacity'); $course->availability = Input::get('status'); $course->save(); Session::flash('message', 'Sukses Menambahkan Kelas Baru'); }
/** * @before _secure, _school */ public function add($grade_id) { $grade = \Grade::first(array("id = ?" => $grade_id), array("title", "id", "organization_id")); if (!$grade || $grade->organization_id != $this->organization->id) { self::redirect("/school"); } $this->setSEO(array("title" => "Add Courses | School")); $view = $this->getActionView(); if (RequestMethods::post("action") == "addCourses") { $title = RequestMethods::post("title"); $description = RequestMethods::post("description"); foreach ($title as $key => $value) { $subject_title = Markup::checkValue($value); if ($subject_title) { $course = new \Course(array("title" => Markup::checkValue($value), "description" => Markup::checkValue($description[$key]), "grade_id" => $grade_id, "user_id" => $this->user->id, "organization_id" => $this->organization->id)); $course->save(); } } $view->set("success", 'Courses added successfully! <a href="/subject/manage/' . $grade_id . '">Manage Courses</a>'); } $view->set("grade", $grade); }
public function prepareData() { $semester = new Semester(); $semester['name'] = 'Semester'; $semester->save(); foreach (array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') as $name) { $weekday = new Weekday(); $weekday['name'] = $name; $weekday->save(); } for ($i = 0; $i < 3; $i++) { $course = new Course(); $course['name'] = 'Course ' . $i; $course['Semester'] = $semester; $course->save(); for ($w = 3; $w < 6; $w++) { $cw = new CourseWeekday(); $cw['Course'] = $course; $cw['weekday_id'] = $w; $cw->save(); } } }
function testFind() { $name = "John Doe"; $password = "******"; $email = "*****@*****.**"; $signed_in = 0; $test_user = new User($name, $password, $email, $signed_in); $test_user->save(); $course_title = "Literature"; $subject = "English"; $course_description = "Deconstructing English literature."; $user_id = $test_user->getId(); $test_course = new Course($course_title, $subject, $course_description, $user_id); $test_course->save(); $unit_title = "Into the Wild"; $unit_description = "The life and death of Chris McCandless."; $course_id = $test_course->getId(); $test_unit = new Unit($unit_title, $unit_description, $course_id); $test_unit->save(); $lesson_title = "Into the Wild: Chapter 1"; $objective = "Students will read and discuss Chapter 1"; $materials = "Books, discussion packets, pencils"; $body = "Lorem ipsum etc etc blah blah blah blah..."; $unit_id = $test_unit->getId(); $test_lesson = new Lesson($lesson_title, $objective, $materials, $body, $unit_id); $test_lesson->save(); $lesson_title2 = "The Catcher in the Rye: Chapter 3"; $objective2 = "Students will read and discuss Chapter 3"; $materials2 = "Books, essay prompts, pens"; $body2 = "Blah blah blah etc etc lorem ipsum..."; $test_lesson2 = new Lesson($lesson_title2, $objective2, $materials2, $body, $unit_id); $test_lesson2->save(); $result = Lesson::find($test_lesson->getId()); $this->assertEquals($test_lesson, $result); }
function testDelete() { //Arrange $course_name = "History"; $id = 1; $crn = "HIST101"; $test_course = new Course($course_name, $crn, $id); $test_course->save(); $student_name = "Paco"; $id2 = 2; $enroll_date = "2015-05-11"; $test_student = new Student($student_name, $enroll_date, $id2); $test_student->save(); //Act $test_student->addCourse($test_course); $test_student->deleteOne(); //Assert $this->assertEquals([], $test_course->getStudents()); }
function testGetUnits() { $name = "John Doe"; $password = "******"; $email = "*****@*****.**"; $signed_in = 0; $test_user = new User($name, $password, $email, $signed_in); $test_user->save(); $course_title = "Literature"; $subject = "English"; $course_description = "Deconstructing English literature."; $user_id = $test_user->getId(); $test_course = new Course($course_title, $subject, $course_description, $user_id); $test_course->save(); $title2 = "Algebra"; $subject2 = "Math"; $description2 = "Introduction to algebraic equations."; $test_course2 = new Course($title2, $subject2, $description2, $user_id); $test_course2->save(); $unit_title = "Into the Wild"; $unit_description = "The life and death of Chris McCandless."; $course_id = $test_course->getId(); $test_unit = new Unit($unit_title, $unit_description, $course_id); $test_unit->save(); $result = $test_course->getUnits(); $this->assertEquals($test_unit, $result[0]); }
function testGetCourses() { //Arrange $id = null; $name = "Intro to Math"; $number = "MATH100"; $test_course = new Course($id, $name, $number); $test_course->save(); $id2 = null; $name2 = "Underwater Basketweaving"; $number2 = "BS133"; $test_course2 = new Course($id2, $name2, $number2); $test_course2->save(); $id3 = null; $student_name = "Billy"; $enroll_date = "2015-09-18"; $test_student = new Student($id3, $student_name, $enroll_date); $test_student->save(); //Act $test_student->addCourse($test_course); $test_student->addCourse($test_course2); //Assert $this->assertEquals([$test_course, $test_course2], $test_student->getCourses()); }
function testDelete() { $name = "Math"; $date = '0000-00-00'; $id = null; $test_course = new Course($name, $id); $test_course->save(); $student_name = "Student1"; $course_id = $test_course->getId(); $test_student = new Student($student_name, $id, $date, $course_id); $test_student->save(); $test_student->addCourse($test_course); $test_student->delete(); $this->assertEquals([], $test_course->getStudents()); }
/** * Start browsing the directory and register files * * @return Exception code = 400 if directory non-existent * An array containing list of non-imported files if successful */ public function doImport() { if (!file_exists($this->_dir)) { throw new Exception("directory non-existent", 400); } $errArr = array(); $handler = opendir($this->_dir); // TODO: does not do recrusive listing, do we need that? while (false !== ($file = readdir($handler))) { if ($file != '.' && $file != '..') { $err = false; $pos = strrpos($file, '.'); $fileName = strtoupper(substr($file, 0, $pos)); $token = strtok($fileName, '_'); $counter = 0; while (false !== $token) { switch ($counter) { case 0: if (strlen($token) != 7) { $err = true; } $rawCourseCode = $token; break; case 1: if ($token != substr($this->_year, 0, 4)) { $err = true; } break; case 2: if ($token != "EXAM") { if (substr($token, 0, 5) == "EXAM(") { // name could have the following syntax: AER205S_2009_EXAM(2).pdf $count = strtok($token, '('); $count = strtok('('); $count = strtok($count, ')'); if ($count === false || !is_numeric($count)) { $err = true; } } else { $err = true; } } break; } $token = strtok("_"); $counter++; } if ($counter != 3 || $err) { $err = true; } else { // assume course code is 7 chars in length with the last char being either S, F or Y $part1 = substr($rawCourseCode, 0, 6); //e.g. AER205 $part2 = substr($rawCourseCode, 6, 1); //e.g. F switch ($part2) { case "F": case "S": $courseCode = $part1 . "H1"; $descr = $part1 . " " . $this->_year . " Official Exam" . (isset($count) ? ' (' . $count . ')' : ''); break; case "Y": $courseCode = $part1 . "Y1"; $descr = $part1 . " " . $this->_year . " Official Exam" . (isset($count) ? ' (' . $count . ')' : ''); break; default: $err = true; break; } if (!$err) { $conn = Propel::getConnection(); // check if we have exam of this descr already $examArr = ExamPeer::getExamsForYearAndCourseId($courseCode, $this->_year, $conn); foreach ($examArr as $ex) { if ($ex->getType() == EnumItemPeer::EXAM && $ex->getDescr() == $descr) { $err = true; break; } } if (!$err) { // first check if course exists $course = CoursePeer::retrieveByPK($courseCode, $conn); if (!isset($course)) { $course = new Course(); //$course->setDeptId(substr($courseCode, 0, 3)); $course->setDescr($courseCode); $course->setIsEng(1); $course->setId($courseCode); $dept = DepartmentPeer::retrieveByPK(substr($courseCode, 0, 3), $conn); if (!isset($dept)) { $dept = new Department(); $dept->setId(substr($courseCode, 0, 3)); $dept->setDescr(substr($courseCode, 0, 3)); $dept->save($conn); } $course->setDepartment($dept); $course->save($conn); } // register exam $exam = new Exam(); $exam->setType(EnumItemPeer::EXAM); $exam->setDescr($descr); $exam->setCourseId($courseCode); $exam->setFilePath($this->_dir . $file); $exam->setYear($this->_year); $exam->save(); } } } if ($err) { $errArr[] = $file; } } } closedir($handler); return $errArr; }
Request::enableHttpMethodParameterOverride(); //Home $app->get("/", function () use($app) { return $app['twig']->render('index.html.twig'); }); $app->post("/delete_courses", function () use($app) { Course::deleteAll(); return $app['twig']->render('index.html.twig'); }); //Courses $app->get("/courses", function () use($app) { return $app['twig']->render('courses.html.twig', array('courses' => Course::getAll())); }); $app->post("/courses", function () use($app) { $course = new Course($_POST['name'], $_POST['number']); $course->save(); return $app['twig']->render('courses.html.twig', array('courses' => Course::getAll())); }); $app->get("/courses/{id}", function ($id) use($app) { $course = Course::find($id); return $app['twig']->render('course.html.twig', array('course' => $course, 'students' => $course->getStudents(), 'all_students' => Student::getAll())); }); $app->get("/courses/{id}/edit", function ($id) use($app) { $course = Course::find($id); return $app['twig']->render('course_edit.html.twig', array('course' => $course)); }); $app->patch("/courses/{id}", function ($id) use($app) { $name = $_POST['name']; $course = Course::find($id); $course->update($name); return $app['twig']->render('course.html.twig', array('course' => $course, 'all_students' => Student::getAll(), 'students' => $course->getStudents()));
function testDelete() { //Arrange $name = "Biology 101"; $number = 101; $id = 1; $test_course = new Course($name, $number, $id); $test_course->save(); $name = "Elliot Michaels"; $date = "2015-08-03"; $id = 1; $test_student = new Student($name, $date, $id); $test_student->save(); //Act $test_student->addCourse($test_course); $test_student->delete(); //Assert $this->assertEquals([], $test_course->getStudents()); }
function testUpdate() { $course_name = "Vampires"; $course_number = 1; $id = 1; $test_course = new Course($course_name, $course_number, $id); $test_course->save(); $course_name2 = "Discrete Math"; $course_number2 = 1; $id2 = 2; $test_course2 = new Course($course_name2, $course_number2, $id2); $test_course2->save(); $test_course->update("BOBBIDY BEE BOO"); $result = $test_course->getCourseName(); $this->assertEquals("BOBBIDY BEE BOO", $result); }
function test_getStudents() { //Arrange $name3 = "Psychology 101"; $course_number = "PSY101"; $test_course = new Course($name3, $course_number); $test_course->save(); $name = "bob"; $date_of_enrollment = "2015-09-16"; $test_student = new Student($name, $date_of_enrollment); $test_student->save(); $name2 = "bill"; $date_of_enrollment2 = "2015-09-15"; $test_student2 = new Student($name2, $date_of_enrollment2); $test_student2->save(); //Act $test_course->addStudent($test_student->getId()); $test_course->addStudent($test_student2->getId()); //Assert $result = $test_course->getStudents(); $this->assertEquals([$test_student, $test_student2], $result); }
function test_GetAll() { $name = "Coding 101"; $enrollment_date = '0000-00-00'; $id = null; $test_course = new Course($name, $id); $test_course->save(); $student_name = "Aladdin"; $course_id = $test_course->getId(); $test_student = new Student($student_name, $id, $enrollment_date, $course_id); $test_student->save(); $student_name2 = "Jasmine"; $id2 = null; $course_id2 = $test_course->getId(); $test_student2 = new Student($student_name2, $id2, $enrollment_date, $course_id2); $test_student->save(); $result = Student::getAll(); $this->assertEquals(['test_student, $test_student2'], $result); }
function test_addCourse() { //Arrange $name = "bowling"; $id = 1; $course_number = "400"; $test_course = new Course($name, $course_number, $id); $test_course->save(); $name2 = "Lebowski"; $enrollment_date = "2015-12-12"; $id2 = 2; $test_student = new Student($name2, $enrollment_date, $id2); $test_student->save(); //Act $test_student->addCourse($test_course); $result = $test_student->getCourses(); //Assert $this->assertEquals([$test_course], $result); }