Exemplo n.º 1
0
 function index_put()
 {
     $models = json_decode($this->put('models'));
     $data["results"] = array();
     $data["count"] = 0;
     foreach ($models as $value) {
         $obj = new Unit(null, $this->entity);
         $obj->get_by_id($value->id);
         $obj->name = $value->name;
         $obj->description = $value->description;
         if ($obj->save()) {
             //Results
             $data["results"][] = array("id" => $obj->id, "name" => $obj->name, "description" => $obj->description);
         }
     }
     $data["count"] = count($data["results"]);
     $this->response($data, 200);
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
 public function submitNewUnit()
 {
     if (Session::has('username') && (Session::get('user_type') == "Root" || Session::get('user_type') == "Admin")) {
         $validator = Validator::make(array("name" => Input::get("name"), "business_line" => Input::get("business_line")), array("name" => "required", "business_line" => "required"));
         if ($validator->fails()) {
             Input::flash();
             return Redirect::to('settings/employees/addunit')->with('message', $validator->messages()->first());
         } else {
             if (!BusinessLine::find(Input::get("business_line"))) {
                 Input::flash();
                 return Redirect::to('settings/employees/addunit')->with('message', "Invalid business line.");
             } else {
                 $desc = "(" . Session::get('user_type') . ") " . "<strong>" . Session::get('username') . "</strong> has created a new Unit: <strong>" . Input::get("name") . "</strong>";
                 $unit = new Unit();
                 $unit->name = trim(Input::get("name"));
                 $unit->businessline_id = Input::get("business_line");
                 $unit->save();
                 //Log the changes made
                 $newLog = new UserLog();
                 $newLog->description = $desc;
                 $newLog->user_id = Session::get('user_id');
                 $newLog->type = "System";
                 $newLog->save();
                 return Redirect::to('settings/employees/addunit')->with('success', "You have successfully created a new unit.");
             }
         }
     } else {
         return Redirect::to("/");
     }
 }
Exemplo n.º 4
0
 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]);
 }
Exemplo n.º 5
0
    $user = User::find($user_id);
    $course = Course::find($course_id);
    //Deleting a course should also delete orphaned units
    $units = $course->getUnits();
    if (count($units) > 0) {
        foreach ($units as $unit) {
            $unit->delete();
        }
    }
    $course->delete();
    return $app['twig']->render("dashboard.html.twig", array('user' => $user, 'courses' => $user->getCourses()));
});
//Add a unit
$app->post("/add_unit/{user_id}/{course_id}", function ($user_id, $course_id) use($app) {
    $new_unit = new Unit($_POST['unit_title'], $_POST['unit_description'], $course_id);
    $new_unit->save();
    $course = Course::find($course_id);
    return $app['twig']->render("course.html.twig", array('course' => $course, 'units' => $course->getUnits(), 'user' => User::find($user_id)));
});
//================= Unit Routes =================
//Show unit
$app->get("/show_unit/{id}", function ($id) use($app) {
    $unit = Unit::find($id);
    $course_id = $unit->getCourseId();
    $course = Course::find($course_id);
    $user_id = $course->getUserId();
    return $app['twig']->render("unit.html.twig", array('unit' => $unit, 'lessons' => $unit->getLessons(), 'course' => $course, 'user' => User::find($user_id)));
});
//Edit a unit
$app->get("/show_unit_edit/{id}", function ($id) use($app) {
    $unit = Unit::find($id);