Created
August 23, 2013 03:19
-
-
Save duellsy/6315222 to your computer and use it in GitHub Desktop.
Displaying multiple revisions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class BaseController extends Controller | |
{ | |
/** | |
* Setup the layout used by the controller. | |
* | |
* @return void | |
*/ | |
protected function setupLayout() | |
{ | |
if (!is_null($this->layout)) { | |
$this->layout = View::make($this->layout); | |
} | |
} | |
/** | |
* Display a listing of the clients. | |
* | |
* @param $model | |
* @param $item_id | |
* | |
* @return Response | |
*/ | |
public function showRevisions($model, $item_id) | |
{ | |
$item = $model::find($item_id); | |
$revisions = $item->revisionHistory; | |
$data = array( | |
'item' => $item, | |
'revisions' => $revisions, | |
'model' => Str::plural(substr($model, strpos($model, '\\') + 1)), | |
'model_id' => $item_id | |
); | |
// var_dump($data);exit; | |
$this->layout->nest('content', 'revisions/index', $data); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h3>Revision History</h3> | |
<table class="table table-striped table-bordered"> | |
<thead> | |
<tr> | |
<th>Field</th> | |
<th>Old value</th> | |
<th>New value</th> | |
<th>User</th> | |
<th>When</th> | |
<th>Tasks</th> | |
</tr> | |
</thead> | |
<tbody> | |
@foreach($revisions as $revision) | |
<?php $date = new ExpressiveDate($revision->created_at); ?> | |
<tr> | |
<td>{{ ucfirst($revision->fieldName()) }}</td> | |
<td>{{ $revision->oldValue() }}</td> | |
<td>{{ $revision->newValue() }}</td> | |
<td>{{ $revision->userResponsible()->first_name }}</td> | |
<td>{{ $date->getRelativeDate() }}</td> | |
<td><a class="btn tip" title="Revert this change" href="{{ URL::action('RevisionsController@revert', encryptId($revision->id, 'revisions')) }}"><i class="icon-signin"></i></a></td> | |
</tr> | |
@endforeach | |
</tbody> | |
</table> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class RevisionsController extends BaseController | |
{ | |
public function revert($revision_id) | |
{ | |
$revision_id = decryptId($revision_id, 'revisions'); | |
$revision = \Venturecraft\Revisionable\Revision::find($revision_id); | |
$item = $revision->revisionable; | |
$field = $revision->key; | |
$item->$field = $revision->old_value; | |
$item->save(); | |
Event::fire(strtolower($revision->revisionable_type) . '.updated', $item); | |
return Redirect::back(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment