-
Notifications
You must be signed in to change notification settings - Fork 0
/
StudentClass.php
45 lines (35 loc) · 1.35 KB
/
StudentClass.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
<?php
class StudentClass extends ObjectModel
{
public $name;
public $bdate;
public $status;
public $avgscore;
public static $definition = array(
'table' => 'student',
'primary' => 'id_student',
'multilang' => true,
'fields' => array(
'name' => array('type' => self::TYPE_STRING, 'validate' => 'isString', 'lang' => TRUE),
'bdate' => array('type' => self::TYPE_DATE),
'status' => array('type' => self::TYPE_BOOL),
'avgscore' => array ('type' => self::TYPE_FLOAT)
),
);
public function getAll()
{
$sql = 'SELECT bdate, status, avgscore, student_lang.name FROM `' . _DB_PREFIX_ . self::$definition['table'] . '` s join `' . _DB_PREFIX_ . self::$definition['table'] . '_lang` l on s.id_student=l.id_student;
return Db::getInstance()->executeS($sql);
}
public function getTopStudent()
{
$sql = 'SELECT * FROM `' . _DB_PREFIX_ . self::$definition['table'] . '`
WHERE avgscore = (SELECT MAX(avgscore) FROM `' . _DB_PREFIX_ . self::$definition['table'] . '`)';
return Db::getInstance()->getValue($sql);
}
public function getTopAvgScore()
{
$sql = 'SELECT MAX(avgscore) FROM `' . _DB_PREFIX_ . self::$definition['table'] . '` ';
return Db::getInstance()->getValue($sql);
}
}