当前位置: 首页>>代码示例>>PHP>>正文


PHP Pool::create方法代码示例

本文整理汇总了PHP中Pool::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Pool::create方法的具体用法?PHP Pool::create怎么用?PHP Pool::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Pool的用法示例。


在下文中一共展示了Pool::create方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: create

 public function create()
 {
     if ($this->request()->isPost()) {
         $pool = Pool::create(array_merge($this->params()->pool, array('user_id' => current_user()->id)));
         if ($pool->errors()->blank()) {
             $this->respond_to_success("Pool created", array(array('#show', 'id' => $pool->id)));
         } else {
             $this->respond_to_error($pool, "#index");
         }
     }
 }
开发者ID:JCQS04,项目名称:myimouto,代码行数:11,代码来源:PoolController.php

示例2: commit_tags

 /**
  * It's strange how actions like changing pool's sequence, that updates the post via
  * update_batch and sends only one metatag: 'pool:$id:$seq' and doesn't send old_tags, don't
  * mess up the rest of the tags (because that metatag is discarted, and the post is left without
  * old_tags or any tag).
  * So we're gonna do a workaround for that: if the new tags only contain metatags, we won't
  * take any further action but commit such metatags.
  * We'll use $had_metatags for that.
  */
 protected function commit_tags()
 {
     if ($this->isNewRecord() || !$this->new_tags) {
         return;
     }
     if ($this->old_tags) {
         # If someone else committed changes to this post before we did,
         # then try to merge the tag changes together.
         $current_tags = explode(' ', $this->cached_tags);
         $this->old_tags = Tag::scan_tags($this->old_tags);
         $this->new_tags = array_filter(array_merge(array_diff(array_merge($current_tags, $this->new_tags), $this->old_tags), array_intersect($current_tags, $this->new_tags)));
     }
     $this->commit_metatags();
     $meta_tags = ['-pool:', 'pool:', 'rating:', 'parent:', 'child:', 'source:'];
     $ratings = ['q', 's', 'e'];
     $had_metatags = false;
     foreach ($this->new_tags as $k => $tag) {
         # To avoid preg_match.
         $is_mt = false;
         foreach ($meta_tags as $mt) {
             if (strpos($tag, $mt) === 0 || in_array($tag, $ratings)) {
                 $is_mt = true;
                 break;
             }
         }
         if (!$is_mt) {
             continue;
         }
         $had_metatags = true;
         unset($this->new_tags[$k]);
         if (in_array($tag, $ratings)) {
             $tag = 'rating:' . $tag;
         }
         $subparam = explode(':', $tag, 3);
         $metatag = array_shift($subparam);
         $param = array_shift($subparam);
         $subparam = empty($subparam) ? null : array_shift($subparam);
         switch ($metatag) {
             case 'rating':
                 # Change rating. This will override rating selected on radio buttons.
                 if (in_array($param, $ratings)) {
                     $this->rating = $param;
                 }
                 break;
             case 'pool':
                 try {
                     $name = $param;
                     $seq = $subparam;
                     # Workaround: I don't understand how can the pool be found when finding_by_name
                     # using the id.
                     if (ctype_digit($name)) {
                         $pool = Pool::where(['id' => $name])->first();
                     } else {
                         $pool = Pool::where(['name' => $name])->first();
                     }
                     # Set :ignore_already_exists, so pool:1:2 can be used to change the sequence number
                     # of a post that already exists in the pool.
                     $options = array('user' => User::where('id = ?', $this->updater_user_id)->first(), 'ignore_already_exists' => true);
                     if ($seq) {
                         $options['sequence'] = $seq;
                     }
                     if (!$pool and !ctype_digit($name)) {
                         $pool = Pool::create(array('name' => $name, 'is_public' => false, 'user_id' => $this->updater_user_id));
                     }
                     if (!$pool || !$pool->can_change(current_user(), null)) {
                         continue;
                     }
                     $pool->add_post($this->id, $options);
                 } catch (Pool_PostAlreadyExistsError $e) {
                 } catch (Pool_AccessDeniedError $e) {
                 }
                 break;
             case '-pool':
                 $name = $param;
                 $cmd = $subparam;
                 $pool = Pool::where(['name' => $name])->first();
                 if (!$pool->can_change(current_user(), null)) {
                     break;
                 }
                 if ($cmd == "parent") {
                     # If we have a parent, remove ourself from the pool and add our parent in
                     # our place.    If we have no parent, do nothing and leave us in the pool.
                     if (!empty($this->parent_id)) {
                         $pool->transfer_post_to_parent($this->id, $this->parent_id);
                         break;
                     }
                 }
                 $pool && $pool->remove_post($id);
                 break;
             case 'source':
                 $this->source = $param;
//.........这里部分代码省略.........
开发者ID:JCQS04,项目名称:myimouto,代码行数:101,代码来源:TagMethods.php

示例3: commit_tags

 function commit_tags()
 {
     if ($this->is_empty_model()) {
         return;
     }
     $this->tags = array_filter(explode(' ', str_replace(array("\r", "\n"), '', $this->tags)));
     $this->current_tags = array_keys($this->parsed_cached_tags);
     if (empty($this->old_tags)) {
         $this->old_tags = $this->tags;
     } elseif (!is_array($this->old_tags)) {
         $this->old_tags = array_filter(explode(' ', $this->old_tags));
     }
     $this->commit_metatags();
     foreach ($this->tags as $k => $tag) {
         if (!preg_match('~^(-pool|pool|rating|parent|child):|^[qse]$~', $tag)) {
             continue;
         }
         if (in_array($tag, array('q', 's', 'e'))) {
             $tag = "rating:{$tag}";
         }
         $subparam = explode(':', $tag);
         $metatag = array_shift($subparam);
         $param = array_shift($subparam);
         $subparam = empty($subparam) ? null : array_shift($subparam);
         switch ($metatag) {
             case 'rating':
                 # Change rating. This will override rating selected on radio buttons.
                 if (in_array($param, array('q', 's', 'e'))) {
                     $this->rating = $param;
                 }
                 unset($this->tags[$k]);
                 break;
             case 'pool':
                 try {
                     $name = $param;
                     $seq = $subparam;
                     # Workaround: I don't understand how can the pool be found when finding_by_name
                     # using the id.
                     if (ctype_digit($name)) {
                         $pool = Pool::find_by_id($name);
                     } else {
                         $pool = Pool::find_by_name($name);
                     }
                     # Set :ignore_already_exists, so pool:1:2 can be used to change the sequence number
                     # of a post that already exists in the pool.
                     $options = array('user' => User::find($this->updater_user_id), 'ignore_already_exists' => true);
                     if ($seq) {
                         $options['sequence'] = $seq;
                     }
                     if (!$pool and !ctype_digit($name)) {
                         $pool = Pool::create(array('name' => $name, 'is_public' => false, 'user_id' => $this->updater_user_id));
                     }
                     if (!$pool) {
                         continue;
                     }
                     if (!$pool->can_change(User::$current, null)) {
                         continue;
                     }
                     $pool->add_post($this->id, $options);
                 } catch (PostAlreadyExistsError $e) {
                 } catch (AccessDeniedError $e) {
                 }
                 unset($this->tags[$k]);
                 break;
             case '-pool':
                 unset($this->tags[$k]);
                 $name = $param;
                 $cmd = $subparam;
                 $pool = Pool::find_by_name($name);
                 if (!$pool->can_change(User::$current, null)) {
                     break;
                 }
                 if ($cmd == "parent") {
                     # If we have a parent, remove ourself from the pool and add our parent in
                     # our place.  If we have no parent, do nothing and leave us in the pool.
                     if (!empty($this->parent_id)) {
                         $pool->transfer_post_to_parent($this->id, $this->parent_id);
                         break;
                     }
                 }
                 $pool && $pool->remove_post($id);
                 break;
             case 'source':
                 $this->source = $param;
                 unset($this->tags[$k]);
                 break;
             case 'parent':
                 if (is_numeric($param)) {
                     $this->parent_id = (int) $param;
                 }
                 unset($this->tags[$k]);
                 break;
             case 'child':
                 unset($this->tags[$k]);
                 break;
             default:
                 unset($this->tags[$k]);
                 break;
         }
     }
//.........这里部分代码省略.........
开发者ID:laiello,项目名称:my-imouto-booru,代码行数:101,代码来源:post.php

示例4: required_params

<?php

if (Request::$post) {
    required_params('pool');
    $pool = Pool::create(array_merge(Request::$params->pool, array('user_id' => User::$current->id)));
    if ($pool->record_errors->blank()) {
        respond_to_success("Pool created", array("#show", array('id' => $pool->id)));
    } else {
        respond_to_error($pool, "#index");
    }
} else {
    $pool = Pool::blank(array('user_id' => User::$current->id));
}
开发者ID:laiello,项目名称:my-imouto-booru,代码行数:13,代码来源:create.php


注:本文中的Pool::create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。