Example #1
0
 public static function getById($id)
 {
     $result = Db::selectOne('SELECT * FROM ' . self::getDbTable() . ' WHERE id = :id', array('id' => $id));
     if (empty($result)) {
         return null;
     }
     $class = get_called_class();
     return new $class($result);
 }
Example #2
0
 public static function get($sql, $vars = array())
 {
     $class = self::getClass();
     $result = Db::selectOne($sql, $vars);
     if (empty($result)) {
         return null;
     }
     return new $class($result);
 }
 public static function getRandom()
 {
     return new Quarter(Db::selectOne('SELECT * FROM quarter ORDER BY RAND() LIMIT 1'));
 }
Example #4
0
 public function getFacebookUser($register_url)
 {
     $fb_user = API_Facebook::getUser($register_url);
     if (empty($fb_user) || !is_object($fb_user)) {
         return false;
     }
     foreach ($this->getFields() as $key => $value) {
         if (property_exists($fb_user, $key)) {
             $this->{$key} = $fb_user->{$key};
         }
     }
     // @FIXME
     $this->password = password_hash($this->fb_id . '-' . $this->email, PASSWORD_BCRYPT);
     $fb_user = Db::selectOne('SELECT * FROM user WHERE fb_id = :fb_id', array('fb_id' => $this->fb_id));
     if (!empty($fb_user)) {
         $user = new User($fb_user);
         return $user->login();
     }
     $this->id = $this->facebookRegister();
     if (!empty($this->id)) {
         return $this->login();
     }
 }
Example #5
0
 public function getPicture()
 {
     $result = Db::selectOne('SELECT src FROM photo WHERE info_id = :info_id', array('info_id' => $this->id));
     if (empty($result)) {
         $picture = new Picture();
         $picture->src = 'http://placehold.it/60x60';
         return $picture;
     }
     return new Picture($result);
 }
Example #6
0
         $files[$quarter_id] = array();
     }
     $find_type = false;
     foreach ($types as $type_name => $type_id) {
         if (strpos($value, $type_name) !== false) {
             $find_type = true;
             if (empty($files[$quarter_id][$type_id])) {
                 $files[$quarter_id][$type_id] = array();
             }
             $sub_folder = trim(str_replace($folder . '/' . $quarter_name . '/' . $type_name, '', $value), '/');
             $sub_folder = ucwords(Utils::cleanString(dirname($sub_folder), ' '));
             if (empty($sub_folder)) {
                 $files[$quarter_id][$type_id][0][] = $value;
                 continue;
             }
             $info = Db::selectOne('SELECT id, name FROM info WHERE name LIKE :name', array('name' => '%' . $sub_folder . '%'));
             if (!empty($info)) {
                 //echo $sub_folder.' => '.print_r($info['id'], true).'<br>';
                 if (empty($files[$quarter_id][$type_id][$info['id']])) {
                     $files[$quarter_id][$type_id][$info['id']] = array();
                 }
                 $files[$quarter_id][$type_id][$info['id']][] = $value;
             } else {
                 $errors[] = $sub_folder;
             }
         }
     }
     if (!$find_type) {
         $files[$quarter_id][0][] = $value;
     }
 }
 public function setPresence($day = null)
 {
     if (is_null($day)) {
         $day = date('Y-m-d');
     }
     $this->presence = new Presence(Db::selectOne('SELECT * FROM presence WHERE student_id = :student_id AND day = :day', array('student_id' => $this->id, 'day' => $day)));
 }
Example #8
0
 public static function selectOne($sql, $bindings = array())
 {
     $entity = get_called_class();
     return new $entity(Db::selectOne($sql, $bindings));
 }
 public function presence()
 {
     $id = $this->getParam(0, 0);
     $presences = array(array('Type', 'Count'), array('R1', 0), array('R2', 0), array('D1', 0), array('D2', 0), array('Absent', 0));
     if (!empty($id)) {
         $student_presence = Db::selectOne('SELECT SUM(r1) as R1, SUM(r2) as R2, SUM(d1) as D1, SUM(d2) as D2, SUM(absent) as Absent FROM presence GROUP BY student_id HAVING student_id = :student_id', array('student_id' => $id));
         if (!empty($student_presence)) {
             $presences = array(array('Type', 'Count'), array('R1', !empty($student_presence['R1']) ? (int) $student_presence['R1'] : 0), array('R2', !empty($student_presence['R2']) ? (int) $student_presence['R2'] : 0), array('D1', !empty($student_presence['D1']) ? (int) $student_presence['D1'] : 0), array('D2', !empty($student_presence['D2']) ? (int) $student_presence['D2'] : 0), array('Absent', !empty($student_presence['Absent']) ? (int) $student_presence['Absent'] : 0));
         }
     }
     $this->response->addVar('presences_data', json_encode($presences));
     return $this->base_list('presence', array('student_id', 'day', 'r1', 'r2', 'd1', 'd2', 'absent', 'motif'));
 }
Example #10
0
<?php

require_once 'config/config.conf.php';
try {
    $articles = Db::selectAll('SELECT * FROM posts LIMIT 5');
    echo Utils::debug($articles);
    echo '<hr>';
    $article = Db::selectOne('SELECT * FROM posts WHERE id = :id', array(':id' => 23));
    echo Utils::debug($article);
} catch (Exception $e) {
    echo $e->getMessage();
}