상속: extends Phalcon\Mvc\Model
예제 #1
0
 /**
  * Shows the latest modification made to a post
  */
 public function historyAction($id = 0)
 {
     $this->view->disable();
     /**
      * Find the post using get
      */
     $post = Posts::findFirstById($id);
     if (!$post) {
         $this->flashSession->error('The discussion does not exist');
         return $this->response->redirect();
     }
     $a = explode("\n", $post->content);
     $first = true;
     $parameters = ['posts_id = ?0', 'bind' => [$post->id], 'order' => 'created_at DESC'];
     /** @var PostsHistory[] $postHistories */
     $postHistories = PostsHistory::find($parameters);
     if (count($postHistories) > 1) {
         foreach ($postHistories as $postHistory) {
             if ($first) {
                 $first = false;
                 continue;
             }
             break;
         }
     } else {
         $postHistory = $postHistories->getFirst();
     }
     if (is_object($postHistory)) {
         $b = explode("\n", $postHistory->content);
         $diff = new \Diff($b, $a, []);
         $renderer = new \Diff_Renderer_Html_SideBySide();
         echo $diff->Render($renderer);
     } else {
         $this->flash->notice('No history available to show');
     }
 }
예제 #2
0
파일: Posts.php 프로젝트: woyifang/forum
 public function afterSave()
 {
     $this->clearCache();
     $history = new PostsHistory();
     $history->posts_id = $this->id;
     $history->users_id = $this->getDI()->getSession()->get('identity');
     $history->content = $this->content;
     $history->save();
 }
예제 #3
0
파일: Posts.php 프로젝트: phalcon/forum
 public function getDifference()
 {
     $history = PostsHistory::findLast($this);
     if (!$history->valid()) {
         return false;
     }
     if ($history->count() > 1) {
         $history = $history->offsetGet(1);
     } else {
         $history = $history->getFirst();
     }
     /** @var PostsHistory $history */
     $b = explode("\n", $history->content);
     $diff = new Diff($b, explode("\n", $this->content), []);
     $difference = $diff->render(new SideBySide());
     return $difference;
 }