FORMidable RAD Framework

class.tx_rdtsearchform.php

00001 <?php
00009 class tx_rdtsearchform extends formidable_mainrenderlet {
00010 
00011         var $oDataSource = FALSE;
00012         var $aCriterias = FALSE;
00013         var $aFilters = FALSE;
00014         var $aDescendants = FALSE;
00015 
00016         function _init(&$oForm, $aElement, $aObjectType, $sXPath) {
00017                 parent::_init($oForm, $aElement, $aObjectType, $sXPath);
00018                 $this->_initDescendants();
00019         }
00020 
00021         function _render() {
00022 
00023                 $this->_initData();
00024 
00025                 $aChildBags = $this->renderChildsBag();
00026                 $sCompiledChilds = $this->renderChildsCompiled($aChildBags);
00027 
00028                 return array(
00029                         "__compiled" => $this->_displayLabel($sLabel) . $sCompiledChilds,
00030                         "childs" => $aChildBags
00031                 );
00032         }
00033         
00034         function getDescendants() {
00035                 
00036                 $aDescendants = array();
00037                 $sMyName = $this->_getName();
00038                 
00039                 $aRdts = array_keys($this->oForm->aORenderlets);
00040                 reset($aRdts);
00041                 while(list(, $sName) = each($aRdts)) {
00042                         if($this->oForm->aORenderlets[$sName]->isDescendantOf($sMyName)) {
00043                                 $aDescendants[] = $sName;
00044                         }
00045                 }
00046 
00047                 return $aDescendants;
00048         }
00049 
00050         function _initDescendants() {
00051                 if($this->aDescendants === FALSE) {
00052                         $this->aDescendants = $this->getDescendants();
00053                 }
00054         }
00055 
00056         function _initData() {
00057                 //$this->_initDescendants();    // done in _init()
00058                 $this->_initCriterias();        // if submitted, take from post ; if not, take from session
00059                                                                         // and inject values into renderlets
00060                 $this->_initFilters();
00061                 $this->_initDataSource();
00062         }
00063 
00064         function mayHaveChilds() {
00065                 return TRUE;
00066         }
00067 
00068         function _initDataSource() {
00069 
00070                 if($this->oDataSource === FALSE) {
00071 
00072                         if(($sDsToUse = $this->_navConf("/datasource/use")) === FALSE) {
00073                                 $this->oForm->mayday("RENDERLET SEARCHFORM - requires /datasource/use to be properly set. Check your XML conf.");
00074                         } elseif(!array_key_exists($sDsToUse, $this->oForm->aODataSources)) {
00075                                 $this->oForm->mayday("RENDERLET SEARCHFORM - refers to undefined datasource '" . $sDsToUse . "'. Check your XML conf.");
00076                         }
00077 
00078                         $this->oDataSource =& $this->oForm->aODataSources[$sDsToUse];
00079                 }
00080         }
00081 
00082         function clearFilters() {
00083 
00084                 reset($this->aDescendants);
00085                 while(list(, $sName) = each($this->aDescendants)) {
00086                         $this->oForm->aORenderlets[$sName]->setValue("");
00087                 }
00088 
00089                 $this->aCriterias = array();
00090                 $aAppData =& $GLOBALS["_SESSION"]["ameos_formidable"]["applicationdata"];
00091                 $aAppData["rdt_lister"][$this->oForm->formid][$this->_getName()]["criterias"] = array();
00092         }
00093 
00094         function _initCriterias() {
00095 
00096                 if($this->aCriterias === FALSE) {
00097                         
00098                         $this->aCriterias = array();
00099 
00100                         $aAppData =& $GLOBALS["_SESSION"]["ameos_formidable"]["applicationdata"];
00101                         if(!array_key_exists("rdt_lister", $aAppData)) {
00102                                 $aAppData["rdt_lister"] = array();
00103                         }
00104 
00105                         if(!array_key_exists($this->oForm->formid, $aAppData["rdt_lister"])) {
00106                                 $aAppData["rdt_lister"][$this->oForm->formid] = array();
00107                         }
00108 
00109                         if(!array_key_exists($this->_getName(), $aAppData["rdt_lister"][$this->oForm->formid])) {
00110                                 $aAppData["rdt_lister"][$this->oForm->formid][$this->_getName()] = array();
00111                         }
00112 
00113                         if(!array_key_exists("criterias", $aAppData["rdt_lister"][$this->oForm->formid][$this->_getName()])) {
00114                                 $aAppData["rdt_lister"][$this->oForm->formid][$this->_getName()]["criterias"] = array();
00115                         }
00116                         
00117                         if($this->_getParamsFromGET()) {
00118                                 if(!$this->shouldUpdateCriterias()) {
00119                                         // take from GET params
00120                                         $this->aCriterias = (t3lib_div::_GET($this->oForm->formid)) ? t3lib_div::_GET($this->oForm->formid) : array();
00121                                         
00122                                         reset($this->aCriterias);
00123                                         while(list($sName, ) = each($this->aCriterias)) {
00124                                                 if(array_key_exists($sName, $this->oForm->aORenderlets)) {
00125                                                         $this->oForm->aORenderlets[$sName]->setValue(
00126                                                                 $this->aCriterias[$sName]
00127                                                         );
00128                                                 }
00129                                         }       
00130                                 }
00131                         } else {
00132                                 if($this->shouldUpdateCriterias()) {
00133                                         // set in session
00134                                         reset($this->aDescendants);
00135                                         while(list(, $sName) = each($this->aDescendants)) {
00136                                                 $this->aCriterias[$sName] = $this->oForm->oDataHandler->getThisFormData($sName);
00137                                         }
00138                                         
00139                                         $aAppData["rdt_lister"][$this->oForm->formid][$this->_getName()]["criterias"] = $this->aCriterias;
00140                                 } else {
00141                                         // take from session
00142                                         $this->aCriterias = $aAppData["rdt_lister"][$this->oForm->formid][$this->_getName()]["criterias"];
00143                                         
00144                                         reset($this->aCriterias);
00145                                         while(list($sName, ) = each($this->aCriterias)) {
00146                                                 if(array_key_exists($sName, $this->oForm->aORenderlets)) {
00147                                                         $this->oForm->aORenderlets[$sName]->setValue(
00148                                                                 $this->aCriterias[$sName]
00149                                                         );
00150                                                 }
00151                                         }
00152                                 }
00153                         }
00154                 }
00155 
00156                 $this->aCriterias = $this->processBeforeSearch($this->aCriterias);
00157 //              $this->oForm->d($this->aCriterias);
00158         }
00159         
00160         function shouldUpdateCriterias() {
00161 
00162                 if($this->oForm->oDataHandler->_isSubmitted() === TRUE) {
00163                         reset($this->aDescendants);
00164                         while(list(, $sName) = each($this->aDescendants)) {
00165                                 if($this->oForm->aORenderlets[$sName]->_getType() === "SUBMIT" || $this->oForm->aORenderlets[$sName]->_getType() === "CHOOSER") {
00166                                         if($this->oForm->aORenderlets[$sName]->hasSubmitted() && $this->oForm->oDataHandler->_isSearchSubmitted()) {
00167                                                 return TRUE;
00168                                         }
00169                                 }
00170                         }
00171                 }
00172 
00173                 return FALSE;
00174         }
00175         
00176         function processBeforeSearch($aCriterias) {
00177                 
00178                 if(($aBeforeSearch = $this->_navConf("/beforesearch")) !== FALSE && $this->oForm->isUserObj($aBeforeSearch)) {
00179                         $aCriterias = $this->oForm->_callUserObj($aBeforeSearch, $aCriterias);
00180                 }
00181 
00182                 return $aCriterias;
00183         }
00184 
00185         function _initFilters() {
00186 
00187                 if($this->aFilters === FALSE) {
00188 
00189                         $this->aFilters = array();
00190 
00191                         //$aFormData = $this->oForm->oDataHandler->_getFormDataManaged();
00192                         $aCriterias = $this->aCriterias;
00193 
00194                         reset($this->aCriterias);
00195                         while(list($sRdtName,) = each($this->aCriterias)) {
00196                                 if(array_key_exists($sRdtName, $this->oForm->aORenderlets)) {
00197                                         $oRdt =& $this->oForm->aORenderlets[$sRdtName];
00198                                         
00199                                         if($oRdt->_searchable()) {
00200                                                 
00201                                                 $sValue = $oRdt->_flatten($aCriterias[$sRdtName]);
00202 
00203                                                 if(!$oRdt->_emptyFormValue($sValue)) {
00204                                                         $this->aFilters[] = $oRdt->_sqlSearchClause($sValue);
00205                                                 }
00206                                         }
00207                                 }
00208                         }
00209 
00210                         reset($this->aFilters);
00211                 }
00212         }
00213 
00214         function &_getFilters() {
00215                 $this->_initFilters();
00216                 reset($this->aFilters);
00217                 return $this->aFilters;
00218         }
00219 
00220         function &_fetchData($aConfig = array()) {
00221 
00222                 return $this->oDataSource->_fetchData(
00223                         $aConfig,
00224                         $this->_getFilters()
00225                 );
00226         }
00227 
00228         function _renderOnly() {
00229                 return $this->_defaultTrue("/renderonly");
00230         }
00231         
00232         function _getParamsFromGET() {
00233                 return $this->_defaultFalse("/paramsfromget");
00234         }
00235 }
00236 
00237 
00238         if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/ameos_formidable/api/base/rdt_searchform/api/class.tx_rdtsearchform.php"])     {
00239                 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/ameos_formidable/api/base/rdt_searchform/api/class.tx_rdtsearchform.php"]);
00240         }
00241 ?>


Généré par Le spécialiste TYPO3 avec  doxygen 1.4.6