| Conditions | 11 |
| Paths | 48 |
| Total Lines | 90 |
| Code Lines | 55 |
| 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 |
||
| 26 | public function execute() |
||
| 27 | { |
||
| 28 | global $sourcedir, $smcFunc, $user_profile; |
||
| 29 | |||
| 30 | // Get everyone who could be notified - those are the people who can see the calendar. |
||
| 31 | require_once($sourcedir . '/Subs-Members.php'); |
||
| 32 | $members = membersAllowedTo('calendar_view'); |
||
| 33 | |||
| 34 | // Don't alert the event creator |
||
| 35 | if (!empty($this->_details['sender_id'])) |
||
| 36 | $members = array_diff($members, array($this->_details['sender_id'])); |
||
| 37 | |||
| 38 | // Having successfully figured this out, now let's get the preferences of everyone. |
||
| 39 | require_once($sourcedir . '/Subs-Notify.php'); |
||
| 40 | $prefs = getNotifyPrefs($members, 'event_new', true); |
||
| 41 | |||
| 42 | // Just before we go any further, we may not have the sender's name. Let's just quickly fix that. |
||
| 43 | // If a guest creates the event, we wouldn't be capturing a username or anything. |
||
| 44 | if (!empty($this->_details['sender_id']) && empty($this->_details['sender_name'])) |
||
| 45 | { |
||
| 46 | loadMemberData($this->_details['sender_id'], 'minimal'); |
||
|
|
|||
| 47 | if (!empty($user_profile[$this->_details['sender_id']])) |
||
| 48 | $this->_details['sender_name'] = $user_profile[$this->_details['sender_id']]['real_name']; |
||
| 49 | else |
||
| 50 | $this->_details['sender_id'] = 0; |
||
| 51 | } |
||
| 52 | |||
| 53 | // So now we find out who wants what. |
||
| 54 | $alert_bits = array( |
||
| 55 | 'alert' => self::RECEIVE_NOTIFY_ALERT, |
||
| 56 | 'email' => self::RECEIVE_NOTIFY_EMAIL, |
||
| 57 | ); |
||
| 58 | $notifies = array(); |
||
| 59 | |||
| 60 | foreach ($prefs as $member => $pref_option) |
||
| 61 | { |
||
| 62 | foreach ($alert_bits as $type => $bitvalue) |
||
| 63 | if ($pref_option['event_new'] & $bitvalue) |
||
| 64 | $notifies[$type][] = $member; |
||
| 65 | } |
||
| 66 | |||
| 67 | // Firstly, anyone who wants alerts. |
||
| 68 | if (!empty($notifies['alert'])) |
||
| 69 | { |
||
| 70 | // Alerts are relatively easy. |
||
| 71 | $insert_rows = array(); |
||
| 72 | foreach ($notifies['alert'] as $member) |
||
| 73 | { |
||
| 74 | $insert_rows[] = array( |
||
| 75 | 'alert_time' => $this->_details['time'], |
||
| 76 | 'id_member' => $member, |
||
| 77 | 'id_member_started' => $this->_details['sender_id'], |
||
| 78 | 'member_name' => $this->_details['sender_name'], |
||
| 79 | 'content_type' => 'event', |
||
| 80 | 'content_id' => $this->_details['event_id'], |
||
| 81 | 'content_action' => empty($this->_details['sender_id']) ? 'new_guest' : 'new', |
||
| 82 | 'is_read' => 0, |
||
| 83 | 'extra' => $smcFunc['json_encode']( |
||
| 84 | array( |
||
| 85 | 'content_link' => '{SCRIPTURL}?action=calendar;event={CONTENT_ID}', |
||
| 86 | "event_id" => $this->_details['event_id'], |
||
| 87 | "event_title" => $this->_details['event_title'], |
||
| 88 | ) |
||
| 89 | ), |
||
| 90 | ); |
||
| 91 | } |
||
| 92 | |||
| 93 | $smcFunc['db_insert']( |
||
| 94 | 'insert', |
||
| 95 | '{db_prefix}user_alerts', |
||
| 96 | array( |
||
| 97 | 'alert_time' => 'int', |
||
| 98 | 'id_member' => 'int', |
||
| 99 | 'id_member_started' => 'int', |
||
| 100 | 'member_name' => 'string', |
||
| 101 | 'content_type' => 'string', |
||
| 102 | 'content_id' => 'int', |
||
| 103 | 'content_action' => 'string', |
||
| 104 | 'is_read' => 'int', |
||
| 105 | 'extra' => 'string', |
||
| 106 | ), |
||
| 107 | $insert_rows, |
||
| 108 | array('id_alert') |
||
| 109 | ); |
||
| 110 | |||
| 111 | // And update the count of alerts for those people. |
||
| 112 | updateMemberData($notifies['alert'], array('alerts' => '+')); |
||
| 113 | } |
||
| 114 | |||
| 115 | return true; |
||
| 116 | } |
||
| 119 | ?> |