Ejemplo n.º 1
0
 public static function get_popup($user_id)
 {
     $q = new query(RUDE_DATABASE_TABLE_SETTINGS);
     $q->where(RUDE_DATABASE_FIELD_USER_ID, (int) $user_id);
     $q->where(RUDE_DATABASE_FIELD_NAME, 'popup');
     $q->query();
     return $q->get_object();
 }
Ejemplo n.º 2
0
 /**
  * Scope only original data without machine error and without data marked as real error (-9999)
  * @param query     $query  Query Object
  * @param string    $type   Data type ("WATER", "RAIN")
  * @return mixed            new query object
  */
 public function scopeCleanOrigin($query, $type)
 {
     if ($type == 'WATER') {
         return $query->where('origin_water1', '!=', '999999')->where('origin_water1', '!=', '-9999');
     } elseif ($type == 'RAIN') {
         return $query->where('origin_rain1h', '!=', '999999')->where('origin_rain1h', '!=', '-9999');
     }
 }
Ejemplo n.º 3
0
 public static function get_by_report($report_id)
 {
     $q = new query(RUDE_DATABASE_TABLE_EDUCATION);
     $q->where(RUDE_DATABASE_FIELD_REPORT_ID, (int) $report_id);
     $q->where('not_save', (int) 0);
     $q->query();
     return $q->get_object_list();
 }
 public static function get($report_id = null, $year = null)
 {
     $q = new query(RUDE_DATABASE_TABLE_CALENDAR_ITEMS);
     if ($year !== null) {
         $q->where(RUDE_DATABASE_FIELD_YEAR, (int) $year);
     }
     if ($report_id !== null) {
         $q->where(RUDE_DATABASE_FIELD_REPORT_ID, (int) $report_id);
     }
     $q->query();
     return $q->get_object_list();
 }
Ejemplo n.º 5
0
 public static function get_by_shortname($shortname)
 {
     $q = new query(RUDE_DATABASE_TABLE_FACULTIES);
     $q->where(RUDE_DATABASE_FIELD_SHORTNAME, $shortname);
     $q->query();
     return $q->get_object();
 }
 public static function get_by_name($name)
 {
     $q = new query(RUDE_DATABASE_TABLE_QUALIFICATIONS);
     $q->where(RUDE_DATABASE_FIELD_NAME, $name);
     $q->query();
     return $q->get_object();
 }
Ejemplo n.º 7
0
 /**
  * Score by data type
  * @param query  $query query object
  * @param string $type  data type (water, rain)
  * @return mixed        new query object
  */
 public function scopeDataType($query, $type)
 {
     $query->join('tele_station', 'problems.station_code', '=', 'tele_station.code')->select('problems.id', 'code', 'name', 'problem_type', 'tambon_name', 'amphoe_name', 'province_name', 'part', 'basin', 'start_datetime', 'end_datetime', 'num', 'problems.status');
     if ($type) {
         return $query->where('data_type', '=', $type);
     }
     return $query;
 }
 public static function get_by_order($education_id)
 {
     $q = new query(RUDE_DATABASE_TABLE_EDUCATION_ITEMS_VALUES);
     $q->where('education_id', (int) $education_id);
     $q->order_by('order_num', 'ASC');
     $q->query();
     return $q->get_object_list();
 }
Ejemplo n.º 9
0
 public static function is_exists($id)
 {
     $q = new query(RUDE_DATABASE_TABLE_USERS);
     $q->where(RUDE_DATABASE_FIELD_ID, (int) $id);
     $q->query();
     if ($q->get_object()) {
         return true;
     }
     return false;
 }
 public static function is_exists($name)
 {
     $q = new query(RUDE_DATABASE_TABLE_TRAINING_FORM);
     $q->where(RUDE_DATABASE_FIELD_NAME, $name);
     $q->query();
     if ($q->get_object()) {
         return true;
     }
     return false;
 }
 public static function get($id = null)
 {
     $q = new query(RUDE_DATABASE_TABLE_CALENDAR_LEGEND);
     if ($id !== null) {
         $q->where(RUDE_DATABASE_FIELD_ID, (int) $id);
         $q->query();
         return $q->get_object();
     }
     $q->query();
     return $q->get_object_list();
 }
 public static function get($id = null)
 {
     $q = new query(RUDE_DATABASE_TABLE_REPORTS_CATEGORIES_ITEMS);
     if ($id !== null) {
         $q->where(RUDE_DATABASE_FIELD_ID, (int) $id);
         $q->query();
         return $q->get_object();
     }
     $q->query();
     return $q->get_object_list();
 }
