value}
public function __construct($sId)
{
$this->sId = $sId;
$this->bRedrawNeeded = true; // By default: redraw each time a property changes
$this->bFormRedrawNeeded = false; // By default: no need to redraw the form (independent fields)
$this->aProperties = array(); // By default: there is no property
}
public function FromDOMNode($oDOMNode)
{
}
public function FromXml($sXml)
{
}
public function FromParams($aParams)
{
foreach ($this->aProperties as $sProperty => $value)
{
if (array_key_exists($sProperty, $aParams))
{
$this->aProperties[$sProperty] = $aParams[$sProperty];
}
}
}
public function DoRender($oPage, $bEditMode = false, $aExtraParams = array())
{
if ($bEditMode)
{
$sId = $this->GetID();
$oPage->add('
');
}
else
{
$oPage->add('
');
}
$this->Render($oPage, $bEditMode, $aExtraParams);
$oPage->add('
');
if ($bEditMode)
{
$sClass = get_class($this);
$oPage->add_ready_script(
<<
sId;
}
abstract public function Render($oPage, $bEditMode = false, $aExtraParams = array());
abstract public function GetPropertiesFields(DesignerForm $oForm);
public function ToXml(DOMNode $oContainerNode)
{
}
public function Update($aValues, $aUpdatedFields)
{
foreach($aUpdatedFields as $sProp)
{
if (array_key_exists($sProp, $this->aProperties))
{
$this->aProperties[$sProp] = $aValues[$sProp];
}
}
}
public function IsRedrawNeeded()
{
return $this->bRedrawNeeded;
}
public function IsFormRedrawNeeded()
{
return $this->bFormRedrawNeeded;
}
static public function GetInfo()
{
return array(
'label' => '',
'icon' => '',
'description' => '',
);
}
public function GetForm()
{
$oForm = new DesignerForm();
$oForm->SetPrefix("dashlet_". $this->GetID());
$oForm->SetParamsContainer('params');
$this->GetPropertiesFields($oForm);
$oDashletClassField = new DesignerHiddenField('dashlet_class', '', get_class($this));
$oForm->AddField($oDashletClassField);
$oDashletIdField = new DesignerHiddenField('dashlet_id', '', $this->GetID());
$oForm->AddField($oDashletIdField);
return $oForm;
}
}
class DashletHelloWorld extends Dashlet
{
public function __construct($sId)
{
parent::__construct($sId);
$this->aProperties['text'] = 'Hello World';
}
public function Render($oPage, $bEditMode = false, $aExtraParams = array())
{
$oPage->add(''.$this->aProperties['text'].'
');
}
public function GetPropertiesFields(DesignerForm $oForm)
{
$oField = new DesignerTextField('text', 'Text', $this->aProperties['text']);
$oForm->AddField($oField);
}
static public function GetInfo()
{
return array(
'label' => 'Hello World',
'icon' => 'images/dashlet-text.png',
'description' => 'Hello World test Dashlet',
);
}
}
class DashletFakeBarChart extends Dashlet
{
public function __construct($sId)
{
parent::__construct($sId);
}
public function FromDOMNode($oDOMNode)
{
}
public function FromXml($sXml)
{
}
public function FromParams($aParams)
{
}
public function Render($oPage, $bEditMode = false, $aExtraParams = array())
{
$oPage->add('Fake Bar Chart

');
}
public function GetPropertiesFields(DesignerForm $oForm, $oDashlet = null)
{
}
public function ToXml(DOMNode $oContainerNode)
{
$oNewNodeNode = $oContainerNode->ownerDocument->createElement('fake_bar_chart', 'test');
$oContainerNode->appendChild($oNewNodeNode);
}
static public function GetInfo()
{
return array(
'label' => 'Bar Chart',
'icon' => 'images/dashlet-bar-chart.png',
'description' => 'Fake Bar Chart (for testing)',
);
}
}
class DashletFakePieChart extends Dashlet
{
public function __construct($sId)
{
parent::__construct($sId);
}
public function FromDOMNode($oDOMNode)
{
}
public function FromXml($sXml)
{
}
public function FromParams($aParams)
{
}
public function Render($oPage, $bEditMode = false, $aExtraParams = array())
{
$oPage->add('');
if ($sHtmlTitle != '')
{
$oPage->add('
'.$sHtmlTitle.'
');
}
$aParams = array();
$sBlockId = 'block_'.$this->sId.($bEditMode ? '_edit' : ''); // make a unique id (edition occuring in the same DOM)
$oBlock = DisplayBlock::FromTemplate($sXML);
$oBlock->Display($oPage, $sBlockId, $aParams);
$oPage->add('
');
}
public function GetPropertiesFields(DesignerForm $oForm)
{
$oField = new DesignerTextField('title', 'Title', $this->aProperties['title']);
$oForm->AddField($oField);
$oField = new DesignerTextField('query', 'Query', $this->aProperties['query']);
$oForm->AddField($oField);
$oField = new DesignerTextField('group_by', 'Group by', $this->aProperties['group_by']);
$oForm->AddField($oField);
$aStyles = array(
'pie' => 'Pie chart',
'bars' => 'Bar chart',
'table' => 'Table',
);
$oField = new DesignerComboField('style', 'Style', $this->aProperties['style']);
$oField->SetAllowedValues($aStyles);
$oForm->AddField($oField);
}
static public function GetInfo()
{
return array(
'label' => 'Objects grouped by...',
'icon' => 'images/dashlet-object-grouped.png',
'description' => 'Grouped objects dashlet',
);
}
}
class DashletHeader extends Dashlet
{
public function __construct($sId)
{
parent::__construct($sId);
$this->aProperties['title'] = 'Hardcoded header of contacts';
$this->aProperties['subtitle'] = 'Contacts';
$this->aProperties['class'] = 'Contact';
}
public function Render($oPage, $bEditMode = false, $aExtraParams = array())
{
$sTitle = $this->aProperties['title'];
$sSubtitle = $this->aProperties['subtitle'];
$sClass = $this->aProperties['class'];
$sTitleReady = str_replace(':', '_', $sTitle);
$sSubtitleReady = str_replace(':', '_', $sSubtitle);
$sStatusAttCode = MetaModel::GetStateAttributeCode($sClass);
if (($sStatusAttCode == '') && MetaModel::IsValidAttCode($sClass, 'status'))
{
// Based on an enum
$sStatusAttCode = 'status';
$aStates = array_keys(MetaModel::GetAllowedValues_att($sClass, $sStatusAttCode));
}
else
{
// Based on a state variable
$aStates = array_keys(MetaModel::EnumStates($sClass));
}
if ($sStatusAttCode == '')
{
// Simple stats
$sXML = '');
$aParams = array();
$sBlockId = 'block_'.$this->sId.($bEditMode ? '_edit' : ''); // make a unique id (edition occuring in the same DOM)
$oBlock = DisplayBlock::FromTemplate($sXML);
$oBlock->Display($oPage, $sBlockId, $aParams);
$oPage->add('
');
}
public function GetPropertiesFields(DesignerForm $oForm)
{
$oField = new DesignerTextField('title', 'Title', $this->aProperties['title']);
$oForm->AddField($oField);
$oField = new DesignerTextField('subtitle', 'Subtitle', $this->aProperties['subtitle']);
$oForm->AddField($oField);
$oField = new DesignerTextField('class', 'Class', $this->aProperties['class']);
$oForm->AddField($oField);
}
static public function GetInfo()
{
return array(
'label' => 'Header with stats',
'icon' => 'images/dashlet-header-stats.png',
'description' => 'Header with stats (grouped by...)',
);
}
}