Changeset 48173 in spip-zone for _plugins_/Association/Associaspip/pdf/extends.php
- Timestamp:
- May 26, 2011, 9:21:52 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
_plugins_/Association/Associaspip/pdf/extends.php
r38578 r48173 24 24 parent::Header(); 25 25 } 26 27 /* fonction ajoute pour Associaspip */ 28 /* alors que la fonction Query de base prend uniquement une query sql, celle-ci permet d'ajouter un tableau et le nom d'un champs sur lequel */ 29 /* faire la jointure avec la query existente. Cela permet d'ajouter a la query (par un array_merge qui peut ecraser des champs si ils sont */ 30 /* nommes comme ceux des tables) un tableau qui sera donc ajoute a chaque ligne de data retournee par le fetch de la query sql. */ 31 /* l'interet est de pouvoir faire des traitement et affichers de donnees traites apres une query (dans notre cas un concat fait en php et qui*/ 32 /* fonctionne donc aussi bien en mysql qu'en postgresql */ 33 34 /* le code reprend donc l'integralite du code de Query mais ajoute un merge_array sur chaque ligne de donnees retournee par le fetch */ 35 /* le parametre data doit donc etre un tableau de la forme: valeur_champ_jointure => array(champs1=>valeur, champs2=>valeur, ..) afin d'inserer */ 36 /* dans le resultat de la requete les champs champs1 et champ2 en jointure = sur le champs fourni dans l'autre parametre */ 37 function Query_extended($res, $prop=array(), $data, $champ_jointure) { 38 //Traite les propriétés 39 if(!isset($prop['width'])) 40 $prop['width']=0; 41 if($prop['width']==0) 42 $prop['width']=$this->w-$this->lMargin-$this->rMargin; 43 if(!isset($prop['align'])) 44 $prop['align']='C'; 45 if(!isset($prop['padding'])) 46 $prop['padding']=$this->cMargin; 47 $cMargin=$this->cMargin; 48 $this->cMargin=$prop['padding']; 49 if(!isset($prop['HeaderColor'])) 50 $prop['HeaderColor']=array(); 51 $this->HeaderColor=$prop['HeaderColor']; 52 if(!isset($prop['color1'])) 53 $prop['color1']=array(); 54 if(!isset($prop['color2'])) 55 $prop['color2']=array(); 56 $this->RowColors=array($prop['color1'],$prop['color2']); 57 //Calcule les largeurs des colonnes 58 $this->CalcWidths($prop['width'],$prop['align']); 59 //Imprime l'en-tête 60 $this->TableHeader(); 61 //Imprime les lignes 62 $this->SetFont('Arial','',8); 63 $this->ColorIndex=0; 64 $this->ProcessingTable=true; 65 /* partie du code modifiee pour etendre la fonction Query */ 66 while($row=sql_fetch($res)) { 67 if (is_array($data[$row[$champ_jointure]])) $row = array_merge($row,$data[$row[$champ_jointure]]); 68 $this->RowMulticell($row); 69 } 70 /* fin de partie du code modifie pour etendre la fonction Query */ 71 $this->ProcessingTable=false; 72 $this->cMargin=$cMargin; 73 $this->aCols=array(); 74 } 75 76 /* fonction qui permet d'utiliser des multicells et non cells pour avoir du texte sur plusieurs lignes dans les cases */ 77 function RowMultiCell($data){ 78 /* on commence par calculer le nombre de lignes de chaque cellule et le max */ 79 $max_nb_lignes = 1; 80 $nb_lignes = array(); 81 foreach($this->aCols as $col) { 82 $lignes = explode("\n",$data[$col['f']]); 83 $nb_lignes[$col['f']] = count($lignes); 84 foreach ($lignes as $ligne) { 85 $nb_lignes[$col['f']] += floor(($this->GetStringWidth($ligne)+4)/$col['w']); /* le +4 c'est le padding a 2 dans pdf_adherents */ 86 } 87 $max_nb_lignes = ($nb_lignes[$col['f']]>$max_nb_lignes)?$nb_lignes[$col['f']]:$max_nb_lignes; 88 } 89 90 $x = $this->TableX; 91 $y = $this->GetY(); 92 $this->SetX($x); 93 $ci=$this->ColorIndex; 94 $fill=!empty($this->RowColors[$ci]); 95 if($fill) 96 $this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]); 97 $y = $this->GetY(); 98 99 foreach($this->aCols as $col) { 100 $this->SetX($x); 101 $y = $this->GetY(); 102 $this->MultiCell($col['w'],5*$max_nb_lignes/$nb_lignes[$col['f']],utf8_decode($data[$col['f']]),1,$col['a'],$fill); 103 $this->SetY($y); 104 $x += $col['w']; 105 106 107 } 108 //$this->Ln(); 109 $this->setY($y+5*$max_nb_lignes); 110 $this->ColorIndex=1-$ci; 111 } 26 112 } 27 113 ?>
Note: See TracChangeset
for help on using the changeset viewer.