/
AlbumGrid.php
120 lines (99 loc) · 3.78 KB
/
AlbumGrid.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
* This is an Album page layout class that extends the an album for a specific layout
*
* AlbumGrid creats a grid block stamps with a given number of rows and columns
*
*
* @package Stamp Album Pro
* @class AlbumRows
* @extends Album
* @version 1.0
* @author Dexter Oddwick <dexter@oddwick.com>
* @copyright Copyright (c)2017
* @license http://www.oddwick.com
*
* @todo
*
*/
class AlbumGrid extends Album {
/**
* default layout of simple rows
*
* @access protected
* @return void
*/
public function layout(){
//$this->params->debug = true;
// force the vertical alignment to be top aligned
// otherwise the layout looks like crap
$this->params->stamp_vert_align = "top";
// assign stamp object list to temp variable
// and initialize the variables
$groups = $this->_groups;
$stamps = array();
$rows = array();
// define an empty page
$page = new Page( $this->_pdf, $this->params, $this->params->max_x, $this->params->max_y);
// get the available dimensions of the field
// and calculate the max dimensions
$data = $page->page();
$maxRowWidth = $data["max_x"] - $data["minX"];
$maxHeight = $data["max_y"] - $data["minY"];
// iterate through the groups, extract the stamps and create an array of row objects
foreach( $groups as $group){
// dump the groups stamps into an array
$stamps = $group->stamps();
// create a new row object
$row = new Row( $this->_pdf, $this->params, $maxRowWidth, $maxHeight);
// iterate through the stamps in this group
for( $i = 0; $i < count( $stamps); $i++){
// if this is the first row, add the group titles
if(!$i){
$row->addTitles( $group->title(), $group->subtitle());
if( $this->params->group_text_location == "above" ) $row->addTextBlock( $group->text());
}
// add stamp to the row
// if the row is full, add the row to the rows[] array, create a new row,
// and reset the count so as to attempt to add the same stamp to the next row
if( !$row->addStamp( $stamps[$i] ) ){
$rows[] = $row;
$row = new Row( $this->_pdf, $this->params, $maxRowWidth, $maxHeight);
$i--;
}
}
// add the remaining stamps or uncompleted row to the rows[] array
$rows[] = $row;
if(!$this->params->group_text_location == "above" ) $row->addTextBlock( $group->text());
} // end of groups
// begin adding the rows to pages
// increment page number counter.
///++$this->_page;
//$data = $page->page( $append = true);
$field = new Field( $this->_pdf, $this->params, $data["minX"], $data["minY"], $data["max_x"],$data["max_y"]);
// iterate through the rows and add to the fields
for( $i = 0; $i < count( $rows); $i++){
// add stamps to the field and if the field is full,
// break and print to pdf, create a new page,
// increment the page counter, and roll back the row counter
// so as to try adding the row to a new page
if( $field->available() > $rows[$i]->height() ){
$field->add( $rows[$i] );
} else {
// write out the field contents
$field->write();
// new page in append mode
$page->page(true);
// increment the page count
++$this->_page;
// create a new field
$field = new Field( $this->_pdf, $this->params, $data["minX"], $data["minY"], $data["max_x"],$data["max_y"]);
// roll back the row counter
--$i;
}
}
// write out the last page
$field->write();
//die;
} // end function -----------------------------------------------------------------------------------------------------------------------------------------------
} // end class