6

I am using SuiteCRM 7.4.3 and need to include two files (a PHP file and a JS file) into the whole project instance. What are the best practices in this situation? Where should I copy the source files and where do I include them?

Jean-Francois T.
  • 11,549
  • 7
  • 68
  • 107
Amirhossein Rzd
  • 359
  • 3
  • 12

2 Answers2

3

SuiteCRM uses its own TimeDate class which from the look of it you will need to extend to create your own (this JalaliDate). Honestly, I don't know how you could implement this without affecting the core SuiteCRM massively.

However, the files you will need to look at are include/TimeDate.php (which is the class Suite uses for all its time formatting). We always recommend that you try to make everything upgrade safe i.e. everything is within custom folder - however, from the look of this it won't be.

But, what I usually do when I include SDK of other applications I place it in custom/include/ and then whenever I need it I link it from there.

MissAran
  • 125
  • 9
0

If you need to use a javascript file SuiteCRM, You can use create a custom view that spits out the "script tags".

class CustomModuleViewSomething extends ViewEdit
{
    function display(){
        $this->ev->process();
        $scripts = array();
        $scripts[] = '<script src="javascript1.js"></script>';
        $scripts[] = '<script src="javascript2.js"></script>';
        $scripts[] = '<script src="javascript3.js"></script>';
        echo $this->ev->display($this->showTitle) . implode($scripts);
    }
}

I have a gist which depends on moment.js in order to process dates in JS. this is useful when you need process dates on the client side dates.

/**
 * returns js Date() from a date that is in the users format
 * @depends momentjs library
 * @param datestr
 * @returns {*|Date}
 */
function toDate(datestr) {
    var $format = "", $splitformat = ["","",""], $dbformat = ["","",""];
    // Get user preferences date format
    $format = cal_date_format
    $format = $format.toUpperCase();
    $format = $format.replace('%D', 'DD')
    $format = $format.replace('%M', 'MM')
    $format = $format.replace('%Y', 'YYYY')

    // return js date
    return moment(datestr, $format).toDate()
}

The better way to handle dates is to create an action in a customController:

class CustomModuleController extends SugarController {
    function action_save() {
        global $timedate;
        $field = "date_entered";
        $timedate->fromString($this->bean->$field);
        $this->bean->save(!empty($this->bean->notify_on_save));
    }
}
Daniel Samson
  • 718
  • 4
  • 18