Conditions | 18 |
Paths | 252 |
Total Lines | 101 |
Code Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 2 |
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 |
||
33 | public function beforeSendToClient($cname, array $expand=null) |
||
34 | { |
||
35 | |||
36 | Framework::includeJS('.','et2_widget_owner','calendar'); |
||
37 | Framework::includeCSS('calendar','calendar'); |
||
38 | |||
39 | $bo = new calendar_bo(); |
||
40 | |||
41 | $form_name = self::form_name($cname, $this->id, $expand); |
||
42 | |||
43 | $value =& self::get_array(self::$request->content, $form_name); |
||
44 | |||
45 | if (!is_array(self::$request->sel_options[$form_name])) |
||
46 | { |
||
47 | self::$request->sel_options[$form_name] = array(); |
||
48 | } |
||
49 | $sel_options =& self::$request->sel_options[$form_name]; |
||
50 | |||
51 | // Get user accounts, formatted nicely for grouping and matching |
||
52 | // the ajax call calendar_uiforms->ajax_owner() - users first |
||
53 | $accounts = array(); |
||
54 | $list = array('accounts', 'owngroups'); |
||
55 | foreach($list as $type) |
||
56 | { |
||
57 | $account_options = array('account_type' => $type); |
||
58 | $accounts_type = Api\Accounts::link_query('',$account_options); |
||
59 | if($type == 'accounts') |
||
60 | { |
||
61 | $accounts_type = array_intersect_key($accounts_type, $GLOBALS['egw']->acl->get_grants('calendar')); |
||
62 | } |
||
63 | $accounts += $accounts_type; |
||
64 | } |
||
65 | $sel_options += array_map( |
||
66 | function($account_id, $account_name) |
||
67 | { |
||
68 | $data = array( |
||
69 | 'value' => ''.$account_id, |
||
70 | 'label' => $account_name, |
||
71 | 'app' => lang('api-accounts'), |
||
72 | ); |
||
73 | if ($account_id > 0) |
||
74 | { |
||
75 | $contact_obj = new Api\Contacts(); |
||
76 | if (($contact = $contact_obj->read('account:'.$account_id, true))) |
||
77 | { |
||
78 | $data['icon'] = Api\Framework::link('/api/avatar.php', array( |
||
79 | 'contact_id' => $contact['id'], |
||
80 | 'etag' => $contact['etag'] ? $contact['etag'] : 1 |
||
81 | )); |
||
82 | } |
||
83 | } |
||
84 | else |
||
85 | { |
||
86 | // Add in group memberships as strings |
||
87 | $data['resources'] = array_map(function($a) { return ''.$a;},$GLOBALS['egw']->accounts->members($account_id, true)); |
||
88 | } |
||
89 | return $data; |
||
90 | }, |
||
91 | array_keys($accounts), $accounts |
||
92 | ); |
||
93 | |||
94 | if(!is_array($value)) |
||
95 | { |
||
96 | // set value with an empty string only if sel options are not |
||
97 | // loaded, for example: setting calendar owner via URL when |
||
98 | // calendar app is not yet loaded. |
||
99 | $value = !empty($sel_options) ? array(): explode(',', $value); |
||
100 | } |
||
101 | |||
102 | // Add external owners that a select account widget will not find |
||
103 | foreach($value as &$owner) |
||
104 | { |
||
105 | $label = self::get_owner_label($owner); |
||
106 | $info = array(); |
||
107 | if(!is_numeric($owner)) |
||
108 | { |
||
109 | $resource = $bo->resources[substr($owner, 0,1)]; |
||
110 | if($resource['info'] && !($info = $bo->resource_info($owner))) |
||
111 | { |
||
112 | continue; // ignore that resource, we would get a PHP Fatal: Unsupported operand types |
||
113 | } |
||
114 | } |
||
115 | else if (!in_array($owner, array_keys($accounts))) |
||
116 | { |
||
117 | $resource = array('app'=> 'api-accounts'); |
||
118 | } |
||
119 | if ($resource && is_numeric ($owner) && (int)$owner < 0) |
||
|
|||
120 | { |
||
121 | // Add in group memberships as strings |
||
122 | $info['resources'] = array_map(function($a) { return ''.$a;},$GLOBALS['egw']->accounts->members($owner, true)); |
||
123 | } |
||
124 | |||
125 | $option = array('value' => $owner, 'label' => $label, 'app' => lang($resource['app'])) + $info; |
||
126 | $sel_option_index = $this->get_index($sel_options, 'value', $owner); |
||
127 | if($sel_option_index === false) |
||
128 | { |
||
129 | $sel_options[] = $option; |
||
130 | } |
||
131 | else |
||
132 | { |
||
133 | $sel_options[$sel_option_index] = array_merge($sel_options[$sel_option_index], $option); |
||
134 | } |
||
342 | } |