| Total Complexity | 83 |
| Total Lines | 412 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like AdvancedSearchListModule often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AdvancedSearchListModule, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 4 | class AdvancedSearchListModule extends ListModule |
||
| 5 | { |
||
| 6 | /** |
||
| 7 | * Constructor |
||
| 8 | * @param int $id unique id. |
||
| 9 | * @param array $data list of all actions. |
||
| 10 | */ |
||
| 11 | function __construct($id, $data) |
||
| 12 | { |
||
| 13 | parent::__construct($id, $data); |
||
| 14 | // TODO: create a new method in Properties class that will return only the properties we |
||
| 15 | // need for search list (and perhaps for preview???) |
||
| 16 | $this->properties = $GLOBALS["properties"]->getMailListProperties(); |
||
| 17 | $this->properties = array_merge($this->properties, $GLOBALS["properties"]->getAppointmentListProperties()); |
||
| 18 | $this->properties = array_merge($this->properties, $GLOBALS["properties"]->getContactListProperties()); |
||
| 19 | $this->properties = array_merge($this->properties, $GLOBALS["properties"]->getStickyNoteListProperties()); |
||
| 20 | $this->properties = array_merge($this->properties, $GLOBALS["properties"]->getTaskListProperties()); |
||
| 21 | $this->properties = array_merge($this->properties, array( |
||
| 22 | 'body' => PR_BODY, |
||
| 23 | 'html_body' => PR_HTML, |
||
| 24 | 'startdate' => "PT_SYSTIME:PSETID_Appointment:0x820d", |
||
| 25 | 'duedate' => "PT_SYSTIME:PSETID_Appointment:0x820e", |
||
| 26 | 'creation_time' => PR_CREATION_TIME, |
||
| 27 | "task_duedate" => "PT_SYSTIME:PSETID_Task:0x8105")); |
||
| 28 | $this->properties = getPropIdsFromStrings($GLOBALS["mapisession"]->getDefaultMessageStore(), $this->properties); |
||
| 29 | |||
| 30 | |||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Executes all the actions in the $data variable. |
||
| 35 | * @return boolean true on success or false on failure. |
||
| 36 | */ |
||
| 37 | function execute() |
||
| 38 | { |
||
| 39 | foreach($this->data as $actionType => $action) |
||
| 40 | { |
||
| 41 | if(isset($actionType)) { |
||
| 42 | try { |
||
| 43 | $store = $this->getActionStore($action); |
||
| 44 | $parententryid = $this->getActionParentEntryID($action); |
||
|
|
|||
| 45 | $entryid = $this->getActionEntryID($action); |
||
| 46 | |||
| 47 | switch($actionType) |
||
| 48 | { |
||
| 49 | case "list": |
||
| 50 | case "updatelist": |
||
| 51 | $this->getDelegateFolderInfo($store); |
||
| 52 | $this->messageList($store, $entryid, $action, $actionType); |
||
| 53 | break; |
||
| 54 | case "search": |
||
| 55 | $this->search($store, $entryid, $action, $actionType); |
||
| 56 | break; |
||
| 57 | case "updatesearch": |
||
| 58 | $this->updatesearch($store, $entryid, $action); |
||
| 59 | break; |
||
| 60 | case "stopsearch": |
||
| 61 | $this->stopSearch($store, $entryid, $action); |
||
| 62 | break; |
||
| 63 | case "delete_searchfolder": |
||
| 64 | $this->deleteSearchFolder($store, $entryid, $action); |
||
| 65 | break; |
||
| 66 | } |
||
| 67 | } catch (MAPIException $e) { |
||
| 68 | // This is a very nasty hack that makes sure that grommunio Web doesn't show an error message when |
||
| 69 | // search wants to throw an error. This is only done because a proper fix for this bug has not |
||
| 70 | // been found yet. When WA-9161 is really solved, this should be removed again. |
||
| 71 | if ( $actionType !== 'search' && $actionType !== 'updatesearch' && $actionType !== 'stopsearch' ){ |
||
| 72 | $this->processException($e, $actionType); |
||
| 73 | } else { |
||
| 74 | if ( DEBUG_LOADER === 'LOAD_SOURCE' ){ |
||
| 75 | // Log all info we can get about this error to the error log of the web server |
||
| 76 | error_log("Error in search: \n" . var_export($e, true) . "\n\n" . var_export(debug_backtrace(), true)); |
||
| 77 | } |
||
| 78 | // Send success feedback without data, as if nothing strange happened... |
||
| 79 | $this->sendFeedback(true); |
||
| 80 | } |
||
| 81 | } |
||
| 82 | } |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Function which retrieves a list of messages in a folder |
||
| 88 | * @param object $store MAPI Message Store Object |
||
| 89 | * @param string $entryid entryid of the folder |
||
| 90 | * @param array $action the action data, sent by the client |
||
| 91 | * @param string $actionType the action type, sent by the client |
||
| 92 | * @return boolean true on success or false on failure |
||
| 93 | */ |
||
| 94 | function messageList($store, $entryid, $action, $actionType) |
||
| 95 | { |
||
| 96 | $this->searchFolderList = false; // Set to indicate this is not the search result, but a normal folder content |
||
| 97 | |||
| 98 | if($store && $entryid) { |
||
| 99 | // Restriction |
||
| 100 | $this->parseRestriction($action); |
||
| 101 | |||
| 102 | // Sort |
||
| 103 | $this->parseSortOrder($action, null, true); |
||
| 104 | |||
| 105 | $limit = false; |
||
| 106 | if(isset($action['restriction']['limit'])){ |
||
| 107 | $limit = $action['restriction']['limit']; |
||
| 108 | } |
||
| 109 | |||
| 110 | $isSearchFolder = isset($action['search_folder_entryid']); |
||
| 111 | $entryid = $isSearchFolder ? hex2bin($action['search_folder_entryid']) : $entryid; |
||
| 112 | |||
| 113 | // Get the table and merge the arrays |
||
| 114 | $data = $GLOBALS["operations"]->getTable($store, $entryid, $this->properties, $this->sort, $this->start, $limit, $this->restriction); |
||
| 115 | |||
| 116 | // If the request come from search folder then no need to send folder information |
||
| 117 | if (!$isSearchFolder) { |
||
| 118 | // Open the folder. |
||
| 119 | $folder = mapi_msgstore_openentry($store, $entryid); |
||
| 120 | $data["folder"] = array(); |
||
| 121 | |||
| 122 | // Obtain some statistics from the folder contents |
||
| 123 | $contentcount = mapi_getprops($folder, array(PR_CONTENT_COUNT, PR_CONTENT_UNREAD)); |
||
| 124 | if (isset($contentcount[PR_CONTENT_COUNT])) { |
||
| 125 | $data["folder"]["content_count"] = $contentcount[PR_CONTENT_COUNT]; |
||
| 126 | } |
||
| 127 | |||
| 128 | if (isset($contentcount[PR_CONTENT_UNREAD])) { |
||
| 129 | $data["folder"]["content_unread"] = $contentcount[PR_CONTENT_UNREAD]; |
||
| 130 | } |
||
| 131 | } |
||
| 132 | |||
| 133 | $data = $this->filterPrivateItems($data); |
||
| 134 | |||
| 135 | // Allowing to hook in just before the data sent away to be sent to the client |
||
| 136 | $GLOBALS['PluginManager']->triggerHook('server.module.listmodule.list.after', array( |
||
| 137 | 'moduleObject' =>& $this, |
||
| 138 | 'store' => $store, |
||
| 139 | 'entryid' => $entryid, |
||
| 140 | 'action' => $action, |
||
| 141 | 'data' =>& $data |
||
| 142 | )); |
||
| 143 | |||
| 144 | // unset will remove the value but will not regenerate array keys, so we need to |
||
| 145 | // do it here |
||
| 146 | $data["item"] = array_values($data["item"]); |
||
| 147 | $this->addActionData($actionType, $data); |
||
| 148 | $GLOBALS["bus"]->addData($this->getResponseData()); |
||
| 149 | } |
||
| 150 | } |
||
| 151 | |||
| 152 | private static function parsePatterns($restriction, &$patterns) { |
||
| 214 | } |
||
| 215 | } |
||
| 216 | } |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Function will set search restrictions on search folder and start search process |
||
| 220 | * and it will also parse visible columns and sorting data when sending results to client |
||
| 221 | * @param object $store MAPI Message Store Object |
||
| 222 | * @param hexString $entryid entryid of the folder |
||
| 223 | * @param object $action the action data, sent by the client |
||
| 224 | * @param string $actionType the action type, sent by the client |
||
| 225 | */ |
||
| 226 | function search($store, $entryid, $action, $actionType) |
||
| 416 | |||
| 417 | } |
||
| 418 | |||
| 421 |