Example #1
0
File: B2.php Project: avz/php-b2
 private function extractWhereDef(Query $query, $args)
 {
     if (sizeof($args) === 1) {
         $query->where($args[0]);
     } else {
         $query->where($args[0], $args[1]);
     }
 }
Example #2
0
 /**
  * Limit results to only records that are eligible to be parents of the provided model.
  * Ineligible parents include: The provided model itself, models with the provided model 
  * as it's own parent already, and a model that is already the current model's parent
  *
  * @param Query $query
  * @param Model $model The model to check for eligible parents against
  * @return Query
  */
 public function scopeEligibleParents($query, $model)
 {
     $query->where('id', '!=', $model->id)->where(function ($query) use($model) {
         $query->where('parent_id', '!=', $model->id)->orWhereNull('parent_id');
     });
     if ($model->parent_id) {
         $query->where('id', '!=', $model->parent_id);
     }
     return $query;
 }
Example #3
0
 function cnt_by_opt($_tid, $_cid, $_where = '')
 {
     // $this->debug();
     $c = new Query();
     $c->from = "recruit r, recruit_opt ro";
     $c->where("ro.recruit_id = r.id");
     $c->where_eq("code_type", $_tid);
     $c->where_eq("code_id", $_cid);
     if ($_where) {
         $c->where($_where);
     }
     $res = $this->counts($c);
     return $res;
 }
 public function article($id)
 {
     $query = new Query();
     $query->where(["id = {$id}"]);
     $post = $query->findOne('Posts');
     $this->render('article.html.twig', array('post' => $post));
 }
