This repository has been archived by the owner on Jul 14, 2022. It is now read-only.
/
grades_model.php
93 lines (67 loc) · 2.01 KB
/
grades_model.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
class Grades_model extends CI_Model {
public function __construct()
{
parent::__construct();
}
public function save_grade($lab, $score)
{
$this->load->database();
$this->load->library('session');
$user = $this->session->userdata('id');
$this->db->set('id', $user)
->set('lab', $lab)
->set('grade', $score);
$this->db->insert('grades');
return true;
}
public function has_taken($lab)
{
$this->load->database();
$this->load->library('session');
$user = $this->session->userdata('id');
$this->db->where('id', $user)
->where('lab', $lab);
$query = $this->db->get('grades');
if ($query->num_rows() > 0)
return true;
return false;
}
public function grades_for_user()
{
$this->load->database();
$this->load->library('session');
$user = $this->session->userdata('id');
$this->db->where('id', $user);
$query = $this->db->get('grades');
$output = array();
foreach ($query->result_array() as $grade)
$output[$grade['lab']] = $grade['grade'];
return $output;
}
public function grades_for_class()
{
$this->load->database();
$this->load->library('session');
$section = $this->session->userdata('section_id');
$this->db->where('section_id', $section);
$this->db->where('account_type', 'student');
$query = $this->db->get('users');
$output = array();
$user_ids = array();
foreach ($query->result_array() as $user)
{
$user_ids[] = $user['id'];
$output[$user['id']] = $user;
}
$this->db->where_in('id', $user_ids);
$query = $this->db->get('grades');
foreach ($query->result_array() as $grade)
{
if (!isset($output[$grade['id']]['grades']))
$output[$grade['id']]['grades'] = array();
$output[$grade['id']]['grades'][$grade['lab']] = $grade['grade'];
}
return $output;
}
}