Changeset 595

Show
Ignore:
Timestamp:
09/28/07 15:38:45 (1 year ago)
Author:
laurentj
Message:

ticket #281 : added some hook methods on jControllerDaoCrud

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0beta3.x/lib/jelix/controllers/jControllerDaoCrud.class.php

    r594 r595  
    113113 
    114114    /** 
    115      * you can do your own datas check of a form. Called only if the $form->check() is ok. 
     115     * you can do your own datas check of a form by overloading this method. 
     116     * You can also do some other things. It is called only if the $form->check() is ok. 
     117     * and before the save of the datas. 
    116118     * @param jFormsBase $form the current form 
     119     * @param boolean $calltype   true for an update, false for a create 
    117120     * @return boolean true if it is ok. 
    118121     */ 
    119     protected function _checkDatas($form){ 
     122    protected function _checkDatas($form, $calltype){ 
    120123        return true; 
    121124    } 
     
    152155        $tpl->assign('recordCount',$dao->countAll()); 
    153156        $tpl->assign('offsetParameterName',$this->offsetParameterName); 
     157 
     158        $this->_index($rep, $tpl); 
     159 
    154160        $rep->body->assign($this->templateAssign, $tpl->fetch($this->listTemplate)); 
    155161 
    156162        return $rep; 
     163    } 
     164 
     165    /** 
     166     * overload this method if you wan to do additionnal things on the response and on the list template 
     167     * during the index action. 
     168     * @param jHtmlResponse $resp the response 
     169     * @param jtpl $tpl the template to display the record list 
     170     */ 
     171    protected function _index($resp, $tpl) { 
     172 
    157173    } 
    158174 
     
    172188        $tpl->assign('submitAction', $this->_getAction('savecreate')); 
    173189        $tpl->assign('listAction' , $this->_getAction('index')); 
     190        $this->_create($rep, $tpl); 
    174191        $rep->body->assign($this->templateAssign, $tpl->fetch($this->editTemplate)); 
    175192        return $rep; 
     193 
     194    } 
     195 
     196    /** 
     197     * overload this method if you wan to do additionnal things on the response and on the edit template 
     198     * during the create action. 
     199     * @param jHtmlResponse $resp the response 
     200     * @param jtpl $tpl the template to display the edit form  
     201     */ 
     202    protected function _create($resp, $tpl) { 
    176203 
    177204    } 
     
    188215        } 
    189216 
    190         if($form->check() && $this->_checkDatas($form)){ 
     217        if($form->check() && $this->_checkDatas($form, false)){ 
    191218            $id = $form->saveToDao($this->dao, null, $this->dbProfil); 
    192219            $form->saveAllFiles($this->uploadsDirectory); 
    193220            $rep->action = $this->_getAction('view'); 
     221            $this->_afterCreate($form, $id); 
    194222            jForms::destroy($this->form); 
    195223            $rep->params['id'] = $id; 
     
    200228        } 
    201229    } 
     230 
     231    /** 
     232     * overload this method if you wan to do additionnal things after the creation of 
     233     * a record 
     234     * @param jFormsBase $form the form object 
     235     * @param mixed $id the new id of the inserted record 
     236     */ 
     237    protected function _afterCreate($form, $id) { 
     238 
     239    } 
     240 
    202241 
    203242    /** 
     
    248287        $tpl->assign('listAction' , $this->_getAction('index')); 
    249288        $tpl->assign('viewAction' , $this->_getAction('view')); 
     289        $this->_editUpdate($rep, $tpl); 
    250290        $rep->body->assign($this->templateAssign, $tpl->fetch($this->editTemplate)); 
    251291        return $rep; 
     292    } 
     293 
     294    /** 
     295     * overload this method if you wan to do additionnal things on the response and on the edit template 
     296     * during the editupdate action. 
     297     * @param jHtmlResponse $resp the response 
     298     * @param jtpl $tpl the template to display the edit form  
     299     */ 
     300    protected function _editUpdate($resp, $tpl) { 
     301 
    252302    } 
    253303 
     
    264314        } 
    265315 
    266         if($form->check() && $this->_checkDatas($form)){ 
     316        if($form->check() && $this->_checkDatas($form, true)){ 
    267317            $id = $form->saveToDao($this->dao, null, $this->dbProfil); 
    268318            $form->saveAllFiles($this->uploadsDirectory); 
     319            $this->_afterUpdate($form, $id); 
    269320            $rep->action = $this->_getAction('view'); 
    270321            jForms::destroy($this->form, $id); 
     
    274325        $rep->params['id'] = $id; 
    275326        return $rep; 
     327    } 
     328 
     329    /** 
     330     * overload this method if you wan to do additionnal things after the update of 
     331     * a record 
     332     * @param jFormsBase $form the form object 
     333     * @param mixed $id the new id of the updated record 
     334     */ 
     335    protected function _afterUpdate($form, $id) { 
     336 
    276337    } 
    277338 
     
    299360        $tpl->assign('deleteAction' , $this->_getAction('delete')); 
    300361        $tpl->assign('listAction' , $this->_getAction('index')); 
     362        $this->_view($rep,$tpl); 
    301363        $rep->body->assign($this->templateAssign, $tpl->fetch($this->viewTemplate)); 
    302364        return $rep; 
     365    } 
     366 
     367    /** 
     368     * overload this method if you want to do additionnal things on the response and on the view template 
     369     * during the view action. 
     370     * @param jHtmlResponse $resp the response 
     371     * @param jtpl $tpl the template to display the form content 
     372     */ 
     373    protected function _view($resp, $tpl) { 
     374 
    303375    } 
    304376 
     
    308380    function delete(){ 
    309381        $id = $this->param('id'); 
    310         if( $id !== null ){ 
     382        if( $id !== null && $this->_delete($id) ){ 
    311383            $dao = jDao::get($this->dao, $this->dbProfil); 
    312384            $dao->delete($id); 
     
    316388        return $rep; 
    317389    } 
     390 
     391    /** 
     392     * overload this method if you want to do additionnal things before the deletion of a record 
     393     * @param mixed $id the new id of the record 
     394     * @return boolean true if the record can be deleted 
     395     */ 
     396    protected function _delete($id) { 
     397        return true; 
     398    } 
     399 
    318400} 
    319401 
  • branches/1.0beta3.x/lib/jelix/controllers/jControllerDaoCrud.class.php

    r594 r595  
    113113 
    114114    /** 
    115      * you can do your own datas check of a form. Called only if the $form->check() is ok. 
     115     * you can do your own datas check of a form by overloading this method. 
     116     * You can also do some other things. It is called only if the $form->check() is ok. 
     117     * and before the save of the datas. 
    116118     * @param jFormsBase $form the current form 
     119     * @param boolean $calltype   true for an update, false for a create 
    117120     * @return boolean true if it is ok. 
    118121     */ 
    119     protected function _checkDatas($form){ 
     122    protected function _checkDatas($form, $calltype){ 
    120123        return true; 
    121124    } 
     
    152155        $tpl->assign('recordCount',$dao->countAll()); 
    153156        $tpl->assign('offsetParameterName',$this->offsetParameterName); 
     157 
     158        $this->_index($rep, $tpl); 
     159 
    154160        $rep->body->assign($this->templateAssign, $tpl->fetch($this->listTemplate)); 
    155161 
    156162        return $rep; 
     163    } 
     164 
     165    /** 
     166     * overload this method if you wan to do additionnal things on the response and on the list template 
     167     * during the index action. 
     168     * @param jHtmlResponse $resp the response 
     169     * @param jtpl $tpl the template to display the record list 
     170     */ 
     171    protected function _index($resp, $tpl) { 
     172 
    157173    } 
    158174 
     
    172188        $tpl->assign('submitAction', $this->_getAction('savecreate')); 
    173189        $tpl->assign('listAction' , $this->_getAction('index')); 
     190        $this->_create($rep, $tpl); 
    174191        $rep->body->assign($this->templateAssign, $tpl->fetch($this->editTemplate)); 
    175192        return $rep; 
     193 
     194    } 
     195 
     196    /** 
     197     * overload this method if you wan to do additionnal things on the response and on the edit template 
     198     * during the create action. 
     199     * @param jHtmlResponse $resp the response 
     200     * @param jtpl $tpl the template to display the edit form  
     201     */ 
     202    protected function _create($resp, $tpl) { 
    176203 
    177204    } 
     
    188215        } 
    189216 
    190         if($form->check() && $this->_checkDatas($form)){ 
     217        if($form->check() && $this->_checkDatas($form, false)){ 
    191218            $id = $form->saveToDao($this->dao, null, $this->dbProfil); 
    192219            $form->saveAllFiles($this->uploadsDirectory); 
    193220            $rep->action = $this->_getAction('view'); 
     221            $this->_afterCreate($form, $id); 
    194222            jForms::destroy($this->form); 
    195223            $rep->params['id'] = $id; 
     
    200228        } 
    201229    } 
     230 
     231    /** 
     232     * overload this method if you wan to do additionnal things after the creation of 
     233     * a record 
     234     * @param jFormsBase $form the form object 
     235     * @param mixed $id the new id of the inserted record 
     236     */ 
     237    protected function _afterCreate($form, $id) { 
     238 
     239    } 
     240 
    202241 
    203242    /** 
     
    248287        $tpl->assign('listAction' , $this->_getAction('index')); 
    249288        $tpl->assign('viewAction' , $this->_getAction('view')); 
     289        $this->_editUpdate($rep, $tpl); 
    250290        $rep->body->assign($this->templateAssign, $tpl->fetch($this->editTemplate)); 
    251291        return $rep; 
     292    } 
     293 
     294    /** 
     295     * overload this method if you wan to do additionnal things on the response and on the edit template 
     296     * during the editupdate action. 
     297     * @param jHtmlResponse $resp the response 
     298     * @param jtpl $tpl the template to display the edit form  
     299     */ 
     300    protected function _editUpdate($resp, $tpl) { 
     301 
    252302    } 
    253303 
     
    264314        } 
    265315 
    266         if($form->check() && $this->_checkDatas($form)){ 
     316        if($form->check() && $this->_checkDatas($form, true)){ 
    267317            $id = $form->saveToDao($this->dao, null, $this->dbProfil); 
    268318            $form->saveAllFiles($this->uploadsDirectory); 
     319            $this->_afterUpdate($form, $id); 
    269320            $rep->action = $this->_getAction('view'); 
    270321            jForms::destroy($this->form, $id); 
     
    274325        $rep->params['id'] = $id; 
    275326        return $rep; 
     327    } 
     328 
     329    /** 
     330     * overload this method if you wan to do additionnal things after the update of 
     331     * a record 
     332     * @param jFormsBase $form the form object 
     333     * @param mixed $id the new id of the updated record 
     334     */ 
     335    protected function _afterUpdate($form, $id) { 
     336 
    276337    } 
    277338 
     
    299360        $tpl->assign('deleteAction' , $this->_getAction('delete')); 
    300361        $tpl->assign('listAction' , $this->_getAction('index')); 
     362        $this->_view($rep,$tpl); 
    301363        $rep->body->assign($this->templateAssign, $tpl->fetch($this->viewTemplate)); 
    302364        return $rep; 
     365    } 
     366 
     367    /** 
     368     * overload this method if you want to do additionnal things on the response and on the view template 
     369     * during the view action. 
     370     * @param jHtmlResponse $resp the response 
     371     * @param jtpl $tpl the template to display the form content 
     372     */ 
     373    protected function _view($resp, $tpl) { 
     374 
    303375    } 
    304376 
     
    308380    function delete(){ 
    309381        $id = $this->param('id'); 
    310         if( $id !== null ){ 
     382        if( $id !== null && $this->_delete($id) ){ 
    311383            $dao = jDao::get($this->dao, $this->dbProfil); 
    312384            $dao->delete($id); 
     
    316388        return $rep; 
    317389    } 
     390 
     391    /** 
     392     * overload this method if you want to do additionnal things before the deletion of a record 
     393     * @param mixed $id the new id of the record 
     394     * @return boolean true if the record can be deleted 
     395     */ 
     396    protected function _delete($id) { 
     397        return true; 
     398    } 
     399 
    318400} 
    319401 
  • trunk/lib/jelix/controllers/jControllerDaoCrud.class.php

    r594 r595  
    113113 
    114114    /** 
    115      * you can do your own datas check of a form. Called only if the $form->check() is ok. 
     115     * you can do your own datas check of a form by overloading this method. 
     116     * You can also do some other things. It is called only if the $form->check() is ok. 
     117     * and before the save of the datas. 
    116118     * @param jFormsBase $form the current form 
     119     * @param boolean $calltype   true for an update, false for a create 
    117120     * @return boolean true if it is ok. 
    118121     */ 
    119     protected function _checkDatas($form){ 
     122    protected function _checkDatas($form, $calltype){ 
    120123        return true; 
    121124    } 
     
    152155        $tpl->assign('recordCount',$dao->countAll()); 
    153156        $tpl->assign('offsetParameterName',$this->offsetParameterName); 
     157 
     158        $this->_index($rep, $tpl); 
     159 
    154160        $rep->body->assign($this->templateAssign, $tpl->fetch($this->listTemplate)); 
    155161 
    156162        return $rep; 
     163    } 
     164 
     165    /** 
     166     * overload this method if you wan to do additionnal things on the response and on the list template 
     167     * during the index action. 
     168     * @param jHtmlResponse $resp the response 
     169     * @param jtpl $tpl the template to display the record list 
     170     */ 
     171    protected function _index($resp, $tpl) { 
     172 
    157173    } 
    158174 
     
    172188        $tpl->assign('submitAction', $this->_getAction('savecreate')); 
    173189        $tpl->assign('listAction' , $this->_getAction('index')); 
     190        $this->_create($rep, $tpl); 
    174191        $rep->body->assign($this->templateAssign, $tpl->fetch($this->editTemplate)); 
    175192        return $rep; 
     193 
     194    } 
     195 
     196    /** 
     197     * overload this method if you wan to do additionnal things on the response and on the edit template 
     198     * during the create action. 
     199     * @param jHtmlResponse $resp the response 
     200     * @param jtpl $tpl the template to display the edit form  
     201     */ 
     202    protected function _create($resp, $tpl) { 
    176203 
    177204    } 
     
    188215        } 
    189216 
    190         if($form->check() && $this->_checkDatas($form)){ 
     217        if($form->check() && $this->_checkDatas($form, false)){ 
    191218            $id = $form->saveToDao($this->dao, null, $this->dbProfil); 
    192219            $form->saveAllFiles($this->uploadsDirectory); 
    193220            $rep->action = $this->_getAction('view'); 
     221            $this->_afterCreate($form, $id); 
    194222            jForms::destroy($this->form); 
    195223            $rep->params['id'] = $id; 
     
    200228        } 
    201229    } 
     230 
     231    /** 
     232     * overload this method if you wan to do additionnal things after the creation of 
     233     * a record 
     234     * @param jFormsBase $form the form object 
     235     * @param mixed $id the new id of the inserted record 
     236     */ 
     237    protected function _afterCreate($form, $id) { 
     238 
     239    } 
     240 
    202241 
    203242    /** 
     
    248287        $tpl->assign('listAction' , $this->_getAction('index')); 
    249288        $tpl->assign('viewAction' , $this->_getAction('view')); 
     289        $this->_editUpdate($rep, $tpl); 
    250290        $rep->body->assign($this->templateAssign, $tpl->fetch($this->editTemplate)); 
    251291        return $rep; 
     292    } 
     293 
     294    /** 
     295     * overload this method if you wan to do additionnal things on the response and on the edit template 
     296     * during the editupdate action. 
     297     * @param jHtmlResponse $resp the response 
     298     * @param jtpl $tpl the template to display the edit form  
     299     */ 
     300    protected function _editUpdate($resp, $tpl) { 
     301 
    252302    } 
    253303 
     
    264314        } 
    265315 
    266         if($form->check() && $this->_checkDatas($form)){ 
     316        if($form->check() && $this->_checkDatas($form, true)){ 
    267317            $id = $form->saveToDao($this->dao, null, $this->dbProfil); 
    268318            $form->saveAllFiles($this->uploadsDirectory); 
     319            $this->_afterUpdate($form, $id); 
    269320            $rep->action = $this->_getAction('view'); 
    270321            jForms::destroy($this->form, $id); 
     
    274325        $rep->params['id'] = $id; 
    275326        return $rep; 
     327    } 
     328 
     329    /** 
     330     * overload this method if you wan to do additionnal things after the update of 
     331     * a record 
     332     * @param jFormsBase $form the form object 
     333     * @param mixed $id the new id of the updated record 
     334     */ 
     335    protected function _afterUpdate($form, $id) { 
     336 
    276337    } 
    277338 
     
    299360        $tpl->assign('deleteAction' , $this->_getAction('delete')); 
    300361        $tpl->assign('listAction' , $this->_getAction('index')); 
     362        $this->_view($rep,$tpl); 
    301363        $rep->body->assign($this->templateAssign, $tpl->fetch($this->viewTemplate)); 
    302364        return $rep; 
     365    } 
     366 
     367    /** 
     368     * overload this method if you want to do additionnal things on the response and on the view template 
     369     * during the view action. 
     370     * @param jHtmlResponse $resp the response 
     371     * @param jtpl $tpl the template to display the form content 
     372     */ 
     373    protected function _view($resp, $tpl) { 
     374 
    303375    } 
    304376 
     
    308380    function delete(){ 
    309381        $id = $this->param('id'); 
    310         if( $id !== null ){ 
     382        if( $id !== null && $this->_delete($id) ){ 
    311383            $dao = jDao::get($this->dao, $this->dbProfil); 
    312384            $dao->delete($id); 
     
    316388        return $rep; 
    317389    } 
     390 
     391    /** 
     392     * overload this method if you want to do additionnal things before the deletion of a record 
     393     * @param mixed $id the new id of the record 
     394     * @return boolean true if the record can be deleted 
     395     */ 
     396    protected function _delete($id) { 
     397        return true; 
     398    } 
     399 
    318400} 
    319401 
  • trunk/lib/jelix/controllers/jControllerDaoCrud.class.php

    r594 r595  
    113113 
    114114    /** 
    115      * you can do your own datas check of a form. Called only if the $form->check() is ok. 
     115     * you can do your own datas check of a form by overloading this method. 
     116     * You can also do some other things. It is called only if the $form->check() is ok. 
     117     * and before the save of the datas. 
    116118     * @param jFormsBase $form the current form 
     119     * @param boolean $calltype   true for an update, false for a create 
    117120     * @return boolean true if it is ok. 
    118121     */ 
    119     protected function _checkDatas($form){ 
     122    protected function _checkDatas($form, $calltype){ 
    120123        return true; 
    121124    } 
     
    152155        $tpl->assign('recordCount',$dao->countAll()); 
    153156        $tpl->assign('offsetParameterName',$this->offsetParameterName); 
     157 
     158        $this->_index($rep, $tpl); 
     159 
    154160        $rep->body->assign($this->templateAssign, $tpl->fetch($this->listTemplate)); 
    155161 
    156162        return $rep; 
     163    } 
     164 
     165    /** 
     166     * overload this method if you wan to do additionnal things on the response and on the list template 
     167     * during the index action. 
     168     * @param jHtmlResponse $resp the response 
     169     * @param jtpl $tpl the template to display the record list 
     170     */ 
     171    protected function _index($resp, $tpl) { 
     172 
    157173    } 
    158174 
     
    172188        $tpl->assign('submitAction', $this->_getAction('savecreate')); 
    173189        $tpl->assign('listAction' , $this->_getAction('index')); 
     190        $this->_create($rep, $tpl); 
    174191        $rep->body->assign($this->templateAssign, $tpl->fetch($this->editTemplate)); 
    175192        return $rep; 
     193 
     194    } 
     195 
     196    /** 
     197     * overload this method if you wan to do additionnal things on the response and on the edit template 
     198     * during the create action. 
     199     * @param jHtmlResponse $resp the response 
     200     * @param jtpl $tpl the template to display the edit form  
     201     */ 
     202    protected function _create($resp, $tpl) { 
    176203 
    177204    } 
     
    188215        } 
    189216 
    190         if($form->check() && $this->_checkDatas($form)){ 
     217        if($form->check() && $this->_checkDatas($form, false)){ 
    191218            $id = $form->saveToDao($this->dao, null, $this->dbProfil); 
    192219            $form->saveAllFiles($this->uploadsDirectory); 
    193220            $rep->action = $this->_getAction('view'); 
     221            $this->_afterCreate($form, $id); 
    194222            jForms::destroy($this->form); 
    195223            $rep->params['id'] = $id; 
     
    200228        } 
    201229    } 
     230 
     231    /** 
     232     * overload this method if you wan to do additionnal things after the creation of 
     233     * a record 
     234     * @param jFormsBase $form the form object 
     235     * @param mixed $id the new id of the inserted record 
     236     */ 
     237    protected function _afterCreate($form, $id) { 
     238 
     239    } 
     240 
    202241 
    203242    /** 
     
    248287        $tpl->assign('listAction' , $this->_getAction('index')); 
    249288        $tpl->assign('viewAction' , $this->_getAction('view')); 
     289        $this->_editUpdate($rep, $tpl); 
    250290        $rep->body->assign($this->templateAssign, $tpl->fetch($this->editTemplate)); 
    251291        return $rep; 
     292    } 
     293 
     294    /** 
     295     * overload this method if you wan to do additionnal things on the response and on the edit template 
     296     * during the editupdate action. 
     297     * @param jHtmlResponse $resp the response 
     298     * @param jtpl $tpl the template to display the edit form  
     299     */ 
     300    protected function _editUpdate($resp, $tpl) { 
     301 
    252302    } 
    253303 
     
    264314        } 
    265315 
    266         if($form->check() && $this->_checkDatas($form)){ 
     316        if($form->check() && $this->_checkDatas($form, true)){ 
    267317            $id = $form->saveToDao($this->dao, null, $this->dbProfil); 
    268318            $form->saveAllFiles($this->uploadsDirectory); 
     319            $this->_afterUpdate($form, $id); 
    269320            $rep->action = $this->_getAction('view'); 
    270321            jForms::destroy($this->form, $id); 
     
    274325        $rep->params['id'] = $id; 
    275326        return $rep; 
     327    } 
     328 
     329    /** 
     330     * overload this method if you wan to do additionnal things after the update of 
     331     * a record 
     332     * @param jFormsBase $form the form object 
     333     * @param mixed $id the new id of the updated record 
     334     */ 
     335    protected function _afterUpdate($form, $id) { 
     336 
    276337    } 
    277338 
     
    299360        $tpl->assign('deleteAction' , $this->_getAction('delete')); 
    300361        $tpl->assign('listAction' , $this->_getAction('index')); 
     362        $this->_view($rep,$tpl); 
    301363        $rep->body->assign($this->templateAssign, $tpl->fetch($this->viewTemplate)); 
    302364        return $rep; 
     365    } 
     366 
     367    /** 
     368     * overload this method if you want to do additionnal things on the response and on the view template 
     369     * during the view action. 
     370     * @param jHtmlResponse $resp the response 
     371     * @param jtpl $tpl the template to display the form content 
     372     */ 
     373    protected function _view($resp, $tpl) { 
     374 
    303375    } 
    304376 
     
    308380    function delete(){ 
    309381        $id = $this->param('id'); 
    310         if( $id !== null ){ 
     382        if( $id !== null && $this->_delete($id) ){ 
    311383            $dao = jDao::get($this->dao, $this->dbProfil); 
    312384            $dao->delete($id); 
     
    316388        return $rep; 
    317389    } 
     390 
     391    /** 
     392     * overload this method if you want to do additionnal things before the deletion of a record 
     393     * @param mixed $id the new id of the record 
     394     * @return boolean true if the record can be deleted 
     395     */ 
     396    protected function _delete($id) { 
     397        return true; 
     398    } 
     399 
    318400} 
    319401 
Download in other formats: Unified Diff Zip Archive