Forums

custom display calendar like

mattiad 01 Sep, 2015
hi
i'm trying to create a custom display view like event calendar.

My db table named "events" is made by columns : id, date, event_type.
Therefore not all day (date column) have an event, so in the db table is not stored the row with a "empty day".
So in the db table i don't have all sequence of calendar dates.

How can i display a range al dates including the "empty dates" that not appair in my db table ?

I would not insert "day by day" in the table in the there aren't events in some days, because too many rows.

what is the best solution
thanks !
GreyHead 02 Sep, 2015
Hi mattiad,

You will need some custom coding to do this. You will need to check the data you have retrieved from the table, find the first and last dates and use some PHP - probably in the Header box of your listing to insert the missing 'blank' entries. There are some PHP functions that will help with this (see here or here for example - they may need to be enabled in your server setup)

Bob
mattiad 02 Sep, 2015
thx Bob

but in "header code" box i haven't access to $row['model']['field'] objects, so i can't build the custom table.

In my opinion the amount of $row objects must depend from my dates range, not from the query result. So in the "body code" box i could have a $row object for each date in my range.

So i think i have to create my custom $row objects in "front list" > "settings" > "pre display processing".
is it the fight way ?
If so, how can i create some $row object by my php code, not from query result ?
GreyHead 02 Sep, 2015
Hi mattiad,

I think that you have access to all of the values from the header row - just not in $row. Try putting this in the Header box and you should see the data
<?php
echo'<div>$this->view->vars[rows]: '.print_r($this->view->vars['rows'], true).'</div>';
?>

Bob
mattiad 02 Sep, 2015
thx Bob
to make a sample i tried to put this code in header box:
$this->view->vars[rows'][]=$this->view->vars['rows']['0'];
print_r($this->view->vars[rows']);

the print_r() show me the correct adding of the the row, but in the listing i see only the rows retrived from the query, without my custom adding.
(in "pre display processing" box seems to no have access to $this->view->vars[rows'] object so i can't manipulate it from that box)
GreyHead 02 Sep, 2015
HI Mattiad,

How are you trying to manipulate it exactly?

Can you post the out put from the print_r() here please so I can see what you are working with.

Bob
mattiad 03 Sep, 2015
in the header box i try to manipulate the whole query (to try) inserting the code :
<?php
$this->view->vars['rows'][]=$this->view->vars['rows']['0']; //add a $row whith a copy of first
echo '<div>$this->view->vars[rows]:<br> '.print_r($this->view->vars['rows'], true).'</div>';
?>

As you can see in the print_r() there is the object just added by me. So now the $this->view->vars[rows] object have a $row object in more than before (so 1 more then the query result).
$this->view->vars[rows]:
Array ( [0] => Array ( [ferieModel] => Array ( [date] => 31-12-2015 [user_id] => 235 [id] => 21 ) ) [1] => Array ( [ferieModel] => Array ( [date] => 27-09-2015 [user_id] => 235 [id] => 25 ) ) [2] => Array ( [ferieModel] => Array ( [date] => 28-09-2015 [user_id] => 235 [id] => 26 ) ) [3] => Array ( [ferieModel] => Array ( [date] => 29-09-2015 [user_id] => 235 [id] => 27 ) ) [4] => Array ( [ferieModel] => Array ( [date] => 31-12-2015 [user_id] => 235 [id] => 21 ) ) )


But as you can see the "$this->view->vars[rows]" object have 5 $rows but in listing i see only 4 rows (the real query result).
GreyHead 04 Sep, 2015
Hi mattiad,

I'm guessing here - the id of the record you've added is the same as one of the other records, What happens if you make that say 999 ?

Bob
mattiad 04 Sep, 2015
 $this->view->vars[rows]:
Array ( [0] => Array ( [ferieModel] => Array ( [date] => 31-12-2015 [user_id] => 235 [id] => 21 ) ) [1] => Array ( [ferieModel] => Array ( [date] => 27-09-2015 [user_id] => 235 [id] => 25 ) ) [2] => Array ( [ferieModel] => Array ( [date] => 28-09-2015 [user_id] => 235 [id] => 26 ) ) [3] => Array ( [ferieModel] => Array ( [date] => 29-09-2015 [user_id] => 235 [id] => 27 ) ) [4] => Array ( [ferieModel] => Array ( [date] => 31-12-2015 [user_id] => 235 [id] => 99 ) ) )


this did not solve the problem !
This topic is locked and no more replies can be posted.