예제 #1
0
 /**
  * @module org.rhaco.net.Session
  * @param int $maxlifetime
  * @return boolean
  */
 public function session_gc($maxlifetime)
 {
     try {
         static::find_delete(Q::lt('expires', time() - $maxlifetime));
         static::commit();
         return true;
     } catch (\Exception $e) {
     }
     return false;
 }
예제 #2
0
 public static function main()
 {
     \org\rhaco\Log::info('main');
     $obj = new \test\model\TestModelLog();
     $obj->run();
     foreach (\test\model\TestModel::find(new \org\rhaco\Paginator(1), \org\rhaco\store\db\Q::order('-id')) as $o) {
         \org\rhaco\Log::info($o->id());
         $o->number(100);
         $o->save();
     }
     $dao = new \test\model\TestModel();
     $dao->number(1);
     $dao->save();
 }
예제 #3
0
파일: Base.php 프로젝트: tokushima/rhaco3
 protected function column_alias_sql(Dao $dao, Column $column, Q $q, $alias = true)
 {
     $column_str = $alias ? $column->table_alias() . '.' . $this->quotation($column->column()) : $this->quotation($column->column());
     if ($q->ignore_case()) {
         return 'upper(' . $column_str . ')';
     }
     return $column_str;
 }
예제 #4
0
파일: Dt.php 프로젝트: tokushima/rhaco3
 /**
  * SmtpBlackholeDaoから送信されたメールの一番新しいものを返す
  * @param string $to
  * @param string $subject
  * @param number $late_time sec
  * @throws \LogicException
  * @return \org\rhaco\net\mail\module\SmtpBlackholeDao
  */
 public static function find_mail($to, $keyword = null, $late_time = 60)
 {
     if (empty($to)) {
         throw new \LogicException('`to` not found');
     }
     $result = array();
     $q = new Q();
     $q->add(Q::eq('to', $to));
     $q->add(Q::gte('create_date', time() - $late_time));
     if (!empty($subject)) {
         $q->add(Q::contains('subject', $subject));
     }
     foreach (\org\rhaco\net\mail\module\SmtpBlackholeDao::find($q, Q::order('-id')) as $mail) {
         $value = $mail->subject() . $mail->message();
         if (empty($keyword) || mb_strpos($value, $keyword) !== false) {
             return $mail;
         }
     }
     throw new \LogicException('指定のメールが飛んでいない > [' . $to . '] ' . $keyword);
 }
예제 #5
0
파일: Dt.php 프로젝트: tokushima/rhaco3
 private function filter_find($class, $order)
 {
     $object_list = array();
     $paginator = new \org\rhaco\Paginator(20, $this->in_vars('page', 1));
     $paginator->cp(array('order' => $order));
     if ($this->is_vars('search_clear')) {
         $object_list = $class::find_all($paginator, Q::select_order($order, $this->in_vars('porder')));
         $this->rm_vars();
     } else {
         if ($this->is_vars('search')) {
             $q = new \org\rhaco\store\db\Q();
             foreach ($this->ar_vars() as $k => $v) {
                 if ($v !== '' && strpos($k, 'search_') === 0) {
                     list(, $type, $key) = explode('_', $k, 3);
                     switch ($type) {
                         case 'timestamp':
                         case 'date':
                             list($fromto, $key) = explode('_', $key);
                             $q->add($fromto == 'to' ? Q::lte($key, $v) : Q::gte($key, $v));
                             break;
                         default:
                             $q->add(Q::contains($key, $v));
                     }
                     $paginator->vars($k, $v);
                 }
                 $paginator->vars('search', true);
             }
             $object_list = $class::find_all($q, $paginator, Q::select_order($order, $this->in_vars('porder')));
             $this->rm_vars('q');
         } else {
             $object_list = $class::find_all(Q::match($this->in_vars('q')), $paginator, Q::select_order($order, $this->in_vars('porder')));
             $paginator->vars('q', $this->in_vars('q'));
         }
     }
     return array($object_list, $paginator);
 }
예제 #6
0
파일: new.php 프로젝트: tokushima/rhaco3
<?php

use org\rhaco\store\db\Q;
\test\model\NewDao::create_table();
$obj = new \test\model\NewDao();
neq(null, $obj);
\test\model\NewDao::find_delete();
eq(0, \test\model\NewDao::find_count());
$obj = new \test\model\NewDao();
$obj->save();
$obj = new \test\model\NewDao();
$obj->value(null);
$obj->save();
$obj = new \test\model\NewDao();
$obj->value('');
$obj->save();
eq(1, \test\model\NewDao::find_count(Q::eq('value', '')));
eq(2, \test\model\NewDao::find_count(Q::eq('value', null)));
eq(3, \test\model\NewDao::find_count());
$r = array(null, null, '');
$i = 0;
foreach (\test\model\NewDao::find(Q::order('id')) as $o) {
    eq($r[$i], $o->value());
    $i++;
}
예제 #7
0
파일: Model.php 프로젝트: tokushima/rhaco3
 /**
  * @automap
  */
 public function delete()
 {
     $model = \test\model\TestModel::find_get(\org\rhaco\store\db\Q::eq('string', 'abcdefg'));
     $model->delete();
 }
