Conditions | 23 |
Paths | 5616 |
Total Lines | 110 |
Code Lines | 59 |
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 |
||
94 | function get_user_interface() |
||
95 | { |
||
96 | $cats = new Api\Categories('','calendar'); |
||
97 | foreach($cats->return_array('all',0,False,'','cat_name','',True) as $cat) |
||
98 | { |
||
99 | $this->arguments['cat_id']['options'][$cat['id']] = str_repeat(' ',$cat['level']).$cat['name']; |
||
100 | } |
||
101 | if (count($this->arguments['cat_id']['options']) > 5) |
||
102 | { |
||
103 | $this->arguments['cat_id']['multiple'] = 5; |
||
104 | } |
||
105 | |||
106 | if (!isset($GLOBALS['egw']->accounts)) |
||
107 | { |
||
108 | $GLOBALS['egw']->accounts = new Api\Accounts(); |
||
109 | } |
||
110 | $this->accounts =& $GLOBALS['egw']->accounts; |
||
111 | $search_params = array( |
||
112 | 'type' => 'both', |
||
113 | 'app' => 'calendar', |
||
114 | ); |
||
115 | $accounts = $this->accounts->search($search_params); |
||
116 | $calendar_bo = new calendar_bo(); |
||
117 | $users = array(); |
||
118 | $groups = array(); |
||
119 | // sort users and groups separately. |
||
120 | $anon_user = $this->accounts->name2id($GLOBALS['Common_BO']->sites->current_site['anonymous_user'],'account_lid','u'); |
||
121 | $anon_groups = $this->accounts->memberships($anon_user,true); |
||
122 | foreach ($accounts as $entry) |
||
123 | { |
||
124 | $is_group = false; |
||
125 | $has_read_permissions = false; |
||
126 | $acl = new Acl($entry['account_id']); |
||
127 | $acl->read_repository(); |
||
128 | // get the rights for each account to check whether the anon user has read permissions. |
||
129 | $rights = $acl->get_rights($anon_user,'calendar'); |
||
130 | // also add the anon user if it's his own calendar. |
||
131 | if ($calendar_bo->check_perms(Acl::READ|calendar_bo::ACL_READ_FOR_PARTICIPANTS|calendar_bo::ACL_FREEBUSY,0,$entry['account_id'],'ts',null,$anon_user) || ($entry['account_id'] == $anon_user)) |
||
132 | { |
||
133 | $has_read_permissions = true; |
||
134 | } |
||
135 | else |
||
136 | { |
||
137 | // scan the groups which pass on permissions to the anon user group member |
||
138 | // or ass permissions if this is the anon group's calendar. |
||
139 | foreach ($anon_groups as $parent_group) |
||
140 | { |
||
141 | $rights = $acl->get_rights($parent_group,'calendar'); |
||
142 | if (($rights & Acl::READ) || ($entry['account_id'] == $parent_group)) |
||
143 | { |
||
144 | $has_read_permissions = true; |
||
145 | break; |
||
146 | } |
||
147 | } |
||
148 | } |
||
149 | if ($has_read_permissions) |
||
150 | { |
||
151 | // Separate groups from users for improved readability. |
||
152 | if ($is_group) |
||
153 | { |
||
154 | $groups[$entry['account_id']] = $entry['account_lid']; |
||
155 | } |
||
156 | else |
||
157 | { |
||
158 | $users[$entry['account_id']] = Api\Accounts::format_username($entry['account_lid'],$entry['account_firstname'],$entry['account_lastname']); |
||
159 | } |
||
160 | } |
||
161 | } |
||
162 | asort($groups); |
||
163 | asort($users); |
||
164 | // concat users and groups to the option array. |
||
165 | $this->arguments['owner']['options'] = array_unique($groups + $users); |
||
166 | if (count($this->arguments['owner']['options']) > 10) |
||
167 | { |
||
168 | $this->arguments['owner']['multiple'] = 10; |
||
169 | } |
||
170 | else if (count($this->arguments['owner']['options']) > 0) |
||
171 | { |
||
172 | $this->arguments['owner']['multiple'] = true; |
||
173 | } |
||
174 | |||
175 | $query = ''; |
||
176 | $options = array('start' => 0); |
||
177 | |||
178 | $acl = new Acl($anon_user); |
||
179 | $acl->read_repository(); |
||
180 | foreach ($calendar_bo->resources as $type => $data) |
||
181 | { |
||
182 | // Check anon user's permissions - must have at least run for the hook to be available |
||
183 | if($acl->check('run',EGW_ACL_READ, $data['app']) && |
||
184 | $type != '' && $data['app'] && Link::get_registry($data['app'], 'query') |
||
185 | ) |
||
186 | { |
||
187 | $_results = Link::query($data['app'], $query,$options); |
||
188 | } |
||
189 | if(!$_results) continue; |
||
190 | $_results = array_unique($_results); |
||
191 | foreach ($_results as $key => $value) |
||
192 | { |
||
193 | if($calendar_bo->check_perms(Acl::READ,0,$type.$key,'ts',null,$anon_user)) |
||
194 | { |
||
195 | $this->arguments['resources']['options'][$type.$key] = $value; |
||
196 | } |
||
197 | } |
||
198 | } |
||
199 | $this->arguments['resources']['options'] = array_unique($this->arguments['resources']['options']); |
||
200 | $this->arguments['resources']['multiple'] = count($this->arguments['resources']['options']) ? 4 : 0; |
||
201 | |||
202 | |||
203 | return parent::get_user_interface(); |
||
204 | } |
||
361 |