Example #1
0
 public static function Model($model, $bdd = null)
 {
     $c = new self($bdd);
     $c->model = $model;
     $c->from($c->bdd->quoteIdent($model->getTableName()));
     return $c;
 }
Example #2
0
 /**
  * メールの内容をDBに保存する
  * @module org.rhaco.net.mail.Mail
  * @param org.rhaco.net.mail.Mail $mail
  */
 public function send_mail(\org\rhaco\net\mail\Mail $mail)
 {
     $self = new self();
     $self->from($mail->from());
     $self->to(implode("\n", array_keys($mail->to())));
     $self->cc(implode("\n", array_keys($mail->cc())));
     $self->bcc(implode("\n", array_keys($mail->bcc())));
     $self->subject(mb_convert_encoding(base64_decode(preg_replace('/^=\\?ISO-2022-JP\\?B\\?(.+)\\?=$/', '\\1', $mail->subject())), 'UTF-8', 'JIS'));
     $self->message(mb_convert_encoding($mail->message(), 'UTF-8', 'JIS'));
     $self->manuscript($mail->manuscript());
     $self->save();
     self::commit();
 }
Example #3
0
 public function join($type, $model, $query = null)
 {
     if ($model instanceof Model and is_null($query)) {
         $query = new self();
         $query->equal($this->from->field($this->from->pk()), $model->fk($this->from));
         $query->from($model);
     }
     if ($model instanceof self) {
         $query = $model;
     }
     $this->joins[strtoupper($type)][] = $query;
     return $this;
 }
Example #4
0
 /**
  * Return relation time from now.
  *
  * @param bool $withoutSuffix
  * @return string
  */
 public function fromNow($withoutSuffix = false)
 {
     $now = new self();
     $output = $now->from($this, $withoutSuffix);
     return $output;
 }
Example #5
0
 public static function factory($conditions)
 {
     if ($conditions instanceof BaseClass) {
         return $conditions;
     }
     $select = new self();
     if (is_array($conditions) || $conditions instanceof \Traversable) {
         foreach ($conditions as $name => $condition) {
             switch ($name) {
                 case 'columns':
                     if (is_array($condition) && array_key_exists(0, $condition) && is_array($condition[0])) {
                         call_user_func_array(array($select, 'columns'), $condition);
                         continue;
                     }
                     $select->columns($condition);
                     break;
                 case 'combine':
                     if (is_array($condition)) {
                         call_user_func_array(array($select, 'combine'), $condition);
                         continue;
                     }
                     $select->combine($condition);
                     break;
                 case 'from':
                     $select->from($condition);
                     break;
                 case 'group':
                     $select->group($condition);
                     break;
                 case 'having':
                     if (is_array($condition) && array_key_exists(1, $condition) && ($condition[1] == PredicateSet::OP_AND || $condition[1] == PredicateSet::OP_OR)) {
                         call_user_func_array(array($select, 'having'), $condition);
                         continue;
                     }
                     $select->having($condition);
                     break;
                 case 'join':
                     call_user_func_array(array($select, 'join'), $condition);
                     break;
                 case 'limit':
                     $select->limit($condition);
                     break;
                 case 'offset':
                     $select->offset($condition);
                     break;
                 case 'order':
                     $select->order($condition);
                     break;
                 case 'where':
                     if (is_array($condition) && array_key_exists(1, $condition) && ($condition[1] == PredicateSet::OP_AND || $condition[1] == PredicateSet::OP_OR)) {
                         call_user_func_array(array($select, 'where'), $condition);
                         continue;
                     }
                     $select->where($condition);
                     break;
                 default:
                     throw new \Exception("Invalid condition ({$name})");
             }
         }
         return $select;
     }
     throw new \Exception(sprintf('Invalid conditions type (%s)', is_object($conditions) ? get_class($conditions) : gettype($conditions)));
 }