예제 #1
0
<?php

required_params('id');
$pool = Pool::find(Request::$params->id);
if (!$pool->can_be_updated_by(User::$current)) {
    access_denied();
}
if (Request::$post) {
    foreach (Request::$params->pool_post_sequence as $i => $seq) {
        PoolPost::update($i, array('sequence' => $seq));
    }
    $pool->reload();
    $pool->update_pool_links();
    notice("Ordering updated");
    // flash[:notice] = "Ordering updated"
    redirect_to('#show', array('id' => Request::$params->id));
} else {
    $pool_posts = $pool->pool_posts;
}
예제 #2
0
    ?>

  <?php 
    if ($this->post->has_children) {
        ?>
    <?php 
        $children = $this->post->children;
        $s = $this;
        ?>
    <div class="status-notice">
      <?php 
        echo $this->t(['.parent.has_child_html', 'child' => $this->linkTo($children->size() == 1 ? $this->t('.parent.child') : $this->t('.parent.children'), array('#index', 'tags' => 'parent:' . $this->post->id))]);
        ?>
 (<?php 
        echo $this->t(['.parent.child_post_html', 'child' => implode(', ', array_map(function ($child) {
            return $this->linkTo($child->id, array('#show', 'id' => $child->id));
        }, $children->members()))]);
        ?>
).
    </div>
  <?php 
    }
}
?>

<?php 
foreach ($this->pools as $pool) {
    ?>
  <?php 
    echo $this->partial("post/show_partials/pool", array('pool' => $pool, 'pool_post' => PoolPost::where("pool_id = ? AND post_id = ?", $pool->id, $this->post->id)->first()));
}
예제 #3
0
 public function order()
 {
     $this->pool = Pool::find($this->params()->id);
     if (!$this->pool->can_be_updated_by(current_user())) {
         $this->access_denied();
     }
     if ($this->request()->isPost()) {
         foreach ($this->params()->pool_post_sequence as $i => $seq) {
             PoolPost::update($i, array('sequence' => $seq));
         }
         $this->pool->reload();
         $this->pool->update_pool_links();
         $this->notice("Ordering updated");
         $this->redirectTo(array('#show', 'id' => $this->params()->id));
     } else {
         $this->pool_posts = $this->pool->pool_posts;
     }
 }
예제 #4
0
 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();
     }
 }
예제 #5
0
파일: Post.php 프로젝트: JCQS04/myimouto
 public function delete_from_database()
 {
     $this->runCallbacks('destroy', function () {
         $this->delete_file();
         self::connection()->executeSql('UPDATE pools SET post_count = post_count - 1 WHERE id IN (SELECT pool_id FROM pools_posts WHERE post_id = ?)', $this->id);
         self::connection()->executeSql('UPDATE tags SET post_count = post_count - 1 WHERE id IN (SELECT tag_id FROM posts_tags WHERE post_id = ?)', $this->id);
         # MI: Destroying pool posts manually so their histories are deleted by foreign keys.
         # This is done in Pool too. This could be done with a MySQL trigger.
         PoolPost::destroyAll('post_id = ?', $this->id);
         self::connection()->executeSql("DELETE FROM posts WHERE id = ?", $this->id);
     });
 }
예제 #6
0
 public function show()
 {
     $this->helper('Avatar');
     try {
         if ($this->params()->cache) {
             $this->response()->headers()->add("Cache-Control", "max-age=300");
         }
         $this->cache = $this->params()->cache;
         # temporary
         $this->body_only = (int) $this->params()->body == 1;
         if ($this->params()->md5) {
             if (!($this->post = Post::where(['md5' => strtolower($this->params())])->first())) {
                 throw Rails\ActiveRecord\Exception\RecordNotFoundException();
             }
         } else {
             $this->post = Post::find($this->params()->id);
         }
         $this->pools = Pool::where("pools_posts.post_id = {$this->post->id} AND pools_posts.active")->joins("JOIN pools_posts ON pools_posts.pool_id = pools.id")->order("pools.name")->select("pools.name, pools.id")->take();
         if ($this->params()->pool_id) {
             $this->following_pool_post = PoolPost::where("pool_id = ? AND post_id = ?", $this->params()->pool_id, $this->post->id)->first();
         } else {
             $this->following_pool_post = PoolPost::where("post_id = ?", $this->post->id)->first();
         }
         $this->tags = array('include' => $this->post->tags());
         $this->include_tag_reverse_aliases = true;
         $this->set_title(str_replace('_', ' ', $this->post->title_tags()));
         $this->respondTo(['html']);
     } catch (Rails\ActiveRecord\Exception\RecordNotFoundException $e) {
         $this->respondTo(['html' => function () {
             $this->render(array('action' => 'show_empty', 'status' => 404));
         }]);
     }
 }
예제 #7
0
    if ($post->has_children) {
        ?>
    <?php 
        $children =& $post->children;
        ?>
    <div class="status-notice">
      This post has <?php 
        echo link_to(count($children) == 1 ? "a child post" : "child posts", array('#index', 'tags' => 'parent:' . $post->id));
        ?>
 (post <?php 
        echo implode(', ', array_map(function (&$child) {
            return link_to($child->id, '#show', array('id' => $child->id));
        }, (array) $children));
        ?>
).
    </div>
  <?php 
    }
}
?>

<?php 
foreach ($pools as $k => &$pool) {
    global $pool;
    $pool = $pools->{$k};
    $pp = PoolPost::find('first', array('conditions' => array("pool_id = ? AND post_id = ?", $pool->id, $post->id)));
    ?>
  <?php 
    render_partial("post/show_partials/pool", array('pool', 'pool_post' => $pp));
}
// endif
예제 #8
0
파일: Pool.php 프로젝트: JCQS04/myimouto
 protected function destroy_pool_posts()
 {
     PoolPost::destroyAll('pool_id = ?', $this->id);
 }