private function graphData($type, $from, $to, $distinct = false) { if ($distinct) { return Activity::select(DB::raw('distinct `ip_address` '))->whereBetween('created_at', array($from, $to))->where('content_type', '=', $type)->count(); } else { return Activity::whereBetween('created_at', array($from, $to))->where('content_type', '=', $type)->count(); } }
function index() { $students = new Student(); $activities = new Activity(); $result = array(); $info = $this->loadModel()->selectAll(); foreach ($info as $key => $item) { extract($item["Activities_student"]); $st = $students->select($student_id); $st2 = array_shift($st); $ac = $activities->select($activity_id); $ac2 = array_shift($ac); $arr = array('student_id' => $st2['first_name'] . " " . $st2['last_name'], 'f_number' => $st2['f_number'], 'activity_id' => $ac2['name'], 'point' => $ac2['point'], 'created_at' => $created_at); array_push($result, $arr); } $this->set('students', $result); }
function handler_ajax_modify($page, $type) { $json = json_decode(Env::v('json')); if ($type == 'instance') { $id = $json->admin_id; $ai = new ActivityInstance($id); $ai->select(ActivityInstanceSelect::base()); if (!S::user()->hasRights($ai->target()->group(), Rights::admin())) { throw new Exception("Invalid credentials"); } S::assert_xsrf_token(); try { $begin = new FrankizDateTime($json->begin); $end = new FrankizDateTime($json->end); if ($ai->regular()) { $ai->comment($json->activity_comment); $ai->begin($begin); $ai->end($end); } else { $ai->begin($begin); $ai->end($end); $a = $ai->activity(); $a->title($json->title); $a->description($json->activity_description); } $page->jsonAssign('success', true); } catch (Exception $e) { $page->jsonAssign('success', false); } } else { if ($type == 'regular') { $id = $json->aid; $a = new Activity($id); $a->select(ActivitySelect::base()); if (!S::user()->hasRights($a->target()->group(), Rights::admin())) { throw new Exception("Invalid credentials"); } S::assert_xsrf_token(); if (preg_match('`^\\d{2}:\\d{2}:\\d{2}$`', $json->begin) && strtotime($json->begin) !== false && preg_match('`^\\d{2}:\\d{2}:\\d{2}$`', $json->end) && strtotime($json->end) !== false) { $a->title($json->title); $a->description($json->activity_description); $key = 'days[]'; $days = unflatten($json->{$key}); $a->days(implode(',', $days)); $a->default_begin($json->begin); $a->default_end($json->end); $page->jsonAssign('success', true); } else { $page->jsonAssign('success', false); } } } return PL_JSON; }