예제 #1
0
파일: user.php 프로젝트: vNative/vnative
 /**
  * Function will calculate the top publisher results
  * from the performance table
  * @return  Array of Top Earners
  */
 public static function topEarners($users, $dateQuery = [], $count = 10)
 {
     $pubClicks = [];
     $result = [];
     foreach ($users as $u) {
         $perf = \Performance::calculate($u, $dateQuery);
         $clicks = $perf['clicks'];
         if ($clicks === 0) {
             continue;
         }
         if (!array_key_exists($clicks, $pubClicks)) {
             $pubClicks[$clicks] = [];
         }
         $pubClicks[$clicks][] = AM::toObject(['name' => $u->name, 'clicks' => $clicks]);
     }
     if (count($pubClicks) === 0) {
         return $result;
     }
     krsort($pubClicks);
     array_splice($pubClicks, $count);
     $i = 0;
     foreach ($pubClicks as $key => $value) {
         foreach ($value as $u) {
             $result[] = $u;
             $i++;
             if ($i >= $count) {
                 break 2;
             }
         }
     }
     return $result;
 }
예제 #2
0
파일: patient.php 프로젝트: HLitmus/WebApp
 public static function findFamily($user)
 {
     $families = \Family::all(["user_id = ?" => $user->id], ["member_id", "relation"]);
     $fs = array();
     foreach ($families as $f) {
         $u = \User::first(["id = ?" => $f->member_id], ["name"]);
         $fs[(int) $f->member_id] = ArrayMethods::toObject(["name" => $u->name, "user_id" => $f->member_id, "relation" => $f->relation]);
     }
     return $fs;
 }
예제 #3
0
 public function all($assignments, $courses)
 {
     $user = Registry::get("session")->get("user");
     $sub = Registry::get("MongoDB")->submission;
     $submissions = $sub->find(array("user_id" => (int) $user));
     $result = array();
     foreach ($assignments as $a) {
         $course = $courses[$a->course_id];
         $submit = $this->_submission($submissions, $a);
         $data = array("title" => $a->title, "description" => $a->description, "deadline" => $a->deadline, "id" => $a->id, "course" => $course->title, "submitted" => $submit["submission"], "filename" => $a->attachment ? $a->attachment : null, "marks" => $submit["grade"], "remarks" => $submit["remarks"], "status" => $submit["status"]);
         $data = ArrayMethods::toObject($data);
         $result[] = $data;
     }
     return $result;
 }
