Categories > OpenTBS with DOCX >

Calendar with Data per Page

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Allan
Date: 2013-01-15
Time: 22:55

Calendar with Data per Page

Great work on TBS and OpenTBS, it is already helping me so much.  I already have TBS and OpenTBS setup and working in my PHP.  I'm using it in the first half of my Word Document, and that part works fine.

In the second part, I'm trying to create a document with multiple pages (using MS Word or Libre Office Writer), each page has a different calendar.  The calendar is a table with 7 columns and a header row with the days of the week: Mon, Tues, etc.  The days in the calendar will have the "Day" (as a number), and in each day's cell there will be zero or more entries (probably no more than 4 or 5 at the most).  I'm trying to figure out how to do this.  Your help would be greatly appreciated.

Some of the cells in the calendar would be empty, no date or data, as those would be days in either the previous month or next month.  I just want an empty cell for those.

I'm not sure how my array(s) should organized.  I would prefer to have a multidimensional array (or separate arrays would also work).  If possible, I would prefer not to have a monster 2 dimensional array, where I would have to constantly repeat certain fields. Either way, I'll do whatever you suggest if I can make it work.

Not sure if I need to somehow use "Grouping Sections", but I need page breaks, one calendar per page.  It seems like the grouping sections would need a monster 2 dimensional array.


Here's what I'm thinking so far for the Word Template.  The Pipe (|) symbols in my text represent multiple cells on the same row.

[ab;block=begin]
<page break is here>
Title Here
[ab.strSite] – [ab.strMonth] [ab.iYear]

<Table here of 7 columns (numbered 0 to 6 for my array), 2 rows: 1 for header, 1 for repeating week rows>
Mon | Tues | Wed | Thurs | Fri | Sat | Sun
------------------------------------------
[ab;D.0.0;block=table:table-row] | [ab;D.1.0] | [ab;D.2.0] | ... | [ab;D.6.0]
[ab;S.0.0.0] | [ab;S.1.0.0] | [ab;S.2.0.0] | ... | [ab;S.6.0.0]
[ab;S.0.0.1] |
------------------------------------------

[ab;block=end]


Here's Rough visual example
        Italy - January 2013
  Mon    Tues   Wed    Thurs ... Sun
|------|------|------|------|------|
|      |      |    1 |    2 |    3 |
|      |      | Str1 |      | Str4 |
|      |      | Str2 |      | Str5 |
|      |      | Str3 |      |      |
|------|------|------|------|------|


Here's a rough idea of how the data in my PHP might look (though I am open for suggestions):
$arrAT = array();
$arrAT[] = array( 'strSite'=>'Site 1', 'strMonth'=>'February', 'strYear'=>'2000',
    array(    'D'=>1, array( 'S'=>'String1', 'S'=>'String2', 'S'=>'String3' ),
        'D'=>2, array( '' ),
        'D'=>3, array( 'S'=>'String4', 'S'=>'String5' )
    ) );
$arrAT[] = array( 'strSite'=>'Site 1', 'strMonth'=>'March', 'strYear'=>'2000',
    array(    'D'=>1, array( 'S'=>'String6' ),
        'D'=>2, array( 'S'=>'String7', 'S'=>'String8' ),
        'D'=>3, array( 'S'=>'String9', 'S'=>'String10' )
    ) );
$arrAT[] = array( 'strSite'=>'Site 2', 'strMonth'=>'January', 'strYear'=>'2000',
    array(    'D'=>1, array( 'S'=>'String6' ),
        'D'=>2, array( 'S'=>'String7', 'S'=>'String8' ),
        'D'=>3, array( 'S'=>'String9', 'S'=>'String10' )
    ) );
$TBS->MergeBlock( 'ab', $arrAT );

Please let me know if something is confusing.  If it helps, I can put the template code in here.  Thanks in advance for your help.

Sincerely,
Allan.
By: Skrol29
Date: 2013-01-15
Time: 23:43

Re: Calendar with Data per Page

Hi Allan,

I don't understand you data structure:
   array( 'S'=>'String1', 'S'=>'String2', 'S'=>'String3' )
should build an array equal to array( 'S'=>'String3' ) since key 'S' is added several times.

Same for array( 'D'=>1, ..., 'D'=>2, ..., 'D'=>3, ... )

By: Allan
Date: 2013-01-16
Time: 01:25

Re: Calendar with Data per Page

Thanks for the quick response.

This array is meant to be a sub-array which is part of the main $arrAT array.  The String1, String2 part is the data that would show up in the calendar cells.  These are appointments / events for a particular day in the month, for a particular site. 
The 'S' just is the block variable reference, which would refer to the String1, String2, etc.

You are right, it has a bug, as the elements are not unique this way.  I haven't yet coded this part up, as I wasn't sure how I needed to provide my data to the OpenTBS.  So I'm completely open to suggestions.

They are events / appointments which I need to show on the calendar.  There could be zero to several of them for any particular day.  They change from month to month, and site (location) to site.

I hope this helps explain it, or at least what I'm trying to do?
By: Allan
Date: 2013-01-16
Time: 18:57

