PhpWord multi-colum layout issue - php

How can I force PhpWord to write at the begin of the next multi-colum ?
I don't think there is a breaker function (such as addTextBreak() or addPageBreak()) for doing this.
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection(array(
'colsNum' => 2,
'colsSpace' => 100,
'breakType' => 'continuous',
));
$table1 = $section->addTable();
//...add rows and cells to table 1
$table2 = $section->addTable();
//...add rows and cells to table 2
As expected, the result of this code snippet is two table stacked on the first multi-colum.
Adding in the code
$section->addPageBreak()
doesn't obviously work.
Any advice on how to solve this problem?
Is it a good option to add some TextBreakers to the bottom of the page for filling the space that remain after the first table?
Thanks!

Related

PHPWord Full-width table with landscape orientation

In my PHPWord document I have a section with landscape orientation and table in it. I want the table to be full-width, but if I add table like this (since width is in percent according to the docs):
$table = $section->addTable(array('width' => 100));
or like this:
$table = $section->addTable(array('unit' => 'pct', 'width' => 5000));
my table is not full-width (actually, it seems that the table takes up the entire width, but for portrait orientation).
I can achieve the desired result in this way:
// Generate document
$word = new PHPWord();
$section = $word->addSection(array());
$sectionStyle = $section->getStyle();
$sectionStyle->setOrientation($sectionStyle::ORIENTATION_LANDSCAPE);
// Add table
$table = $section->addTable(array());
$tableStyle = $table->getStyle();
$tableStyle->setUnit($tableStyle::WIDTH_TWIP);
$tableStyle->setWidth($sectionStyle->getPageSizeW() - $sectionStyle->getMarginLeft() - $sectionStyle->getMarginRight());
But I doubt that this is good solution. Is there a better solution?

How to interact with preview and save using flourishlib's fRecordSet's build method?

Let's suppose I have a database table called local_ads.
Now, when a local ad is created, one has to be able to view its preview and if he is satisfied, then save it. Also, if one wants to update a local ad, then he might want to see its preview before he overwrites the live version of the record.
So, I have a foreign key for the local_ads table called parent_id. If this is null, then it is a preview (at least according to my initial thoughts). Otherwise it is live. When one saves a preview, there are two cases:
Case 1: There was no live record yet linked to the preview. In this case a new record is inserted into the local_ads table with the parent_id pointing to the preview.
Case 2: There is a live record linked to the preview. In this case the live record is updated.
Everything looks and works nicely, but I have a problem showing the results in a grid. I want to show the preview if no live version of the record exists and only the live version if it exists. I would like to show something in the spirit of
select col1, col2, col3, col4
from local_ads glob
where (not (parent_id is null))
or ((select id from local_ads temp where temp.parent_id = glob.id limit 0, 1) is null)
but I have several problems. We have a logical or (I wonder how can I use logical or between logical operands using the build method of fRecordSet of flourishlib). Also, this query is of two dimensions, it is slow. Also, I wonder how can a sub-query be executed. Also, I do not know how can I use the is operator as in is null.
So, I had to re-think my idea and I came up with the following:
select col1, col2, col3, col4
from local_ads
where parent_id < id or parent_id >= id
the idea is simple: If a preview does not have a live version, then parent_id matches the id, otherwise the parent_id of a preview is null. I know this is an ugly hack, but this was the best idea I could came up with to solve the problem and decrease memory and performance complexity.
So, the only problem which remained was to check the two logical values in the where clause separated by the logical or.
From the documentation I have seen this:
* 'column<:' => 'other_column' // column < other_column
and this:
* 'column>=:' => 'other_column' // column >= other_column
so I know how can I add these to the filters, but how am I supposed to 'or' them?
So far I have tried it this way:
public static function localAd() {
$User = Globe::load('CurrentUser');
$Smarty = Globe::load('Smarty');
//handle default options
$options = array(
'recordsPerPage' => 20,
'pageLinks' => 10,
);
$page = 0;
if (isset($_GET['p'])) {
$page = $_GET['p'];
}
//get the data
$startIndex = (isset($page)) ? $page * $options['recordsPerPage'] : 0;
$filters = array();
if ($User->getType() == 'local_admin') {
$filters['domain='] = $User->getDomain();
}
$records = fRecordSet::build('LocalAd', $filters, array('created' => 'desc'), $options['recordsPerPage'], $page + 1);
//create result object for pagination
$Result = array(
"recordsReturned" => $records->count(),
"totalRecords" => $records->count(true),
"startIndex" => intval($startIndex),
"records" => $records->export(),
'recordsPerPage' => $options['recordsPerPage'],
'pageLinks' => $options['pageLinks'],
'currentPage' => $page,
//'options' => $options
);
$Result['totalPages'] = ceil($Result['totalRecords'] / $Result['recordsPerPage']);
$Smarty->assign('Result', $Result);
$Smarty->assign('ManagerURL', '?a=localAd');
AdminView::display('Admin/LocalAd/main.tpl');
}
Note, that in some cases I have to check the domain as well.
In the meantime I have managed to solve the problem. This is how we can define the filter set to solve the problem mentioned in the question:
$filters = array();
if ($User->getType() == 'local_admin') {
$filters['domain='] = $User->getDomain();
}
$filters['parent_id<:|parent_id>=:'] = array('id', 'id');