예제 #4
0
파일: home.php 프로젝트: HLitmus/WebApp
 public function cart()
 {
     $this->seo(array("title" => "Cart", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $session = Registry::get("session");
     $cart_items = $session->get('User\\Cart:$cart', array());
     $result = $cart_items;
     if (count($cart_items) == 0 && $this->user) {
         $result = Cart::all(array("user_id = ?" => $this->user->id));
     } elseif (count($cart_items) > 0) {
         $result = array();
         foreach ($cart_items as $c) {
             $result[] = ArrayMethods::toObject($c);
         }
     }
     $view->set("items", $result);
 }
예제 #5
0
 /**
  * @before _secure, _school
  */
 public function index()
 {
     $this->setSEO(array("title" => "Admin | School | Dashboard"));
     $view = $this->getActionView();
     $counts = array();
     $counts["students"] = Scholar::count(array("organization_id = ?" => $this->organization->id));
     $counts["teachers"] = Educator::count(array("organization_id = ?" => $this->organization->id));
     $counts["classes"] = Grade::count(array("organization_id = ?" => $this->organization->id));
     $counts = ArrayMethods::toObject($counts);
     $session = Registry::get("session");
     $message = $session->get("redirectMessage");
     if ($message) {
         $view->set("message", $message);
         $session->erase("redirectMessage");
     }
     $view->set("counts", $counts);
 }
예제 #6
0
 /**
  * @before _secure, _school
  */
 public function enrollments($classroom_id, $grade_id)
 {
     $classroom = \Classroom::first(array("id = ?" => $classroom_id), array("id", "organization_id", "grade_id", "educator_id"));
     if (!$classroom || $classroom->organization_id != $this->organization->id || $classroom->grade_id != $grade_id) {
         self::redirect("/school");
     }
     $this->setSEO(array("title" => "School | View students in section"));
     $view = $this->getActionView();
     $enrollments = \Enrollment::all(array("classroom_id = ?" => $classroom_id));
     $students = array();
     foreach ($enrollments as $e) {
         $student = \Scholar::first(array("id = ?" => $e->scholar_id), array("user_id", "dob", "parent_id"));
         $parent = \StudentParent::first(array("id = ?" => $student->parent_id), array("name", "relation"));
         $usr = \User::first(array("id = ?" => $student->user_id));
         $students[] = array("name" => $usr->name, "parent_name" => $parent->name, "parent_relation" => $parent->relation, "dob" => $student->dob, "username" => $usr->username);
     }
     $students = ArrayMethods::toObject($students);
     $view->set("students", $students);
 }
예제 #7
0
파일: ini.php 프로젝트: royalwang/SwiftMVC
 /**
  * Parse files from ini and include them
  * 
  * @param type $path
  * @return type
  * @throws Exception\Argument
  * @throws Exception\Syntax
  */
 public function parse($path)
 {
     if (empty($path)) {
         throw new Exception\Argument("\$path argument is not valid");
     }
     if (!isset($this->_parsed[$path])) {
         $config = array();
         ob_start();
         include "{$path}.ini";
         $string = ob_get_contents();
         ob_end_clean();
         $pairs = parse_ini_string($string);
         if ($pairs == false) {
             throw new Exception\Syntax("Could not parse Configuration file");
         }
         foreach ($pairs as $key => $value) {
             $config = $this->_pair($config, $key, $value);
         }
         $this->_parsed[$path] = ArrayMethods::toObject($config);
     }
     return $this->_parsed[$path];
 }
예제 #8
0
 /**
  * @before _secure, memberLayout
  */
 public function stats($keyword_id)
 {
     $keyword = \Keyword::first(array("id = ?" => $keyword_id, "serp = ?" => false), array("link", "user_id", "id"));
     $this->_authority($keyword);
     Shared\Service\Social::record($keyword);
     $end_date = RequestMethods::get("enddate", date("Y-m-d"));
     $start_date = RequestMethods::get("startdate", date("Y-m-d", strtotime($end_date . "-7 day")));
     $social_media = RequestMethods::get("media", "facebook");
     $this->seo(array("title" => "Serp | Stats", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $socials = Registry::get("MongoDB")->socials;
     $start_time = strtotime($start_date);
     $end_time = strtotime($end_date);
     $obj = array();
     $records = $socials->find(array('created' => array('$gte' => new MongoDate($start_time), '$lte' => new MongoDate($end_time)), 'social_media' => (string) $social_media, 'keyword_id' => (int) $keyword->id));
     foreach ($records as $r) {
         $position = $r['count'];
         $media = array();
         $media['count_type'] = $r['count_type'];
         $media['social_media'] = $r['social_media'];
         $obj[] = array('y' => date('Y-m-d', $r['created']->sec), 'a' => $position);
     }
     $view->set("keyword", $keyword)->set("label", $media['count_type'])->set("social", array("type" => $media['count_type'], "media" => $media['social_media']))->set("data", ArrayMethods::toObject($obj));
 }
예제 #9
0
 public function enrollments($classroom, $opts = array())
 {
     $enrollments = \Enrollment::all(array("classroom_id = ?" => $classroom->id), array("user_id"));
     $students = array();
     foreach ($enrollments as $e) {
         $usr = \User::first(array("id = ?" => $e->user_id), array("name", "username"));
         if (!isset($opts['only_user'])) {
             $scholar = \Scholar::first(array("user_id = ?" => $e->user_id), array("roll_no"));
         }
         $extra = $this->_extraFields($e, $opts);
         if (isset($opts['conversation'])) {
             $extra = array('username' => $usr->username, 'class' => $classroom->grade, 'section' => $classroom->section, 'display' => $usr->name . " (Class: " . $classroom->grade . " - " . $classroom->section . ") Roll No: " . $scholar->roll_no);
         }
         if (!isset($opts['only_user'])) {
             $data = array("user_id" => $e->user_id, "name" => $usr->name, "roll_no" => $scholar->roll_no);
         } else {
             $data = array("user_id" => $e->user_id);
         }
         $data = array_merge($data, $extra);
         $data = ArrayMethods::toObject($data);
         $students[] = $data;
     }
     return $students;
 }
예제 #10
0
 /**
  * @before _secure, memberLayout
  */
 public function logs($website_id)
 {
     $this->seo(array("title" => "Logs for your website", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $this->getLayoutView()->set("logs", true);
     $mongo = Registry::get("MongoDB");
     $website = $mongo->website;
     $record = $website->findOne(array("website_id" => (int) $website_id));
     if (!$record || $record['user_id'] != $this->user->id) {
         $this->redirect("/404");
     }
     $this->_clearLogs($website_id);
     $logs = $mongo->logs;
     $where = array('website_id' => (int) $website_id);
     $page = RequestMethods::get("page", 1);
     $limit = RequestMethods::get("limit", 30);
     $count = $logs->count($where);
     $cursor = $logs->find($where, array('_id' => false));
     $cursor->skip($limit * ($page - 1));
     $cursor->limit($limit);
     $cursor->sort(array('created' => -1));
     $results = array();
     foreach ($cursor as $c) {
         $c = ArrayMethods::toObject($c);
         $results[] = $c;
     }
     $view->set("logs", $results)->set("page", $page)->set("limit", $limit)->set("actions", $this->actions)->set("ts", $this->triggers)->set("count", $count);
 }
예제 #11
0
파일: patient.php 프로젝트: HLitmus/WebApp
 /**
  * @before _secure
  */
 public function profile()
 {
     $this->seo(array("title" => "Profile", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $user = $this->user;
     $view->set("errors", array());
     if (RequestMethods::post("action") == "saveUser") {
         $user->name = RequestMethods::post("name");
         $user->phone = RequestMethods::post("phone");
         $password = RequestMethods::post("password");
         if (!empty($password)) {
             $user->password = sha1($password);
         }
         $user->save();
         $this->setUser($user);
         $view->set("success", "Info updated!!");
     }
     $locations = Location::all(array("user_id = ?" => $this->user->id), array("*"), "created", "desc");
     $family = Shared\Services\Patient::findFamily($this->user);
     $flocations = Shared\Services\Patient::familyLoc($family);
     if (RequestMethods::post("action") == "saveLocation") {
         $location_id = RequestMethods::post("location_id");
         $location = $locations[$location_id];
         $l = \Location::saveRecord(null, $location, array("validate" => true));
         if (is_array($l)) {
             $view->set("success", "Fix the following errors")->set("errors", $l);
         } else {
             $locations[$location_id] = $l;
             $view->set("success", "Updated Location");
         }
     }
     if (RequestMethods::post("addLocation")) {
         $user_id = (int) RequestMethods::post("user_id", $this->user->id);
         if ((int) $this->user->id == $user_id) {
             $u = $this->user;
         } else {
             $u = ArrayMethods::toObject(['id' => $family[$user_id]->user_id]);
         }
         $location = \Location::saveRecord($u, null, array("validate" => true));
         if (is_array($location)) {
             $view->set("success", "Fix the following errors")->set("errors", $location);
         } else {
             $view->set("success", "Added New Location");
             $arr = array($location->id => $location);
             $locations = array_merge($locations, $arr);
         }
     }
     $view->set("locations", $locations)->set("family", $family)->set("flocations", $flocations);
 }
예제 #12
0
파일: serp.php 프로젝트: SwiftDeal/detectr
 private static function makeObject($k)
 {
     return ArrayMethods::toObject(["keyword_id" => (int) $k->id, "user_id" => (int) $k->user_id, "keyword" => $k->keyword, "link" => $k->link]);
 }
예제 #13
0
 private function _findMarks($opts = array())
 {
     $setCourses = $opts["setCourses"];
     $exams = $opts["exams"];
     $results = array();
     $setResults = array();
     foreach ($exams as $e) {
         $result = ExamResult::first(array("exam_id = ?" => $e->id, "user_id = ?" => $opts["user_id"]));
         $setResults["{$result->id}"] = $result;
         $data = array("course" => $setCourses["{$e->course_id}"], "marks" => $result->marks, "course_id" => $e->course_id, "result_id" => $result->id);
         $data = ArrayMethods::toObject($data);
         $results[] = $data;
     }
     return array("results" => $results, "setResults" => $setResults);
 }
예제 #14
0
 /**
  * @before _secure, _teacher
  */
 public function submissions($assgmt_id)
 {
     $assignment = \Assignment::first(array("id = ?" => $assgmt_id));
     if (!$assignment || $assignment->user_id != $this->user->id) {
         self::redirect("/404");
     }
     $this->setSEO(array("title" => "View Assignment Submissions | Teacher"));
     $view = $this->getActionView();
     $classroom = TeacherService::$_classes[$assignment->classroom_id];
     $sub = Registry::get("MongoDB")->submission;
     $find = $sub->find(array('assignment_id' => (int) $assgmt_id));
     $submissions = array();
     foreach ($find as $f) {
         $usr = \User::first(array("id = ?" => $f['user_id']), array("name"));
         $student = \Scholar::first(array("user_id = ?" => $f['user_id']), array("roll_no"));
         $submissions[] = array("student" => $usr->name, "student_roll_no" => $student->roll_no, "response" => $f['response'], "live" => $f['live'], "submitted_on" => date('Y-m-d H:i:s', $f['created']->sec));
     }
     $submissions = ArrayMethods::toObject($submissions);
     $view->set("class", $klass);
     $view->set("submissions", $submissions);
     $view->set("assignment", $assignment);
 }
예제 #15
0
파일: admin.php 프로젝트: SwiftDeal/detectr
 /**
  * @before _secure, _admin
  */
 public function dataAnalysis()
 {
     $this->seo(array("title" => "Data Analysis", "keywords" => "admin", "description" => "admin", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     if (RequestMethods::get("action") == "dataAnalysis") {
         $startdate = RequestMethods::get("startdate");
         $enddate = RequestMethods::get("enddate");
         $model = ucfirst(RequestMethods::get("model"));
         $diff = date_diff(date_create($startdate), date_create($enddate));
         for ($i = 0; $i < $diff->format("%a"); $i++) {
             $date = date('Y-m-d', strtotime($startdate . " +{$i} day"));
             $count = $model::count(array("created LIKE ?" => "%{$date}%"));
             $obj[] = array('y' => $date, 'a' => $count);
         }
         $view->set("data", \Framework\ArrayMethods::toObject($obj));
     }
 }
예제 #16
0
파일: serp.php 프로젝트: SwiftDeal/detectr
 /**
  * See stats of a keyword
  * @before _secure, memberLayout
  */
 public function stats($keyword_id)
 {
     $keyword = \Keyword::first(array("id = ?" => $keyword_id, "serp = ?" => true));
     $this->_authority($keyword);
     $rank = Registry::get("MongoDB")->rank;
     $r = $rank->findOne(['keyword_id' => (int) $keyword->id, 'created' => date('Y-m-d')]);
     if ($keyword->live && !$r) {
         try {
             Shared\Service\Serp::record(array($keyword));
         } catch (\Exception $e) {
         }
     }
     $end_date = RequestMethods::get("enddate", date("Y-m-d"));
     $start_date = RequestMethods::get("startdate", date("Y-m-d", strtotime($end_date . "-7 day")));
     $this->seo(array("title" => "Serp | Stats", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $start_time = strtotime($start_date);
     $end_time = strtotime($end_date);
     $i = 0;
     $obj = array();
     while ($start_time < $end_time) {
         $start_time = strtotime($start_date . " +{$i} day");
         $date = date('Y-m-d', $start_time);
         $record = $rank->findOne(array('created' => $date, 'keyword_id' => (int) $keyword->id));
         if (isset($record)) {
             $position = $record['position'];
         } else {
             $position = 0;
         }
         $obj[] = array('y' => $date, 'a' => $position);
         ++$i;
     }
     $view->set("keyword", $keyword)->set("label", "Rank")->set("data", ArrayMethods::toObject($obj));
 }
예제 #17
0
 /**
  * Find all the courses to which the teacher is assigned
  * @before _secure, _teacher
  */
 public function courses()
 {
     $this->setSEO(array("title" => "Manage Your Courses | Teacher"));
     $view = $this->getActionView();
     $teaches = \Teach::all(array("user_id = ?" => $this->user->id, "live = ?" => true));
     $grades = \Grade::all(array("organization_id = ?" => $this->organization->id), array("id", "title"));
     $storedGrades = array();
     foreach ($grades as $g) {
         $storedGrades[$g->id] = $g;
     }
     $courses = TeacherService::$_courses;
     $classes = TeacherService::$_classes;
     $result = array();
     foreach ($teaches as $t) {
         $grade = $storedGrades[$t->grade_id];
         $class = $classes[$t->classroom_id];
         $course = $courses[$t->course_id];
         $asgmnt = \Assignment::count(array("course_id = ?" => $t->course_id));
         $data = array("grade" => $grade->title, "grade_id" => $g->id, "section" => $class->section, "course" => $course->title, "course_id" => $course->id, "classroom_id" => $class->id, "assignments" => $asgmnt);
         $data = ArrayMethods::toObject($data);
         $result[] = $data;
     }
     $session = Registry::get("session");
     if ($session->get('Notification\\Students:$sent')) {
         $view->set("success", "Notification sent to students");
         $session->erase('Notification\\Students:$sent');
     }
     $view->set("courses", $result);
 }
예제 #18
0
 protected static function _findClasses($teaches)
 {
     $class_ids = array();
     foreach ($teaches as $t) {
         $class_ids[] = $t->classroom_id;
     }
     $class_ids = array_unique($class_ids);
     $classes = array();
     foreach ($class_ids as $key => $value) {
         $k = \Classroom::first(array("id = ?" => $value));
         $g = \Grade::first(array("id = ?" => $k->grade_id));
         $data = array("id" => $k->id, "grade_id" => $g->id, "grade" => $g->title, "section" => $k->section, "year" => $k->year, "educator_id" => $k->educator_id);
         $classes[$k->id] = ArrayMethods::toObject($data);
     }
     return $classes;
 }
예제 #19
0
 protected function setPagination($pageRoot, $current, $start = 1, $end = 5)
 {
     $count = array();
     for ($i = $start; $i <= $end; ++$i) {
         $count[] = $i;
     }
     $pagination = array('pageRoot' => $pageRoot, 'count' => $count, 'firstPage' => $start, 'currentPage' => $current, 'lastPage' => $end);
     $pagination = ArrayMethods::toObject($pagination);
     return $pagination;
 }
예제 #20
0
 /**
  * Finds the conversations for the student
  * @before _secure
  */
 public function find()
 {
     $this->setSEO(array("title" => "Messages | Student"));
     $view = $this->getActionView();
     $this->layoutView->set("scholar", true);
     $mongo = Registry::get("MongoDB");
     $conv_users = $mongo->conv_users;
     $conv = $mongo->conversation;
     $records = $conv_users->find(array('user_id' => (int) $this->user->id, 'live' => true));
     $conversations = array();
     foreach ($records as $r) {
         $c = $conv->findOne(array('_id' => $r['conversation_id']));
         $usr = User::first(array("id = ?" => $c['user_id']), array("name"));
         $d = array("teacher" => $usr->name, "id" => $c['_id']->{'$id'}, "created" => date('Y-m-d H:i:s', $c['created']->sec));
         $conversations[] = ArrayMethods::toObject($d);
     }
     $view->set("conversations", $conversations);
 }
예제 #21
0
 /**
  * Fetch notifications for the APP
  * @before _secure
  */
 public function fetch($return = false)
 {
     if (!$return) {
         $this->JSONView();
         $view = $this->getActionView();
     }
     $notifications = Registry::get("MongoDB")->notifications;
     $records = $notifications->find(array('recipient' => 'user', 'recipient_id' => (int) $this->user->id));
     $records->sort(array('created' => -1, 'live' => 1));
     $results = array();
     foreach ($records as $r) {
         $d = array("id" => $r['_id']->{'$id'}, "content" => $r['template'], "url" => $r['url'], "created" => date('Y-m-d H:i:s', $r['created']->sec), "read" => $r['live'], "type" => $r['type'], "type_id" => $r['type_id']);
         $results[] = ArrayMethods::toObject($d);
     }
     if ($return) {
         return $results;
     }
     $view->set("notifications", count($results) == 0 ? ArrayMethods::toObject(array()) : $results);
 }
예제 #22
0
 /**
  * @before _secure, _student
  */
 public function courses()
 {
     $this->setSEO(array("title" => "Result | Student"));
     $view = $this->getActionView();
     $session = Registry::get("session");
     $courses = StudentService::$_courses;
     $result = array();
     $sub = Registry::get("MongoDB")->submission;
     foreach ($courses as $c) {
         $a = Assignment::count(array("course_id = ?" => $c->id));
         $s = $sub->count(array("course_id" => (int) $c->id, "user_id" => (int) $this->user->id));
         $data = array("_title" => $c->title, "_description" => $c->description, "_grade_id" => $c->grade_id, "_id" => $c->id, "_assignments" => $a, "_assignment_submitted" => $s);
         $data = ArrayMethods::toObject($data);
         $result[] = $data;
     }
     $view->set("courses", $result);
 }
예제 #23
0
 /**
  * Returns an array of objects
  * @return array|string Array of objects of \stdClass (success), Error Message (failure)
  */
 protected function _getSiteMaps(&$gClient, $website, $opts = array())
 {
     try {
         $webmaster = new Google_Service_Webmasters($gClient);
         $sitemaps = $webmaster->sitemaps;
         $response = $sitemaps->listSitemaps($website, $opts);
         $response = $response->getSitemap();
         $result = array();
         foreach ($response as $r) {
             $contents = $r->getContents();
             $content = array();
             foreach ($contents as $c) {
                 $content[] = array("type" => $c->type, "submitted" => $c->submitted, "indexed" => $c->indexed);
             }
             $result[] = array("path" => $r->path, "errors" => $r->errors, "pending" => $r->isPending, "type" => $r->type, "warnings" => $r->warnings, "lastDownloaded" => array_shift(StringMethods::match($r->lastDownloaded, "(.*)T")), "lastSubmitted" => array_shift(StringMethods::match($r->lastSubmitted, "(.*)T")), "contents" => $content);
         }
         $result = ArrayMethods::toObject($result);
     } catch (\Exception $e) {
         $result = $e->getMessage();
     }
     return $result;
 }
예제 #24
0
파일: runner.php 프로젝트: HLitmus/WebApp
 /**
  * @before _secure, _vendor
  */
 public function create()
 {
     $this->seo(array("title" => "Create runner", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $msg = "";
     $centres = Centre::all(array("organization_id = ?" => $this->organization->id), array("id", "location_id"));
     $upload = function ($key) {
         if (isset($_FILES["image"]["name"][$key])) {
             $file = $_FILES["image"];
             $path = APP_PATH . "/public/assets/uploads/images/";
             $extension = pathinfo($file["name"][$key], PATHINFO_EXTENSION);
             if (!preg_match("/^(jpe?g|gif|png|bmp)\$/", $extension)) {
                 return false;
             }
             $filename = uniqid() . ".{$extension}";
             if (move_uploaded_file($file["tmp_name"][$key], $path . $filename)) {
                 return $filename;
             } else {
                 return FALSE;
             }
         } else {
             return false;
         }
     };
     if (RequestMethods::post("phone")) {
         $phone = RequestMethods::post("phone");
         $name = RequestMethods::post("name");
         $centre_id = RequestMethods::post("centre_id");
         foreach ($phone as $key => $value) {
             if (!empty($value)) {
                 $exist = User::first(array("phone = ?" => $phone[$key]), array("id"));
                 $img = $upload($key);
                 if (!$img) {
                     $msg = 'Not a vaild image';
                 } else {
                     if ($exist) {
                         $msg = 'Phone number already exists';
                     }
                 }
                 if (!$exist && $img) {
                     $user = new User(array("name" => $name[$key], "email" => "", "phone" => $phone[$key], "password" => sha1(rand(100000, 9999999)), "gender" => $gender[$key], "birthday" => "", "live" => true));
                     $user->save();
                     foreach ($centre_id[$key] as $k => $v) {
                         $runner = new Member(array("user_id" => $user->id, "organization_id" => $this->organization->id, "centre_id" => $v, "designation" => "runner", "image" => $img, "live" => true));
                         $runner->save();
                     }
                     $msg = "Runner Created Successfully";
                 } else {
                     $msg .= ", Not all were added";
                 }
             }
         }
         $view->set("message", $msg);
     }
     $locations = array();
     foreach ($centres as $c) {
         $l = Location::first(array("id = ?" => $c->location_id), array("area_id"));
         $a = Area::first(array("id = ?" => $l->area_id), array("name", "id"));
         $data = array("id" => $c->id, "name" => $a->name);
         $data = ArrayMethods::toObject($data);
         $locations[$c->id] = $data;
     }
     $view->set("centres", $locations);
 }
예제 #25
0
 public function results($course)
 {
     $exams = \Exam::all(array("course_id = ?" => $course->id), array("year", "type", "id"));
     $result = array();
     foreach ($exams as $e) {
         $whole_class = \ExamResult::all(array("exam_id = ?" => $e->id), array("marks", "user_id"));
         $total = 0;
         $highest = -1;
         $count = 0;
         $user_marks = 0;
         foreach ($whole_class as $w_c) {
             $total += $w_c->marks;
             if ((int) $w_c->marks > $highest) {
                 $highest = (int) $w_c->marks;
             }
             if ($w_c->user_id == self::$_student->user_id) {
                 $user_marks = (int) $w_c->marks;
             }
             ++$count;
         }
         $data = array("type" => $e->type, "year" => $e->year, "exam_id" => $e->id, "marks" => $user_marks, "highest" => $highest, "average" => $total / $count);
         $data = ArrayMethods::toObject($data);
         $result[] = $data;
     }
     return $result;
 }
예제 #26
0
파일: ping.php 프로젝트: SwiftDeal/detectr
 /**
  * @before _secure, memberLayout
  */
 public function stats()
 {
     $this->seo(array("title" => "Ping | Stats", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $url = RequestMethods::get("link");
     $ping = Registry::get("MongoDB")->ping;
     $search = array('user_id' => (int) $this->user->id, 'url' => $url);
     $record = $ping->findOne($search);
     if (!$record) {
         $this->redirect("/404");
     }
     $end_date = RequestMethods::get("enddate", date("Y-m-d"));
     $start_date = RequestMethods::get("startdate", date("Y-m-d", strtotime($end_date . "-7 day")));
     $start_time = strtotime($start_date);
     $end_time = strtotime($end_date);
     $ping_stats = Registry::get("MongoDB")->ping_stats;
     $records = $ping_stats->find(array('ping_id' => $record['_id'], 'created' => array('$gte' => new \MongoDate($start_time), '$lte' => new \MongoDate($end_time))));
     $obj = array();
     foreach ($records as $r) {
         $obj[] = array('y' => date('Y-m-d H:i:s', $r['created']->sec), 'a' => $r['latency']);
     }
     $view->set('ping', ArrayMethods::toObject($record))->set('label', 'Latency')->set('data', ArrayMethods::toObject($obj));
 }
예제 #27
0
 public function popularPackages()
 {
     $this->seo(array("title" => "Popular Packages", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $organizations = Organization::all(array("live = ?" => true), array("id", "name"));
     $limit = RequestMethods::get("limit", 10);
     $page = RequestMethods::get("page", 1);
     $packages = Package::all(array("live = ?" => 1), array("title", "organization_id", "charge", "id"), "created", "desc", $limit, $page);
     $total = (int) Package::count(array("live = ?" => 1));
     $results = array();
     foreach ($packages as $p) {
         $data = array("title" => $p->title, "lab" => $organizations[$p->organization_id]->name, "lab_id" => $p->organization_id, "charge" => $p->charge, "id" => $p->id);
         $results[] = ArrayMethods::toObject($data);
     }
     $view->set("packages", $results)->set("total", $total);
 }