예제 #8
0
파일: all.php 프로젝트: tokushima/rhaco3
    try {
        $result[0]->value("fuga");
        $result[0]->save();
        eq("fuga", $result[0]->value());
    } catch (\BadMethodCallException $e) {
        fail();
    }
}
\test\model\CompositePrimaryKeys::create_table();
\test\model\CompositePrimaryKeysRef::create_table();
\test\model\CompositePrimaryKeys::find_delete();
$ref(new \test\model\CompositePrimaryKeys())->id1(1)->id2(1)->value('AAA1')->save();
$ref(new \test\model\CompositePrimaryKeys())->id1(1)->id2(2)->value('AAA2')->save();
$ref(new \test\model\CompositePrimaryKeys())->id1(1)->id2(3)->value('AAA3')->save();
$ref(new \test\model\CompositePrimaryKeys())->id1(2)->id2(1)->value('BBB1')->save();
$ref(new \test\model\CompositePrimaryKeys())->id1(2)->id2(2)->value('BBB2')->save();
$ref(new \test\model\CompositePrimaryKeys())->id1(2)->id2(3)->value('BBB3')->save();
\test\model\CompositePrimaryKeysRef::find_delete();
$ref(new \test\model\CompositePrimaryKeysRef())->ref_id(1)->type_id(1)->save();
$ref(new \test\model\CompositePrimaryKeysRef())->ref_id(2)->type_id(1)->save();
$ref(new \test\model\CompositePrimaryKeysRef())->ref_id(1)->type_id(2)->save();
$ref(new \test\model\CompositePrimaryKeysRef())->ref_id(2)->type_id(2)->save();
$i = 0;
$r = array(array(1, 1, 'AAA1'), array(2, 1, 'BBB1'), array(1, 2, 'AAA2'), array(2, 2, 'BBB2'));
foreach (\test\model\CompositePrimaryKeysRefValue::find(Q::order('type_id,id')) as $o) {
    eq($r[$i][0], $o->ref_id());
    eq($r[$i][1], $o->type_id());
    eq($r[$i][2], $o->value());
    $i++;
}
eq(4, $i);
예제 #9
0
파일: Dao.php 프로젝트: tokushima/rhaco3
 /**
  * @module org.rhaco.store.queue.Queue
  * 終了したものを削除する
  * @param string $type
  * @param timestamp $fin
  */
 public function clean($type, $fin, \org\rhaco\Paginator $paginator)
 {
     foreach (\org\rhaco\store\queue\module\Dao\QueueDao::find(Q::eq('type', $type), Q::neq('fin', null), Q::lte('fin', $fin), Q::order('id'), $paginator) as $obj) {
         $obj->delete();
     }
     \org\rhaco\store\queue\module\Dao\QueueDao::commit();
 }
예제 #10
0
<?php

use org\rhaco\store\db\Q;
\test\model\DateTime::find_delete();
$obj = new \test\model\DateTime();
$obj->ts('2015/07/21 12:13:14')->save();
$obj = new \test\model\DateTime();
$obj->ts('2015/07/22 12:13:14')->save();
$obj = new \test\model\DateTime();
$obj->ts('2015/07/23 13:13:14')->save();
$obj = new \test\model\DateTime();
$obj->ts('2015/07/21 14:13:14')->save();
eq(array('2015/07/21 00:00:00', '2015/07/22 00:00:00', '2015/07/23 00:00:00'), \test\model\DateTime::find_distinct('ts', Q::date_format('ts', 'Ymd')));
eq(array('2000/01/01 12:00:00', '2000/01/01 13:00:00', '2000/01/01 14:00:00'), \test\model\DateTime::find_distinct('ts', Q::date_format('ts', 'H')));
예제 #11
0
파일: find.php 프로젝트: tokushima/rhaco3
    }
}
neq(10, $c);
$result = \test\model\Find::find_all(Q::ob(Q::b(Q::eq("value1", "abc")), Q::b(Q::eq("value2", "EDC"))));
eq(2, sizeof($result));
eq("EDC", \test\model\Find::find_get(Q::eq("value1", "jkl"))->value2());
$i = 0;
$r = array("abc", "def", "ghi", "jkl");
foreach (\test\model\RefFind::find() as $obj) {
    eq(isset($r[$i]) ? $r[$i] : null, $obj->value());
    $i++;
}
eq(4, $i);
$i = 0;
$r = array("abc");
foreach (\test\model\RefRefFind::find() as $obj) {
    eq(isset($r[$i]) ? $r[$i] : null, $obj->value());
    $i++;
}
eq(1, $i);
$i = 0;
$r = array("abc", "def", "ghi", "jkl");
foreach (\test\model\HasFind::find() as $obj) {
    eq(isset($r[$i]) ? $r[$i] : null, $obj->parent()->value1());
    $i++;
}
eq(4, $i);
$result = \test\model\Find::find_all(Q::in("value1", \test\model\SubFind::find_sub("value")));
eq(4, sizeof($result));
$result = \test\model\Find::find_all(Q::in("value1", \test\model\SubFind::find_sub("value", Q::lt("order", 3))));
eq(2, sizeof($result));
예제 #12
0
 protected function __find_conds__()
 {
     return Q::b(Q::eq("value1", "abc"));
 }
예제 #13
0
파일: Dao.php 프로젝트: tokushima/rhaco3
 /**
  * DBの値と同じにする
  * @return $this
  */
 public final function sync()
 {
     $query = new Q();
     $query->add(new \org\rhaco\Paginator(1, 1));
     foreach ($this->primary_columns() as $column) {
         $query->add(Q::eq($column->name(), $this->{$column->name()}()));
     }
     foreach (self::get_statement_iterator($this, $query) as $dao) {
         foreach (get_object_vars($dao) as $k => $v) {
             if ($k[0] != '_') {
                 $this->{$k}($v);
             }
         }
         return $this;
     }
     throw new \org\rhaco\store\db\exception\NotfoundDaoException('synchronization failed');
 }
예제 #14
0
$obj->ts($date);
$obj->num(20);
$obj->save();
$date = strtotime('2015/07/30 12:34:56');
$obj = new \test\model\DateFormat();
$obj->ts($date);
$obj->num(30);
$obj->save();
foreach (\test\model\DateFormat::find(Q::date_format('ts', 'Ym')) as $o) {
    eq(date('Y/m/01 00:00:00', $date), $o->fm_ts());
}
$date = strtotime('2015/08/30 12:34:56');
$obj = new \test\model\DateFormat();
$obj->ts($date);
$obj->num(40);
$obj->save();
$date = strtotime('2015/08/30 12:34:56');
$obj = new \test\model\DateFormat();
$obj->ts($date);
$obj->num(20);
$obj->save();
eq(4, sizeof(\test\model\DateFormat::find_sum_by('num', 'ts')));
eq(2, sizeof(\test\model\DateFormat::find_sum_by('num', 'ts', Q::date_format('ts', 'Ym'))));
foreach (\test\model\DateFormat::find_sum_by('num', 'ts', Q::date_format('ts', 'Ym')) as $k => $num) {
    eq('2015', date('Y', $k));
    eq(60, $num);
}
foreach (\test\model\DateFormat::find_sum_by('num', 'ts', Q::date_format('ts', 'm')) as $k => $num) {
    eq('2000', date('Y', $k));
    eq(60, $num);
}
예제 #15
0
파일: join.php 프로젝트: tokushima/rhaco3
<?php

use org\rhaco\store\db\Q;
$ref = function ($obj) {
    return $obj;
};
$a1 = $ref(new \test\model\JoinA())->save();
$a2 = $ref(new \test\model\JoinA())->save();
$a3 = $ref(new \test\model\JoinA())->save();
$a4 = $ref(new \test\model\JoinA())->save();
$a5 = $ref(new \test\model\JoinA())->save();
$a6 = $ref(new \test\model\JoinA())->save();
$b1 = $ref(new \test\model\JoinB())->name("aaa")->save();
$b2 = $ref(new \test\model\JoinB())->name("bbb")->save();
$c1 = $ref(new \test\model\JoinC())->a_id($a1->id())->b_id($b1->id())->save();
$c2 = $ref(new \test\model\JoinC())->a_id($a2->id())->b_id($b1->id())->save();
$c3 = $ref(new \test\model\JoinC())->a_id($a3->id())->b_id($b1->id())->save();
$c4 = $ref(new \test\model\JoinC())->a_id($a4->id())->b_id($b2->id())->save();
$c5 = $ref(new \test\model\JoinC())->a_id($a4->id())->b_id($b1->id())->save();
$c6 = $ref(new \test\model\JoinC())->a_id($a5->id())->b_id($b2->id())->save();
$c7 = $ref(new \test\model\JoinC())->a_id($a5->id())->b_id($b1->id())->save();
$re = \test\model\JoinABC::find_all();
eq(7, sizeof($re));
$re = \test\model\JoinABC::find_all(Q::eq("name", "aaa"));
eq(5, sizeof($re));
$re = \test\model\JoinABC::find_all(Q::eq("name", "bbb"));
eq(2, sizeof($re));
$re = \test\model\JoinABBCC::find_all(Q::eq("name", "bbb"));
eq(2, sizeof($re));