SS/Sugar

How to: Create an own chart Dashlet in 5.0.0c in 9 Steps

onesixx 2013. 1. 20. 21:05
반응형
http://forums.sugarcrm.com/f148/how-create-own-chart-dashlet-5-0-0c-32695/

-Configure
dashlet.data
dashlet.en_us
dashlet.meta
dashlet

As 5.0.0 differs a little from 4.5.1 I want to describe how you can create your own Chart Dashlet from an existing one.
Let's suppose I want to have a "Weighted Pipeline" Dashlet which shows the weighted pipeline for all users in one chart.

STEP 1 

폴더 만들기

./custom/modules/Charts
./custom/modules/Charts/Dashlets

./custom/modules/Home
./custom/modules/Home/language


STEP 2

Copy the whole directory 
./modules/Charts/Dashlets/MyPipelineBySalesStageDashlet
to
./custom/modules/Charts/Dashlets/WgPipelineBySalesStageDashlet


STEP 3

Rename the files

./custom/modules/Charts/Dashlets/WgPipelineBySalesStageDashlet/MyPipelineBySalesStageConfigure.tpl
./custom/modules/Charts/Dashlets/WgPipelineBySalesStageDashlet/MyPipelineBySalesStageDashlet.en_us.lang.php
./custom/modules/Charts/Dashlets/WgPipelineBySalesStageDashlet/MyPipelineBySalesStageDashlet.meta.php
./custom/modules/Charts/Dashlets/WgPipelineBySalesStageDashlet/MyPipelineBySalesStageDashlet.php

to

./custom/modules/Charts/Dashlets/WgPipelineBySalesStageDashlet/WgPipelineBySalesStageConfigure.tpl
./custom/modules/Charts/Dashlets/WgPipelineBySalesStageDashlet/WgPipelineBySalesStageDashlet.en_us.lang.php
./custom/modules/Charts/Dashlets/WgPipelineBySalesStageDashlet/WgPipelineBySalesStageDashlet.meta.php
./custom/modules/Charts/Dashlets/WgPipelineBySalesStageDashlet/WgPipelineBySalesStageDashlet.php


STEP 4

Edit ./custom/modules/Charts/Dashlets/WgPipelineBySalesStageDashlet/WgPipelineBySalesStageDashlet.en_us.lang.php

Change

$dashletStrings['MyPipelineBySalesStageDashlet'] = array('LBL_TITLE' => 'My Pipeline By Sales Stage',
'LBL_DESCRIPTION' => 'Vertical Bar Chart of My Sales Stage Pipeline',
'LBL_REFRESH' => 'Refresh Chart');

to

$dashletStrings['WgPipelineBySalesStageDashlet'] = array('LBL_TITLE' => 'Weighted Pipeline By Sales Stage',
'LBL_DESCRIPTION' => 'Vertical Bar Chart of Weighted Sales Stage Pipeline',
'LBL_REFRESH' => 'Refresh Chart');


STEP 5

Edit ./custom/modules/Charts/Dashlets/WgPipelineBySalesStageDashlet/WgPipelineBySalesStageDashlet.meta.php

Change

$dashletMeta['MyPipelineBySalesStageDashlet'] = array('title' => 'LBL_TITLE', 
'description' => 'LBL_TITLE',
'icon' => 'themes/default/images/icon_Charts_Funnel_32.gif',
'module' => 'Opportunities', 
'category' => 'Charts');

to


$dashletMeta['WgPipelineBySalesStageDashlet'] = array('title' => 'LBL_TITLE', 
'description' => 'LBL_TITLE',
'icon' => 'themes/default/images/icon_Charts_Funnel_32.gif',
'module' => 'Opportunities', 
'category' => 'Charts');


STEP 6

Edit ./custom/modules/Charts/Dashlets/WgPipelineBySalesStageDashlet/WgPipelineBySalesStageDashlet.php

