Skip to content

Commit

Permalink
Domain Hooks
Browse files Browse the repository at this point in the history
Add hooks in domain controller :
- domain_add_formPostProcess
- domain_add_addPrepare
- domain_add_addPrevalidate
- domain_add_addPostvalidate
- domain_add_addFinish
- domain_purge_preRemove
- domain_purge_purgeFinish
  • Loading branch information
Tribal-Dolphin committed Mar 14, 2015
1 parent f423437 commit 88783c2
Showing 1 changed file with 55 additions and 18 deletions.
73 changes: 55 additions & 18 deletions application/controllers/DomainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
class DomainController extends ViMbAdmin_Controller_Action
{

/**
* Local store for the form
* @var ViMbAdmin_Form_Domain_AddEdit
*/
private $domainForm = null;

/**
* Most actions in this object will require a domain object to edit / act on.
*
Expand Down Expand Up @@ -138,17 +144,31 @@ public function ajaxToggleActiveAction()
}


/**
* Instantiate / get the domain add-edit form
* @return ViMbAdmin_Form_Domain_AddEdit
*/
public function getDomainForm()
{
if( $this->domainForm == null )
{
$form = new ViMbAdmin_Form_Domain_AddEdit();
if( isset( $this->_options['defaults']['quota']['multiplier'] ) )
$form->setFilterFileSizeMultiplier( $this->_options['defaults']['quota']['multiplier'] );

$this->view->form = $this->domainForm = $form;

// call plugins
$this->notify( 'domain', 'add', 'formPostProcess', $this );
}
return $this->domainForm;
}

/**
* Add / edit a domain.
*/
public function addAction()
{
$form = $this->view->form = new ViMbAdmin_Form_Domain_AddEdit();
if( isset( $this->_options['defaults']['quota']['multiplier'] ) )
$form->setFilterFileSizeMultiplier( $this->_options['defaults']['quota']['multiplier'] );

$this->view->quota_multiplier = $form->getFilterFileSizeMultiplier();

if( !$this->getDomain() )
{
$this->view->isEdit = $isEdit = false;
Expand All @@ -159,7 +179,7 @@ public function addAction()
$this->getD2EM()->persist( $this->_domain );

// set defaults

$form = $this->getDomainForm();
$form->getElement( 'max_mailboxes' )->setValue( $this->_options['defaults']['domain']['mailboxes'] );
$form->getElement( 'max_aliases' )->setValue( $this->_options['defaults']['domain']['aliases'] );
$form->getElement( 'transport' )->setValue( $this->_options['defaults']['domain']['transport'] );
Expand All @@ -169,32 +189,47 @@ public function addAction()
else
{
$this->view->isEdit = $isEdit = true;
$form = $this->getDomainForm();
$form->assignEntityToForm( $this->getDomain(), $this, $isEdit );
$form->getElement( 'domain' )
->setAttrib( 'readonly', 'readonly' )
->setRequired( false )
->removeValidator( 'OSSDoctrine2Uniqueness' );
}

$this->view->quota_multiplier = $form->getFilterFileSizeMultiplier();

$this->view->domain = $this->getDomain();

if( $this->getRequest()->isPost() && $form->isValid( $_POST ) )
$this->notify( 'domain', 'add', 'addPrepare', $this );

if( $this->getRequest()->isPost() )
{
$form->assignFormToEntity( $this->getDomain(), $this, $isEdit );
$this->notify( 'domain', 'add', 'addPrevalidate', $this );

if( $form->isValid( $_POST ) )
{
$this->notify( 'domain', 'add', 'addPostvalidate', $this );

$form->assignFormToEntity( $this->getDomain(), $this, $isEdit );

if( $isEdit )
$this->getDomain()->setModified( new \DateTime() );
if( $isEdit )
$this->getDomain()->setModified( new \DateTime() );

$this->log(
$isEdit ? \Entities\Log::ACTION_DOMAIN_EDIT : \Entities\Log::ACTION_DOMAIN_ADD,
"{$this->getAdmin()->getFormattedName()} " . ( $isEdit ? ' edited' : ' added' ) . " domain {$this->getDomain()->getDomain()}"
);
$this->log(
$isEdit ? \Entities\Log::ACTION_DOMAIN_EDIT : \Entities\Log::ACTION_DOMAIN_ADD,
"{$this->getAdmin()->getFormattedName()} " . ( $isEdit ? ' edited' : ' added' ) . " domain {$this->getDomain()->getDomain()}"
);

$this->getD2EM()->flush();
$this->notify( 'domain', 'add', 'addPreflush', $this );
$this->getD2EM()->flush();
$this->notify( 'domain', 'add', 'addPostflush', $this );

$this->addMessage( _( "You have successfully added/edited the domain record." ), OSS_Message::SUCCESS );
$this->notify( 'domain', 'add', 'addFinish', $this );
$this->addMessage( _( "You have successfully added/edited the domain record." ), OSS_Message::SUCCESS );

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

Expand Down Expand Up @@ -295,7 +330,9 @@ public function assignAdminAction()
public function purgeAction()
{
$this->authorise( true );
$this->notify( 'domain', 'purge', 'preRemove', $this );
$this->getD2EM()->getRepository( '\\Entities\\Domain' )->purge( $this->getDomain() );
$this->notify( 'domain', 'purge', 'purgeFinish', $this );
$this->redirect( 'domain/list' );
}
}

0 comments on commit 88783c2

Please sign in to comment.