PostgreSQL Update Issue With Quotation('')

I'm using PostgreSQL & Codeigniter. There is a table called folio in the database. It has few columns containing remarks1, remarks2, remarks3 as well. Data for the all the other columns are inserted when the INSERT statement executes for the 1st time.
When I try to execute below UPDATE statement later for the below 3 columns, remarks1 column get updated correctly. But remarks2, remarks3 columns are updated with ''.
UPDATE "folio" SET "remarks1" = 'test remark', "remarks2" = '', "remarks3" = '' WHERE "id" = '51';
Given that remarks1, remarks2, remarks3 columns data type is character varying. I'm using Codeigniter active records. At a time all 3 columns could be updated else single column could be updated depending on the user input.
What could be the issue? How can I fix this? Why columns are updated with ''?
As requested the php array in CI would be below
$data = array(
'remark1' => $this->input->post('remark1'),
'remark2' => $this->input->post('remark1'),
'remark3' => $this->input->post('remark1')
);
Function which saves the data contains below two lines only
$this->db->where('id', $folio_id);
$this->db->update('folio', $data);
Those columns are updated with '' because you tell them to?
Let's take a closer look at the query
UPDATE "folio"
SET
"remarks1" = 'test remark',
"remarks2" = '',
"remarks3" = ''
WHERE
"id" = '51';
First you select the table folio for the update.
Then you tell it to update remarks1 through remarks3 with new values. For remarks2 and remarks3 you specify to set them to an empty string. And that's what's going to happen.
Last but not least, you tell it to only apply this update to rows where id equals 51.
So, in order to only update remarks1 you can simply remove the other columns from your update:
UPDATE "folio"
SET
"remarks1" = 'test remark'
WHERE
"id" = '51';
Update:
I'm by far not a CI expert, but from what I see, I'd change the $data array to only contain information for remark1:
$data = array(
'remark1' => $this->input->post('remark1')
);
And (from my understanding) it should only update this single column.

Codeigniter update record

I have an update record that looks like this
$data_gallery = array(
'order' => $value
);
$this->db->where('order', $newOrder);
$this->db->update('gallery', $data_gallery);
I have say, 5 images I have reorderd. I have their old position and their new position.
But as I loop through they sometime overwrite each other.
Example:
5 images 1,2,3,4,5
I change the order 2,1,3,4,5
I update in the loop as it goes through the array of new order.
Update order = 2 where order = 1
Update order = 1 where order = 2
Obviously the second one never gets hit as order = 2 no longer exits.
I guess this more a logic question than anything else.
Any ideas how I can easily loop through and update without losing some of the data? I though maybe updating in a batch operation but didn't get very far with it.
Thanks in advance.
Use the image's ID in your WHERE clause:
$this->db->where('imageid', $imageid);
This will set the new order to each image without previously overwriting (and disappearing!) any information.
Check if you have any other fields to check for your criteria to match the exact records.
$data_gallery = array(
'order' => $value
);
$this->db->where('order', $newOrder);
//check if you have any other fields to match also image id, record id or any other ids to match
$this->db->where('second_id',$second_id);
$this->db->update('gallery', $data_gallery);

PHP PDF Creation, EZPDF Class: table with just one line and row

This code:
$data = array(array('row1'=>'row2'));
$this->ezTable($data, null, '',
array('width'=>'460', 'fontSize'=>'8', 'showLines'=>'1'));
shows a table with 2 rows and one column.
I need a table with just one row and one column, or four borders (top, bottom, right and left) around a text.
How can I do that?
$this->ezTable($data, null, '',
array('width'=>'460', 'fontSize'=>'8', 'showLines'=>'1','showHeadings'=>0));

Categories