Skip to content

Commit

Permalink
Início do porte do plugin para Cake 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
CauanCabral committed Feb 29, 2012
1 parent fb09c83 commit 1ae05fb
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 15 deletions.
6 changes: 3 additions & 3 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ sobre o usuário logado e o modelo que salvará a mensagem de log no BD. Para is
public function beforeFilter() {
parent::beforeFilter();

if($this->Auth->loggedIn()) {
if(!empty($this->Auth->user())) {
AuditableConfig::$userId = $this->Auth->user('id');
}

Expand Down Expand Up @@ -79,6 +79,6 @@ você pode usa-lo de forma isolada ou em conjunto com seu próprio código.

h2. Observações

* Este behavior requer PHP versão >= 5.3
* Compatível com CakePHP 2.0 e 2.1
* Este behavior requer PHP versão >= 5.2
* Compatível com CakePHP 1.3 (há branche para versão 2.x)
* Consulte os testes incluído no plugin para ver melhor seu funcionamento
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public function view($id)

if(!$this->Logger->exists())
{
throw new NotFoundException(__d('auditable', 'Log entry could not be find.'));
$this->Session->setFlash(__d('auditable', 'Log entry could not be find.'));

return;
}

$this->set('logger', $this->Logger->get($id));
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @package radig
* @subpackage Auditable.Model.Behavior
*/
App::uses('AuditableConfig', 'Auditable.Lib');
App::import('Vendor', 'Auditable.AuditableConfig');

class AuditableBehavior extends ModelBehavior
{
Expand Down
15 changes: 15 additions & 0 deletions Model/Logger.php → models/logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,19 @@ public function get($id)

return $data;
}

/**
* Implementa função existis da API do Cake 2.0 na versão 1.3
*
* Verifica se um registro existe no BD
*
* @return bool
*/
public function exists()
{
if(empty($this->id))
return false;

return ($this->find('count', array('conditions' => array('Logger.id' => $this->id), 'recursive' => -1)) > 0);
}
}
File renamed without changes.
20 changes: 10 additions & 10 deletions View/Helper/AuditorHelper.php → views/helpers/auditor_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @subpackage Auditable.View.Helper
*/

App::uses('AuditableConfig', 'Auditable.Lib');
App::import('Vendor', 'Auditable.AuditableConfig');
class AuditorHelper extends AppHelper
{
/**
Expand Down Expand Up @@ -58,7 +58,7 @@ class AuditorHelper extends AppHelper
*/
public function type($t)
{
return ucfirst(__d('auditable', $this->typesEnum[$t]));
return ucfirst(__d('auditable', $this->typesEnum[$t], true));
}

/**
Expand All @@ -82,42 +82,42 @@ public function format($data, $type)
$data = call_user_func($func, $data);

$placeHolders = array();
$prepend = __d('auditable', $this->settings['formats']['prepend']) . ' ';
$pospend = ' ' . __d('auditable', $this->settings['formats']['pospend']);
$prepend = __d('auditable', $this->settings['formats']['prepend'], true) . ' ';
$pospend = ' ' . __d('auditable', $this->settings['formats']['pospend'], true);
$humanDiff = '';
$action = $this->typesEnum[$type];

switch($type)
{
case 2:
$placeHolders['action'] = __d('auditable', 'modified');
$placeHolders['action'] = __d('auditable', 'modified', true);

foreach($data as $field => $changes)
$humanDiff .= $prepend . String::insert($this->settings['formats']['modify'], array('field' => $field, 'old' => $changes['old'], 'new' => $changes['new'])) . $pospend;

break;

case 1:
$placeHolders['action'] = __d('auditable', 'created');
$placeHolders['action'] = __d('auditable', 'created', true);

case 3:
if(!isset($placeHolders['action']))
$placeHolders['action'] = __d('auditable', 'deleted');
$placeHolders['action'] = __d('auditable', 'deleted', true);

foreach($data as $field => $value)
$humanDiff .= $prepend . String::insert($this->settings['formats'][$action], compact('field', 'value')) . $pospend;

break;

default:
$placeHolders['action'] = __d('auditable', 'undefined');
$humanDiff .= __d('auditable', 'nothing changed');
$placeHolders['action'] = __d('auditable', 'undefined', true);
$humanDiff .= __d('auditable', 'nothing changed', true);
break;
}

$placeHolders['data'] = $humanDiff;

$msg = String::insert(__d('auditable', $this->settings['formats']['general']), $placeHolders);
$msg = String::insert(__d('auditable', $this->settings['formats']['general'], true), $placeHolders);

return $msg;
}
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 1ae05fb

Please sign in to comment.