@@ -17,7 +17,8 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * class import_csv for calendar |
19 | 19 | */ |
20 | -class calendar_import_csv extends importexport_basic_import_csv { |
|
20 | +class calendar_import_csv extends importexport_basic_import_csv |
|
21 | +{ |
|
21 | 22 | |
22 | 23 | /** |
23 | 24 | * actions wich could be done to data entries |
@@ -83,8 +84,10 @@ discard block |
||
83 | 84 | $options['owner'] = $options['owner'] ? $options['owner'] : $this->user; |
84 | 85 | |
85 | 86 | // Set owner, unless it's supposed to come from CSV file |
86 | - if($options['owner_from_csv']) { |
|
87 | - if(!is_numeric($record['owner'])) { |
|
87 | + if($options['owner_from_csv']) |
|
88 | + { |
|
89 | + if(!is_numeric($record['owner'])) |
|
90 | + { |
|
88 | 91 | $this->errors[$import_csv->get_current_position()] = lang( |
89 | 92 | 'Invalid owner ID: %1. Might be a bad field translation. Used %2 instead.', |
90 | 93 | $record->owner, |
@@ -106,14 +109,16 @@ discard block |
||
106 | 109 | } |
107 | 110 | |
108 | 111 | // Parse particpants |
109 | - if ($record->participants && !is_array($record->participants)) { |
|
112 | + if ($record->participants && !is_array($record->participants)) |
|
113 | + { |
|
110 | 114 | // Importing participants in human friendly format: |
111 | 115 | // Name (quantity)? (status) Role[, Name (quantity)? (status) Role]+ |
112 | 116 | preg_match_all('/(([^(]+?)(?: \(([\d]+)\))? \(([^,)]+)\)(?: ([^ ,]+))?)(?:, )?/',$record->participants,$participants); |
113 | 117 | $p_participants = array(); |
114 | 118 | $missing = array(); |
115 | 119 | list($lines, $p, $names, $quantity, $status, $role) = $participants; |
116 | - foreach($names as $key => $name) { |
|
120 | + foreach($names as $key => $name) |
|
121 | + { |
|
117 | 122 | //error_log("Name: $name Quantity: {$quantity[$key]} Status: {$status[$key]} Role: {$role[$key]}"); |
118 | 123 | |
119 | 124 | // Search for direct account name, then user in accounts first |
@@ -121,9 +126,13 @@ discard block |
||
121 | 126 | $id = importexport_helper_functions::account_name2id($name); |
122 | 127 | |
123 | 128 | // If not found, or not an exact match to a user (account_name2id is pretty generous) |
124 | - if(!$id || $names[$key] !== $this->bo->participant_name($id)) { |
|
129 | + if(!$id || $names[$key] !== $this->bo->participant_name($id)) |
|
130 | + { |
|
125 | 131 | $contacts = ExecMethod2('addressbook.addressbook_bo.search', $search,array('contact_id','account_id'),'org_name,n_family,n_given,cat_id,contact_email','','%',false,'OR',array(0,1)); |
126 | - if($contacts) $id = $contacts[0]['account_id'] ? $contacts[0]['account_id'] : 'c'.$contacts[0]['contact_id']; |
|
132 | + if($contacts) |
|
133 | + { |
|
134 | + $id = $contacts[0]['account_id'] ? $contacts[0]['account_id'] : 'c'.$contacts[0]['contact_id']; |
|
135 | + } |
|
127 | 136 | } |
128 | 137 | if(!$id) |
129 | 138 | { |
@@ -131,7 +140,10 @@ discard block |
||
131 | 140 | foreach($this->bo->resources as $resource) |
132 | 141 | { |
133 | 142 | // Can't search for email |
134 | - if($resource['app'] == 'email') continue; |
|
143 | + if($resource['app'] == 'email') |
|
144 | + { |
|
145 | + continue; |
|
146 | + } |
|
135 | 147 | // Special resource search, since it does special stuff in link_query |
136 | 148 | if($resource['app'] == 'resources') |
137 | 149 | { |
@@ -140,7 +152,8 @@ discard block |
||
140 | 152 | $this->resource_so = new resources_so(); |
141 | 153 | } |
142 | 154 | $result = $this->resource_so->search($search,'res_id'); |
143 | - if(count($result) >= 1) { |
|
155 | + if(count($result) >= 1) |
|
156 | + { |
|
144 | 157 | $id = $resource['type'].$result[0]['res_id']; |
145 | 158 | break; |
146 | 159 | } |
@@ -159,7 +172,8 @@ discard block |
||
159 | 172 | } |
160 | 173 | } |
161 | 174 | } |
162 | - if($id) { |
|
175 | + if($id) |
|
176 | + { |
|
163 | 177 | $p_participants[$id] = calendar_so::combine_status( |
164 | 178 | $this->status_map[lang($status[$key])] ? $this->status_map[lang($status[$key])] : $status[$key][0], |
165 | 179 | $quantity[$key] ? $quantity[$key] : 1, |
@@ -188,27 +202,38 @@ discard block |
||
188 | 202 | } |
189 | 203 | $record->tzid = calendar_timezones::id2tz($record->tz_id); |
190 | 204 | |
191 | - if ( $options['conditions'] ) { |
|
192 | - foreach ( $options['conditions'] as $condition ) { |
|
205 | + if ( $options['conditions'] ) |
|
206 | + { |
|
207 | + foreach ( $options['conditions'] as $condition ) |
|
208 | + { |
|
193 | 209 | $records = array(); |
194 | - switch ( $condition['type'] ) { |
|
210 | + switch ( $condition['type'] ) |
|
211 | + { |
|
195 | 212 | // exists |
196 | 213 | case 'exists' : |
197 | 214 | // Check for that record |
198 | 215 | $result = $this->exists($record, $condition, $records); |
199 | 216 | |
200 | - if ( is_array( $records ) && count( $records ) >= 1) { |
|
217 | + if ( is_array( $records ) && count( $records ) >= 1) |
|
218 | + { |
|
201 | 219 | // apply action to all records matching this exists condition |
202 | 220 | $action = $condition['true']; |
203 | - foreach ( (array)$records as $event ) { |
|
221 | + foreach ( (array)$records as $event ) |
|
222 | + { |
|
204 | 223 | $record->id = $event['id']; |
205 | - if ( $this->definition->plugin_options['update_cats'] == 'add' ) { |
|
206 | - if ( !is_array( $record->category ) ) $record->category = explode( ',', $record->category ); |
|
224 | + if ( $this->definition->plugin_options['update_cats'] == 'add' ) |
|
225 | + { |
|
226 | + if ( !is_array( $record->category ) ) |
|
227 | + { |
|
228 | + $record->category = explode( ',', $record->category ); |
|
229 | + } |
|
207 | 230 | $record->category = implode( ',', array_unique( array_merge( $record->category, $event['category'] ) ) ); |
208 | 231 | } |
209 | 232 | $success = $this->action( $action['action'], $record, $import_csv->get_current_position() ); |
210 | 233 | } |
211 | - } else { |
|
234 | + } |
|
235 | + else |
|
236 | + { |
|
212 | 237 | $action = $condition['false']; |
213 | 238 | $success = ($this->action( $action['action'], $record, $import_csv->get_current_position() )); |
214 | 239 | } |
@@ -219,9 +244,14 @@ discard block |
||
219 | 244 | die('condition / action not supported!!!'); |
220 | 245 | break; |
221 | 246 | } |
222 | - if ($action['last']) break; |
|
247 | + if ($action['last']) |
|
248 | + { |
|
249 | + break; |
|
250 | + } |
|
223 | 251 | } |
224 | - } else { |
|
252 | + } |
|
253 | + else |
|
254 | + { |
|
225 | 255 | // unconditional insert |
226 | 256 | $success = $this->action( 'insert', $record, $import_csv->get_current_position() ); |
227 | 257 | } |
@@ -240,12 +270,14 @@ discard block |
||
240 | 270 | */ |
241 | 271 | protected function exists(importexport_iface_egw_record &$record, Array &$condition, &$records = array()) |
242 | 272 | { |
243 | - if($record->__get($condition['string']) && $condition['string'] == 'id') { |
|
273 | + if($record->__get($condition['string']) && $condition['string'] == 'id') |
|
274 | + { |
|
244 | 275 | $event = $this->bo->read($record->__get($condition['string'])); |
245 | 276 | $records = array($event); |
246 | 277 | } |
247 | 278 | |
248 | - if ( is_array( $records ) && count( $records ) >= 1) { |
|
279 | + if ( is_array( $records ) && count( $records ) >= 1) |
|
280 | + { |
|
249 | 281 | return true; |
250 | 282 | } |
251 | 283 | return false; |
@@ -261,7 +293,8 @@ discard block |
||
261 | 293 | protected function action ( $_action, importexport_iface_egw_record &$record, $record_num = 0 ) |
262 | 294 | { |
263 | 295 | $_data = $record->get_record_array(); |
264 | - switch ($_action) { |
|
296 | + switch ($_action) |
|
297 | + { |
|
265 | 298 | case 'none' : |
266 | 299 | return true; |
267 | 300 | case 'update' : |
@@ -269,7 +302,8 @@ discard block |
||
269 | 302 | $old = $this->bo->read($_data['id']); |
270 | 303 | |
271 | 304 | // Don't change a user account into a record |
272 | - if(!$this->definition->plugin_options['change_owner']) { |
|
305 | + if(!$this->definition->plugin_options['change_owner']) |
|
306 | + { |
|
273 | 307 | // Don't change owner of an existing record |
274 | 308 | unset($_data['owner']); |
275 | 309 | } |
@@ -277,23 +311,27 @@ discard block |
||
277 | 311 | // Merge to deal with fields not in import record |
278 | 312 | $_data = array_merge($old, $_data); |
279 | 313 | $changed = $this->tracking->changed_fields($_data, $old); |
280 | - if(count($changed) == 0) { |
|
314 | + if(count($changed) == 0) |
|
315 | + { |
|
281 | 316 | return true; |
282 | 317 | } |
283 | 318 | // Fall through |
284 | 319 | case 'insert' : |
285 | - if($_action == 'insert') { |
|
320 | + if($_action == 'insert') |
|
321 | + { |
|
286 | 322 | // Backend doesn't like inserting with ID specified, can overwrite existing |
287 | 323 | unset($_data['id']); |
288 | 324 | } |
289 | 325 | // Make sure participants are set |
290 | - if(!$_data['participants']) { |
|
326 | + if(!$_data['participants']) |
|
327 | + { |
|
291 | 328 | $user = $_data['owner'] ? $_data['owner'] : $this->user; |
292 | 329 | $_data['participants'] = array( |
293 | 330 | $user => 'U' |
294 | 331 | ); |
295 | 332 | } |
296 | - if ( $this->dry_run ) { |
|
333 | + if ( $this->dry_run ) |
|
334 | + { |
|
297 | 335 | //print_r($_data); |
298 | 336 | // User is interested in conflict checks, do so for dry run |
299 | 337 | // Otherwise, conflicts are just ignored and imported anyway |
@@ -309,7 +347,9 @@ discard block |
||
309 | 347 | } |
310 | 348 | $this->results[$_action]++; |
311 | 349 | return true; |
312 | - } else { |
|
350 | + } |
|
351 | + else |
|
352 | + { |
|
313 | 353 | $messages = null; |
314 | 354 | $result = $this->bo->update( $_data, |
315 | 355 | !$this->definition->plugin_options['skip_conflicts'], |
@@ -360,7 +400,8 @@ discard block |
||
360 | 400 | * |
361 | 401 | * @return string name |
362 | 402 | */ |
363 | - public static function get_name() { |
|
403 | + public static function get_name() |
|
404 | + { |
|
364 | 405 | return lang('Calendar CSV import'); |
365 | 406 | } |
366 | 407 | |
@@ -369,7 +410,8 @@ discard block |
||
369 | 410 | * |
370 | 411 | * @return string descriprion |
371 | 412 | */ |
372 | - public static function get_description() { |
|
413 | + public static function get_description() |
|
414 | + { |
|
373 | 415 | return lang("Imports events into your Calendar from a CSV File. CSV means 'Comma Seperated Values'. However in the options Tab you can also choose other seperators."); |
374 | 416 | } |
375 | 417 | |
@@ -378,7 +420,8 @@ discard block |
||
378 | 420 | * |
379 | 421 | * @return string suffix (comma seperated) |
380 | 422 | */ |
381 | - public static function get_filesuffix() { |
|
423 | + public static function get_filesuffix() |
|
424 | + { |
|
382 | 425 | return 'csv'; |
383 | 426 | } |
384 | 427 |
@@ -37,12 +37,15 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @param string $_identifier |
39 | 39 | */ |
40 | - public function __construct( $_identifier='' ){ |
|
40 | + public function __construct( $_identifier='' ) |
|
41 | + { |
|
41 | 42 | $this->identifier = $_identifier; |
42 | - if(!is_object($this->bo)) { |
|
43 | + if(!is_object($this->bo)) |
|
44 | + { |
|
43 | 45 | $this->bo = new calendar_bo(); |
44 | 46 | } |
45 | - if($this->identifier) { |
|
47 | + if($this->identifier) |
|
48 | + { |
|
46 | 49 | $this->record = $this->bo->read($this->identifier); |
47 | 50 | } |
48 | 51 | } |
@@ -52,7 +55,8 @@ discard block |
||
52 | 55 | * |
53 | 56 | * @param string $_attribute_name |
54 | 57 | */ |
55 | - public function __get($_attribute_name) { |
|
58 | + public function __get($_attribute_name) |
|
59 | + { |
|
56 | 60 | return $this->record[$_attribute_name]; |
57 | 61 | } |
58 | 62 | |
@@ -62,11 +66,13 @@ discard block |
||
62 | 66 | * @param string $_attribute_name |
63 | 67 | * @param data $data |
64 | 68 | */ |
65 | - public function __set($_attribute_name, $data) { |
|
69 | + public function __set($_attribute_name, $data) |
|
70 | + { |
|
66 | 71 | $this->record[$_attribute_name] = $data; |
67 | 72 | } |
68 | 73 | |
69 | - public function __unset($_attribute_name) { |
|
74 | + public function __unset($_attribute_name) |
|
75 | + { |
|
70 | 76 | unset($this->record[$_attribute_name]); |
71 | 77 | } |
72 | 78 | |
@@ -78,7 +84,8 @@ discard block |
||
78 | 84 | * |
79 | 85 | * @return array complete record as associative array |
80 | 86 | */ |
81 | - public function get_record_array() { |
|
87 | + public function get_record_array() |
|
88 | + { |
|
82 | 89 | return $this->record; |
83 | 90 | } |
84 | 91 | |
@@ -87,8 +94,10 @@ discard block |
||
87 | 94 | * |
88 | 95 | *@return string tiltle |
89 | 96 | */ |
90 | - public function get_title() { |
|
91 | - if (empty($this->record)) { |
|
97 | + public function get_title() |
|
98 | + { |
|
99 | + if (empty($this->record)) |
|
100 | + { |
|
92 | 101 | $this->get_record(); |
93 | 102 | } |
94 | 103 | return $this->record['title']; |
@@ -100,7 +109,8 @@ discard block |
||
100 | 109 | * @todo add some checks |
101 | 110 | * @return void |
102 | 111 | */ |
103 | - public function set_record(array $_record){ |
|
112 | + public function set_record(array $_record) |
|
113 | + { |
|
104 | 114 | $this->record = $_record; |
105 | 115 | } |
106 | 116 | |
@@ -109,7 +119,8 @@ discard block |
||
109 | 119 | * |
110 | 120 | * @return string identifier of current record |
111 | 121 | */ |
112 | - public function get_identifier() { |
|
122 | + public function get_identifier() |
|
123 | + { |
|
113 | 124 | return $this->identifier; |
114 | 125 | } |
115 | 126 | |
@@ -119,7 +130,8 @@ discard block |
||
119 | 130 | * |
120 | 131 | * @return string Full URL of an icon, or appname/icon_name |
121 | 132 | */ |
122 | - public function get_icon() { |
|
133 | + public function get_icon() |
|
134 | + { |
|
123 | 135 | return 'calendar/navbar'; |
124 | 136 | } |
125 | 137 | |
@@ -128,7 +140,8 @@ discard block |
||
128 | 140 | * |
129 | 141 | * @return string identifier |
130 | 142 | */ |
131 | - public function save ( $_dst_identifier ) { |
|
143 | + public function save ( $_dst_identifier ) |
|
144 | + { |
|
132 | 145 | // Not yet implemeted |
133 | 146 | $this->identifier = $_dst_identifier; |
134 | 147 | } |
@@ -139,7 +152,8 @@ discard block |
||
139 | 152 | * @param string $_dst_identifier |
140 | 153 | * @return string dst_identifier |
141 | 154 | */ |
142 | - public function copy ( $_dst_identifier ) { |
|
155 | + public function copy ( $_dst_identifier ) |
|
156 | + { |
|
143 | 157 | |
144 | 158 | } |
145 | 159 | |
@@ -150,7 +164,8 @@ discard block |
||
150 | 164 | * @param string $_dst_identifier |
151 | 165 | * @return string dst_identifier |
152 | 166 | */ |
153 | - public function move ( $_dst_identifier ) { |
|
167 | + public function move ( $_dst_identifier ) |
|
168 | + { |
|
154 | 169 | |
155 | 170 | } |
156 | 171 | |
@@ -158,7 +173,8 @@ discard block |
||
158 | 173 | * delets current record from backend |
159 | 174 | * |
160 | 175 | */ |
161 | - public function delete () { |
|
176 | + public function delete () |
|
177 | + { |
|
162 | 178 | |
163 | 179 | } |
164 | 180 | |
@@ -166,7 +182,8 @@ discard block |
||
166 | 182 | * destructor |
167 | 183 | * |
168 | 184 | */ |
169 | - public function __destruct() { |
|
185 | + public function __destruct() |
|
186 | + { |
|
170 | 187 | } |
171 | 188 | |
172 | 189 | } // end of calendar_egw_record |