示例#1
0
 /**
  * トップページ
  *
  * @context integer $package_count パッケージ総数
  * @context $primary_tags primary がセットされているタグリスト(上限付き)
  * @context $recent_releases 最新 OpenpearRelease モデルの配列
  */
 public function index()
 {
     if (Store::has('index/package_count', 3600)) {
         $package_count = Store::get('index/package_count');
     } else {
         $package_count = C(OpenpearPackage)->find_count();
         Store::set('index/package_count', $package_count, 3600);
     }
     if (Store::has('index/primary_tags', 3600)) {
         $primary_tags = Store::get('index/primary_tags');
     } else {
         $primary_tags = OpenpearPackage::getActiveCategories(8);
         Store::set('index/primary_tags', $primary_tags, 3600);
     }
     if (Store::has('index/recent_releases', 3600)) {
         $recent_releases = Store::get('index/recent_releases');
     } else {
         $recent_releases = C(OpenpearPackage)->find_all(new Paginator(5), Q::neq('latest_release_id', null), Q::order('-released_at'));
         Store::set('index/recent_releases', $recent_releases, 3600);
     }
     if (Store::has('index/most_downloaded', 3600)) {
         $most_downloaded = Store::get('index/most_downloaded');
     } else {
         $most_downloaded = C(OpenpearPackage)->find_all(new Paginator(5), Q::order('-download_count'));
         Store::set('index/most_downloaded', $most_downloaded, 3600);
     }
     $this->vars('package_count', $package_count);
     $this->vars('primary_tags', $primary_tags);
     $this->vars('recent_releases', $recent_releases);
     $this->vars('most_downloaded', $most_downloaded);
 }
示例#2
0
 public function after_delete()
 {
     $this->_reset_primaries();
     $this->_recount_tags();
     if (C(OpenpearPackageTag)->find_count(Q::neq('package_id', $this->package_id()), Q::eq('tag_id', $this->tag_id())) === 0) {
         $tag = $this->tag();
         $tag->delete();
     }
 }
示例#3
0
文件: Dao.php 项目: tokushima/ebi
 /**
  * 値の妥当性チェックを行う
  */
 public function validate()
 {
     foreach ($this->columns(true) as $name => $column) {
         if (!\ebi\Exceptions::has($name)) {
             $value = $this->{$name}();
             \ebi\Validator::value($name, $value, ['type' => $this->prop_anon($name, 'type'), 'min' => $this->prop_anon($name, 'min'), 'max' => $this->prop_anon($name, 'max'), 'require' => $this->prop_anon($name, 'require')]);
             $unique_together = $this->prop_anon($name, 'unique_together');
             if ($value !== '' && $value !== null && ($this->prop_anon($name, 'unique') === true || !empty($unique_together))) {
                 $uvalue = $value;
                 $q = [\ebi\Q::eq($name, $uvalue)];
                 if (!empty($unique_together)) {
                     foreach (is_array($unique_together) ? $unique_together : [$unique_together] as $c) {
                         $q[] = Q::eq($c, $this->{$c}());
                     }
                 }
                 foreach ($this->primary_columns() as $primary) {
                     if (null !== $this->{$primary->name()}) {
                         $q[] = Q::neq($primary->name(), $this->{$primary->name()});
                     }
                 }
                 if (0 < call_user_func_array([get_class($this), 'find_count'], $q)) {
                     \ebi\Exceptions::add(new \ebi\exception\UniqueException($name . ' unique'), $name);
                 }
             }
             $master = $this->prop_anon($name, 'master');
             if (!empty($master)) {
                 $master = str_replace('.', "\\", $master);
                 if ($master[0] !== '\\') {
                     $master = '\\' . $master;
                 }
                 try {
                     $r = new \ReflectionClass($master);
                 } catch (\ReflectionException $e) {
                     $self = new \ReflectionClass(get_class($this));
                     $r = new \ReflectionClass("\\" . $self->getNamespaceName() . $master);
                 }
                 $mo = $r->newInstanceArgs();
                 $primarys = $mo->primary_columns();
                 if (empty($primarys) || 0 === call_user_func_array([$mo, 'find_count'], [Q::eq(key($primarys), $this->{$name})])) {
                     \ebi\Exceptions::add(new \ebi\exception\NotFoundException($name . ' master not found'), $name);
                 }
             }
             try {
                 if (method_exists($this, '__verify_' . $column->name() . '__') && call_user_func([$this, '__verify_' . $column->name() . '__']) === false) {
                     \ebi\Exceptions::add(new \ebi\exception\VerifyException($column->name() . ' verification failed'), $column->name());
                 }
             } catch (\ebi\Exceptions $e) {
             } catch (\Exception $e) {
                 \ebi\Exceptions::add($e, $column->name());
             }
         }
     }
     \ebi\Exceptions::throw_over();
 }
示例#4
0
文件: Dao.php 项目: hisaboh/w2t
 private final function save_verify()
 {
     foreach ($this->self_columns() as $name => $column) {
         $type = $this->a($name, "type");
         $value = $this->{$name};
         if ($this->a($name, "require") === true && ($value === "" || $value === null)) {
             Exceptions::add(new Exception($name . " required"));
         }
         if ($this->a($name, "unique") === true) {
             $q = array(Q::eq($name, $value));
             foreach ($this->primary_columns() as $column) {
                 if (null !== ($value = $this->{$column->name()}())) {
                     $q[] = Q::neq($column->name(), $this->{$column->name()}());
                 }
             }
             if (0 < call_user_func_array(array(C($this), "find_count"), $q)) {
                 Exceptions::add(new Exception($name . " unique"));
             }
         }
     }
     foreach ($this->self_columns() as $column) {
         if (!$this->{"is" . ucfirst($column->name())}()) {
             Exceptions::add(new Exception("verify fail"));
         }
     }
     $this->__save_verify__();
     Exceptions::validation();
 }
示例#5
0
 protected function where_match(Q $q, array $self_columns)
 {
     $query = new Q();
     foreach ($q->arArg1() 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 $query;
 }