get_ip(); $data['last_ip'] = $this->get_user_agent(); return $data; } /** * If you need to modify payload before edit, overload this function * * @param mixed $data * @return mixed */ protected function _post_edit_processing($data) { return $data; } /** * Allow user to add extra counting condition so user don't have to change main function * * @param mixed $parameters * @return $db */ protected function _custom_counting_conditions(&$db) { return $db; } function get_ip() { if(!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip = $_SERVER['REMOTE_ADDR']; } return $ip; } function get_user_agent() { return $_SERVER['HTTP_USER_AGENT']; } public function get_user ($where) { return $this->_join ('user', 'user_id', $where, []); } public function get_user_paginated ($page, $limit, $where, $order_by, $direction) { return $this->_join_paginate ('user', 'user_id', $where, $page, $limit, $order_by, $direction, []); } public function count_paginated ($where) { return count($this->_join ('user', 'user_id', $where, [])); } public function getMemberAccountData(){ $data = [ 'month'=>0, 'week'=>0, 'year'=>0, 'total'=>0 ]; $result = $this->db->select('count(*) as count')->from('phinxlog')->where('breakpoint',0)->get()->row_array(); if($result){ $data['total'] = $result['count']; } $result = $this->db->select('count(id) as count')->from('credential')->where('role_id',2)->where('MONTH(created_at) =',date('n')) ->where('YEAR(created_at)',date('Y'))->get()->row_array(); if($result){ $data['month'] = $result['count']; } $result = $this->db->select('count(id) as count')->from('credential')->where('role_id',1) ->where('YEAR(created_at) =',date('Y'))->get()->row_array(); if($result){ $data['year'] = $result['count']; } $result = $this->db->select('count(id) as count')->from('credential')->where('role_id',1) ->where('YEARWEEK(created_at, 1) = YEARWEEK(CURDATE(), 1)')->get()->row_array(); if($result){ $data['week'] = $result['count']; } return $data; } public function getMemberUploadData(){ $data = [ 'month'=>0, 'week'=>0, 'year'=>0, 'total'=>0 ]; $result = $this->db->select('count(id) as count')->from('inventory')->where('status',1)->get()->row_array(); if($result){ $data['total'] = $result['count']; } $result = $this->db->select('count(id) as count')->from('inventory')->where('status',1)->where('MONTH(created_at) =',date('n')) ->where('YEAR(created_at)',date('Y'))->get()->row_array(); if($result){ $data['month'] = $result['count']; } $result = $this->db->select('count(id) as count')->from('inventory')->where('status',1) ->where('YEAR(created_at) =',date('Y'))->get()->row_array(); if($result){ $data['year'] = $result['count']; } $result = $this->db->select('count(id) as count')->from('inventory')->where('status',1) ->where('YEARWEEK(created_at, 1) = YEARWEEK(CURDATE(), 1)')->get()->row_array(); if($result){ $data['week'] = $result['count']; } return $data; } public function getAccountsBySchool(){ $result = $this->db->select('count(c.id) as count,s.name as school')->from('credential c') ->join('member_profile m','m.user_id=c.user_id') ->join('school s','s.id=m.school_id','left') ->where('c.role_id',1) ->group_by('m.school_id') ->order_by('count') ->limit(5) ->get()->result_array(); return $result; } public function getUploadsBySchool(){ $result = $this->db->select('count(i.id) as count,s.name as school')->from('inventory i') ->join('school s','s.id=i.school_id') ->where('i.status',1) ->group_by('i.school_id') ->order_by('count') ->limit(5) ->get()->result_array(); return $result; } }