| Conditions | 23 |
| Paths | 8640 |
| Total Lines | 96 |
| Code Lines | 65 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 552 |
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 |
||
| 50 | function process() { |
||
| 51 | global $current_user, $timedate, $app_list_strings, $current_language, $mod_strings; |
||
| 52 | $mod_strings = return_module_language($current_language, 'Calls'); |
||
| 53 | |||
| 54 | parent::process(); |
||
| 55 | |||
| 56 | $this->ss->assign("TIME_FORMAT", '('. $timedate->get_user_time_format().')'); |
||
| 57 | $this->ss->assign("USER_DATEFORMAT", '('. $timedate->get_user_date_format().')'); |
||
| 58 | $this->ss->assign("CALENDAR_DATEFORMAT", $timedate->get_cal_date_format()); |
||
| 59 | |||
| 60 | |||
| 61 | if($this->viaAJAX) { // override for ajax call |
||
| 62 | $this->ss->assign('saveOnclick', "onclick='if(check_form(\"callsQuickCreate\")) return SUGAR.subpanelUtils.inlineSave(this.form.id, \"activities\"); else return false;'"); |
||
| 63 | $this->ss->assign('cancelOnclick', "onclick='return SUGAR.subpanelUtils.cancelCreate(\"subpanel_activities\")';"); |
||
| 64 | } |
||
| 65 | |||
| 66 | $this->ss->assign('viaAJAX', $this->viaAJAX); |
||
| 67 | |||
| 68 | $this->javascript = new javascript(); |
||
| 69 | $this->javascript->setFormName('callsQuickCreate'); |
||
| 70 | |||
| 71 | $focus = new Call(); |
||
| 72 | $this->javascript->setSugarBean($focus); |
||
| 73 | $this->javascript->addAllFields(''); |
||
| 74 | |||
| 75 | if (is_null($focus->date_start)) |
||
| 76 | $focus->date_start = $timedate->nowDate(); |
||
| 77 | if (is_null($focus->time_start)) |
||
| 78 | $focus->time_start = $timedate->asUserTime($timedate->getNow(), true); |
||
| 79 | if (!isset ($focus->duration_hours)) |
||
| 80 | $focus->duration_hours = "1"; |
||
| 81 | |||
| 82 | $this->ss->assign("DATE_START", $focus->date_start); |
||
| 83 | $this->ss->assign("TIME_START", substr($focus->time_start,0,5)); |
||
| 84 | $time_start_hour = intval(substr($focus->time_start, 0, 2)); |
||
| 85 | $time_start_minutes = substr($focus->time_start, 3, 5); |
||
| 86 | |||
| 87 | if ($time_start_minutes > 0 && $time_start_minutes < 15) { |
||
| 88 | $time_start_minutes = "15"; |
||
| 89 | } else |
||
| 90 | if ($time_start_minutes > 15 && $time_start_minutes < 30) { |
||
| 91 | $time_start_minutes = "30"; |
||
| 92 | } else |
||
| 93 | if ($time_start_minutes > 30 && $time_start_minutes < 45) { |
||
| 94 | $time_start_minutes = "45"; |
||
| 95 | } else |
||
| 96 | if ($time_start_minutes > 45) { |
||
| 97 | $time_start_hour += 1; |
||
| 98 | $time_start_minutes = "00"; |
||
| 99 | } |
||
| 100 | |||
| 101 | |||
| 102 | // We default the to assume that the time preference is set to 11:00 (i.e. without meridiem) |
||
| 103 | $hours_arr = array (); |
||
| 104 | $num_of_hours = 24; |
||
| 105 | $start_at = 0; |
||
| 106 | |||
| 107 | $time_pref = $timedate->get_time_format(); |
||
| 108 | if(strpos($time_pref, 'a') || strpos($time_pref, 'A')) { |
||
| 109 | $num_of_hours = 13; |
||
| 110 | $start_at = 1; |
||
| 111 | |||
| 112 | // It's important to do this block first before we recalculate $time_start_hour |
||
| 113 | $options = strpos($time_pref, 'a') ? $app_list_strings['dom_meridiem_lowercase'] : $app_list_strings['dom_meridiem_uppercase']; |
||
| 114 | if(strpos($time_pref, 'a')) { |
||
| 115 | $this->ss->assign("TIME_MERIDIEM", get_select_options_with_id($options, strpos($focus->time_start,'a') ? 'am' : 'pm')); |
||
| 116 | } else { |
||
| 117 | $this->ss->assign("TIME_MERIDIEM", get_select_options_with_id($options, strpos($focus->time_start,'A') ? 'AM' : 'PM')); |
||
| 118 | } |
||
| 119 | |||
| 120 | // the $num_of_hours array is keyed by values 01, 02, ... 12 for meridiem times |
||
| 121 | $time_start_hour = $time_start_hour < 10 ? '0'.$time_start_hour : $time_start_hour; |
||
| 122 | } |
||
| 123 | |||
| 124 | for ($i = $start_at; $i < $num_of_hours; $i ++) { |
||
| 125 | $i = $i.""; |
||
| 126 | if (strlen($i) == 1) { |
||
| 127 | $i = "0".$i; |
||
| 128 | } |
||
| 129 | $hours_arr[$i] = $i; |
||
| 130 | } |
||
| 131 | |||
| 132 | $this->ss->assign("TIME_START_HOUR_OPTIONS", get_select_options_with_id($hours_arr, $time_start_hour)); |
||
| 133 | $this->ss->assign("TIME_START_MINUTE_OPTIONS", get_select_options_with_id($focus->minutes_values, $time_start_minutes)); |
||
| 134 | |||
| 135 | $this->ss->assign("DURATION_HOURS", $focus->duration_hours); |
||
| 136 | $this->ss->assign("DURATION_MINUTES_OPTIONS", get_select_options_with_id($focus->minutes_values, $focus->duration_minutes)); |
||
| 137 | |||
| 138 | $focus->direction = (isset ($app_list_strings['call_direction_dom']['Outbound']) ? 'Outbound' : $focus->direction); |
||
| 139 | $focus->status = (isset ($app_list_strings['call_status_dom']['Planned']) ? 'Outbound' : $focus->status); |
||
| 140 | |||
| 141 | $this->ss->assign("DIRECTION_OPTIONS", get_select_options_with_id($app_list_strings['call_direction_dom'], $focus->direction)); |
||
| 142 | $this->ss->assign("STATUS_OPTIONS", get_select_options_with_id($app_list_strings['call_status_dom'], $focus->status)); |
||
| 143 | |||
| 144 | $this->ss->assign('additionalScripts', $this->javascript->getScript(false)); |
||
| 145 | } |
||
| 146 | } |
||
| 147 | ?> |