Display multiple select field in an custom export file

More
9 years 9 months ago #48526 by shinji
Hello,

This is the pdf export file of my site (i didnt write the code, but i'm trying to fix the multiple values problem).
From here all the fields are displaying correctly on the pdf execept the multiple-select fields. They only Display the first value. (but all the values are correctly saved in DB)

Here i can't use the code
Code:
<?php foreach ($this->item->positions['pres-secteur'] as $field) : ?> <?php echo $field->label; ?><br /> <?php echo $field->display; ?> <?php endforeach; ?>
I guess because $field is not define on this file so the ->display doesnt show nothing.(?)
I see that the value is directly call from the database with (line 160)
Code:
<?php echo $pres_secteur;?>
pres_secteur is a multiple select field in flexicontent

i tryed to add $pres_secteur[] to display all the values but it didnt work. I tryed a foreach spin and lot a tips found on google about displaying multiple selected values but it seems i'm stuck. It still display only ONE of the values selected (or nothing...).
Is the previous code not working because there is no 'positions' on my pdf export file?
I simply want to display a list of my selected values on my export.
Could you please guide me on this?

Best regards,
Shinji


Code:
<?php error_reporting(E_ALL); ini_set('display_errors','On'); ini_set('default_charset', 'UTF-8'); iconv_set_encoding("input_encoding", "UTF-8"); iconv_set_encoding("internal_encoding", "UTF-8"); iconv_set_encoding("output_encoding", "UTF-8"); mb_internal_encoding("UTF-8"); //echo JPATH_BASE;exit; define( '_JEXEC', 1 ); define( 'DS', DIRECTORY_SEPARATOR ); define( 'JPATH_BASE', dirname(__FILE__).(DS.'..'.DS.'..') ); //echo JPATH_BASE;exit; require_once( JPATH_BASE . DS . 'includes' . DS . 'defines.php' ); require_once( JPATH_BASE . DS . 'includes' . DS . 'framework.php' ); require_once( JPATH_BASE . DS . 'libraries' . DS . 'joomla' . DS . 'factory.php' ); //echo ."<br/>"; if($_SERVER['SERVER_NAME'] == "xxxxx" || $_SERVER['SERVER_NAME'] == "xxxxx"){ $uri_root = "xxxxxxx"; }else{ if($_SERVER['SERVER_NAME'] == "xxxxx" || $_SERVER['SERVER_NAME'] == "xxxxxxxx") $uri_root = "xxxxxx"; else $uri_root = "xxxxxxxx"; } $uri_root = JURI::base(); $id = JRequest::getInt('id'); $extra = JRequest::getInt('extra'); //if(id == 0) //require_once('../../libraries/joomla/database/table.php'); //JTable::addIncludePath(JPATH_SITE.DS.'components'.DS.'com_content'.DS.'tables'); function htmlallentities($str){ $res = ''; $strlen = strlen($str); for($i=0; $i<$strlen; $i++){ $byte = ord($str[$i]); if($byte < 128) // 1-byte char $res .= $str[$i]; elseif($byte < 192); // invalid utf8 elseif($byte < 224) // 2-byte char $res .= '&#'.((63&$byte)*64 + (63&ord($str[++$i]))).';'; elseif($byte < 240) // 3-byte char $res .= '&#'.((15&$byte)*4096 + (63&ord($str[++$i]))*64 + (63&ord($str[++$i]))).';'; elseif($byte < 248) // 4-byte char $res .= '&#'.((15&$byte)*262144 + (63&ord($str[++$i]))*4096 + (63&ord($str[++$i]))*64 + (63&ord($str[++$i]))).';'; } return $res; } $tmp_query = JFactory::getdbo(); $db =& $tmp_query; $q = " SELECT `c`.`introtext` as `description`, `c`.`title` as `title` FROM `#__content` as `c` WHERE `id` = '{$id}'"; $db->setQuery($q); $article = $db->loadObjectList(); foreach ($article[0] as $key => $value) { $$key = utf8_decode($value); } $q = " SELECT `fir`.`value` as `value`, `ff`.`name` as `field_name`, `ff`.`label` as `field_label`, `fil`.`filename` as `filename`, `fil`.`description` as `file_description` FROM `#__flexicontent_fields_item_relations` as `fir` INNER JOIN `#__flexicontent_fields` as `ff` ON `fir`.`field_id` = `ff`.`id` LEFT JOIN `#__flexicontent_files` as `fil` ON `fir`.`value` = `fil`.`id` WHERE `fir`.`item_id` = '{$id}' "; $db->setQuery($q); $flexi_infos = $db->loadObjectList(); /*echo "<pre>"; print_r($flexi_infos);exit;*/ foreach ($flexi_infos as $item) { $var_name = $item->field_name; //echo htmlallentities($item->value); $$var_name = htmlallentities($item->value); if(!empty($item->filename) && $item->field_name != 'pres_realisation' && $item->field_name != 'pres_superficie' && $item->field_name != 'pres_chiffres' && $item->field_name != 'honoraires' && $item->field_name != 'cp' && $item->field_name != 'adresse' && $item->field_name != 'ville' && $item->field_name != 'patenaires' && $item->field_name != 'pres_ouvre' && $item->field_name != 'pres_secteur'){ $$var_name = $item->filename; } } //exit; ini_set('memory_limit','256M'); $save_pdf = true; $euro_sign = "&euro;";//iconv("UTF-8", "cp1250", '€'); if ($save_pdf) ob_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title>OTCE</title> <meta name="title" content="" /> <meta name="description" content="" /> <meta name="keywords" content="" /> <link rel="shortcut icon" href="favicon.ico" /> <link rel="stylesheet" href="css/reset.css" type="text/css" media="screen" /> <link rel="stylesheet" href="css/screen.css" type="text/css" media="screen" /> </head> <!--[if lt IE 7]> <body class="ie ie6 lte9 lte8 lte7"> <![endif]--> <!--[if IE 7]> <body class="ie ie7 lte9 lte8 lte7"> <![endif]--> <!--[if IE 8]> <body class="ie ie8 lte9 lte8"> <![endif]--> <!--[if IE 9]> <body class="ie ie9 lte9"> <![endif]--> <!--[if gt IE 9]> <body> <![endif]--> <!--[if !IE]><!--> <body> <!--<![endif]--> <div class="wrap"> <div id="center"> <form id="pdf-form" action="" method="post"> <div class="pdf-header"> <p align='left' class='top_text' style='text-transform:uppercase;color:#394f8f;'><strong><div class="top_desc_title"><?php echo $title;?></div></strong><br/><div class="top_sub"><?php echo $pres_nom;?></div><div class="top_desc"><?php echo $description;?></div></p> </div> <div class="position"> <div class="pdf-image"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td> <?php if(isset($slider_img1)){ ?> <img src="<?php echo $uri_root.'components/com_flexicontent/uploads/'.$slider_img1; ?>" width="500" height="310" alt="" /> <?php } ?> </td> <td align="right"> <?php if(isset($slider_img2)){ ?> <img src="<?php echo $uri_root.'components/com_flexicontent/uploads/'.$slider_img2; ?>" width="245" height="150" alt="" /> <?php } ?> <br/> <?php if(isset($slider_img3)){ ?> <img style="padding-top:8px;" src="<?php echo $uri_root.'components/com_flexicontent/uploads/'.$slider_img3; ?>" width="245" alt="" height="156" /> <?php } ?> </td> </tr> </table> </div> <br/> <table width="752" class="pdf-content" cellpadding="0" cellspacing="0" border="0"> <tr> <td width="40%" style="padding-left:25px;"> <?php if(isset($pres_secteur)){ ?> <h1>Secteur</h1> <p><?php echo $pres_secteur;?></p> <br/> <?php }?> <?php if(isset($pres_lieu)){ ?> <h1>Lieu de r&eacute;alisation</h1> <p><?php echo $pres_lieu; ?></p> <br/> <?php } ?> <?php if(isset($pres_ouvrage)){ ?> <h1>Ma&icirc;trise d'ouvrage</h1> <p><?php echo $pres_ouvrage; ?></p> <br/> <?php }?> <?php if(isset($pres_ouvre)){ ?> <h1>Missions</h1> <p><?php echo $pres_ouvre; ?></p> <br/> <?php } ?> <?php if(isset($pres_chiffres)){ ?> <h1>Chiffres cl&eacute;s</h1> <span class="chcl">Montant des travaux :</span><?php echo $pres_chiffres; ?> <br/> <br/> <?php } ?> <?php if(isset($pres_superficie)){ ?> <span class="chcl">Superficie :</span><?php echo nl2br($pres_superficie); ?> <br/> <?php } ?> <br/> <?php if(isset($pres_calendrier)){ ?> <h3>Calendrier : </h3> <p><?php echo nl2br($pres_calendrier); ?></p> <br/> <?php } ?> <br/> <?php if(isset($pres_operation)){ ?> <?php //$pres_operation = str_replace('?','&rsquo;',$pres_operation); ?> <h1>Op&eacute;ration</h1> <?php //$pres_operation = mb_convert_encoding($pres_operation, 'HTML-ENTITIES', 'UTF-8'); ?> <p><?php echo $pres_operation; ?></p> <br/> <?php } ?> </td> <td width="40%" style="padding-left:0px;"> <?php if(isset($pres_specificites )){ ?> <h1>Sp&eacute;cificit&eacute;s</h1> <p><?php echo $pres_specificites ; ?></p> <br/> <?php } ?> <br/> <?php if(isset($pres_efficacite_logo) || isset($pres_efficacite_image)){ ?> <h1>Efficacit&eacute; &eacute;nerg&eacute;tique</h1> <?php } ?> <?php if(isset($pres_efficacite_texte )){ ?> <p><?php echo $pres_efficacite_texte ; ?></p> <?php }?> <?php if(isset($pres_efficacite_logo)){ ?> <p><img width="80" src="<?php echo $uri_root.'components/com_flexicontent/uploads/'.$pres_efficacite_logo; ?>" alt="" /></p> <?php } ?> <br/> <?php if(isset($pres_efficacite_image)){ ?> <p><img width="350" styles="height:100%; width:100%; max-height:160px; max-width:350px;" src="<?php echo $uri_root.'components/com_flexicontent/uploads/'.$pres_efficacite_image; ?>" alt="" /></p> <?php } ?> </td> </tr> </table> <br/> <div class="pdf-footer"> <img width="752" height="92" src="<?php echo $uri_root."templates/otce/images/pdf-footer.png";?>" alt=""/> </div> <?php if($extra == 1){ ?> <br/> <div class="extra-admin"> <?php if(isset($architectes)){ ?> <h1>Architectes</h1> <p><?php echo $architectes; ?></p> <br/> <?php } ?> <?php if(isset($field50)){ ?> <h1>AMO</h1> <p><?php echo $field50; ?></p> <br/> <?php } ?> <?php if(isset($nom_contact_technique)){ ?> <h1>Contact technique MO</h1> <p><?php echo $nom_contact_technique; ?></p> <br/> <?php } ?> <?php if(isset($adresse)){ ?> <h1>Adresse MO</h1> <p><?php echo $adresse; ?></p> <br/> <?php } ?> <?php if(isset($ville)){ ?> <h1>T&eacute;l MO</h1> <p><?php echo $ville; ?></p> <br/> <?php } ?> <?php if(isset($cp)){ ?> <h1>Contact MO</h1> <p><?php echo $cp; ?></p> <br/> <?php } ?> <?php if(isset($patenaires)){ ?> <h1>Partenaires MOE</h1> <p><?php echo $patenaires; ?></p> <br/> <?php } ?> <?php if(isset($honoraires)){ ?> <h1>Honoraires OTCE</h1> <p><?php echo $honoraires; ?></p> <br/> <?php } ?> <?php if(isset($filiale_realisation)){ ?> <h1>Filiale OTCE qui a suivi la r&eacute;alisation</h1> <p><?php echo $filiale_realisation; ?></p> <br/> <?php } ?> <?php if(isset($creation)){ ?> <h1>Date de cr&eacute;ation</h1> <p><?php echo $creation; ?></p> <br/> <?php } ?> <?php if(isset($date_mise_jour)){ ?> <h1>Date de mise &agrave; jour</h1> <p><?php echo $date_mise_jour; ?></p> <br/> <?php } ?> <?php if(isset($chef_projet)){ ?> <h1>Chef de projet</h1> <p><?php echo $chef_projet; ?></p> <br/> <?php } ?> <?php if(isset($redacteur)){ ?> <h1>R&eacute;dacteur</h1> <p><?php echo $redacteur; ?></p> <br/> <?php } ?> <?php if(isset($titre_champ_perso)){ ?> <h1><?php echo $titre_champ_perso; ?></h1> <?php } ?> <?php if(isset($champ_perso)){ ?> <p><?php echo $champ_perso; ?></p> <br/> <?php } ?> </div> <br/> <div class="pdf-footer"> <img width="752" height="92" src="<?php echo $uri_root."templates/otce/images/pdf-footer.png";?>" alt=""/> </div> <?php } ?> </div> </form> <!--<div class="img"<?php echo (!$save_pdf) ? " style='position:relative;bottom:0;'" : "";?>> <img class="change_img" src="images/img1.png" width="752" height="180" alt=""/> </div>--> </div> </div><!-- /.wrap --> <script src="js/jquery-latest.min.js" type="text/javascript" charset="utf-8"></script> <script src="js/script.js" type="text/javascript" charset="utf-8"></script> </body> </html><? if ($save_pdf) { $html = ob_get_contents(); $html = str_replace("images/img1.png","images/img".$_REQUEST['select_img'].".png",$html); ob_end_clean(); require_once("dompdf/dompdf_config.inc.php"); $dompdf = new DOMPDF(); $dompdf->set_paper( array(0,0, 564, 800), "portrait" ); $dompdf->load_html(utf8_encode($html)); $dompdf->render(); $uniqname = uniqid(); $uniqname = "sample"; file_put_contents('generated/'.$uniqname.'.pdf', $dompdf->output()); echo $uri_root.'templates/otce/generated/'.$uniqname.'.pdf?v='.time(); }

Please Log in or Create an account to join the conversation.

More
9 years 9 months ago #48531 by ggppdk
Hello

the variable
->display

-- contains the rendered HTML of every field, and it is created when the field is placed in a template position

-- it is created according to the parameters of the field

since the field is display properly in FLEXIcontent item view and category view, there is no reason for it not be created properly,



i guess that the field code is given only 1 value

1. check that your script retrieving ALL field values and not just 1 of them for each item ?

2. check how you create the ->display of the fields


Regards

Regards


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

More
9 years 9 months ago - 9 years 9 months ago #48541 by shinji

ggppdk wrote: 1. check that your script retrieving ALL field values and not just 1 of them for each item ?


I think my problem is in that part.
I found some doc on selecting data using JDatabase with multiple select
Am i searching in the right direction?
Code:
$tmp_query = JFactory::getdbo(); $db =& $tmp_query; $q = " SELECT `c`.`introtext` as `description`, `c`.`title` as `title` FROM `#__content` as `c` WHERE `id` = '{$id}'"; $db->setQuery($q); $article = $db->loadObjectList(); foreach ($article[0] as $key => $value) { $$key = utf8_decode($value); } $q = " SELECT `fir`.`value` as `value`, `ff`.`name` as `field_name`, `ff`.`label` as `field_label`, `fil`.`filename` as `filename`, `fil`.`description` as `file_description` FROM `#__flexicontent_fields_item_relations` as `fir` INNER JOIN `#__flexicontent_fields` as `ff` ON `fir`.`field_id` = `ff`.`id` LEFT JOIN `#__flexicontent_files` as `fil` ON `fir`.`value` = `fil`.`id` WHERE `fir`.`item_id` = '{$id}' "; $db->setQuery($q); $flexi_infos = $db->loadObjectList();

is there an other way to write
Code:
$flexi_infos = $db->loadObjectList();
to make it load all the values?
Last edit: 9 years 9 months ago by shinji.

Please Log in or Create an account to join the conversation.

More
9 years 9 months ago #48543 by ggppdk
Hello

from what i see you retrieve ALL value of the field for every item,

but you have a loop:

foreach ($flexi_infos as $item) {
...
}

that seems to only use 1 value for every field ?

sorry we do not have time to investigate custom code further

Regards


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

More
9 years 9 months ago #48545 by shinji
Thanks, i'm gonna check this.

Last question, how the field is save in DB? All the values are chained with ',' or are they separated in different tables?

Is there a way to call these values more directly that
Code:
<?php echo $pres_secteur;?>
?

Regards

Please Log in or Create an account to join the conversation.

More
9 years 9 months ago #48552 by ggppdk
Hello

normal there is 1 DB row per field value

if field value has multiple properties then it the array of properits is serialized


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.287 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline