| Conditions | 20 |
| Paths | 556 |
| Total Lines | 189 |
| Code Lines | 104 |
| 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 |
||
| 29 | function open($store, $entryid, $action) |
||
| 30 | { |
||
| 31 | if($entryid) { |
||
| 32 | $data = array(); |
||
| 33 | |||
| 34 | try { |
||
| 35 | $abentry = mapi_ab_openentry($GLOBALS["mapisession"]->getAddressbook(false, true), $entryid); |
||
| 36 | } catch (MAPIException $e) { |
||
| 37 | // If the item not found in addressbook, it might be possible that |
||
| 38 | // this particular item was added by setup-contact-provider mechanism. |
||
| 39 | // Let us try to get that particular contact item in respective user store. |
||
| 40 | // @Fixme: After implementation of KC-350 this extra handling can be removed. |
||
| 41 | if ($e->getCode() == MAPI_E_NOT_FOUND || $e->getCode() == MAPI_E_INVALID_PARAMETER) { |
||
| 42 | $hexEntryid = bin2hex($entryid); |
||
| 43 | // Remove Address-Book-Provider prefix from the entryid |
||
| 44 | $externalEntryid = $GLOBALS["entryid"]->unwrapABEntryIdObj($hexEntryid); |
||
| 45 | // Check if it's a contact from the user's contacts folder |
||
| 46 | $contactItem = $GLOBALS['operations']->openMessage($GLOBALS['mapisession']->getDefaultMessageStore(), hex2bin($externalEntryid)); |
||
| 47 | |||
| 48 | if ($contactItem === false) { |
||
| 49 | // Retrieve user store entryid to which this external item belongs |
||
| 50 | $userStore = $GLOBALS['operations']->getOtherStoreFromEntryid($externalEntryid); |
||
| 51 | |||
| 52 | // If userStore not found it means user is not exists in address book |
||
| 53 | if($userStore === false) { |
||
| 54 | $msg = "The contact \"%s\" could not be displayed because it could not be retrieved or has been deleted"; |
||
| 55 | |||
| 56 | error_log(sprintf($msg, $action["message_action"]["username"])); |
||
| 57 | |||
| 58 | $e->setTitle(_('Contact not found')); |
||
| 59 | $e->setDisplayMessage(_("Contact information could not be displayed because the server had trouble retrieving the information.") . |
||
| 60 | _("Please contact your system administrator if the problem persists.")); |
||
| 61 | throw $e; |
||
| 62 | return false; |
||
| 63 | } |
||
| 64 | |||
| 65 | $e->setHandled(); |
||
| 66 | $contactItem = $GLOBALS['operations']->openMessage($userStore, hex2bin($externalEntryid)); |
||
| 67 | } |
||
| 68 | |||
| 69 | |||
| 70 | if ($contactItem != false) { |
||
| 71 | // Get necessary property from respective contact item |
||
| 72 | $contactItemProps = mapi_getprops($contactItem, Array(PR_GIVEN_NAME, PR_DISPLAY_NAME, PR_TITLE, PR_COMPANY_NAME)); |
||
| 73 | |||
| 74 | // Use the data retrieved from contact item to prepare response |
||
| 75 | // as similar as it seems like an addressbook item. |
||
| 76 | $data['props'] = array ( |
||
| 77 | 'object_type' => MAPI_MAILUSER, |
||
| 78 | 'given_name' => $contactItemProps[PR_GIVEN_NAME], |
||
| 79 | 'display_name' => $contactItemProps[PR_DISPLAY_NAME], |
||
| 80 | 'title' => $contactItemProps[PR_TITLE], |
||
| 81 | 'company_name' => $contactItemProps[PR_COMPANY_NAME] |
||
| 82 | ); |
||
| 83 | $data['entryid'] = $hexEntryid; |
||
| 84 | |||
| 85 | $this->addActionData("item", $data); |
||
| 86 | $GLOBALS["bus"]->addData($this->getResponseData()); |
||
| 87 | return; |
||
| 88 | } |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | if(mapi_last_hresult() == NOERROR && $abentry){ |
||
| 93 | $objecttypeprop = mapi_getprops($abentry, Array(PR_OBJECT_TYPE)); |
||
| 94 | |||
| 95 | if(isset($objecttypeprop[PR_OBJECT_TYPE])){ |
||
| 96 | // Get the properties for a MAILUSER object and process those MAILUSER specific props that require some more actions |
||
| 97 | if($objecttypeprop[PR_OBJECT_TYPE] == MAPI_MAILUSER){ |
||
| 98 | $messageprops = mapi_getprops($abentry, $this->userDetailProperties); |
||
| 99 | |||
| 100 | $props = Conversion::mapMAPI2XML($this->userDetailProperties, $messageprops); |
||
| 101 | |||
| 102 | if(isset($messageprops[PR_EMS_AB_THUMBNAIL_PHOTO])){ |
||
| 103 | $props['props']['ems_ab_thumbnail_photo'] = $GLOBALS['operations']->compressedImage($messageprops[PR_EMS_AB_THUMBNAIL_PHOTO]); |
||
| 104 | } |
||
| 105 | |||
| 106 | // Get the properties of the manager |
||
| 107 | $managerProps = $this->getManagerDetails($messageprops); |
||
| 108 | if($managerProps!==false){ |
||
| 109 | $props['ems_ab_manager'] = array( |
||
| 110 | 'item' => $managerProps |
||
| 111 | ); |
||
| 112 | } |
||
| 113 | |||
| 114 | $homePhoneNumbers = $this->getHomePhoneNumbers($messageprops); |
||
| 115 | if (!empty($homePhoneNumbers)){ |
||
| 116 | // Add the list of home2_telephone_number_mv in the correct format to $props list to be send to the client |
||
| 117 | $props['home2_telephone_numbers'] = array( |
||
| 118 | 'item' => $homePhoneNumbers |
||
| 119 | ); |
||
| 120 | } |
||
| 121 | |||
| 122 | $businessPhoneNumbers = $this->getBusinessPhoneNumbers($messageprops); |
||
| 123 | if (!empty($businessPhoneNumbers)){ |
||
| 124 | // Add the list of business2_telephone_number_mv in the correct format to $props list to be send to the client |
||
| 125 | $props['business2_telephone_numbers'] = array( |
||
| 126 | 'item' => $businessPhoneNumbers |
||
| 127 | ); |
||
| 128 | } |
||
| 129 | |||
| 130 | // Get the properties of the "direct reports" |
||
| 131 | $directReportsList = $this->getDirectReportsDetails($messageprops); |
||
| 132 | if(!empty($directReportsList)){ |
||
| 133 | // Add the list of proxy_addresses in the correct format to the $props list to be send to the client. |
||
| 134 | $props['ems_ab_reports'] = array( |
||
| 135 | 'item' => $directReportsList |
||
| 136 | ); |
||
| 137 | } |
||
| 138 | |||
| 139 | // Get the properties for a DISTLIST object and process those DISTLIST specific props that require some more actions |
||
| 140 | } else { |
||
| 141 | $messageprops = mapi_getprops($abentry, $this->groupDetailProperties); |
||
| 142 | $props = Conversion::mapMAPI2XML($this->groupDetailProperties, $messageprops); |
||
| 143 | |||
| 144 | // Get the properties of the owner |
||
| 145 | $ownerProps = $this->getOwnerDetails($messageprops); |
||
| 146 | if($ownerProps!==false){ |
||
| 147 | // We can use the same properties as we use for the manager in a MAILUSER |
||
| 148 | $props['ems_ab_owner'] = array( |
||
| 149 | 'item' => $ownerProps |
||
| 150 | ); |
||
| 151 | } |
||
| 152 | |||
| 153 | // Get the list of members for this DISTLSIT |
||
| 154 | $props['members'] = array( |
||
| 155 | 'item' => $this->getMembersDetails($abentry) |
||
| 156 | ); |
||
| 157 | } |
||
| 158 | |||
| 159 | // Get the proxy addresses list, this property exists in both MAILUSER and DISTLIST |
||
| 160 | $proxyAddresses = $this->getProxyAddressesDetails($messageprops); |
||
| 161 | // Remove the MV-flagged property |
||
| 162 | if(!empty($proxyAddresses)){ |
||
| 163 | // Add the list of proxy_addresses in the correct format to the $props list to be send to the client. |
||
| 164 | $props['ems_ab_proxy_addresses'] = array( |
||
| 165 | 'item' => $proxyAddresses |
||
| 166 | ); |
||
| 167 | } |
||
| 168 | |||
| 169 | // Get the properties of the group membership, this property exists in both MAILUSER and DISTLIST |
||
| 170 | $memberOfList = $this->getMemberOfDetails($messageprops); |
||
| 171 | if(!empty($memberOfList)){ |
||
| 172 | // Add the list of proxy_addresses in the correct format to the $props list to be send to the client. |
||
| 173 | $props['ems_ab_is_member_of_dl'] = array( |
||
| 174 | 'item' => $memberOfList |
||
| 175 | ); |
||
| 176 | } |
||
| 177 | |||
| 178 | // Remove the MV-flagged properties and also its single valued counterpart |
||
| 179 | unset($props['props']['ems_ab_is_member_of_dl']); |
||
| 180 | unset($props['props']['business2_telephone_number_mv']); |
||
| 181 | unset($props['props']['business2_telephone_number']); |
||
| 182 | unset($props['props']['home2_telephone_number_mv']); |
||
| 183 | unset($props['props']['home2_telephone_number']); |
||
| 184 | unset($props['props']['ems_ab_proxy_addresses_mv']); |
||
| 185 | unset($props['props']['ems_ab_proxy_addresses']); |
||
| 186 | unset($props['props']['ems_ab_reports_mv']); |
||
| 187 | unset($props['props']['ems_ab_reports']); |
||
| 188 | unset($props['props']['ems_ab_owner']); |
||
| 189 | unset($props['props']['ems_ab_manager']); |
||
| 190 | |||
| 191 | // Allowing to hook in and add more properties |
||
| 192 | $GLOBALS['PluginManager']->triggerHook("server.module.addressbookitemmodule.open.props", array( |
||
| 193 | 'moduleObject' =>& $this, |
||
| 194 | 'abentry' => $abentry, |
||
| 195 | 'object_type' => $objecttypeprop[PR_OBJECT_TYPE], |
||
| 196 | 'messageprops' => $messageprops, |
||
| 197 | 'props' =>& $props |
||
| 198 | )); |
||
| 199 | |||
| 200 | $data["item"] = $props; |
||
| 201 | $this->addActionData("item", $data); |
||
| 202 | } else { |
||
| 203 | // Handling error: not able to handle this type of object |
||
| 204 | $data["error"] = array(); |
||
| 205 | $data["error"]["message"] = _("Could not handle this type of object."); |
||
| 206 | $this->addActionData("error", $data); |
||
| 207 | } |
||
| 208 | } else { |
||
| 209 | // Handle not being able to open the object |
||
| 210 | $data["error"] = array(); |
||
| 211 | $data["error"]["hresult"] = mapi_last_hresult(); |
||
| 212 | $data["error"]["hresult_name"] = get_mapi_error_name(mapi_last_hresult()); |
||
| 213 | $data["error"]["message"] = _("Could not open this object."); |
||
| 214 | $this->addActionData("error", $data); |
||
| 215 | } |
||
| 216 | |||
| 217 | $GLOBALS["bus"]->addData($this->getResponseData()); |
||
| 218 | } |
||
| 429 |