Ejemplo n.º 13
0
 /**
  * scope query with filter options
  * @param  query $query
  * @return Query
  */
 public static function scopeFilter($query)
 {
     if ($name = \Request::get('q')) {
         $query->where('name', 'like', "%{$name}%");
         $query->orWhere('asset_no', 'like', "%{$name}%");
         $query->orWhere('model', 'like', "%{$name}%");
     }
     if ($category_id = \Request::get('category_id')) {
         $query->where('category_id', '=', $category_id);
     }
     if ($department_id = \Request::get('department_id')) {
         $query->where('department_id', '=', $department_id);
     }
     if ($vendor_id = \Request::get('vendor_id')) {
         $query->where('vendor_id', '=', $vendor_id);
     }
     if ($status = \Request::get('status')) {
         $query->where('status', '=', $status);
     }
     return $query;
 }
 public static function get($id = null)
 {
     $q = new query(RUDE_DATABASE_TABLE_SPECIALIZATIONS);
     if ($id !== null) {
         $q->where(RUDE_DATABASE_FIELD_ID, (int) $id);
         $q->query();
         return $q->get_object();
     }
     $q->order_by(RUDE_DATABASE_FIELD_NAME);
     $q->query();
     return $q->get_object_list();
 }
Ejemplo n.º 15
0
 /**
  * Save the user instance in database
  * @return Boolean true if successfully saved, false otherwise
  */
 public function save()
 {
     // Si l'utilisateur existe, on le met à jour
     if ($this->ok()) {
         // Mise à jour de l'utilisateur
         $user = new query();
         $user->update('user');
         foreach ($this->field as $key => $value) {
             switch ($key) {
                 case "id":
                 case "login":
                     // On ne modifie jamais l'ID de l'utilisateur et on enregistre pas le temps de mise à jour de la session s'il y en a une.
                     break;
                 default:
                     // On modifie la ligne
                     $user->set($key, trim($value));
                     break;
             }
         }
         $user->where('id', '=', $this->get('id'));
         $user->exec();
         //Mise à jour des options
         foreach ($this->create as $create) {
             $query = new query();
             $query->insert('user_option')->set('key', $create)->set('value', $this->option[$create])->set('owner', $this->get('id'))->exec();
         }
         foreach ($this->change as $change) {
             $query = new query();
             $query->update('user_option')->set('value', $this->option[$change])->where('owner', '=', $this->get('id'))->where('key', '=', $change)->exec();
         }
         return true;
         // Si l'utilisateur n'existe pas, impossible de le mettre à jour, on retourne une erreur.
     } else {
         $user = new query();
         $user->insert('user')->set('username', $this->get('username'));
         $id = $user->exec();
         $this->set('id', $id);
         $this->ok = true;
         $this->save();
         return true;
     }
 }
 /**
  * @param $attribute
  * @param $value
  * @param array $columns
  * @return mixed
  */
 public function findBy($attribute, $value, $columns = array('*'))
 {
     return $this->query->where($attribute, '=', $value)->first($columns);
 }
Ejemplo n.º 17
0
 /**
  * Get the featured posts
  * @param  query $query
  * @return query
  */
 public function scopeFeatured($query)
 {
     return $query->where('featured', true);
 }
