| Conditions | 42 |
| Paths | 6120 |
| Total Lines | 166 |
| Code Lines | 111 |
| Lines | 35 |
| Ratio | 21.08 % |
| 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 |
||
| 30 | public function export( $_stream, importexport_definition $_definition) { |
||
| 31 | $options = $_definition->plugin_options; |
||
|
|
|||
| 32 | |||
| 33 | $limit_exception = bo_merge::is_export_limit_excepted(); |
||
| 34 | if (!$limit_exception) $export_limit = bo_merge::getExportLimit('calendar'); |
||
| 35 | // Custom fields need to be specifically requested |
||
| 36 | $cfs = array(); |
||
| 37 | foreach($options['mapping'] + (array)$_definition->filter as $key => $label) { |
||
| 38 | if($key[0] == '#') $cfs[] = substr($key,1); |
||
| 39 | } |
||
| 40 | |||
| 41 | $query = array( |
||
| 42 | 'cfs' => $cfs, // Otherwise we shouldn't get any custom fields |
||
| 43 | 'num_rows' => -1, |
||
| 44 | 'csv_export' => true |
||
| 45 | ); |
||
| 46 | switch($options['selection']) |
||
| 47 | { |
||
| 48 | case 'criteria': |
||
| 49 | $query = array( |
||
| 50 | 'start' => $options['criteria']['start'], |
||
| 51 | 'end' => strtotime('+1 day',$options['criteria']['end'])-1, |
||
| 52 | 'categories' => $options['categories'] ? $options['categories'] : $options['criteria']['categories'], |
||
| 53 | //'enum_recuring' => false, // we want the recurring events enumerated for csv export |
||
| 54 | 'daywise' => false, |
||
| 55 | 'users' => $options['criteria']['owner'], |
||
| 56 | 'cfs' => $cfs // Otherwise we shouldn't get any custom fields |
||
| 57 | ); |
||
| 58 | View Code Duplication | if(bo_merge::hasExportLimit($export_limit) && !$limit_exception) { |
|
| 59 | $query['offset'] = 0; |
||
| 60 | $query['num_rows'] = (int)$export_limit; // ! int of 'no' is 0 |
||
| 61 | } |
||
| 62 | $events =& $this->bo->search($query); |
||
| 63 | break; |
||
| 64 | case 'search_results': |
||
| 65 | $states = $GLOBALS['egw']->session->appsession('session_data','calendar'); |
||
| 66 | if($states['view'] == 'listview') { |
||
| 67 | $query = $GLOBALS['egw']->session->appsession('calendar_list','calendar'); |
||
| 68 | $query['num_rows'] = -1; // all |
||
| 69 | $query['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session |
||
| 70 | $query['start'] = 0; |
||
| 71 | $query['cfs'] = $cfs; |
||
| 72 | |||
| 73 | if(bo_merge::hasExportLimit($export_limit) && !$limit_exception) { |
||
| 74 | $query['num_rows'] = (int)$export_limit; // ! int of 'no' is 0 |
||
| 75 | } |
||
| 76 | $ui = new calendar_uilist(); |
||
| 77 | $ui->get_rows($query, $events, $unused); |
||
| 78 | } else { |
||
| 79 | $query = $GLOBALS['egw']->session->appsession('session_data','calendar'); |
||
| 80 | $query['users'] = explode(',', $query['owner']); |
||
| 81 | $query['num_rows'] = -1; |
||
| 82 | if(bo_merge::hasExportLimit($export_limit) && !$limit_exception) { |
||
| 83 | $query['num_rows'] = (int)$export_limit; // ! int of 'no' is 0 |
||
| 84 | } |
||
| 85 | |||
| 86 | $events = array(); |
||
| 87 | switch($states['view']) { |
||
| 88 | case 'month': |
||
| 89 | $query += $this->get_query_month($states); |
||
| 90 | break; |
||
| 91 | case 'week': |
||
| 92 | case 'weekN': |
||
| 93 | $query += $this->get_query_week($states); |
||
| 94 | break; |
||
| 95 | case 'day': |
||
| 96 | $query += $this->get_query_day($states); |
||
| 97 | break; |
||
| 98 | View Code Duplication | default: |
|
| 99 | // Let UI set the date ranges |
||
| 100 | $ui = new calendar_uiviews($query); |
||
| 101 | if(method_exists($ui, $states['view'])) |
||
| 102 | { |
||
| 103 | ob_start(); |
||
| 104 | $ui->$states['view'](); |
||
| 105 | ob_end_clean(); |
||
| 106 | } |
||
| 107 | $query += array( |
||
| 108 | 'start' => is_array($ui->first) ? $this->bo->date2ts($ui->first) : $ui->first, |
||
| 109 | 'end' => is_array($ui->last) ? $this->bo->date2ts($ui->last) : $ui->last |
||
| 110 | ); |
||
| 111 | |||
| 112 | } |
||
| 113 | $boupdate = new calendar_boupdate(); |
||
| 114 | $events = $boupdate->search($query + array( |
||
| 115 | 'offset' => 0, |
||
| 116 | 'order' => 'cal_start', |
||
| 117 | )); |
||
| 118 | } |
||
| 119 | break; |
||
| 120 | case 'filter': |
||
| 121 | $fields = importexport_helper_functions::get_filter_fields($_definition->application, $this); |
||
| 122 | $filter = $_definition->filter; |
||
| 123 | |||
| 124 | // Handle ranges |
||
| 125 | View Code Duplication | foreach($filter as $field => $value) |
|
| 126 | { |
||
| 127 | if($field == 'filter' && $value) |
||
| 128 | { |
||
| 129 | $query['filter'] = $value; |
||
| 130 | continue; |
||
| 131 | } |
||
| 132 | if(!is_array($value) || (!$value['from'] && !$value['to'])) |
||
| 133 | { |
||
| 134 | $query['query']["cal_$field"] = $value; |
||
| 135 | continue; |
||
| 136 | } |
||
| 137 | |||
| 138 | // Ranges are inclusive, so should be provided that way (from 2 to 10 includes 2 and 10) |
||
| 139 | if($value['from']) $query['sql_filter'][] = "cal_$field >= " . (int)$value['from']; |
||
| 140 | if($value['to']) $query['sql_filter'][] = "cal_$field <= " . (int)$value['to']; |
||
| 141 | |||
| 142 | } |
||
| 143 | if($query['sql_filter'] && is_array($query['sql_filter'])) |
||
| 144 | { |
||
| 145 | // Set as an extra parameter |
||
| 146 | $sql_filter = implode(' AND ',$query['sql_filter']); |
||
| 147 | } |
||
| 148 | |||
| 149 | case 'all': |
||
| 150 | $events = $this->bo->search($query + array( |
||
| 151 | 'offset' => 0, |
||
| 152 | 'order' => 'cal_start', |
||
| 153 | ),$sql_filter); |
||
| 154 | break; |
||
| 155 | } |
||
| 156 | |||
| 157 | $export_object = new importexport_export_csv($_stream, (array)$options); |
||
| 158 | if (!$limit_exception) $export_object->export_limit = $export_limit; |
||
| 159 | $export_object->set_mapping($options['mapping']); |
||
| 160 | $convert_fields = calendar_egw_record::$types; |
||
| 161 | |||
| 162 | $recurrence = $this->bo->recur_types; |
||
| 163 | |||
| 164 | $record = new calendar_egw_record(); |
||
| 165 | foreach ($events as $event) { |
||
| 166 | // the condition below (2 lines) may only work on enum_recuring=false and using the iterator to test an recurring event on the given timerange |
||
| 167 | // Get rid of yearly recurring events that don't belong |
||
| 168 | //if($options['selection']['select'] == 'criteria' && ($event['start'] > $query['end'] || $event['end'] < $query['start'])) continue; |
||
| 169 | // Add in participants |
||
| 170 | if($options['mapping']['participants']) { |
||
| 171 | $event['participants'] = implode(", ",$this->bo->participants($event,true)); |
||
| 172 | } |
||
| 173 | if (is_array($event)) |
||
| 174 | { |
||
| 175 | $record->set_record($event); |
||
| 176 | if($options['mapping']['recurrence']) { |
||
| 177 | $record->recurrence = $recurrence[$record->recur_type]; |
||
| 178 | if($record->recur_type != MCAL_RECUR_NONE) $record->recurrence .= ' / '. $record->recur_interval; |
||
| 179 | } |
||
| 180 | |||
| 181 | // Standard stuff |
||
| 182 | if($options['convert']) { |
||
| 183 | importexport_export_csv::convert($record, $convert_fields, 'calendar', $this->selects); |
||
| 184 | } else { |
||
| 185 | // Implode arrays, so they don't say 'Array' |
||
| 186 | foreach($record->get_record_array() as $key => $value) { |
||
| 187 | if(is_array($value)) $record->$key = implode(',', $value); |
||
| 188 | } |
||
| 189 | } |
||
| 190 | $export_object->export_record($record); |
||
| 191 | } |
||
| 192 | } |
||
| 193 | unset($record); |
||
| 194 | return $export_object; |
||
| 195 | } |
||
| 196 | |||
| 435 |
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.