Categories > OpenTBS with DOCX >

Sub bloc with à list

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: nawbacan
Date: 2014-03-26
Time: 13:26

Sub bloc with à list

Hello everyone,

I work for some day on this problem, maybe you can help.

My application generate a Docx document which contains for each page informations about one inscriptions.
A the end, I have a document with n pages for n inscriptions.

the php side :
$data = array();

foreach ($object as $index=>$current){
  $tmp['field_name'] = $current->getvalue();
  // the same for each value of the inscription

  $data[] = $tmp;
}
$TBS->MergeBlock('inscription', 'array' , $data);

$TBS->Show(OPENTBS_DOWNLOAD, 'title' . '.docx');



the tag on the template

    [inscription;block=tbs:page]
    [inscription.student_title] [inscription.firstname] [inscription.lastname]
   etc...


My problem is that I want to add a list of Informations (n evaluations) for each inscriptions.
I try with the function mergebloc like that : $TBS->MergeBlock('notes',  $notes_detail); , but every inscriptions have the same evaluation.
I try to construct an array, but I don't understand how to get the datas of the array without using Mergblock.

Thanks in advance for your help.
By: Skrol29
Date: 2014-03-26
Time: 22:44

Re: Sub bloc with à list

Hi,

You have to use sub-blocks.
The dimpliest is to save the evaluations as an array in each inscription row.

foreach ($object as $index=>$current){
  $data['evaluations] = array(...);
  ...
  $data[] = $tmp;
}

See for more info aobut automatic sub-blocks :
http://www.tinybutstrong.com/manual.php#html_block_subauto

The other solution is sub-blocks with dynamic queries.
It needs two MergeBlock()
http://www.tinybutstrong.com/manual.php#html_block_dynsb
By: nawbacan
Date: 2014-03-27
Time: 15:33

Re: Sub bloc with à list

Hi,
Thanks for your answer !

I try
foreach ($object as $index=>$current){
  $data['evaluations] = array(...);
  ...
  $data[] = $tmp;
}

with I have an error.
so I try this to peut each evaluation in each inscription row.
foreach ($object as $index=>$current){
  $tmp['evaluations] = array(...);
  ...
  $data[] = $tmp;
}

It's better. But in the template, with the system of automatic sub-block, I have one more problem. The tag is not interpreted.
I have something like that
[inscription.session_title;block=tr;sub1=evaluations_list]
    [inscription_sub1.val;block=tr]
The first line it's ok. But not the second.
By: Skrol29
Date: 2014-03-28
Time: 14:10

Re: Sub bloc with à list

Hi

> The first line it's ok. But not the second.

Can you be more precise on what is happening ?

In your HTML snippet, the bound of the sub-block should not go over the main block information, or it may behave logically but unexpectedly for you.

You should something like:
<table>
  <tr>
    <td>

      [inscription.session_title;block=tr;sub1=evaluations_list]

      <table>
        <tr><td> [inscription_sub1.val;block=tr] </td> </tr>
      </table>
  
    </td>
  </tr>
</table>
By: nawbacan
Date: 2014-03-31
Time: 10:18

Re: Sub bloc with à list

>> The first line it's ok. But not the second.
>Can you be more precise on what is happening ?

My problem is that the second line isn't interpreted. The tag isn't replaced by the right value.
The first line :
[inscription.session_title;block=tr;sub1=evaluations_list]
I have the session title in the document generation, It's work !

The second line :
[inscription_sub1.val;block=tr]
I have the code in the document generation. I didn't understand why It don't work,

You talk me about HTML snippet. I put the tag directly in a template called "Template.docx". I open it with LibreOffice, and write in the document my tags.
It is a problem for the sub-block ?

By: Skrol29
Date: 2014-03-31
Time: 23:10

Re: Sub bloc with à list

>You talk me about HTML snippet. I put the tag directly in a template called "Template.docx".
>I open it with LibreOffice, and write in the document my tags.

"block=tr" cannot work in a DOCX template. It should be "block=tbs:row".

>The second line : [inscription_sub1.val;block=tr]
>I have the code in the document generation. I didn't understand why It don't work,

The special  keyword "val" is supposed to display the value of the item in the PHP array.
Can you tel how is the data structure for your records ?
By: nawbacan
Date: 2014-04-01
Time: 10:12

Re: Sub bloc with à list

For each record, I have the following structure :
Array
(
   [id] => 101624
   [session_price] => 100
   [session_title] => 'session test'
   [schedule_list] =>
   .....
   [evaluations_list] => Array
      (
         [0] => note 1
         [1] => note 2
         [2] => note 3
      )
   ....
)


Each record is stocked in a main array :
array(
[0]=> record1,
[1]=> record2,
...
)


I want to thanks you for the time you take.
I'm very confused about this problem.
By: Skrol29
Date: 2014-04-03
Time: 01:21

Re: Sub bloc with à list

What happens if you build a table in the DOCX like this :

---------------------------------------------------------------------------------------------------------------------------
|                                                                 |                                                       |
|                                                                 |              ---------------------------------------- |
| [inscription.session_title;block=tbs:row;sub1=evaluations_list] | new table :  | [inscription_sub1.val;block=tbs:row] | |
|                                                                 |              ---------------------------------------- |
---------------------------------------------------------------------------------------------------------------------------
By: nawbacan
Date: 2014-04-03
Time: 10:05

Re: Sub bloc with à list

I try with this construction.
The problem is always de same, the part
[inscription_sub1.val;block=tbs:row]
isn't interpreted.
By: Skrol29
Date: 2014-04-05
Time: 01:03

Re: Sub bloc with à list

It worked fine for me.

My PHP snippet:
$data = array(
    array(
       'id' => 101624,
       'session_price' => 100,
       'session_title' => 'session test',
       'evaluations_list' => array(
             0 => "note 1",
             1 => "note 2",
             2 => "note 3",
          )
    )
);
$TBS->MergeBlock('inscription', $data);
By: nawbacan
Date: 2014-04-08
Time: 10:12

Re: Sub bloc with à list

I have always de same problem : the line
[inscription_sub1.val;block=tbs:row]
is not interpreted.

I continue to search. Maybe It's because I work with LibreOffice for the template. Maybe, It's because I work with a Mac.

By: Skrol29
Date: 2014-04-08
Time: 22:22

Re: Sub bloc with à list

There may be a thing to check: cut the TBS field, paste it in a text editor, then copy it from the text editor and paste it again in the template.
This way all text formating will be drop.

It it does work, can you send the template to me ?

By: Skrol29
Date: 2014-04-10
Time: 01:51

Re: Sub bloc with à list

Thanks for the file you sent to me.

In your template, the sub-block is not recognized by TBS because :
The block "inscription" is defined with the first TBS field containing parameter "block".

So, replace:
[inscription;block=tbs:page;]
[inscription.firstname][inscription.lastname]

[inscription.session_title;block=tbs:row;sub1=evaluationslist]
[inscription_sub1.val;block=tbs:row]

with:
[inscription;block=tbs:page;sub1=evaluationslist]
[inscription.firstname][inscription.lastname]

[inscription.session_title]
[inscription_sub1.val;block=tbs:row]

And you also have to put the field [inscription_sub1.val;block=tbs:row] into a real table cell, other wise you'll have an error.
By: nawbacan
Date: 2014-04-11
Time: 15:10

Re: Sub bloc with à list

Hi Skrol,

I juste want to thank you very much for your help !
It's ok now.

Thank you !