mapping de valeurs
This commit is contained in:
		
							parent
							
								
									5da28fc142
								
							
						
					
					
						commit
						ec7ebfefc1
					
				| @ -78,6 +78,7 @@ class CTable extends ComponentPrintable implements IParametrable { | |||||||
|     "rows" => ["?iterable", null, "source des lignes à afficher"], |     "rows" => ["?iterable", null, "source des lignes à afficher"], | ||||||
|     "filter_func" => ["?callable", null, "fonction permettant de filter les éléments à afficher"], |     "filter_func" => ["?callable", null, "fonction permettant de filter les éléments à afficher"], | ||||||
|     "map_func" => ["?callable", null, "fonction permettant de mapper les éléments"], |     "map_func" => ["?callable", null, "fonction permettant de mapper les éléments"], | ||||||
|  |     #XXX ajouter "map" qui prend directement un tableau comme celui retourné par map_func()
 | ||||||
|     "cols" => ["?array", null, "colonnes à extraire et à afficher"], |     "cols" => ["?array", null, "colonnes à extraire et à afficher"], | ||||||
|     "exclude_cols" => ["?array", null, "colonnes à exclure de la liste calculée automatiquement"], |     "exclude_cols" => ["?array", null, "colonnes à exclure de la liste calculée automatiquement"], | ||||||
|     "add_cols" => ["?array", null, "colonnes à ajouter à la liste calculée automatiquement"], |     "add_cols" => ["?array", null, "colonnes à ajouter à la liste calculée automatiquement"], | ||||||
| @ -358,10 +359,29 @@ class CTable extends ComponentPrintable implements IParametrable { | |||||||
|     $mapCtx = $this->mapCtx; |     $mapCtx = $this->mapCtx; | ||||||
|     $row = $this->_currentRow($this->rowKey); |     $row = $this->_currentRow($this->rowKey); | ||||||
|     if ($filterCtx !== null) { |     if ($filterCtx !== null) { | ||||||
|       if (!func::_call($filterCtx, [$row, $this->rowKey])) return null; |       if (!func::_call($filterCtx, [$row, $this->rowKey, $this->rowIndex])) return null; | ||||||
|  |     } | ||||||
|  |     if ($mapCtx !== null) { | ||||||
|  |       # si la valeur est séquentielle, c'est une clé dans $row
 | ||||||
|  |       # si la valeur est associative et que c'est une fonction, elle est appelée
 | ||||||
|  |       # avec la valeur
 | ||||||
|  |       $result = func::_call($mapCtx, [$row, $this->rowKey, $this->rowIndex]); | ||||||
|  |       $index = 0; | ||||||
|  |       $mapped = []; | ||||||
|  |       foreach ($result as $key => $value) { | ||||||
|  |         if ($key === $index) { | ||||||
|  |           $index++; | ||||||
|  |           $mapped[$value] = A::get($row, $value); | ||||||
|  |         } elseif (is_callable($value)) { | ||||||
|  |           $mapped[$key] = func::call($value, A::get($row, $key), $key, $row, $this->rowKey, $this->rowIndex); | ||||||
|  |         } else { | ||||||
|  |           $mapped[$key] = $value; | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |       $row = $mapped; | ||||||
|  |     } else { | ||||||
|  |       $row = $this->ensureArray($row); | ||||||
|     } |     } | ||||||
|     if ($mapCtx !== null) $row = func::_call($mapCtx, [$row]); |  | ||||||
|     else $row = $this->ensureArray($row); |  | ||||||
|     return $row; |     return $row; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -44,7 +44,7 @@ class Word { | |||||||
|       $spec = substr($spec, strlen($ms[0])); |       $spec = substr($spec, strlen($ms[0])); | ||||||
|     } elseif (preg_match('/^m(asc(ulin)?)?\s*:\s*/i', $spec, $ms)) { |     } elseif (preg_match('/^m(asc(ulin)?)?\s*:\s*/i', $spec, $ms)) { | ||||||
|       $fem = false; |       $fem = false; | ||||||
|       $spec = substr($spec, $ms[0]); |       $spec = substr($spec, strlen($ms[0])); | ||||||
|     } elseif (preg_match('/\s*\|f(?:[eé]m(?:inin)?)?\s*$/iu', $spec, $ms, PREG_OFFSET_CAPTURE)) { |     } elseif (preg_match('/\s*\|f(?:[eé]m(?:inin)?)?\s*$/iu', $spec, $ms, PREG_OFFSET_CAPTURE)) { | ||||||
|       $fem = true; |       $fem = true; | ||||||
|       $spec = substr($spec, 0, $ms[0][1]); |       $spec = substr($spec, 0, $ms[0][1]); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user