No Naci Caminando Buscador

Envia sms gratis a Personal, Tigo; Claro y Vox...

miércoles, 8 de abril de 2009

CODIGO MODIFICADO PARA HACER AUDITORIA EN SYMFONY GENERADO POR EL PROPEL INIT


/**
* banco actions.
*
* @package click
* @subpackage banco
* @author Your name here
* @version SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
*/

class bancoActions extends autobancoActions
{


public function executeIndex($request)
{
return $this->forward('banco', 'list');
}

public function executeList($request)
{
$this->processSort();

$this->processFilters();

$this->filters = $this->getUser()->getAttributeHolder()->getAll('sf_admin/banco/filters');

// pager
$this->pager = new sfPropelPager('Banco', 10);
$c = new Criteria();
$this->addSortCriteria($c);
$this->addFiltersCriteria($c);
$this->pager->setCriteria($c);
$this->pager->setPage($this->getRequestParameter('page', $this->getUser()->getAttribute('page', 1, 'sf_admin/banco')));
$this->pager->init();
// save page
if ($this->getRequestParameter('page')) {
$this->getUser()->setAttribute('page', $this->getRequestParameter('page'), 'sf_admin/banco');
}
}

public function executeCreate($request)
{
return $this->forward('banco', 'edit');
}

public function executeSave($request)
{

return $this->forward('banco', 'edit');
}


public function executeDeleteSelected($request)
{
$this->selectedItems = $this->getRequestParameter('sf_admin_batch_selection', array());

try
{
foreach (BancoPeer::retrieveByPks($this->selectedItems) as $object)
{
$object->delete();
}
}
catch (PropelException $e)
{
$request->setError('delete', 'Could not delete the selected Bancos. Make sure they do not have any associated items.');
return $this->forward('banco', 'list');
}

return $this->redirect('banco/list');
}

public function executeEdit($request)
{
$this->banco = $this->getBancoOrCreate();

if ($request->isMethod('post'))
{
$this->updateBancoFromRequest();

try
{
if(($this->getRequestParameter('idbanco'))!= '' || ($this->getRequestParameter('idbanco'))!=null)
{
$this->saveBanco($this->banco); ///////////////////////////////////////////////////////////////////
$this->Aupostupdate($this->getRequestParameter('idbanco'));//para auditar despues del update agragego el id para mi criteria//
} ///////////////////////////////////////////////////////////////////
else
{
$this->saveBanco($this->banco); ///////////////////////////////////////////////////////////////////
$this->Ausave();//para auditar despues del save, agragego el id para mi criteria//
} ///////////////////////////////////////////////////////////////////


}
catch (PropelException $e)
{
$request->setError('edit', 'Could not save the edited Bancos.');
return $this->forward('banco', 'list');
}

$this->getUser()->setFlash('notice', 'Your modifications have been saved');

if ($this->getRequestParameter('save_and_add'))
{
return $this->redirect('banco/create');
}
else if ($this->getRequestParameter('save_and_list'))
{
return $this->redirect('banco/list');
}
else
{
return $this->redirect('banco/edit?idbanco='.$this->banco->getIdbanco());
}
}
else
{
$this->labels = $this->getLabels();
}
}

public function executeDelete($request)
{
$this->banco = BancoPeer::retrieveByPk($this->getRequestParameter('idbanco'));
$this->forward404Unless($this->banco);

try
{ //////////////////////////////////////////////////
$this->Audelete($this->getRequestParameter('idbanco'));//para auditar agragego el id para mi criteria ///
$this->deleteBanco($this->banco); //////////////////////////////////////////////////
}
catch (PropelException $e)
{
$request->setError('delete', 'Could not delete the selected Banco. Make sure it does not have any associated items.');
return $this->forward('banco', 'list');
}

return $this->redirect('banco/list');
}

public function handleErrorEdit()
{
$this->preExecute();
$this->banco = $this->getBancoOrCreate();
$this->updateBancoFromRequest();

$this->labels = $this->getLabels();

return sfView::SUCCESS;
}

protected function saveBanco($banco)
{
$banco->save();
}

protected function deleteBanco($banco)
{

$banco->delete();


}
protected function Audelete($id)
{ //auditando...

$b = new Criteria();
$b->add(BancoPeer::IDBANCO,$id);
$bs = BancoPeer::DoSelect($b);
foreach ($bs as $dat)
{
$valorAnt=$dat->getIdbanco().'/'.$dat->getNombreBanco();
}
$audit = new Auditoria();
$audit->setUsuarioIdusuario(1);//rescaten el usuario con sf_user->
$audit->setValorAct(''); //vacio
$audit->setValorAnt($valorAnt);
$audit->setOperacion('Delete');
$audit->setTablaModificada('Banco');
$audit->setFechaAcceso(Date('Y/m/d H:i:s '));
$audit->save();

}
protected function Audpreupdate($id)
{ //auditando antes de actualizar...
$b = new Criteria();
$b->add(BancoPeer::IDBANCO,$id);
$bs = BancoPeer::DoSelect($b);
foreach ($bs as $dat)
{
$valorAnt=$dat->getIdbanco().'/'.$dat->getNombreBanco();
}
$audit = new Auditoria();
$audit->setUsuarioIdusuario(1);//rescaten el usuario con sf_user->
$audit->setValorAct(''); //vacio
$audit->setValorAnt($valorAnt);
$audit->setOperacion('Update');
$audit->setTablaModificada('Banco');
$audit->setFechaAcceso(Date('Y/m/d H:i:s '));
$audit->save();

}
protected function Aupostupdate($id)
{ //auditando despues de actualizar...
$b = new Criteria();
$b->add(BancoPeer::IDBANCO,$id);
$bs = BancoPeer::DoSelect($b);
foreach ($bs as $dat)
{
$valorAct=$dat->getIdbanco().'/'.$dat->getNombreBanco();
}
$c = new Criteria();$c->addSelectColumn('MAX('.AuditoriaPeer::NUMERO_AUDITORIA.')');//////////////////////////////////////
$rs = AuditoriaPeer::DoSelect($c); /// rescato mi ultimo id auditoria ///
foreach ($rs as $max){$Ultimoid=$max->getNumeroAuditoria();} //////////////////////////////////////

$d = new Criteria();
$d->add(AuditoriaPeer::NUMERO_AUDITORIA,$Ultimoid);
$ce = AuditoriaPeer::doSelect($d);
foreach ($ce as $med)
{$med->setValorAct($valorAct);//solo seteo el valor vacio de Aupreupdate() por el valoractual
$med->save();
}

}
protected function Ausave()
{ //auditando despues de actualizar...
$c = new Criteria();$c->addSelectColumn('MAX('.BancoPeer::IDBANCO.')');//////////////////////////////////////
$rs = BancoPeer::DoSelect($c); /// rescato mi ultimo id Banco ///
foreach ($rs as $max){$Ultimoid=$max->getIdbanco();} //////////////////////////////////////
$b = new Criteria();
$b->add(BancoPeer::IDBANCO,$Ultimoid);
$bs = BancoPeer::DoSelect($b);
foreach ($bs as $dat)
{
$valorAct=$dat->getIdbanco().'/'.$dat->getNombreBanco();
}
$audit = new Auditoria();
$audit->setUsuarioIdusuario(1);//rescaten el usuario con sf_user->
$audit->setValorAct($valorAct);
$audit->setValorAnt(''); //vacio
$audit->setOperacion('Save');
$audit->setTablaModificada('Banco');
$audit->setFechaAcceso(Date('Y/m/d H:i:s '));
$audit->save();

}

protected function updateBancoFromRequest()
{
$banco = $this->getRequestParameter('banco');
if(($this->getRequestParameter('idbanco'))!= '' || ($this->getRequestParameter('idbanco'))!=null)
{ ///////////////////////////////////////////////////////////////////
$this->Audpreupdate($this->getRequestParameter('idbanco'));//para auditar despues del update agragego el id para mi criteria /
} ///////////////////////////////////////////////////////////////////
if (isset($banco['nombre_banco']))
{
$this->banco->setNombreBanco($banco['nombre_banco']);
}

}

protected function getBancoOrCreate($idbanco = 'idbanco')

{
if ($this->getRequestParameter($idbanco) === ''
|| $this->getRequestParameter($idbanco) === null)
{
$banco = new Banco();

}
else
{
$banco = BancoPeer::retrieveByPk($this->getRequestParameter($idbanco));

$this->forward404Unless($banco);
}

return $banco;
}

protected function processFilters()
{
if ($this->getRequest()->hasParameter('filter'))
{
$this->getUser()->getAttributeHolder()->removeNamespace('sf_admin/banco/filters');

$filters = $this->getRequestParameter('filters');
if(is_array($filters))
{
$this->getUser()->getAttributeHolder()->removeNamespace('sf_admin/banco');
$this->getUser()->getAttributeHolder()->removeNamespace('sf_admin/banco/filters');
$this->getUser()->getAttributeHolder()->add($filters, 'sf_admin/banco/filters');
}
}
}

protected function processSort()
{
if ($this->getRequestParameter('sort'))
{
$this->getUser()->setAttribute('sort', $this->getRequestParameter('sort'), 'sf_admin/banco/sort');
$this->getUser()->setAttribute('type', $this->getRequestParameter('type', 'asc'), 'sf_admin/banco/sort');
}

if (!$this->getUser()->getAttribute('sort', null, 'sf_admin/banco/sort'))
{
}
}

protected function addFiltersCriteria($c)
{
if (isset($this->filters['idbanco_is_empty']))
{
$criterion = $c->getNewCriterion(BancoPeer::IDBANCO, '');
$criterion->addOr($c->getNewCriterion(BancoPeer::IDBANCO, null, Criteria::ISNULL));
$c->add($criterion);
}
else if (isset($this->filters['idbanco']) && $this->filters['idbanco'] !== '')
{
$c->add(BancoPeer::IDBANCO, $this->filters['idbanco']);
}
if (isset($this->filters['nombre_banco_is_empty']))
{
$criterion = $c->getNewCriterion(BancoPeer::NOMBRE_BANCO, '');
$criterion->addOr($c->getNewCriterion(BancoPeer::NOMBRE_BANCO, null, Criteria::ISNULL));
$c->add($criterion);
}
else if (isset($this->filters['nombre_banco']) && $this->filters['nombre_banco'] !== '')
{
$c->add(BancoPeer::NOMBRE_BANCO, strtr($this->filters['nombre_banco'], '*', '%'), Criteria::LIKE);
}
}

protected function addSortCriteria($c)
{
if ($sort_column = $this->getUser()->getAttribute('sort', null, 'sf_admin/banco/sort'))
{
// camelize lower case to be able to compare with BasePeer::TYPE_PHPNAME translate field name
$sort_column = BancoPeer::translateFieldName(sfInflector::camelize(strtolower($sort_column)), BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME);
if ($this->getUser()->getAttribute('type', null, 'sf_admin/banco/sort') == 'asc')
{
$c->addAscendingOrderByColumn($sort_column);
}
else
{
$c->addDescendingOrderByColumn($sort_column);
}
}
}

protected function getLabels()
{
return array(
'banco{idbanco}' => 'Codigo Banco:',
'banco{nombre_banco}' => 'nombre Banco:',
);
}
}

No hay comentarios:

Publicar un comentario