Ejemplo n.º 1
0
 /**
  * Registers new principal and school for platform access
  * @return [type] [description]
  */
 public function register()
 {
     $this->setSEO(array("title" => "Register School"));
     $view = $this->getActionView();
     if (RequestMethods::post("action") == "register") {
         $user = new \User(array("name" => RequestMethods::post("name"), "email" => RequestMethods::post("email"), "phone" => RequestMethods::post("phone"), "username" => strtolower(implode("", explode(" ", RequestMethods::post("name")))), "password" => Markup::encrypt("password"), "admin" => 0));
         $user->save();
         $location = new Location(array("user_id" => $user->id, "address" => RequestMethods::post("address"), "city" => RequestMethods::post("city"), "latitude" => "", "longitude" => ""));
         $location->save();
         $organization = new Organization(array("user_id" => $user->id, "name" => RequestMethods::post("sname"), "location_id" => $location->id, "phone" => RequestMethods::post("sphone"), "logo" => ""));
         $organization->save();
         $view->set("success", true);
     }
 }
Ejemplo n.º 2
0
 /**
  * @before _secure, _school
  */
 public function add()
 {
     $this->setSEO(array("title" => "School | Add Grades"));
     $view = $this->getActionView();
     if (RequestMethods::post("action") == "addGrades") {
         $title = RequestMethods::post("title");
         $description = RequestMethods::post("description");
         foreach ($title as $key => $value) {
             $grade = new \Grade(array("title" => Markup::checkValue($value), "description" => Markup::checkValue($description[$key]), "organization_id" => $this->organization->id));
             $grade->save();
         }
         $view->set("success", 'Classes added successfully! See <a href="/grades/manage">Manage Classes</a>');
     }
 }
Ejemplo n.º 3
0
 /**
  * @before _secure, _school
  */
 public function create()
 {
     $this->setSEO(array("title" => "Create Exam | School"));
     $view = $this->getActionView();
     $grades = Grade::all(array("organization_id = ?" => $this->organization->id), array("id", "title"));
     if (RequestMethods::post("action") == "createExam") {
         $exams = $this->reArray($_POST);
         foreach ($exams as $e) {
             $course = $e["course"];
             if (Markup::checkValue($course)) {
                 $exam = new Exam(array("grade_id" => $e["grade"], "course_id" => $course, "user_id" => $this->user->id, "organization_id" => $this->organization->id, "type" => $e["type"], "start_date" => $e["start_date"], "start_time" => $e["start_time"] . ":00", "end_time" => $e["end_time"] . ":00"));
                 $exam->save();
             }
         }
         $view->set("success", "Exams created successfully!!");
     }
     $view->set("grades", $grades);
 }
Ejemplo n.º 4
0
 /**
  * @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);
 }
Ejemplo n.º 5
0
 /**
  * @before _secure, _school
  */
 public function addToClass($user_id)
 {
     $usr = \User::first(array("id = ?" => $user_id), array("id"));
     if (!$usr) {
         self::redirect("/school");
     }
     $this->setSEO(array("title" => "Parent Info | Student | School"));
     $view = $this->getActionView();
     $grades = \Grade::all(array("organization_id = ?" => $this->organization->id), array("id", "title"));
     $enrollment = Enrollment::first(array("user_id = ?" => $user_id));
     if ($enrollment) {
         $view->set("success", "Student has already been added! Response will be updated");
     }
     if (RequestMethods::post("action") == "addToClass") {
         $classroom = Markup::checkValue(RequestMethods::post("classroom"));
         if (!$enrollment) {
             $enrollment = new Enrollment(array());
         }
         $enrollment->user_id = $usr->id;
         $enrollment->classroom_id = $classroom;
         $enrollment->organization_id = $this->organization->id;
         if ($enrollment->validate()) {
             $enrollment->save();
             $view->set("success", "Student successfully added to classroom");
         }
     }
     if ($enrollment) {
         $class = Classroom::first(array("id = ?" => $enrollment->classroom_id), array("id", "grade_id", "section"));
         foreach ($grades as $g) {
             if ($g->id == $class->grade_id) {
                 $grade = $g->id;
                 break;
             }
         }
         $view->set("class", $class);
     }
     if (!isset($grade)) {
         $grade = null;
     }
     $view->set("grade", $grade);
     $view->set("enrollment", $enrollment);
     $view->set("grades", $grades);
 }
Ejemplo n.º 6
0
 /**
  * Sets the meta for app login
  */
 private function _meta($user, $app)
 {
     $meta = Meta::first(array("property = ?" => "user", "property_id = ?" => $user->id, "meta_key = ?" => $app . "-app"));
     if (!$meta) {
         $meta = new Meta(array("property" => "user", "property_id" => $user->id, "meta_key" => $app . "-app", "meta_value" => Markup::uniqueString(44)));
         $meta->save();
     }
     return $meta;
 }