public function afterSave() { $this->clearCache(); $history = new PostsRepliesHistory(); $history->posts_replies_id = $this->id; $usersId = $this->getDI()->getSession()->get('identity'); if ($usersId) { $history->users_id = $usersId; } else { $history->users_id = $this->users_id; } $history->content = $this->content; $history->save(); }
/** * Shows the latest modification made to a post */ public function historyAction($id = 0) { $this->view->disable(); /** * Find the post using get */ $postReply = PostsReplies::findFirstById($id); if (!$postReply) { $this->flashSession->error('The reply does not exist'); return $this->response->redirect(); } $a = explode("\n", $postReply->content); $first = true; $parametersHistory = array('posts_replies_id = ?0', 'bind' => array($postReply->id), 'order' => 'created_at DESC'); $postHistories = PostsRepliesHistory::find($parametersHistory); if (count($postHistories) > 1) { foreach ($postHistories as $postHistory) { if ($first) { if ($postHistory->content != $postReply->content) { $first = false; } continue; } break; } } else { $postHistory = $postHistories->getFirst(); } if (is_object($postHistory)) { $b = explode("\n", $postHistory->content); $diff = new \Diff($b, $a, array()); $renderer = new \Diff_Renderer_Html_SideBySide(); echo $diff->Render($renderer); } else { $this->flash->notice('No history available to show'); } }
public function getDifference() { $history = PostsRepliesHistory::findLast($this); if (!$history->valid()) { return false; } if ($history->count() > 1) { $history = $history->offsetGet(1); } else { $history = $history->getFirst(); } /** @var PostsRepliesHistory $history */ $b = explode("\n", $history->content); $diff = new Diff($b, explode("\n", $this->content), []); $difference = $diff->render(new SideBySide()); return $difference; }