'key', 'label'=>'string', 'slug'=>'string', 'report'=>'int', 'type' => 'string', 'default' => 'string', 'datasource' => 'longstring', 'sort' => 'int' ); public static function getMetaTerms(){ global $myUser; return array( 'date.year' => array('value' => date('Y') ,'description' => 'Année courante'), 'date.month' => array('value' => date('m'),'description' => 'Mois courant'), 'date.day' => array('value' => date('d'),'description' => 'Jour courant'), 'date.hour' => array('value' => date('H'),'description' => 'heure courante'), 'date.minut' => array('value' => date('i'),'description' => 'Minutes courantes'), 'date.second' => array('value' => date('s'),'description' => 'Secondes courantes'), 'user.login' => array('value' => $myUser->login,'description' => 'Identifiant utilisateur courant') ); } //Vérification des acces sur le widget courant ou sur le rapport du widget courant public function check_access($crud,$user = null){ global $myUser,$myFirm; if(!isset($user)) $user = $myUser; //pour avoir 'lacces, l'utilisateur doit être le créateur OU avoir access au rapport OU avoir acces au widget return $user->login == $this->creator || $user->can('statistic_report',$crud,$this->report) || $user->can('statistic_filter',$crud,$this->id); } public function toHtml(){ $readony = $this->check_access('edit') ? '': ' readonly="readonly" '; $html = ''; $default = $this->default; $meta = self::getMetaTerms(); $default = preg_replace_callback('|{{(.*)([\-\+]*)([0-9]*)}}|U', function($matches) use($meta) { $t = $matches[0]; if(isset($meta[$matches[1]])) $t = $meta[$matches[1]]['value']; if(!empty($matches[2]) && !empty($matches[3])){ if($matches[2]=='+') $t+=$matches[3]; if($matches[2]=='-') $t-=$matches[3]; } return $t; }, $default); switch($this->type){ case 'list' : $html .= ''; break; case 'date' : $default = explode('/',$default); //s'assure que les mois/jours sont sur deux nombres foreach ($default as $i=>$value) { if( ($i==0 || $i==1) && strlen($value)==1 ) $default[$i] = str_pad($value, 2,'0',STR_PAD_LEFT); } $default = implode('/',$default); $html .= ''; break; case 'hour' : $html .= ''; break; case 'user' : $html .= ''; break; case 'year' : $html .= ''; break; case 'month' : $months = array("Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre"); $html .= ''; break; case 'number' : $html .= ''; break; case 'boolean' : $html .= ''; break; default : $html .= ''; break; } return $html; } public function getSlug(){ return slugify($this->label); } public static function types(){ return array( 'text' => array('label'=>'Texte','datasource'=>false), 'list' => array('label'=>'Liste','datasource'=>true), 'date' => array('label'=>'Date','placeholder'=>'jj/mm/aaaaa','datasource'=>false), 'hour' => array('label'=>'Heure','placeholder'=>'08:00','datasource'=>false), 'user' => array('label'=>'Utilisateur','placeholder'=>'login.utilisateur','datasource'=>false), 'number' => array('label'=>'Nombre','placeholder'=>'ex: 12','datasource'=>false), 'year' => array('label'=>'Année','placeholder'=>'ex: 2009','datasource'=>false), 'month' => array('label'=>'Mois','placeholder'=>'ex: 01','datasource'=>false), 'boolean' => array('label'=>'Vrai/Faux','placeholder'=>'0 ou 1','datasource'=>false), ); } } ?>