コード例 #1
0
ファイル: Pool.php プロジェクト: JCQS04/myimouto
 public function add_post($post_id, $options = array())
 {
     if (isset($options['user']) && !$this->can_be_updated_by($options['user'])) {
         throw new Pool_AccessDeniedError();
     }
     $seq = isset($options['sequence']) ? $options['sequence'] : $this->next_sequence();
     $pool_post = $this->all_pool_posts ? $this->all_pool_posts->search('post_id', $post_id) : null;
     if ($pool_post) {
         # If :ignore_already_exists, we won't raise PostAlreadyExistsError; this allows
         # he sequence to be changed if the post already exists.
         if ($pool_post->active && empty($options['ignore_already_exists'])) {
             throw new Pool_PostAlreadyExistsError();
         }
         $pool_post->active = 1;
         $pool_post->sequence = $seq;
         $pool_post->save();
     } else {
         /**
          * MI: Passing "active" because otherwise such attribute would be Null and
          * History wouldn't work nicely.
          */
         PoolPost::create(array('pool_id' => $this->id, 'post_id' => $post_id, 'sequence' => $seq, 'active' => 1));
     }
     if (empty($options['skip_update_pool_links'])) {
         $this->reload();
         $this->update_pool_links();
     }
 }
コード例 #2
0
ファイル: pool.php プロジェクト: laiello/my-imouto-booru
 function add_post($post_id, $options = array())
 {
     if (isset($options['user']) && !$this->can_be_updated_by($options['user'])) {
         throw new Exception('Access Denied');
     }
     $seq = isset($options['sequence']) ? $options['sequence'] : $this->next_sequence();
     $pool_post = $this->all_pool_posts ? $this->all_pool_posts->search('post_id', $post_id) : null;
     if ($pool_post) {
         # If :ignore_already_exists, we won't raise PostAlreadyExistsError; this allows
         # he sequence to be changed if the post already exists.
         if ($pool_post->active && empty($options['ignore_already_exists'])) {
             throw new Exception('Post already exists');
         }
         $pool_post->active = true;
         $pool_post->sequence = $seq;
         $pool_post->save();
     } else {
         PoolPost::create(array('pool_id' => $this->id, 'post_id' => $post_id, 'sequence' => $seq));
         // new PoolPost('create', array('pool_id' => $this->id, 'post_id' => $post_id, 'sequence' => $seq));
     }
     if (empty($options['skip_update_pool_links'])) {
         $this->reload();
         $this->update_pool_links();
     }
 }