Ejemplo n.º 18
0
Archivo: db.php Proyecto: hazardland/db
 public function delete($object)
 {
     if (is_array($object)) {
         $result = true;
         foreach ($object as $item) {
             if (!$this->delete($item)) {
                 $result = false;
             }
         }
         return $result;
     }
     if (is_object($object) && type($object) == '.db.by') {
         $query = new query();
         $query->where($object->result($this));
         $database = $this->database();
         $request = "delete from " . $this->name() . " where " . $query->where->result($this);
         $result = $database->link($this->link)->query($request);
         if ($result) {
         }
     } else {
         $database = $this->database();
         $request = "delete from " . $this->name() . " where " . $this->name($this->primary) . "='" . id($object, $this->primary->name) . "' limit 1";
         $result = $database->link($this->link)->query($request);
         if ($result) {
             $database->set($this, id($object, $this->primary->name), false);
         }
     }
 }
 public function __construct()
 {
     if (!template_session::is_admin() and !template_session::is_editor()) {
         if (get('ajax')) {
             exit(RUDE_AJAX_ACCESS_VIOLATION);
         }
         return false;
     }
     $report_id = (int) get('report_id');
     if (!$report_id) {
         $reports = new reports();
         $report_id = $reports::add();
         header('Location: /?page=reports-edit&report_id=' . $report_id);
         die;
     }
     if (get('is_tmp')) {
         $reports = new reports_preview();
     } else {
         $reports = new reports();
     }
     if (!$reports::is_exists($report_id)) {
         new template_404(true);
     }
     $this->report = $reports::get($report_id);
     if (!$this->report) {
         new template_404(true);
     }
     switch (get('task')) {
         case 'update':
             $status = true;
             exit((string) $reports::update(get('report_id'), get('year'), get('duration'), get('rector'), get('registration_number'), get('training_form_id'), get('qualification_id'), get('specialty_id'), get('specialization_id'), get('study_practice'), get('manufact_practice'), get('grad_work'), get('gos_exam')));
             break;
         case 'update_education':
             $q = new uquery(RUDE_DATABASE_TABLE_EDUCATION);
             $q->update('not_save', (int) 0);
             $q->where('id', (int) get('dis_id'));
             $q->query();
             $status = true;
             break;
         case 'update_education_item':
             $q = new uquery(RUDE_DATABASE_TABLE_EDUCATION_ITEMS);
             $q->update('order_num', (int) get('item_order'));
             $q->update('is_optional', (int) get('optional'));
             $q->where('id', (int) get('item_id'));
             $q->query();
             $status = true;
             break;
         case 'delete_item_discipline':
             $q = new dquery(RUDE_DATABASE_TABLE_EDUCATION_ITEMS);
             $q->where('id', (int) get('id'));
             $q->query();
             $status = true;
             break;
         case 'save_education':
             $data = get('data');
             $item_id = get('item_id');
             if (!$data or !$item_id) {
                 return false;
             }
             $education_items = new education_items_values();
             if ($education_items::is_exists($item_id)) {
                 $education_items::remove($item_id);
             }
             $y = 0;
             $id = $item_id[$y];
             foreach ($item_id as $d_id) {
                 $q = new dquery(RUDE_DATABASE_TABLE_EDUCATION_ITEMS_VALUES);
                 $q->where('item_id', $d_id);
                 $q->query();
             }
             $col_num = 1;
             foreach ($data as $item) {
                 if ($item != '') {
                     $education_items::add($id, $item, $col_num);
                 }
                 if ($col_num == 40) {
                     $col_num = 0;
                     $id = $item_id[$y + 1];
                     $y++;
                 }
                 $col_num++;
             }
             //debug($data);
             $status = true;
             break;
         case 'add_education':
             $tmp = education::add(get('report_id'), get('name'));
             $status = true;
             die(json_encode($tmp));
             break;
         case 'remove_education':
             education::remove(get('id'));
             break;
         case 'add_education_item':
             $tmp = education_items::add(get('education_id'), get('name'), get('order'));
             $status = true;
             die(json_encode($tmp));
             break;
         case 'copy_education':
             $education = education::get(get('dis_id'));
             $q = new cquery(RUDE_DATABASE_TABLE_EDUCATION_PREVIEW);
             $q->add('report_id', (int) get('report_id'));
             $q->add('name', $education->name);
             $q->query();
             $new_id = $q->get_id();
             $q = new query(RUDE_DATABASE_TABLE_EDUCATION_ITEMS);
             $q->where('education_id', (int) get('dis_id'));
             $q->query();
             $all_dis = $q->get_object_list();
             foreach ($all_dis as $cur_dis) {
                 $q = new cquery(RUDE_DATABASE_TABLE_EDUCATION_ITEMS_PREVIEW);
                 $q->add('name', $cur_dis->name);
                 $q->add('education_id', $new_id);
                 $q->add('order_num', $cur_dis->order_num);
                 $q->add('is_optional', $cur_dis->is_optional);
                 $q->query();
                 $new_item_id = $q->get_id();
                 $q = new query(RUDE_DATABASE_TABLE_EDUCATION_ITEMS_VALUES);
                 $q->where('item_id', $cur_dis->id);
                 $q->query();
                 $all_item_val = $q->get_object_list();
                 foreach ($all_item_val as $cur_item_val) {
                     $q = new cquery(RUDE_DATABASE_TABLE_EDUCATION_ITEMS_VALUES_PREVIEW);
                     $q->add('value', $cur_item_val->value);
                     $q->add('item_id', $new_item_id);
                     $q->add('col_num', $cur_item_val->col_num);
                     $q->query();
                 }
             }
             $status = true;
             break;
         default:
             $status = false;
             break;
     }
     if (get('ajax')) {
         if ($status) {
             exit(RUDE_AJAX_OK);
         } else {
             exit(RUDE_AJAX_ERROR);
         }
     }
     return true;
 }
Ejemplo n.º 20
0
 /**
  * Get all the posts belonging to a specific type
  * @param  query $query
  * @param  string $type
  * @return query
  */
 public function scopeType($query, $type = 'post')
 {
     return $query->where('type', '=', $type);
 }