Customize Calendar.php and CalendarDisplay.php

What is the best way to add customization to the two files Calendar.php and CalendarDisplay.php and keep it upgrade safe?

Is this even possible?

I never tried it with Calendar, but you might be able to achieve something with this technique (shown here for another module):

Watch out for some instances of hard-coded requires in the code, like this:

require_once 'modules/Calendar/Calendar.php';

the functionalities which depend on such commands will need some extra work in order to work (for example, the Calendars Dashlet).

Good luck, and if you get it done please come back here and let us know the details!

Let me see if I can recall all that I did.

  1. I created the drop downs that I needed for my custom fields in Cases.

  2. Added my custom fields to Cases and positioned on the Edit panel.

  3. I modified include/utils/activity_utils.php
    This was erroring out on those tables that do not have some of the custom fields.
    Looks to me that this should be a bug fix.

    Changed

       $select = "SELECT {$bean->table_name}.* from {$bean->rel_users_table},{$bean->table_name} ";
    

    To

        if ($bean->db->tableExists($bean->get_custom_table_name())){
            $select = "SELECT {$bean->table_name}.*,{$bean->get_custom_table_name()}.* from {$bean->rel_users_table},{$bean->table_name},{$bean->get_custom_table_name()} ";
       } else {
           $select = "SELECT {$bean->table_name}.* from {$bean->rel_users_table},{$bean->table_name} ";
        }
    
  4. Copied modules/Calendar/index.php to custom/modules/Calendar/index.php

    Changed

       require_once('modules/Calendar/Calendar.php');
       require_once('modules/Calendar/CalendarDisplay.php');
    

    To

    require_once('custom/modules/Calendar/Calendar.php');
    require_once('custom/modules/Calendar/CalendarDisplay.php');
    

    Change Calendar to CustomCalendar

    $cal = new Calendar($_REQUEST['view'], array(), $views);
    

    To

    $cal = new CustomCalendar($_REQUEST['view'], array(), $views);
    
  5. Copied modules/Calendar/Calendar.php to custom/modules/Calendar/Calendar.php

    Changed Line 52

    class Calendar
    

    To

    class CustomCalendar extends Calendar
    

    Add new code to starting at line 326 just under:

    if (!isset($item['duration_minutes']) || empty($item['duration_minutes'])) {
         $item['duration_minutes'] = 0;
    }
    

    New Code

    /** Check for Cases related meeting and load up fields */
    if ($item['parent_type'] == "Cases") {
         $caseBean = BeanFactory::getBean('Cases', $item['parent_id']);
         $item['tag_c'] = $caseBean->tag_c;
         $item['event_type_c'] = $caseBean->event_type_c;
         $item['cancel_reason_c'] = $caseBean->cancel_reason_c;
         $item['schedule_service_c'] = $caseBean->schedule_service_c;
     }
    
  6. Copied modules/Calendar/CalendarDisplay.php to custom/Calendar/CalendarDisplay.php
    Add New code around line 254 which is just above

    return $activity
    
        /** Add Custom Colors */
        if (isset($GLOBALS['sugar_config']['CalendarColors']['tag'])){
            foreach ($GLOBALS['sugar_config']['CalendarColors']['tag'] as $tagkey => $tagArr) {
                foreach ($tagArr as $key => $value) {
                    $this->activity_colors['tag'][$tagkey] = $GLOBALS['sugar_config']['CalendarColors']['tag'][$tagkey];
                    $activity['tag'][$tagkey] = $GLOBALS['sugar_config']['CalendarColors']['tag'][$tagkey];
                }
            }            
        }
    
  7. Copied modules/Calendar/tpls/header.tpl and main.tpl to custom/modules/Calendar/tpls
    Note: I do not want custom setings so I am hiding the buttons that allow you to do that.
    Diff Changes for header.tpl

    7a. Changed

    <img border="0" src="{$cal_img}" alt="{$APP.LBL_ENTER_DATE}" id="goto_date_trigger" align="absmiddle">
    

    To

    <!-- img border="0" src="{$cal_img}" alt="{$APP.LBL_ENTER_DATE}" id="goto_date_trigger" align="absmiddle" -->
    

    Changed

     <input type="button" id="cal_settings" class="btn btn-info" onclick="CAL.toggle_settings()" value="{$MOD.LBL_SETTINGS}">
    

    To

    <!-- input type="button" id="cal_settings" class="btn btn-info" onclick="CAL.toggle_settings()" value="{$MOD.LBL_SETTINGS}" -->
    

    7b. Changes for main.tpl have to point Cal.js to the customize js file.
    Changed

    {sugar_getscript file="modules/Calendar/Cal.js"}
    

    To

    {sugar_getscript file="custom/modules/Calendar/Cal.js"}
    
  8. Copied modules/Calendar/Cal.js to custom/modules/Calendar/Cal.js
    Near the bottom of the file change:

      if (
      	 undefined !== global_colorList[element.module_name]) {
          valueToPush["backgroundColor"] = "#" + global_colorList[element.module_name].body;
          valueToPush["borderColor"] = "#" + global_colorList[element.module_name].border;
          valueToPush["textColor"] = "#" + global_colorList[element.module_name].text;
        }
    
        if ((element['duration_hours'] % 24 === 0) && (element['time_start'] == "12:00am" || element['time_start'] == "00:00")) {
          valueToPush['allDay'] = true;
        }
    
        users_activities.push(valueToPush);
    

    To

      if (
      	 undefined !== global_colorList[element.module_name]) {
          valueToPush["backgroundColor"] = "#" + global_colorList[element.module_name].body;
          valueToPush["borderColor"] = "#" + global_colorList[element.module_name].border;
          valueToPush["textColor"] = "#" + global_colorList[element.module_name].text;
        }
    
        /** Color Customization */
        if (
          undefined !== global_colorList["tag"][element.tag_c] && element.parent_type == "Cases" ) {
          valueToPush["backgroundColor"] = "#" + global_colorList["tag"][element.tag_c].body;
          valueToPush["borderColor"] = "#" + global_colorList["tag"][element.tag_c].border;
          valueToPush["textColor"] = "#" + global_colorList["tag"][element.tag_c].text;
        }
        /** End of Customization */
    
        if ((element['duration_hours'] % 24 === 0) && (element['time_start'] == "12:00am" || element['time_start'] == "00:00")) {
          valueToPush['allDay'] = true;
       }
    
       users_activities.push(valueToPush);
    
  9. In config_override.php I added my custom color schema
    Added

    /** Custom Calendar Colors using Tag*/
    $sugar_config[‘CalendarColors’][‘tag’][1][‘body’] = ‘E5E5E5’;
    $sugar_config[‘CalendarColors’][‘tag’][1][‘border’] = ‘000000’;
    $sugar_config[‘CalendarColors’][‘tag’][1][‘text’] = ‘000000’;

    $sugar_config[‘CalendarColors’][‘tag’][44][‘body’] = “f4a00e”;
    $sugar_config[‘CalendarColors’][‘tag’][44][‘border’] = ‘000000’;
    $sugar_config[‘CalendarColors’][‘tag’][44][‘text’] = ‘000000’;

    $sugar_config[‘CalendarColors’][‘tag’][7][‘body’] = “9900FF”;
    $sugar_config[‘CalendarColors’][‘tag’][7][‘border’] = ‘000000’;
    $sugar_config[‘CalendarColors’][‘tag’][7][‘text’] = ‘000000’;

    The [number] refers to the dropdown value in my case_tag_reason dropdown.
    This numeric values were imported from another system.

    $GLOBALS[‘app_list_strings’][‘case_tag_reason’]=array (
    46 => ‘DID NOT SELECT TAG’,
    44 => ‘Install - Wireless - BIZ’,
    43 => ‘Install - Wireless - RES’,
    19 => ‘Service Call - Router’,
    14 => ‘Install - Router Only’,
    5 => ‘Service Call - Misc’,
    1 => ‘Install - Misc’,
    6 => ‘Cancel - Misc’,
    8 => ‘Site Survey - Misc’,
    9 => ‘Move Service - Misc’,
    10 => ‘Upgrade’,
    27 => ‘Upgrade - Router’,
    7 => ‘Miscellaneous’,
    );

I hope I got all of the steps needed. I tried to keep track of my changes but you know how that can go.

1 Like

That looks great! Thanks for taking the trouble to share your solution.

A couple of suggestions:

The best way to put code on these forums is to include it in a triple-backtick block, like this:

```
code
```

That way you get a nice syntax highlighting.

For the requires, I suggest making the change like this, it has the same effect as your code but it is the typical way it’s done in SuiteCRM codebase, for flexibility:

require_once get_custom_file_if_exists('modules/Calendar/Calendar.php');
1 Like