Skip to content
Snippets Groups Projects

Support für Dropdowns mit Lookup - task #4630

Merged Hahn Axel (hahn) requested to merge rollout-plugins into master
3 files
+ 193
5
Compare changes
  • Side-by-side
  • Inline

Files

<?php
require_once 'rollout.interface.php';
require_once 'cache.class.php';
/**
* rollout_base class that will beextended in a rollout plugin
@@ -117,6 +118,30 @@ class rollout_base implements iRolloutplugin{
: 'plugins[rollout]['.$this->getId().']'
);
}
/**
* get Data from a callback function and store it in a cache
* The response type depends on the callback function
*
* @param string $sFunctionname name of the callback function
* @param string $sKey name of the key; "project" or name of phase
* @param integr $iTtl ttl value = how many seconds to use cache
* @param integr $iTtlOnError ttl value = how many seconds to use cache if there was no response
* @return type
*/
protected function _getCallback($sFunctionname, $sKey, $iTtl=15,$iTtlOnError=10){
$oCache=new AhCache('rollout-'.$this->getId(), 'callback-'.$sFunctionname.'-'.$sKey);
if($oCache->isExpired()){
$aMydata= call_user_func(array($this, $sFunctionname));
// echo "$sFunctionname fresh ".($aMydata ? "OK": "false")." - storing for $iTtl sec<br>";
$oCache->write($aMydata, ($aMydata ? $iTtl : $iTtlOnError));
} else {
// echo "$sFunctionname from cache ... ".$oCache->iExpired()." sec <br>";
$aMydata=$oCache->read();
}
// echo '<pre>'.print_r($aMydata, 1).'</pre>'; die(__METHOD__);
return $aMydata;
}
/**
* render a form by given form elementes
* @param array $aFormdata array of form elements
@@ -186,6 +211,27 @@ class rollout_base implements iRolloutplugin{
? htmlentities($aDefaultValues[$sVarname])
: (isset($aVarinfos['default']) ? $aVarinfos['default'] : 'N.A.')
);
// if a callback was set for this variable
if(isset($aVarinfos['callback'])){
$aCallbackData=$this->_getCallback(
$aVarinfos['callback'],
(isset($aVarinfos['per_scope']) && $aVarinfos['per_scope'] ? $sKey : ''),
(isset($aVarinfos['ttl']) ? $aVarinfos['ttl'] : 60)
);
if(!$aCallbackData){
$aVarinfos['type']='text';
} else {
$aEffectiveConfig=$this->getConfig($sPhase);
// echo $sKey.' ... '; print_r($aEffectiveConfig[$sVarname]); echo '<br>';
if(isset($aEffectiveConfig[$sVarname]) && isset($aCallbackData[$aEffectiveConfig[$sVarname]])){
$aCallbackData[$aEffectiveConfig[$sVarname]]['selected']='selected';
// wenn value = defaultvalue, dann value auf '' setzen
}
// print_r($aCallbackData[$sVarname]); echo "<br>";
}
// echo '<pre>'.$sCallbackfunktion .' = '. print_r($aMydata,1 ).'</pre>';
}
switch ($aVarinfos['type']) {
case "password":
$sMyPlaceholder=(isset($aDefaultValues[$sVarname])
@@ -205,6 +251,20 @@ class rollout_base implements iRolloutplugin{
'placeholder' => $sMyPlaceholder
);
break;
case "select":
$aOptions=$aCallbackData;
$aFormdata[]=array(
'type' => $aVarinfos['type'],
'name' => $sPrefixName.'['.$sVarname.']',
'label' => $this->_t($sVarname.'-label'),
'title' => $this->_t($sVarname.'-hint'),
'validate' => 'isastring',
'options' => $aOptions,
'placeholder' => $sMyPlaceholder
);
break;
case "text":
$aFormdata[]=array(
'type' => $aVarinfos['type'],
Loading