Example #5
0
File: Bool.php Project: ajb/rfpez
 /**
  * Filters a query object
  *
  * @param Query		$query
  * @param Eloquent	$model
  *
  * @return void
  */
 public function filterQuery(&$query, $model)
 {
     //if the field is
     if ($this->value !== '') {
         $query->where($model->table() . '.' . $this->field, '=', $this->value);
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('holidays')->delete();
     $db = App::make('AccessDB');
     $query = new Query('HOLIDAYS', $db->get_dbh());
     $query->where('DURATION', '>', 0);
     $result = $query->get('HOLIDAYID,STARTTIME,DURATION');
     $result_array = [];
     foreach ($result as $row) {
         $start_time = strtotime($row['STARTTIME']);
         $duration = $row['DURATION'] - 1;
         $end_time = strtotime("+{$duration} days", $start_time);
         $result_array[] = ['id' => $row['HOLIDAYID'], 'start' => $row['STARTTIME'], 'duration' => $row['DURATION'], 'end' => date('Y-m-d H:i:s', $end_time)];
     }
     $holiday = array_chunk($result_array, 1000);
     foreach ($holiday as $value) {
         Holiday::insert($value);
     }
     $convert_file = public_path() . '\\Last Convert.txt';
     $record = explode(';', file_get_contents($convert_file));
     $record[2] = $result[count($result) - 1]['HOLIDAYID'];
     $file = fopen($convert_file, 'w');
     fwrite($file, implode(';', $record));
     fclose($file);
 }
Example #7
0
 public function testShouldGenerateSelectWithWhere()
 {
     $query = new Query('users');
     $expected = "SELECT * FROM users WHERE username = '******';";
     $query->where("username = '******'");
     $result = $query->generate();
     $this->assertEquals($expected, $result);
 }
Example #8
0
 function cnt($_where)
 {
     $c = new Query();
     if ($_where) {
         $c->where($_where);
     }
     return $this->counts();
 }
Example #9
0
 function get_by_member($_user)
 {
     $c = new Query();
     $c->from = "startup_local sl, local l";
     $c->where("sl.local_id = l.id");
     $c->where_eq("startup_id", $_user);
     $res = $this->fetch("*", $c);
     return $res;
 }
Example #10
0
 function cnt($_where = '')
 {
     // $this->debug();
     $c = new Query();
     if ($_where) {
         $c->where($_where);
     }
     return $this->counts($c);
 }
Example #11
0
 function get_by_member_c($_user)
 {
     $c = new Query();
     $c->from = "member_local ml, code c";
     $c->where("ml.local_id = c.id");
     $c->where_eq("user_id", $_user);
     $res = $this->fetch("*", $c);
     return $res;
 }
Example #12
0
 function list_($_user)
 {
     $c = new Query();
     $c->from = "member_project mp, startup s";
     $c->where("mp.startup_id = s.id");
     $c->where_eq("user_id", $_user);
     $c->order = "mp.id ASC";
     $res = $this->fetch("mp.*, s.name", $c);
     return $res;
 }
Example #13
0
 function list_($_user)
 {
     //        $this->debug();
     $c = new Query();
     $c->from = "startup_reference mr, members m";
     $c->where("mr.user_id = m.id");
     $c->where_eq("req_id", $_user);
     $c->order = "mr.date_created DESC";
     $res = $this->fetch("*, mr.date_created mr_created, mr.id mrid", $c);
     return $res;
 }
Example #14
0
 function list_($_page, $_pagesize, $_where = '', $_order = '')
 {
     // $this->debug();
     $c = new Query();
     $c->from = "members m, member_grade mg, member_interist mi";
     $c->where("mg.id = m.grade");
     $c->where("mi.user_id = m.id");
     if ($_where) {
         $c->where($_where);
     }
     if ($_order) {
         $c->order = $_order;
     } else {
         $c->order = "m.id DESC";
     }
     $c->page = $_page;
     $c->page_size = $_pagesize;
     $res = $this->fetch("m.*, mg.name gname", $c);
     return $res;
 }
Example #15
0
 function get_by_form_res_user($_fid, $_aid)
 {
     // $this->debug();
     $c = new Query();
     $c->from = "competitions_form_res cfr, competitions_form cf";
     $c->where("cf.id = cfr.c_form_id");
     $c->where_eq("c_form_id", $_fid);
     $c->where_eq("apply_id", $_aid);
     $res = $this->fetch_one("*", $c);
     return $res;
 }
Example #16
0
 static function getElectives($program, $elective_type, $elective_group, $exclude = [])
 {
     $results = array();
     foreach (explode("|", $elective_group) as $group) {
         $q = new Query("electives");
         $q->select("course_code");
         $q->where("program_id=?\n\t\t\t\t\t\t\tAND elective_type=?\n\t\t\t\t\t\t\tAND note=?\n\t\t\t\t\t\t\tAND course_code NOT IN " . Query::valuelistsql($exclude), array_merge([$program, $elective_type, $group], $exclude));
         $results = array_merge($results, $q->executeFetchAll());
     }
     return $results;
 }
Example #17
0
 function get_by_oh($_id, $_where = '')
 {
     $c = new Query();
     $c->where_eq("oh_id", $_id);
     if ($_where) {
         $c->where($_where);
     }
     $c->order = "id ASC";
     $res = $this->fetch("*", $c);
     return $res;
 }
Example #18
0
 function get_by_com_cnt($_type, $_id, $_where = '')
 {
     $c = new Query();
     $c->where_eq("com_type", $_type);
     $c->where_eq("com_id", $_id);
     if ($_where) {
         $c->where($_where);
     }
     $res = $this->counts($c);
     return $res;
 }
Example #19
0
 function list_($_page, $_pagesize, $_where = 1)
 {
     $c = new Query();
     if ($_where) {
         $c->where($_where);
     }
     $c->order = "id DESC";
     $c->page = $_page;
     $c->page_size = $_pagesize;
     $res = $this->fetch("*", $c);
     return $res;
 }
Example #20
0
 public function testWhere()
 {
     $path = __DIR__ . '/fixtures/datastore/querytest';
     $config = new Config($path . '/');
     $repo = new Repository('countries', $config);
     $query = new Query($repo);
     $query->where('cca2', '==', 'GB');
     $result = $query->execute();
     $this->assertInstanceOf('\\JamesMoss\\Flywheel\\Result', $result);
     $this->assertEquals(1, count($result));
     $this->assertEquals(1, $result->total());
 }
Example #21
0
 function get_by_member_c($_user)
 {
     //        $res = $this->cache->get('st_buss_get_by_member_c'.$_user);
     //        if (!$res) {
     $c = new Query();
     $c->from = "startup_bussiness sb, code c";
     $c->where("sb.bussiness_id = c.id");
     $c->where_eq("startup_id", $_user);
     $res = $this->fetch("*", $c);
     //            $this->cache->set('st_buss_get_by_member_c'.$_user, $res, 0);
     //        }
     return $res;
 }
Example #22
0
 function list_($_order = '', $_where = '')
 {
     // $this->debug();
     $c = new Query();
     if ($_where) {
         $c->where($_where);
     }
     if ($_order) {
         $c->order = "id DESC";
     } else {
         $c->order = "id ASC";
     }
     return $this->fetch("*", $c);
 }
Example #23
0
 function list_($_where = '', $_order = '')
 {
     // $this->debug();
     $c = new Query();
     if ($_where) {
         $c->where($_where);
     }
     if ($_order) {
         $c->order = $_order;
     } else {
         $c->order = "dates ASC";
     }
     $res = $this->fetch("*", $c);
     return $res;
 }
Example #24
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     // Clean unsent responses older than 30 minutes, since the client likely exited the page.
     $unsent_min = \Carbon\Carbon::now()->subMinutes(30);
     QueryResponse::unsent()->where('created_at', '<', $unsent_min)->delete();
     // Check the archive
     if (Config::get('lowendping.archive.enabled', false)) {
         $mintime = \Carbon\Carbon::now()->subDays(Config::get('lowendping.archive.days'));
         $queries = Query::where('created_at', '<', $mintime)->get();
         foreach ($queries as $query) {
             $this->info('Deleting query ' . $query->id);
             QueryResponse::where('query_id', $query->id)->delete();
             $query->delete();
         }
     }
 }
