| Conditions | 11 |
| Paths | 192 |
| Total Lines | 72 |
| Code Lines | 52 |
| 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 |
||
| 109 | public function exportCompleteReportCSV($document_path = '', $hotpotato_name = '') |
||
| 110 | { |
||
| 111 | global $charset; |
||
| 112 | $this->getExercisesReporting($document_path, $hotpotato_name); |
||
| 113 | $filename = 'exercise_results_'.date('YmdGis').'.csv'; |
||
| 114 | if (!empty($user_id)) { |
||
| 115 | $filename = 'exercise_results_user_'.$user_id.'_'.date('YmdGis').'.csv'; |
||
| 116 | } |
||
| 117 | $data = ''; |
||
| 118 | |||
| 119 | if (api_is_western_name_order()) { |
||
| 120 | if (!empty($this->results[0]['first_name'])) { |
||
| 121 | $data .= get_lang('FirstName').';'; |
||
| 122 | } |
||
| 123 | if (!empty($this->results[0]['last_name'])) { |
||
| 124 | $data .= get_lang('LastName').';'; |
||
| 125 | } |
||
| 126 | } else { |
||
| 127 | if (!empty($this->results[0]['last_name'])) { |
||
| 128 | $data .= get_lang('LastName').';'; |
||
| 129 | } |
||
| 130 | if (!empty($this->results[0]['first_name'])) { |
||
| 131 | $data .= get_lang('FirstName').';'; |
||
| 132 | } |
||
| 133 | } |
||
| 134 | $data .= get_lang('Email').';'; |
||
| 135 | $data .= get_lang('Title').';'; |
||
| 136 | $data .= get_lang('StartDate').';'; |
||
| 137 | $data .= get_lang('Score').';'; |
||
| 138 | $data .= get_lang('Total').';'; |
||
| 139 | $data .= "\n"; |
||
| 140 | |||
| 141 | // Results |
||
| 142 | foreach ($this->results as $row) { |
||
| 143 | if (api_is_western_name_order()) { |
||
| 144 | $data .= str_replace("\r\n", ' ', api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';'; |
||
| 145 | $data .= str_replace("\r\n", ' ', api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';'; |
||
| 146 | } else { |
||
| 147 | $data .= str_replace("\r\n", ' ', api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';'; |
||
| 148 | $data .= str_replace("\r\n", ' ', api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';'; |
||
| 149 | } |
||
| 150 | |||
| 151 | $data .= str_replace("\r\n", ' ', api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset)).';'; |
||
| 152 | $data .= str_replace("\r\n", ' ', api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset)).';'; |
||
| 153 | $data .= str_replace("\r\n", ' ', $row['exe_date']).';'; |
||
| 154 | $data .= str_replace("\r\n", ' ', $row['result']).';'; |
||
| 155 | $data .= str_replace("\r\n", ' ', $row['max']).';'; |
||
| 156 | $data .= "\n"; |
||
| 157 | } |
||
| 158 | |||
| 159 | //output the results |
||
| 160 | $len = strlen($data); |
||
| 161 | header('Content-type: application/octet-stream'); |
||
| 162 | header('Content-Type: application/force-download'); |
||
| 163 | header('Content-length: '.$len); |
||
| 164 | if (preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT'])) { |
||
| 165 | header('Content-Disposition: filename= '.$filename); |
||
| 166 | } else { |
||
| 167 | header('Content-Disposition: attachment; filename= '.$filename); |
||
| 168 | } |
||
| 169 | if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) { |
||
| 170 | header('Pragma: '); |
||
| 171 | header('Cache-Control: '); |
||
| 172 | header('Cache-Control: public'); // IE cannot download from sessions without a cache |
||
| 173 | } |
||
| 174 | header('Content-Description: '.$filename); |
||
| 175 | header('Content-transfer-encoding: binary'); |
||
| 176 | // @todo add this utf-8 header for all csv files |
||
| 177 | echo "\xEF\xBB\xBF"; // force utf-8 header of csv file |
||
| 178 | echo $data; |
||
| 179 | |||
| 180 | return true; |
||
| 181 | } |
||
| 327 |