1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Table PDF style plugin
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
/**
|
10 |
|
|
* Style plugin to render each item as a row in a table.
|
11 |
|
|
*
|
12 |
|
|
* @ingroup views_style_plugins
|
13 |
|
|
*/
|
14 |
|
|
class views_pdf_plugin_style_table extends views_plugin_style {
|
15 |
|
|
|
16 |
|
|
/**
|
17 |
|
|
* Render the style
|
18 |
|
|
*/
|
19 |
|
|
function render() {
|
20 |
|
|
$output = '';
|
21 |
|
|
|
22 |
|
|
$this->view->numberOfRecords = count($this->view->result);
|
23 |
|
|
$this->view->pdf->drawTable($this->view, $this->options);
|
24 |
|
|
|
25 |
|
|
return $output;
|
26 |
|
|
}
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
/**
|
30 |
|
|
* Option definitions
|
31 |
|
|
*/
|
32 |
|
|
function option_definition() {
|
33 |
|
|
$options = parent::option_definition();
|
34 |
|
|
|
35 |
|
|
$options['info'] = array('default' => array());
|
36 |
|
|
$options['position'] = array('default' => array());
|
37 |
|
|
|
38 |
|
|
return $options;
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
/**
|
42 |
|
|
* Options form
|
43 |
|
|
*/
|
44 |
|
|
function options_form(&$form, &$form_state) {
|
45 |
|
|
parent::options_form($form, $form_state);
|
46 |
|
|
$handlers = $this->display->handler->get_handlers('field');
|
47 |
|
|
if (empty($handlers)) {
|
48 |
|
|
$form['error_markup'] = array(
|
49 |
|
|
'#markup' => '<div class="error messages">' . t('You need at least one field before you can configure your table settings') . '</div>',
|
50 |
|
|
);
|
51 |
|
|
return;
|
52 |
|
|
}
|
53 |
|
|
$attached = array(
|
54 |
|
|
'css' => array(drupal_get_path('module', 'views_pdf') . '/theme/admin.css'),
|
55 |
|
|
);
|
56 |
|
|
|
57 |
|
|
$form['#theme'] = 'views_pdf_plugin_style_table';
|
58 |
|
|
$form['#attached'] = $attached;
|
59 |
|
|
|
60 |
|
|
$columns = $this->display->handler->get_field_labels();
|
61 |
|
|
$fields = $this->display->handler->get_option('fields');
|
62 |
|
|
|
63 |
|
|
$fonts = array_merge(array('default' => t('-- Default --')), views_pdf_get_font_list());
|
64 |
|
|
|
65 |
|
|
$font_styles = array(
|
66 |
|
|
'b' => t('Bold'),
|
67 |
|
|
'i' => t('Italic'),
|
68 |
|
|
'u' => t('Underline'),
|
69 |
|
|
'd' => t('Line through'),
|
70 |
|
|
'o' => t('Overline')
|
71 |
|
|
);
|
72 |
|
|
$align = array(
|
73 |
|
|
'L' => t('Left'),
|
74 |
|
|
'C' => t('Center'),
|
75 |
|
|
'R' => t('Right'),
|
76 |
|
|
'J' => t('Justify'),
|
77 |
|
|
);
|
78 |
|
|
|
79 |
|
|
$hyphenate = array(
|
80 |
|
|
'none' => t('None'),
|
81 |
|
|
'auto' => t('Detect automatically'),
|
82 |
|
|
);
|
83 |
|
|
$hyphenate = array_merge($hyphenate, views_pdf_get_hyphenations());
|
84 |
|
|
|
85 |
|
|
foreach ($columns as $field => $column) {
|
86 |
|
|
|
87 |
|
|
if ($fields[$field]['exclude'] == 1) {
|
88 |
|
|
continue;
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
$safe = str_replace(array('][', '_', ' '), '-', $field);
|
92 |
|
|
|
93 |
|
|
// the $id of the column for dependency checking.
|
94 |
|
|
$id = 'edit-style-options-columns-' . $safe;
|
95 |
|
|
|
96 |
|
|
// markup for the field name
|
97 |
|
|
$form['info'][$field]['name'] = array(
|
98 |
|
|
'#markup' => $column,
|
99 |
|
|
);
|
100 |
|
|
|
101 |
|
|
$form['info'][$field]['header_style']['text'] = array(
|
102 |
|
|
'#type' => 'fieldset',
|
103 |
|
|
'#title' => t('Text Settings'),
|
104 |
|
|
'#collapsed' => FALSE,
|
105 |
|
|
'#collapsible' => TRUE,
|
106 |
|
|
);
|
107 |
|
|
|
108 |
|
|
$form['info'][$field]['header_style']['text']['font_size'] = array(
|
109 |
|
|
'#type' => 'textfield',
|
110 |
|
|
'#size' => 10,
|
111 |
|
|
'#title' => t('Font Size'),
|
112 |
|
|
'#default_value' => isset($this->options['info'][$field]['header_style']['text']['font_size']) ? $this->options['info'][$field]['header_style']['text']['font_size'] : '',
|
113 |
|
|
);
|
114 |
|
|
|
115 |
|
|
$form['info'][$field]['header_style']['text']['font_family'] = array(
|
116 |
|
|
'#type' => 'select',
|
117 |
|
|
'#title' => t('Font Family'),
|
118 |
|
|
'#required' => TRUE,
|
119 |
|
|
'#options' => $fonts,
|
120 |
|
|
'#size' => 5,
|
121 |
|
|
'#default_value' => !empty($this->options['info'][$field]['header_style']['text']['font_family']) ? $this->options['info'][$field]['header_style']['text']['font_family'] : 'default',
|
122 |
|
|
);
|
123 |
|
|
|
124 |
|
|
$form['info'][$field]['header_style']['text']['font_style'] = array(
|
125 |
|
|
'#type' => 'checkboxes',
|
126 |
|
|
'#title' => t('Font Style'),
|
127 |
|
|
'#options' => $font_styles,
|
128 |
|
|
'#size' => 10,
|
129 |
|
|
'#default_value' => $this->options['info'][$field]['header_style']['text']['font_style'] == NULL ? $this->display->handler->get_option('default_font_style') : $this->options['info'][$field]['header_style']['text']['font_style'],
|
130 |
|
|
);
|
131 |
|
|
$form['info'][$field]['header_style']['text']['align'] = array(
|
132 |
|
|
'#type' => 'radios',
|
133 |
|
|
'#title' => t('Alignment'),
|
134 |
|
|
'#options' => $align,
|
135 |
|
|
'#default_value' => $this->options['info'][$field]['header_style']['text']['align'] == NULL ? $this->display->handler->get_option('default_text_align') : $this->options['info'][$field]['header_style']['text']['align'],
|
136 |
|
|
);
|
137 |
|
|
|
138 |
|
|
$form['info'][$field]['header_style']['text']['hyphenate'] = array(
|
139 |
|
|
'#type' => 'select',
|
140 |
|
|
'#title' => t('Text Hyphenation'),
|
141 |
|
|
'#options' => $hyphenate,
|
142 |
|
|
'#description' => t('upload patterns from <a href="@url">ctan.org</a> to <br />sites/libraries/tcpdf/hyphenate_patterns', array('@url' => 'http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/tex')),
|
143 |
|
|
'#default_value' => $this->options['info'][$field]['header_style']['text']['hyphenate'] == NULL ? $this->display->handler->get_option('default_text_hyphenate') : $this->options['info'][$field]['header_style']['text']['hyphenate'],
|
144 |
|
|
);
|
145 |
|
|
|
146 |
|
|
$form['info'][$field]['header_style']['text']['color'] = array(
|
147 |
|
|
'#type' => 'textfield',
|
148 |
|
|
'#title' => t('Text Color'),
|
149 |
|
|
'#description' => t('Enter Any format: <br />000000 (HexRGB) - 000,000,000 (RGB) - 000,000,000,000 (CMYK)'),
|
150 |
|
|
'#size' => 10,
|
151 |
|
|
'#default_value' => $this->options['info'][$field]['header_style']['text']['color'] == NULL ? $this->display->handler->get_option('default_text_color') : $this->options['info'][$field]['header_style']['text']['color'],
|
152 |
|
|
);
|
153 |
|
|
|
154 |
|
|
$form['info'][$field]['header_style']['render'] = array(
|
155 |
|
|
'#type' => 'fieldset',
|
156 |
|
|
'#title' => t('Render Settings'),
|
157 |
|
|
'#collapsed' => FALSE,
|
158 |
|
|
'#collapsible' => TRUE,
|
159 |
|
|
);
|
160 |
|
|
|
161 |
|
|
$form['info'][$field]['header_style']['render']['is_html'] = array(
|
162 |
|
|
'#type' => 'checkbox',
|
163 |
|
|
'#title' => t('Render As HTML'),
|
164 |
|
|
'#default_value' => isset($this->options['info'][$field]['header_style']['render']['is_html']) ? $this->options['info'][$field]['header_style']['render']['is_html'] : 1,
|
165 |
|
|
);
|
166 |
|
|
|
167 |
|
|
$form['info'][$field]['header_style']['render']['eval_before'] = array(
|
168 |
|
|
'#type' => 'textarea',
|
169 |
|
|
'#title' => t('PHP Code Before Output'),
|
170 |
|
|
'#default_value' => isset($this->options['info'][$field]['header_style']['render']['eval_before']) ? $this->options['info'][$field]['header_style']['render']['eval_before'] : '',
|
171 |
|
|
);
|
172 |
|
|
|
173 |
|
|
$form['info'][$field]['header_style']['render']['eval_after'] = array(
|
174 |
|
|
'#type' => 'textarea',
|
175 |
|
|
'#title' => t('PHP Code After Output'),
|
176 |
|
|
'#default_value' => isset($this->options['info'][$field]['header_style']['render']['eval_after']) ? $this->options['info'][$field]['header_style']['render']['eval_after'] : '',
|
177 |
|
|
);
|
178 |
|
|
|
179 |
|
|
$form['info'][$field]['body_style']['text'] = array(
|
180 |
|
|
'#type' => 'fieldset',
|
181 |
|
|
'#title' => t('Text Settings'),
|
182 |
|
|
'#collapsed' => FALSE,
|
183 |
|
|
'#collapsible' => TRUE,
|
184 |
|
|
);
|
185 |
|
|
$form['info'][$field]['body_style']['text']['font_size'] = array(
|
186 |
|
|
'#type' => 'textfield',
|
187 |
|
|
'#size' => 10,
|
188 |
|
|
'#title' => t('Font Size'),
|
189 |
|
|
'#default_value' => isset($this->options['info'][$field]['body_style']['text']['font_size']) ? $this->options['info'][$field]['body_style']['text']['font_size'] : '',
|
190 |
|
|
);
|
191 |
|
|
|
192 |
|
|
$form['info'][$field]['body_style']['text']['font_family'] = array(
|
193 |
|
|
'#type' => 'select',
|
194 |
|
|
'#title' => t('Font Family'),
|
195 |
|
|
'#required' => TRUE,
|
196 |
|
|
'#options' => $fonts,
|
197 |
|
|
'#size' => 5,
|
198 |
|
|
'#default_value' => !empty($this->options['info'][$field]['body_style']['text']['font_family']) ? $this->options['info'][$field]['body_style']['text']['font_family'] : 'default',
|
199 |
|
|
);
|
200 |
|
|
|
201 |
|
|
$form['info'][$field]['body_style']['text']['font_style'] = array(
|
202 |
|
|
'#type' => 'checkboxes',
|
203 |
|
|
'#title' => t('Font Style'),
|
204 |
|
|
'#options' => $font_styles,
|
205 |
|
|
'#size' => 10,
|
206 |
|
|
'#default_value' => $this->options['info'][$field]['body_style']['text']['font_style'] == NULL ? $this->display->handler->get_option('default_font_style') : $this->options['info'][$field]['body_style']['text']['font_style'],
|
207 |
|
|
);
|
208 |
|
|
$form['info'][$field]['body_style']['text']['align'] = array(
|
209 |
|
|
'#type' => 'radios',
|
210 |
|
|
'#title' => t('Alignment'),
|
211 |
|
|
'#options' => $align,
|
212 |
|
|
'#default_value' => $this->options['info'][$field]['body_style']['text']['align'] == NULL ? $this->display->handler->get_option('default_text_align') : $this->options['info'][$field]['body_style']['text']['align'],
|
213 |
|
|
);
|
214 |
|
|
|
215 |
|
|
$form['info'][$field]['body_style']['text']['hyphenate'] = array(
|
216 |
|
|
'#type' => 'select',
|
217 |
|
|
'#title' => t('Text Hyphenation'),
|
218 |
|
|
'#options' => $hyphenate,
|
219 |
|
|
'#description' => t('upload patterns from <a href="@url">ctan.org</a> to <br />sites/libraries/tcpdf/hyphenate_patterns', array('@url' => 'http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/tex')),
|
220 |
|
|
'#default_value' => $this->options['info'][$field]['body_style']['text']['hyphenate'] == NULL ? $this->display->handler->get_option('default_text_hyphenate') : $this->options['info'][$field]['body_style']['text']['hyphenate'],
|
221 |
|
|
);
|
222 |
|
|
|
223 |
|
|
$form['info'][$field]['body_style']['text']['color'] = array(
|
224 |
|
|
'#type' => 'textfield',
|
225 |
|
|
'#title' => t('Text Color'),
|
226 |
|
|
'#description' => t('Enter Any format: <br />000000 (HexRGB) - 000,000,000 (RGB) - 000,000,000,000 (CMYK)'),
|
227 |
|
|
'#size' => 20,
|
228 |
|
|
'#default_value' => $this->options['info'][$field]['body_style']['text']['color'] == NULL ? $this->display->handler->get_option('default_text_color') : $this->options['info'][$field]['body_style']['text']['color'],
|
229 |
|
|
);
|
230 |
|
|
|
231 |
|
|
$form['info'][$field]['body_style']['render'] = array(
|
232 |
|
|
'#type' => 'fieldset',
|
233 |
|
|
'#title' => t('Render Settings'),
|
234 |
|
|
'#collapsed' => FALSE,
|
235 |
|
|
'#collapsible' => TRUE,
|
236 |
|
|
);
|
237 |
|
|
|
238 |
|
|
$form['info'][$field]['body_style']['render']['is_html'] = array(
|
239 |
|
|
'#type' => 'checkbox',
|
240 |
|
|
'#title' => t('Render As HTML'),
|
241 |
|
|
'#default_value' => isset($this->options['info'][$field]['body_style']['render']['is_html']) ? $this->options['info'][$field]['body_style']['render']['is_html'] : 1,
|
242 |
|
|
);
|
243 |
|
|
|
244 |
|
|
$form['info'][$field]['body_style']['render']['eval_before'] = array(
|
245 |
|
|
'#type' => 'textarea',
|
246 |
|
|
'#title' => t('PHP Code Before Output'),
|
247 |
|
|
'#default_value' => isset($this->options['info'][$field]['body_style']['render']['eval_before']) ? $this->options['info'][$field]['body_style']['render']['eval_before'] : '',
|
248 |
|
|
);
|
249 |
|
|
|
250 |
|
|
$form['info'][$field]['body_style']['render']['eval_after'] = array(
|
251 |
|
|
'#type' => 'textarea',
|
252 |
|
|
'#title' => t('PHP Code After Output'),
|
253 |
|
|
'#default_value' => isset($this->options['info'][$field]['body_style']['render']['eval_after']) ? $this->options['info'][$field]['body_style']['render']['eval_after'] : '',
|
254 |
|
|
);
|
255 |
|
|
|
256 |
|
|
$form['info'][$field]['position']['width'] = array(
|
257 |
|
|
'#type' => 'textfield',
|
258 |
|
|
'#size' => 10,
|
259 |
|
|
'#title' => t('Width'),
|
260 |
|
|
'#default_value' => isset($this->options['info'][$field]['position']['width']) ? $this->options['info'][$field]['position']['width'] : '',
|
261 |
|
|
);
|
262 |
|
|
}
|
263 |
|
|
|
264 |
|
|
// Some general options
|
265 |
|
|
$form['position'] = array(
|
266 |
|
|
'#type' => 'fieldset',
|
267 |
|
|
'#title' => t('Table Position'),
|
268 |
|
|
'#collapsed' => FALSE,
|
269 |
|
|
'#collapsible' => TRUE,
|
270 |
|
|
);
|
271 |
|
|
|
272 |
|
|
$form['position']['last_writing_position'] = array(
|
273 |
|
|
'#type' => 'checkbox',
|
274 |
|
|
'#title' => t('Relative to last writing position'),
|
275 |
|
|
'#default_value' => isset($this->options['position']['last_writing_position']) ? $this->options['position']['last_writing_position'] : 1,
|
276 |
|
|
);
|
277 |
|
|
|
278 |
|
|
$form['position']['x'] = array(
|
279 |
|
|
'#type' => 'textfield',
|
280 |
|
|
'#size' => 10,
|
281 |
|
|
'#title' => t('X'),
|
282 |
|
|
'#description' => t('X Coordinate (relative to page with margins)'),
|
283 |
|
|
'#default_value' => isset($this->options['position']['x']) ? $this->options['position']['x'] : '',
|
284 |
|
|
);
|
285 |
|
|
$form['position']['y'] = array(
|
286 |
|
|
'#type' => 'textfield',
|
287 |
|
|
'#size' => 10,
|
288 |
|
|
'#title' => t('Y'),
|
289 |
|
|
'#description' => t('Y Coordinate (relative to page with margins)'),
|
290 |
|
|
'#default_value' => isset($this->options['position']['y']) ? $this->options['position']['y'] : '',
|
291 |
|
|
);
|
292 |
|
|
$form['position']['width'] = array(
|
293 |
|
|
'#type' => 'textfield',
|
294 |
|
|
'#size' => 10,
|
295 |
|
|
'#title' => t('Table Width'),
|
296 |
|
|
'#default_value' => isset($this->options['position']['width']) ? $this->options['position']['width'] : '',
|
297 |
|
|
);
|
298 |
|
|
|
299 |
|
|
$form['position']['row_height'] = array(
|
300 |
|
|
'#type' => 'textfield',
|
301 |
|
|
'#size' => 10,
|
302 |
|
|
'#title' => t('Row Height'),
|
303 |
|
|
'#default_value' => isset($this->options['position']['row_height']) ? $this->options['position']['row_height'] : '',
|
304 |
|
|
);
|
305 |
|
|
|
306 |
|
|
parent::options_form($form, $form_state);
|
307 |
|
|
|
308 |
|
|
}
|
309 |
|
|
|
310 |
|
|
/**
|
311 |
|
|
* Options form storage
|
312 |
|
|
*/
|
313 |
|
|
function options_submit(&$form, &$form_state) {
|
314 |
|
|
$default_font_style = $this->display->handler->get_option('default_font_style');
|
315 |
|
|
foreach ($form_state['values']['style_options']['info'] as $id => $field) {
|
316 |
|
|
|
317 |
|
|
// Reset to default, if the elements are equal to the default settings
|
318 |
|
|
if (
|
319 |
|
|
count(array_diff($default_font_style, $field['header_style']['text']['font_style'])) == 0 &&
|
320 |
|
|
count(array_diff($field['header_style']['text']['font_style'], $default_font_style)) == 0) {
|
321 |
|
|
$form_state['values']['style_options']['info'][$id]['header_style']['text']['font_style'] = NULL;
|
322 |
|
|
}
|
323 |
|
|
|
324 |
|
|
if ($field['header_style']['text']['align'] == $this->display->handler->get_option('default_text_align')) {
|
325 |
|
|
$form_state['values']['style_options']['info'][$id]['header_style']['text']['align'] = NULL;
|
326 |
|
|
}
|
327 |
|
|
|
328 |
|
|
if ($field['header_style']['text']['hyphenate'] == $this->display->handler->get_option('default_text_hyphenate')) {
|
329 |
|
|
$form_state['values']['style_options']['info'][$id]['header_style']['text']['hyphenate'] = NULL;
|
330 |
|
|
}
|
331 |
|
|
|
332 |
|
|
// Reset to default, if the elements are equal to the default settings
|
333 |
|
|
if (
|
334 |
|
|
count(array_diff($default_font_style, $field['body_style']['text']['font_style'])) == 0 &&
|
335 |
|
|
count(array_diff($field['body_style']['text']['font_style'], $default_font_style)) == 0) {
|
336 |
|
|
$form_state['values']['style_options']['info'][$id]['body_style']['text']['font_style'] = NULL;
|
337 |
|
|
}
|
338 |
|
|
|
339 |
|
|
if ($field['body_style']['text']['align'] == $this->display->handler->get_option('default_text_align')) {
|
340 |
|
|
$form_state['values']['style_options']['info'][$id]['body_style']['text']['align'] = NULL;
|
341 |
|
|
}
|
342 |
|
|
|
343 |
|
|
if ($field['body_style']['text']['hyphenate'] == $this->display->handler->get_option('default_text_hyphenate')) {
|
344 |
|
|
$form_state['values']['style_options']['info'][$id]['body_style']['text']['hyphenate'] = NULL;
|
345 |
|
|
}
|
346 |
|
|
|
347 |
|
|
}
|
348 |
|
|
|
349 |
|
|
}
|
350 |
|
|
|
351 |
|
|
/**
|
352 |
|
|
* Attach this view to another display as a feed.
|
353 |
|
|
*
|
354 |
|
|
* Provide basic functionality for all export style views like attaching a
|
355 |
|
|
* feed image link.
|
356 |
|
|
*/
|
357 |
|
|
function attach_to($display_id, $path, $title) {
|
358 |
|
|
$display = $this->view->display[$display_id]->handler;
|
359 |
|
|
$url_options = array();
|
360 |
|
|
$input = $this->view->get_exposed_input();
|
361 |
|
|
if ($input) {
|
362 |
|
|
$url_options['query'] = $input;
|
363 |
|
|
}
|
364 |
|
|
|
365 |
|
|
if (empty($this->view->feed_icon)) {
|
366 |
|
|
$this->view->feed_icon = '';
|
367 |
|
|
}
|
368 |
|
|
$this->view->feed_icon .= theme(
|
369 |
|
|
'views_pdf_icon',
|
370 |
|
|
array(
|
371 |
|
|
'path' => $this->view->get_url(NULL, $path),
|
372 |
|
|
'title' => $title,
|
373 |
|
|
'options' => $url_options
|
374 |
|
|
)
|
375 |
|
|
);
|
376 |
|
|
}
|
377 |
|
|
|
378 |
|
|
} |