Blogs
20
February
February
Here are the steps to create new dashlet based on SugarCRM's OOB dashlet.
In this blog, we are extending My Open Tasks dashlet to show Tasks until NOW.
Step 1: Copy modules/Tasks/Dashlets/MyTasksDashlet to custom/modules/Tasks/Dashlets folder. Rename MyTasksDashlet folder to MyTasksUntilNowDashlet.
Step 2: Go to custom/modules/Tasks/Dashlets/MyTasksUntilNowDashlet/
Rename MyTasksDashlet.data.php to MyTasksUntilNowDashlet.data.php
Rename MyTasksDashlet.meta.php to MyTasksUntilNowDashlet.meta.php
Rename MyTasksDashlet.php to MyTasksUntilNowDashlet.php
Step 3: Open custom/modules/Tasks/Dashlets/MyTasksUntilNowDashlet/MyTasksUntilNowDashlet.data.php
Find and replace MyTasksDashlet to MyTasksUntilNowDashlet
Step 4: Open custom/modules/Tasks/Dashlets/MyTasksUntilNowDashlet/MyTasksUntilNowDashlet.meta.php
Find and replace MyTasksDashlet to MyTasksUntilNowDashlet
Change LBL_LIST_MY_TASKS to LBL_LIST_MY_TASKS_UNTIL_NOW
Step 5: Open custom/modules/Tasks/Dashlets/MyTasksUntilNowDashlet/MyTasksUntilNowDashlet.php
Find and replace MyTasksDashlet to MyTasksUntilNowDashlet
Step 6: Lets guide Sugar to take new path
Change
require('modules/Tasks/Dashlets/MyTasksDashlet/MyTasksDashlet.data.php');
to
require('custom/modules/Tasks/Dashlets/MyTasksUntilNowDashlet/MyTasksUntilNowDashlet.data.php');
Step 7: Lets now add custom functionality.
Add following function in the class
Step 8:
Lets now change label of the Dashlet to know which is new dashlet we just created.
Create/Open custom/modules/Tasks/language/en_us.lang.php and add following line
Change the name which suits you more.
Step 9: Go to Admin > Repair > Quick Repair and Rebuild. Go to Home > Add dashlet and you should see the new dashlet there.
Hope it works as easy as it was while writing.
Feel free to leave comments.
In this blog, we are extending My Open Tasks dashlet to show Tasks until NOW.
Step 1: Copy modules/Tasks/Dashlets/MyTasksDashlet to custom/modules/Tasks/Dashlets folder. Rename MyTasksDashlet folder to MyTasksUntilNowDashlet.
Step 2: Go to custom/modules/Tasks/Dashlets/MyTasksUntilNowDashlet/
Rename MyTasksDashlet.data.php to MyTasksUntilNowDashlet.data.php
Rename MyTasksDashlet.meta.php to MyTasksUntilNowDashlet.meta.php
Rename MyTasksDashlet.php to MyTasksUntilNowDashlet.php
Step 3: Open custom/modules/Tasks/Dashlets/MyTasksUntilNowDashlet/MyTasksUntilNowDashlet.data.php
Find and replace MyTasksDashlet to MyTasksUntilNowDashlet
Step 4: Open custom/modules/Tasks/Dashlets/MyTasksUntilNowDashlet/MyTasksUntilNowDashlet.meta.php
Find and replace MyTasksDashlet to MyTasksUntilNowDashlet
Change LBL_LIST_MY_TASKS to LBL_LIST_MY_TASKS_UNTIL_NOW
Step 5: Open custom/modules/Tasks/Dashlets/MyTasksUntilNowDashlet/MyTasksUntilNowDashlet.php
Find and replace MyTasksDashlet to MyTasksUntilNowDashlet
Step 6: Lets guide Sugar to take new path
Change
require('modules/Tasks/Dashlets/MyTasksDashlet/MyTasksDashlet.data.php');
to
require('custom/modules/Tasks/Dashlets/MyTasksUntilNowDashlet/MyTasksUntilNowDashlet.data.php');
Step 7: Lets now add custom functionality.
Add following function in the class
function process($lvsParams = array()) {
global $timedate, $current_user;
$format = $timedate->get_date_time_format($current_user);
$dbformat = date('Y-m-d H:i:s', strtotime(date($format)));
// MYSQL database
$lvsParams['custom_where'] = ' AND DATE_FORMAT(tasks.date_start, "%Y-%m-%d %H:%i:%s") <= "'. $dbformat.'" ';
// MSSQL
// $lvsParams['custom_where'] = " AND REPLACE(CONVERT(varchar, tasks.date_start,111),'/','-') = '".$dbformat."')";
parent::process($lvsParams);
}
global $timedate, $current_user;
$format = $timedate->get_date_time_format($current_user);
$dbformat = date('Y-m-d H:i:s', strtotime(date($format)));
// MYSQL database
$lvsParams['custom_where'] = ' AND DATE_FORMAT(tasks.date_start, "%Y-%m-%d %H:%i:%s") <= "'. $dbformat.'" ';
// MSSQL
// $lvsParams['custom_where'] = " AND REPLACE(CONVERT(varchar, tasks.date_start,111),'/','-') = '".$dbformat."')";
parent::process($lvsParams);
}
Step 8:
Lets now change label of the Dashlet to know which is new dashlet we just created.
Create/Open custom/modules/Tasks/language/en_us.lang.php and add following line
<?php
$mod_strings['LBL_LIST_MY_TASKS_UNTIL_NOW'] = 'My Open Tasks until now';
$mod_strings['LBL_LIST_MY_TASKS_UNTIL_NOW'] = 'My Open Tasks until now';
Change the name which suits you more.
Step 9: Go to Admin > Repair > Quick Repair and Rebuild. Go to Home > Add dashlet and you should see the new dashlet there.
Hope it works as easy as it was while writing.
Just to make life easier pasting the final look of the main class file.
I.e. custom/modules/Tasks/Dashlets/MyTasksUntilNowDashlet/MyTasksUntilNowDashlet.php
I.e. custom/modules/Tasks/Dashlets/MyTasksUntilNowDashlet/MyTasksUntilNowDashlet.php
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/Dashlets/DashletGeneric.php');
class MyTasksUntilNowDashlet extends DashletGeneric {
function MyTasksUntilNowDashlet($id, $def = null) {
require('custom/modules/Tasks/Dashlets/MyTasksUntilNowDashlet/MyTasksUntilNowDashlet.data.php');
parent::DashletGeneric($id, $def);
if (empty($def['title']))
$this->title = translate('LBL_LIST_MY_TASKS', 'Tasks');
$this->searchFields = $dashletData['MyTasksUntilNowDashlet']['searchFields'];
$this->columns = $dashletData['MyTasksUntilNowDashlet']['columns'];
$this->seedBean = new Task();
}
function process($lvsParams = array()) {
global $timedate, $current_user;
$format = $timedate->get_date_time_format($current_user);
$dbformat = date('Y-m-d H:i:s', strtotime(date($format)));
// MYSQL database
$lvsParams['custom_where'] = ' AND DATE_FORMAT(tasks.date_start, "%Y-%m-%d %H:%i:%s") <= "'. $dbformat.'" ';
// MSSQL
// $lvsParams['custom_where'] = " AND REPLACE(CONVERT(varchar, tasks.date_start,111),'/','-') = '".$dbformat."')";
parent::process($lvsParams);
}
}
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/Dashlets/DashletGeneric.php');
class MyTasksUntilNowDashlet extends DashletGeneric {
function MyTasksUntilNowDashlet($id, $def = null) {
require('custom/modules/Tasks/Dashlets/MyTasksUntilNowDashlet/MyTasksUntilNowDashlet.data.php');
parent::DashletGeneric($id, $def);
if (empty($def['title']))
$this->title = translate('LBL_LIST_MY_TASKS', 'Tasks');
$this->searchFields = $dashletData['MyTasksUntilNowDashlet']['searchFields'];
$this->columns = $dashletData['MyTasksUntilNowDashlet']['columns'];
$this->seedBean = new Task();
}
function process($lvsParams = array()) {
global $timedate, $current_user;
$format = $timedate->get_date_time_format($current_user);
$dbformat = date('Y-m-d H:i:s', strtotime(date($format)));
// MYSQL database
$lvsParams['custom_where'] = ' AND DATE_FORMAT(tasks.date_start, "%Y-%m-%d %H:%i:%s") <= "'. $dbformat.'" ';
// MSSQL
// $lvsParams['custom_where'] = " AND REPLACE(CONVERT(varchar, tasks.date_start,111),'/','-') = '".$dbformat."')";
parent::process($lvsParams);
}
}
P.S. Comment out Mysql Query and uncomment MSSql query if you are using MSSQL database.
Feel free to leave comments.
Download attachments:
Comments
- No Comments Found.