Re: Calendar with Data per Page

I think this should work for the array:

    $arrAT[] = array(   'strSite'=>'Site 1', 'strMonth'=>'February', 'strYear'=>'2000',
                        'D'=>array( 1, 'S'=>array( 'String1', 'String2', 'String3' ),
                                    2, 'S'=>array( '' ),
                                    3, 'S'=>array( 'String4', 'String5' ) ) );
    $arrAT[] = array(   'strSite'=>'Site 1', 'strMonth'=>'March', 'strYear'=>'2000',
                        'D'=>array( 1, 'S'=>array( 'String6' ),
                                    2, 'S'=>array( 'String7', 'String8' ),
                                    3, 'S'=>array( 'String9', 'String10' ) ) );
    $arrAT[] = array(   'strSite'=>'Site 2', 'strMonth'=>'January', 'strYear'=>'2000',
                        'D'=>array( 1, 'S'=>array( 'String6' ),
                                    2, 'S'=>array( 'String7', 'String8' ),
                                    3, 'S'=>array( 'String9', 'String10' ) ) );

I really need help with this.  I don't know how to setup the template to show the calendars with optional appointments in the days/cells.
By: Skrol29
Date: 2013-01-17
Time: 01:17

Re: Calendar with Data per Page

Hi,

You don't need grouping, but the automatic sub-block feature seems to be relevant for your problem.

I still don't understand your data structure. It is not a possible structure for a PHP array.

Here is an example if data. Each record is a month, and each month have a 'D' item that contains the weeks of the month.

$arrAT[] = array( 'strSite'=>'Site 1', 'strMonth'=>'February', 'strYear'=>'2000',
               'D' => array(
                      array(1=>'txtMon1', 2=>'txtTue1', 3=>'txtWen1', 4=>'txtTh', 5=>'txtFri1', 6=>'txtSat1', 7=> 'txtSun'),
                      array(1=>'txtMon2', 7=>'txtSun'),
                      array(3=> 'txtWen3', 4=>'txtTh'),
                ),
             );


Here a snippet of a DOCX template that should work with this data.

[ab;block=begin;sub1=D]

<page break is here>
Title Here
[ab.strSite] – [ab.strMonth] [ab.iYear]

------------------------------------------
Mon | Tues | Wed | Thurs | Fri | Sat | Sun
------------------------------------------
[ab_sub1.1;noerr;block=table:table-row] | [ab_sub1.2;noerr] | [ab_sub1.3;noerr] | ... | [ab_sub1.7;noerr]
------------------------------------------

[ab;block=end]


Please also note that OpenTBS 1.8.0 (available in stable beta version) has a neaw feature for defining blocks on pages and rows:
block=tbs:page
block=tbs:row
By: Allan
Date: 2013-01-24
Time: 19:19

Re: Calendar with Data per Page

Hey Scrol29:

Thanks for the info.  I've been reviewing the code you supplied above, trying to figure out how to make it work for me, so far, thanks to your input, I'm closer but still missing that last piece that makes it click for me in my head.

I ran what you provided and I see it would be missing a couple of things for what I need to do.  I need to plug in the calendar dates for each day of the month (just the day part).  I also need to be able to handle potentially multiple appointments on any given day (table cell).

Is it possible to nest the sub-blocks, and maybe that would be how I would handle the multiple events per day?

I'm thinking the data array might need to look more like this, though I'm still missing the day of the month.  It's difficult for me, only because I'm not sure how I need to present the data for the OpenTBS to process it the way it will need it.
$arrAT[] = array( 'strSite'=>'Site 1', 'strMonth'=>'February', 'strYear'=>'2000',
               'D' => array(
                      array( 1=>array( 'txtMon1a', 'txtMon1b', 'txtMon1c' ),
                                 2=>array( 'txtTue1' ),
                                 2=>array( 'txtWen1' ),
                                 2=>array( 'txtTh' ),
                                 2=>array( 'txtFri1a', 'txtFri1b' ),
                                 2=>array( 'txtSat1a', 'txtSat1b', 'txtSat1c', 'txtSat1d' ),
                                 2=>array( 'txtSun' ) ),
                      array (1=>array( 'txtMon2' ), 7=>array( 'txtSun' ) ),
                      array( 3=>array( 'txtWen3' ), 4=>array( 'txtTh' ) ),
                ),
             );

I am unclear how exactly I would also need to modify the template to handle the extra data.  As I asked / wondered, maybe some sort of nested automatic sub-block, or perhaps I need to somehow use a sub-template?

While I've been reviewing your code, once you mentioned the sub-blocks, I've also found your sub-block example with the teams, matches and scores.  I'm just trying to figure out how transpose that, as that seems like it would be closer to what I need (and probably similar to what you gave me above).

I'm using the latest version of your posted libraries, so if I need to use the block=tbs:page or block=tbs:row (that you mentioned), to handle this with the need to have multiple pages, one site/year/month combo per page, that is OK, I just need to know how.

Thanks again for all the help.

Sincerely,
Allan.