Conditions | 21 |
Paths | 100 |
Total Lines | 87 |
Code Lines | 58 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
99 | function export_pdf_with_html($headers_table, $data_table, $headers_pdf, $footers_pdf, $title_pdf) |
||
100 | { |
||
101 | $headers_in_pdf = '<img src="'.api_get_path(WEB_CSS_PATH).api_get_setting('stylesheets').'/images/header-logo.png">'; |
||
|
|||
102 | |||
103 | if (is_array($headers_pdf)) { |
||
104 | // preparing headers pdf |
||
105 | $header = '<br/><br/> |
||
106 | <table width="100%" cellspacing="1" cellpadding="5" border="0" class="strong"> |
||
107 | <tr> |
||
108 | <td width="100%" style="text-align: center;" class="title" colspan="4"> |
||
109 | <h1>'.$title_pdf.'</h1></td></tr>'; |
||
110 | foreach ($headers_pdf as $header_pdf) { |
||
111 | if (!empty($header_pdf[0]) && !empty($header_pdf[1])) { |
||
112 | $header .= '<tr><td><strong>'.$header_pdf[0].'</strong> </td><td>'.$header_pdf[1].'</td></tr>'; |
||
113 | } |
||
114 | } |
||
115 | $header .= '</table><br />'; |
||
116 | } |
||
117 | |||
118 | // preparing footer pdf |
||
119 | $footer = '<table width="100%" cellspacing="2" cellpadding="10" border="0">'; |
||
120 | if (is_array($footers_pdf)) { |
||
121 | $footer .= '<tr>'; |
||
122 | foreach ($footers_pdf as $foot_pdf) { |
||
123 | $footer .= '<td width="33%" style="text-align: center;">'.$foot_pdf.'</td>'; |
||
124 | } |
||
125 | $footer .= '</tr>'; |
||
126 | } |
||
127 | $footer .= '</table>'; |
||
128 | $footer .= '<div align="right" style="font-weight: bold;">{PAGENO}/{nb}</div>'; |
||
129 | |||
130 | // preparing content pdf |
||
131 | $css = Container::getThemeHelper()->getAssetContents('print.css'); |
||
132 | $items_per_page = 30; |
||
133 | $count_pages = ceil(count($data_table) / $items_per_page); |
||
134 | $content_table = ''; |
||
135 | for ($x = 0; $x < $count_pages; $x++) { |
||
136 | $content_table .= '<table width="100%" border="1" style="border-collapse:collapse">'; |
||
137 | // header table |
||
138 | $content_table .= '<tr>'; |
||
139 | $i = 0; |
||
140 | if (is_array($headers_table)) { |
||
141 | foreach ($headers_table as $head_table) { |
||
142 | if (!empty($head_table[0])) { |
||
143 | $width = (!empty($head_table[1]) ? $head_table[1].'%' : ''); |
||
144 | $content_table .= '<th width="'.$width.'">'.$head_table[0].'</th>'; |
||
145 | $i++; |
||
146 | } |
||
147 | } |
||
148 | } |
||
149 | $content_table .= '</tr>'; |
||
150 | // body table |
||
151 | |||
152 | if (is_array($data_table) && count($data_table) > 0) { |
||
153 | $offset = $x * $items_per_page; |
||
154 | $data_table = array_slice($data_table, $offset, count($data_table)); |
||
155 | $i = 1; |
||
156 | $item = $offset + 1; |
||
157 | foreach ($data_table as $data) { |
||
158 | $content_table .= '<tr>'; |
||
159 | $content_table .= '<td>'.($item < 10 ? '0'.$item : $item).'</td>'; |
||
160 | foreach ($data as $key => $content) { |
||
161 | if (isset($content)) { |
||
162 | 1 == $key ? $align = 'align="left"' : $align = 'align="center"'; |
||
163 | $content_table .= '<td '.$align.' style="padding:4px;" >'.$content.'</td>'; |
||
164 | } |
||
165 | } |
||
166 | $content_table .= '</tr>'; |
||
167 | $i++; |
||
168 | $item++; |
||
169 | if ($i > $items_per_page) { |
||
170 | break; |
||
171 | } |
||
172 | } |
||
173 | } else { |
||
174 | $content_table .= '<tr colspan="'.$i.'"><td>'.get_lang('You left some fields empty.<br>Use the <b>Back</b> button on your browser and try again.<br>If you ignore your training code, see the Training Program').'</td></tr>'; |
||
175 | } |
||
176 | $content_table .= '</table>'; |
||
177 | if ($x < ($count_pages - 1)) { |
||
178 | $content_table .= '<pagebreak />'; |
||
179 | } |
||
180 | } |
||
181 | $pdf = new PDF(); |
||
182 | $pdf->set_custom_footer($footer); |
||
183 | $pdf->set_custom_header($headers_in_pdf); |
||
184 | $pdf->content_to_pdf($header.$content_table, $css, $title_pdf); |
||
185 | exit; |
||
186 | } |
||
219 |