Change
class MyPipelineBySalesStageDashlet extends Dashlet {
to
class WgPipelineBySalesStageDashlet extends Dashlet {

Change 
function MyPipelineBySalesStageDashlet($id, $options) {
to
function WgPipelineBySalesStageDashlet($id, $options) {

Change X
$this->title = translate('LBL_MY_PIPELINE_FORM_TITLE', 'Home');
to
$this->title = translate('LBL_WG_PIPELINE_FORM_TITLE', 'Home');
Change
$options['title'] = translate('LBL_MY_PIPELINE_FORM_TITLE', 'Home');
to 
$options['title'] = translate('LBL_KOSS_PIPELINE_FORM_TITLE', 'Home');

Change X
return parent::displayOptions() . $ss->fetch('modules/Charts/Dashlets/MyPipelineBySalesStageDashlet/MyPipelineBySalesStageConfigure.tpl');
to
return parent::displayOptions() . $ss->fetch('custom/modules/Charts/Dashlets/WgPipelineBySalesStageDashlet/WgPipelineBySalesStageConfigure.tpl');

Change X
$this->loadLanguage('MyPipelineBySalesStageDashlet', 'modules/Charts/Dashlets/');
to
$this->loadLanguage('WgPipelineBySalesStageDashlet', 'custom/modules/Charts/Dashlets/');

Change X
$cache_file_name = $current_user->getUserPrivGuid()."_".$theme."_my_pipeline_".$dat eFileNameSafe[0]."_".$dateFileNameSafe[1].".xml";
to
$cache_file_name = $current_user->getUserPrivGuid()."_".$theme."_wg_pipeline_".$dateFileNameSafe[0]."_".$dateFileNameSafe[1].".xml";

Change
if(is_file($sugar_config['tmp_dir'] . $current_user->getUserPrivGuid()."_".$theme."_my_pipeline_".$dat eFileNameSafe[0]."_".$dateFileNameSafe[1].".xml"))
unlink($sugar_config['tmp_dir'] . $current_user->getUserPrivGuid()."_".$theme."_my_pipeline_".$dat eFileNameSafe[0]."_".$dateFileNameSafe[1].".xml");
to
if(is_file($sugar_config['tmp_dir'] . $current_user->getUserPrivGuid()."_".$theme."_wg_pipeline_".$dateFileNameSafe[0]."_".$dateFileNameSafe[1].".xml"))
unlink($sugar_config['tmp_dir'] . $current_user->getUserPrivGuid()."_".$theme."_wg_pipeline_".$dateFileNameSafe[0]."_".$dateFileNameSafe[1].".xml");


STEP 7

Now we change the logic of the dashlet.

Edit ./custom/modules/Charts/Dashlets/WgPipelineBySalesStageDashlet/WgPipelineBySalesStageDashlet.php

Find the SQL statement

Code:
 $query = " SELECT opportunities.sales_stage,
users.user_name,opportunities.assigned_user_id, count( * ) AS opp_count, sum(amount_usdollar/1000 * probability/100) AS total FROM users,opportunities ";
As we want to have the weighted sum of all opportunities with no user information we must change it to

Code:
 $query = " SELECT opportunities.sales_stage,
                   count( * ) AS opp_count,
                   sum(amount_usdollar/1000 * probability/100) AS total
              FROM users,opportunities ";
The additional group statement

// $query .= ",users.user_name,opportunities.assigned_user_ id";

must be commented out.

The user-selection in the statement block

Code:
/****
//build the where clause for the query that matches $user
$count = count($user_id);
$id = array();
$user_list = get_user_array(false);
foreach ($user_id as $key) {
$new_ids[$key] = $user_list[$key];
}
if ($count>0) {
foreach ($new_ids as $the_id=>$the_name) {
$id[] = "'".$the_id."'";
}
$ids = join(",",$id);
$where .= "opportunities.assigned_user_id IN ($ids) ";
 
}
****/
must be commented out because we want to see all opportunities not only the own.

The salesstage selection 
$where .= "AND opportunities.sales_stage IN ($dataxArr) ";
must be changed to (remove AND)
$where .= " opportunities.sales_stage IN ($dataxArr) ";

At last you should remove the user paremter from chart link by commenting it out:

// $sugarChart->url_params = array( 'assigned_user_id' => $current_user->id ); 


STEP 8

Create an empty file with following content:

Code:
<?php
// Title of Dashlet "Weighted Pipeline:
$mod_strings['LBL_WG_PIPELINE_FORM_TITLE'] = 'Weighted Pipeline';
?>
and write it to 

./custom/modules/Home/language/en_us.lang.php

Now you are ready to test your new Dashlet.


STEP 9

Call "admin" - "repair" - "Clear Vardefs Data Cache" 
and
call "admin" -"repair" - "Rebuild Dashlets"


READY TO GO

Have a lot of fun writing your own chart dashlets.

Harald Kuske
Last edited by kuske; 2008-08-21 at 10:33 AM.
 
반응형

'SS > Sugar' 카테고리의 다른 글

sugar error  (0) 2013.10.16
Angel's Blog: SugarCRM: SOAP API Performance  (0) 2013.10.09
CONNECT BY LEVEL  (0) 2013.05.07
Add a search field2  (0) 2013.04.24
dropdown by role  (0) 2012.08.20
campaign tracker  (0) 2012.07.16