Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once __DIR__.'/config.php';
- function countTotalEvent()
- {
- $total = db()->table('match_event')->select('count(*) as total');
- $total = json_decode($total);
- return $total[0]->total;
- }
- function getGroupName($group_id) {
- $condition = 'where id = ?';
- $queryParameterValue = array($group_id);
- $result = db()->table('groups')->select('name',$condition,$queryParameterValue);
- $result = json_decode($result);
- return $result[0]->name;
- }
- function getGroupScoreByEvent($event_id,$group_id)
- {
- $condition = 'where match_event_id = ? AND group_id = ?';
- $queryParameterValue = array($event_id,$group_id);
- $result = db()->table('match_score')->select('score',$condition,$queryParameterValue);
- $result = json_decode($result);
- if (count($result) > 0) {
- return $result[0]->score;
- }
- else {
- return "No Score Found Yet";
- }
- }
- function loginAdmin($username,$password)
- {
- $condition = 'where username = ? AND password = ?';
- $queryParameterValue = array($username,md5($password));
- // First check if the record exist based on the given credential
- $checkIfExist = db()->table('users')->select('count(*) as total',$condition,$queryParameterValue);
- $checkIfExist = json_decode($checkIfExist);
- if ($checkIfExist[0]->total > 0) {
- //After we check the record exist, then we create the session and allow the admin to enter the system.
- $getAdminDetails = db()->table('users')->select('id,username,role',$condition,$queryParameterValue);
- $getAdminDetails = json_decode($getAdminDetails);
- $_SESSION['admin'] = array(
- 'id' => $getAdminDetails[0]->id,
- 'username' => $getAdminDetails[0]->username,
- 'role' => $getAdminDetails[0]->role
- );
- return true;
- }
- else {
- return false;
- }
- }
- function authenticate()
- {
- if (isset($_SESSION['admin'])) {
- return true;
- }
- else {
- header("Location: index.php");
- }
- }
- function addNewGroup($name,$school_name)
- {
- $queryParameterValue = array($name,$school_name);
- $insert = db()->table('groups')->insert('name,school_name',$queryParameterValue);
- if ($insert) {
- return true;
- }
- else {
- return false;
- }
- }
- function getListGroups()
- {
- $listGroups = db()->table('groups')->select('id,name');
- $listGroups = json_decode($listGroups);
- return $listGroups;
- }
- function addNewParticipant($fullname,$group_id)
- {
- $queryParameterValue = array($fullname,$group_id);
- $insert = db()->table('users')->insert('fullname,group_id',$queryParameterValue);
- if ($insert) {
- return true;
- }
- else {
- return false;
- }
- }
- //baru tambah
- function getAllListParticipant()
- {
- $condition = 'where role = student';
- $queryParameterValue = array($fullname,$group_id);
- $result = db()->table('users')->select('fullname','group_id',$condition,$queryParameterValue);
- $result=json_decode($result);
- return $result;
- }
- function addNewEventMatch($date_match,$home_group_id,$away_group_id,$name)
- {
- $queryParameterValue = array($home_group_id,$away_group_id,$date_match,$name);
- $checkIfEventNameExist = db()->table('match_event')->select('count(*) as total','where name = ? limit 1',array($name));
- $checkIfEventNameExist = json_decode($checkIfEventNameExist);
- if ($checkIfEventNameExist[0]->total > 0) {
- return false;
- }
- else {
- $insert = db()->table('match_event')->insert('home_group_id,away_group_id,date_match,name',$queryParameterValue);
- if ($insert) {
- return true;
- }
- else {
- return false;
- }
- }
- }
- function getListEventMatch()
- {
- $listAllMatchEvent = db()->table('match_event')->select('id,name');
- $listAllMatchEvent = json_decode($listAllMatchEvent);
- return $listAllMatchEvent;
- }
- function getEventMatchName($match_event_id)
- {
- $condition = 'where id = ?';
- $queryParameterValue = array($match_event_id);
- $matchEventName = db()->table('match_event')->select('name',$condition,$queryParameterValue);
- $matchEventName = json_decode($matchEventName);
- return $matchEventName[0]->name;
- }
- function addNewEventMatchScore($match_event_id,$group_id,$score)
- {
- $queryParameterValue = array($match_event_id,$group_id,$score);
- $insert = db()->table('match_score')->insert('match_event_id,group_id,score',$queryParameterValue);
- if ($insert) {
- return true;
- }
- else {
- return false;
- }
- }
- function getListEventMatchScore()
- {
- $listAllMatchEventScore = db()->table('match_score')->select('id,match_event_id,group_id');
- $listAllMatchEventScore = json_decode($listAllMatchEventScore);
- $temp = array();
- foreach ($listAllMatchEventScore as $key => $value) {
- $temp[] = (object) array(
- 'id' => $listAllMatchEventScore[$key]->id,
- 'name' => getEventMatchName($listAllMatchEventScore[$key]->match_event_id)." ( ".getGroupName($listAllMatchEventScore[$key]->group_id)." )"
- );
- }
- return $temp;
- }
- function getDetailsEventMatchScoreByID($id)
- {
- $condition = 'where id = ? limit 1';
- $queryParameterValue = array($id);
- $result = db()->table('match_score')->select('id,match_event_id,group_id,score',$condition,$queryParameterValue);
- $result = json_decode($result);
- return $result[0];
- }
- function updateEventMatchScore($match_score_id,$match_event_id,$group_id,$score)
- {
- $condition = 'where id = ?';
- $queryParameterValue = array($match_event_id,$group_id,$score,$match_score_id);
- $update = db()->table('match_score')->update('match_event_id = ?,group_id = ?,score = ?',$condition,$queryParameterValue);
- if ($update) {
- return true;
- }
- else {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement