Concrete5.8 Express Object could not be converted to String - concrete5

Following the guide here
http://documentation.concrete5.org/developers/express/using-the-express-entry-block-to-output-entry-data
I am able to create the same results but if I change the example and attempt to use the attribute of an express object which is a file link or a date field the view block returns the following error
"Object of class DoctrineProxies__CG__\Concrete\Core\Entity\File\File could not be converted to string"
Can the below code be modified to resolve this or is this a core issue?
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); ?>
<?php
if (isset($entry) && is_object($entry)) {
$drawings = $entry->getDrawings();
?>
<table id="datatable", class="table">
<thead>
<tr>
<th>Drawing Name</th>
<th>Drawing Number</th>
<th>Revision</th>
<th>Revision Date</th>
<th>Category</th>
<th>PDF</th>
</tr>
</thead>
<tbody>
<?php if (count($drawings)) {
foreach($drawings as $drawing) { ?>
<tr>
<td><?=$drawing->getDrawingName()?></td>
<td><?=$drawing->getDrawingNumber()?></td>
<td><?=$drawing->getRevision()?></td>
<td><?=$drawing->getDrawingRevisionDate()?></td>
<td><?=$drawing->getDrawingCategory()?></td>
<td><?=$drawing->getDrawingPdf()?></td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td colspan="6">No drawings found.</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>

the problem comes from this line:
<?=$drawing->getDrawingPdf()?>
what getDrawingPdf() is returning is a file object so it cannot be output to the screen like a simple string. First, you would have to extract a string from it. For instance, the following code would extract the file name and show it.
<?php
$drawingPdf = $drawing->getDrawingPdf();
$pdfFileName = is_object($drawingPdf)? $drawingPdf->getFileName() : '';
?>
<td><?=$pdfFileName?></td>
What this code does is first get the file object which you already had in your code.
Then if we have a proper file object, get the file name. If it's not a proper file object (you never now it might have been deleted) we return and empty string.
And finally, we output our string $pdfFileName (which is either the filename or an empty string) in your table.
Hope this helps

Related

I need to create a table on 2 different Page on Dom PDF Using PHP for loop?

I have tried to Create a Table using DOM PDF but uncertainly I got error of syntax token error, Can any body help me to figure out this issue.
Below is my code of for loop which i have used inside the $html variables.
$html = "<html></head>
<body>
<main>
<table>
<tr>
<th '>Year</th>
<th '>Age</th>
<th align='center'>Saving</th>
<th >Expenses</th>
</tr>"
for ($year=0; $year < 15; $year++) {
$html.=
'<tr class="table_row">
<td align="center">'.$year.'</td>
<td align="center">'.$table_data['age'][$year].'</td>
<td align="center">'.$table_data['savings'][$year].'</td>
<td align="center">'.$table_data['expenses'][$year].'</td>
</tr>';
}
" </table>
</main>
</body>
</html>";
You need to create two pdf & use 2 foreach loops on both pdf to get the data as you need.
Try this solution. it works for me.

Data rendering in blade using foreach loop

This code should list all of the missing majors from the database to the blade file. The database query successfully retrieves the correct data, but it is not rendering in the blade?
for($i=0;$i<sizeof($majors_array1);$i++)
{ if (School::where('major', '=', $majors_array1[$i])->exists())
{ echo $majors_array1[$i] . ' ' ." found"."<br/>";}
else
{ return view('enter-school-dept')->with('majors_array1',
$majors_array1[$i]);}
}
<table>
<tr>
<th>Title</th>
<th>School</th></tr>
<tr>
#foreach (majors_array1 as $majors)
<td>$majors</td>
#endforeach
</tr>
</table>
ex-
CSE
EEE
I am getting the error:
Use of undefined constant majors_array1 - assumed 'majors_array1' (this will throw an Error in a future version of PHP) (View: C:\xampp\htdocs\test\resources\views\enter-school-dept.blade.php)
Replace your foreach:
#foreach (majors_array1 as $majors)
<td>$majors</td>
#endforeach
With:
#foreach ($majors_array1 as $major)
<td>{{ $major }}</td>
#endforeach

how to generate pdf from ckeditor content along with data?

I am trying to generate pdf using TCPDF I have to parse dynamic data in pdf html table working fine.
App::import('Vendor', 'tcpdf');
$tcpdf = new TCPDF();
//$tcpdf->SetHeaderData($header_logo, $header_logo_width, $header_title,
PDF_HEADER_STRING);
$textfont = 'freesans';
$tcpdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$tcpdf->AddPage();
$tcpdf->SetFont('dejavusans', '', 10, '', true);
$test = '
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="height:20px"></td>
</tr>
<tr>
<td style="text-align:center;">Test Report</td>
</tr>
<tr>
<td height="1"> </td>
</tr>
</table>
';
$test.="--- Dynamic Data----";
$html = <<<EOF
$test
EOF;
$filename="Test.pdf";
$tcpdf->writeHTML($html, true, false, true, false, '');
$tcpdf->lastPage();
//ob_end_clean();
$tcpdf->Output($filename, 'D');
The above code is working good, But When I parse CKEditor content along with dynamic content pdf design was collapse. There is one cell having CKEditor data (any data contents with html) When I was trying to generate pdf the Pdf design was collapse.
Is there any way to generate good format to generate pdf.
try to use MDFP which is a php class who generate pdf et see this video :
https://www.youtube.com/watch?v=fPbW7JhIZOQ

Zend_mail send duplicate attachment

I am using phpexcel library with zend framwork.
I want to send mail to user with excel file attachment, all are working good but mail send with two attachment one is duplicate, i dont know why.
here is my function which is used to export excel and send it to user
public function exportandmail($name = NULL) {
if ($name === NULL) {
$name = 'excel_' . date('Y_m_d');
}
$name = $name.'.xlsx';
$objWriter = PHPExcel_IOFactory::createWriter($this->_excel, 'Excel2007');
$objWriter->save("public/uploads/Mailexcel/".$name);
$message="<table width='90%' align='center' >
<tr>
<th height='15' style='background-color:#037296;padding:10px;color:#FFFFFF' align='left'>excel</th>
</tr>
<tr>
<td style='padding:10px'><strong>Please find the attachment. </strong>
</td>
<tr>
<td style='padding:10px'>
Thanks,
</td>
</tr>
</table>";
$mail = new Zend_Mail();
$mail->setBodyHtml($message);
$mail->setFrom('sender#gmail.com', 'sender');
$mail->addTo('user#gmail.com');
$mail->setSubject('find attachment');
$fileContents = file_get_contents("public/uploads/Mailexcel/".$name);
$file = $mail->createAttachment($fileContents);
$file->filename = "excel.xlsx";
$mail->addAttachment($file);
$mail->send();
exit;
}
Thanks in advance.
I got the solution,
In my code, i use both createAttachment and addAttachment, thats why my mail send with duplicate attachment.
Remove addAttachment and its working fine.
$fileContents = file_get_contents("public/uploads/Mailexcel/".$name);
$file = $mail->createAttachment($fileContents);
$file->filename = "excel.xlsx";
$mail->addAttachment($file); // Remove this
$mail->send();

PHPExcel: HTML to Excel, writing remove the CSS in excel file

I want to export(force download) HTML(with CSS) to EXCEL sheet, for now I am using the PHPExcel library to perform this, it generate the excel file but remove the CSS (using inline with html tags), can anyone guide me, that how to keep CSS in excel sheet.
I am using this code, But I also want to keep the css and force to download
//html
$html = "<table>
<thead> <tr> <td colspan='2'> <h1> Main Heading </h1> <td> </tr> </thead>
<tbody>
<tr>
<th style='background:#ccc; color:red; font-size:15px'> Name <th>
<th style='background:#ccc; color:red; font-size:15px'> Class <th>
</tr>
<tr>
<td style='background:#fff; color:green; font-size:13px'> Jhon <th>
<td style='background:#fff; color:gree; font-size:13px'> 9th <th>
</tr>
</tbody>
</table>";
// Put the html into a temporary file
$tmpfile = time().'.html';
file_put_contents($tmpfile, $html);
// Read the contents of the file into PHPExcel Reader class
$reader = new PHPExcel_Reader_HTML;
$content = $reader->load($tmpfile);
// Pass to writer and output as needed
$objWriter = PHPExcel_IOFactory::createWriter($content, 'Excel2007');
$objWriter->save('excelfile.xlsx');
// Delete temporary file
unlink($tmpfile);
You can't read styles from HTML markup at the moment, unless you rewrite PHPExcel's HTML Reader to handle styles; it simply isn't supported yet. If you're building the spreadsheet from HTML, perhaps you should reconsider building it directly from a new PHPExcel object, which gives you access to all the features of PHPExcel.
To send to the browser, send to php://output with the appropriate headings, as shown in Examples/01simple-download-xlsx.php, and described in the section of the developer documentation entitled Redirect output to a client’s web browser

Resources