예제 #1
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);
 }
예제 #2
0
파일: Base.php 프로젝트: tokushima/rhaco3
 protected function where_sql(Dao $dao, &$from, Q $q, array $self_columns, $require_where = null, $alias = true)
 {
     if ($q->is_block()) {
         $vars = $and_block_sql = $or_block_sql = array();
         $where_sql = '';
         foreach ($q->ar_and_block() as $qa) {
             list($where, $var) = $this->where_sql($dao, $from, $qa, $self_columns, null, $alias);
             if (!empty($where)) {
                 $and_block_sql[] = $where;
                 $vars = array_merge($vars, $var);
             }
         }
         if (!empty($and_block_sql)) {
             $where_sql .= ' (' . implode(' and ', $and_block_sql) . ') ';
         }
         foreach ($q->ar_or_block() as $or_block) {
             list($where, $var) = $this->where_sql($dao, $from, $or_block, $self_columns, null, $alias);
             if (!empty($where)) {
                 $or_block_sql[] = $where;
                 $vars = array_merge($vars, $var);
             }
         }
         if (!empty($or_block_sql)) {
             $where_sql .= (empty($where_sql) ? '' : ' and ') . ' (' . implode(' or ', $or_block_sql) . ') ';
         }
         if (empty($where_sql)) {
             $where_sql = $require_where;
         } else {
             if (!empty($require_where)) {
                 $where_sql = '(' . $require_where . ') and (' . $where_sql . ')';
             }
         }
         return array($where_sql, $vars);
     }
     if ($q->type() == Q::MATCH) {
         $query = new Q();
         foreach ($q->ar_arg1() as $cond) {
             if (strpos($cond, '=') !== false) {
                 list($column, $value) = explode('=', $cond);
                 $not = substr($value, 0, 1) == '!';
                 $value = $not ? strlen($value) > 1 ? substr($value, 1) : '' : $value;
                 if ($value === '') {
                     $query->add($not ? Q::neq($column, '') : Q::eq($column, ''));
                 } else {
                     $query->add($not ? Q::contains($column, $value, $q->param() | Q::NOT) : Q::contains($column, $value, $q->param()));
                 }
             } else {
                 $columns = array();
                 foreach ($self_columns as $column) {
                     $columns[] = $column->name();
                 }
                 $query->add(Q::contains(implode(',', $columns), explode(' ', $cond), $q->param()));
             }
         }
         return $this->where_sql($dao, $from, $query, $self_columns, null, $alias);
     }
     $and = $vars = array();
     foreach ($q->ar_arg2() as $base_value) {
         $or = array();
         foreach ($q->ar_arg1() as $column_str) {
             $value = $base_value;
             $column = $this->get_column($column_str, $self_columns);
             $column_alias = $this->column_alias_sql($dao, $column, $q, $alias);
             $is_add_value = true;
             switch ($q->type()) {
                 case Q::EQ:
                     if ($value === null) {
                         $is_add_value = false;
                         $column_alias .= ' is null';
                         break;
                     }
                     $column_alias .= ' = ' . ($value instanceof Daq ? '(' . $value->unique_sql() . ')' : '?');
                     break;
                 case Q::NEQ:
                     if ($value === null) {
                         $is_add_value = false;
                         $column_alias .= ' is not null';
                         break;
                     }
                     $column_alias .= ' <> ' . ($value instanceof Daq ? '(' . $value->unique_sql() . ')' : '?');
                     break;
                 case Q::GT:
                     $column_alias .= ' > ' . ($value instanceof Daq ? '(' . $value->unique_sql() . ')' : '?');
                     break;
                 case Q::GTE:
                     $column_alias .= ' >= ' . ($value instanceof Daq ? '(' . $value->unique_sql() . ')' : '?');
                     break;
                 case Q::LT:
                     $column_alias .= ' < ' . ($value instanceof Daq ? '(' . $value->unique_sql() . ')' : '?');
                     break;
                 case Q::LTE:
                     $column_alias .= ' <= ' . ($value instanceof Daq ? '(' . $value->unique_sql() . ')' : '?');
                     break;
                 case Q::CONTAINS:
                 case Q::START_WITH:
                 case Q::END_WITH:
                     $column_alias = $this->format_column_alias_sql($dao, $column, $q, $alias);
                     $column_alias .= ($q->not() ? ' not' : '') . ' like(?)';
                     $value = ($q->type() == Q::CONTAINS || $q->type() == Q::END_WITH ? '%' : '') . $value . ($q->type() == Q::CONTAINS || $q->type() == Q::START_WITH ? '%' : '');
                     break;
                 case Q::IN:
                     $column_alias .= ($q->not() ? ' not' : '') . ($value instanceof Daq ? ' in(' . $value->unique_sql() . ')' : ' in(' . substr(str_repeat('?,', sizeof($value)), 0, -1) . ')');
                     break;
             }
             if ($value instanceof Daq) {
                 $is_add_value = false;
                 $vars = array_merge($vars, $value->ar_vars());
             }
             $add_join_conds = $dao->join_conds($column->name());
             if (!empty($add_join_conds)) {
                 $column_alias .= ' and ' . $this->where_cond_columns($add_join_conds, $from);
             }
             $or[] = $column_alias;
             if ($is_add_value) {
                 if (is_array($value)) {
                     $values = array();
                     foreach ($value as $v) {
                         $values[] = $q->ignore_case() ? strtoupper($this->column_value($dao, $column->name(), $v)) : $this->column_value($dao, $column->name(), $v);
                     }
                     $vars = array_merge($vars, $values);
                 } else {
                     $vars[] = $q->ignore_case() ? strtoupper($this->column_value($dao, $column->name(), $value)) : $this->column_value($dao, $column->name(), $value);
                 }
             }
         }
         $and[] = ' (' . implode(' or ', $or) . ') ';
     }
     return array(implode(' and ', $and), $vars);
 }
예제 #3
0
파일: find.php 프로젝트: tokushima/rhaco3
$r = array("aaa", "bbb", "ccc");
foreach (\test\model\Find::find(Q::startswith("value1,value2", array("aa"), Q::IGNORE)) as $obj) {
    eq(isset($r[$i]) ? $r[$i] : null, $obj->value1());
    $i++;
}
eq(3, $i);
$i = 0;
$r = array("abc", "jkl", "ccc");
foreach (\test\model\Find::find(Q::endswith("value1,value2", array("c"), Q::IGNORE)) as $obj) {
    eq(isset($r[$i]) ? $r[$i] : null, $obj->value1());
    $i++;
}
eq(3, $i);
$i = 0;
$r = array("abc", "bbb");
foreach (\test\model\Find::find(Q::contains("value1,value2", array("b"))) as $obj) {
    eq(isset($r[$i]) ? $r[$i] : null, $obj->value1());
    $i++;
}
eq(2, $i);
$i = 0;
$r = array("abc", "jkl", "ccc");
foreach (\test\model\Find::find(Q::endswith("value1,value2", array("C"), Q::IGNORE)) as $obj) {
    eq(isset($r[$i]) ? $r[$i] : null, $obj->value1());
    $i++;
    $t[] = $obj->value1();
}
eq(3, $i);
$i = 0;
foreach (\test\model\Find::find(Q::in("value1", array("abc"))) as $obj) {
    eq("abc", $obj->value1());