Example #25
0
 function list_($_page = '', $_pagesize = '', $_where = '', $_order = '')
 {
     $c = new Query();
     if ($_where) {
         $c->where($_where);
     }
     if ($_page) {
         $c->page = $_page;
     }
     if ($_pagesize) {
         $c->page_size = $_pagesize;
     }
     if ($_order) {
         $c->order = $_order;
     }
     $res = $this->fetch("*", $c);
     return $res;
 }
Example #26
0
 function get_by_key($_key, $_return = '', $_where = '', $_order = '')
 {
     // $this->debug();
     $c = new Query();
     if ($_where) {
         $c->where($_where);
     }
     $c->where_eq("_key", $_key);
     if ($_order) {
         $c->order = $_order;
     } else {
         $c->order = "id ASC";
     }
     if ($_return) {
         $res = $this->fetch($_return, $c);
     } else {
         $res = $this->fetch("*", $c);
     }
     return $res;
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('absences')->delete();
     $db = App::make('AccessDB');
     $query = new Query('USER_SPEDAY', $db->get_dbh());
     $query->where('STARTSPECDAY', '>=', '2014-07-01');
     $query->order('DATE,STARTSPECDAY');
     $result = $query->get();
     $result_array = [];
     foreach ($result as $row) {
         $result_array[] = ['start_date' => $row['STARTSPECDAY'], 'end_date' => $row['ENDSPECDAY'], 'reason' => isset($row['YUANYING']) ? $row['YUANYING'] : '', 'employee_id' => $row['USERID'], 'absence_category_id' => $row['DATEID']];
     }
     $absence = array_chunk($result_array, 1000);
     foreach ($absence as $value) {
         Absence::insert($value);
     }
     $convert_file = public_path() . '\\Last Convert.txt';
     $record = explode(';', file_get_contents($convert_file));
     $record[6] = $result[count($result) - 1]['DATE'];
     $file = fopen($convert_file, 'w');
     fwrite($file, implode(';', $record));
     fclose($file);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('manual_checks')->delete();
     $db = App::make('AccessDB');
     $query = new Query('CHECKEXACT', $db->get_dbh());
     $query->where('EXACTID', '>=', 1455);
     $query->order('EXACTID');
     $result = $query->get('EXACTID,USERID,CHECKTIME,CHECKTYPE');
     $result_array = [];
     foreach ($result as $row) {
         $result_array[] = ['date_time' => $row['CHECKTIME'], 'is_in' => $row['CHECKTYPE'] == 'I' ? 1 : 0, 'employee_id' => $row['USERID']];
     }
     $manual_check = array_chunk($result_array, 1000);
     foreach ($manual_check as $value) {
         ManualCheck::insert($value);
     }
     $convert_file = public_path() . '\\Last Convert.txt';
     $record = explode(';', file_get_contents($convert_file));
     $record[0] = $result[count($result) - 1]['EXACTID'];
     $file = fopen($convert_file, 'w');
     fwrite($file, implode(';', $record));
     fclose($file);
 }
Example #29
0
 /**
  * Save the model to the database.
  *
  * @return bool
  */
 public function save()
 {
     // If the model does not have any dirty attributes, there is no reason
     // to save it to the database.
     if ($this->exists and count($this->dirty) == 0) {
         return true;
     }
     $model = get_class($this);
     // Since the model was instantiated using "new", a query instance has not been set.
     // Only models being used for querying have their query instances set by default.
     $this->query = DB::connection(static::$connection)->table(static::table($model));
     if (property_exists($model, 'timestamps') and $model::$timestamps) {
         $this->timestamp();
     }
     // If the model already exists in the database, we will just update it.
     // Otherwise, we will insert the model and set the ID attribute.
     if ($this->exists) {
         $success = $this->query->where(static::$primary_key, '=', $this->attributes[static::$primary_key])->update($this->dirty) === 1;
     } else {
         $success = is_numeric($this->attributes[static::$primary_key] = $this->query->insert_get_id($this->attributes, static::$sequence));
     }
     $this->exists = true and $this->dirty = array();
     return $success;
 }
Example #30
-2
 public function login($login_name)
 {
     $result = array("error_code" => 0, "error_desc" => "");
     $user = $this->Users->get_by_login_name($login_name);
     if (!$user) {
         $result["error_code"] = "404";
         $result["error_desc"] = "Non-exist user";
         echo json_encode($result);
         exit(0);
     }
     $ticket = $this->Mobile_tickets->get_login_ticket($user["id"]);
     $datas = array();
     $pw_string = sha256($user["password"] . $ticket["login_ticket"]);
     $pw_input = $_REQUEST["confirm_key"];
     if ($pw_string == $pw_input) {
         $session = $this->Mobile_sessions->new_session($user["id"]);
         $datas["session_key"] = $session["session_key"];
         $datas["session_id"] = $session["id"];
     } else {
         $result["error_code"] = "403";
         $result["error_desc"] = "Key error";
         echo json_encode($result);
         exit(0);
         return;
     }
     $c = new Query();
     $c->where("id_users = " . $user["id"]);
     $this->Mobile_tickets->delete_cond($c);
     $result["result"] = $datas;
     echo json_encode($result);
     exit(0);
 }