dashlet.class.inc.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. <?php
  2. // Copyright (C) 2012 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. require_once(APPROOT.'application/forms.class.inc.php');
  17. /**
  18. * Base class for all 'dashlets' (i.e. widgets to be inserted into a dashboard)
  19. *
  20. */
  21. abstract class Dashlet
  22. {
  23. protected $sId;
  24. protected $bRedrawNeeded;
  25. protected $bFormRedrawNeeded;
  26. protected $aProperties; // array of {property => value}
  27. protected $aCSSClasses;
  28. public function __construct($sId)
  29. {
  30. $this->sId = $sId;
  31. $this->bRedrawNeeded = true; // By default: redraw each time a property changes
  32. $this->bFormRedrawNeeded = false; // By default: no need to redraw the form (independent fields)
  33. $this->aProperties = array(); // By default: there is no property
  34. $this->aCSSClasses = array('dashlet');
  35. }
  36. // Assuming that a property has the type of its default value, set in the constructor
  37. //
  38. public function Str2Prop($sProperty, $sValue)
  39. {
  40. $refValue = $this->aProperties[$sProperty];
  41. $sRefType = gettype($refValue);
  42. if ($sRefType == 'boolean')
  43. {
  44. $ret = ($sValue == 'true');
  45. }
  46. else
  47. {
  48. $ret = $sValue;
  49. settype($ret, $sRefType);
  50. }
  51. return $ret;
  52. }
  53. public function Prop2Str($value)
  54. {
  55. if (gettype($value) == 'boolean')
  56. {
  57. $sRet = $value ? 'true' : 'false';
  58. }
  59. else
  60. {
  61. $sRet = (string) $value;
  62. }
  63. return $sRet;
  64. }
  65. public function FromDOMNode($oDOMNode)
  66. {
  67. foreach ($this->aProperties as $sProperty => $value)
  68. {
  69. $this->oDOMNode = $oDOMNode->getElementsByTagName($sProperty)->item(0);
  70. if ($this->oDOMNode != null)
  71. {
  72. $newvalue = $this->Str2Prop($sProperty, $this->oDOMNode->textContent);
  73. $this->aProperties[$sProperty] = $newvalue;
  74. }
  75. }
  76. }
  77. public function ToDOMNode($oDOMNode)
  78. {
  79. foreach ($this->aProperties as $sProperty => $value)
  80. {
  81. $sXmlValue = $this->Prop2Str($value);
  82. $oPropNode = $oDOMNode->ownerDocument->createElement($sProperty, $sXmlValue);
  83. $oDOMNode->appendChild($oPropNode);
  84. }
  85. }
  86. public function FromXml($sXml)
  87. {
  88. $oDomDoc = new DOMDocument('1.0', 'UTF-8');
  89. $oDomDoc->loadXml($sXml);
  90. $this->FromDOMNode($oDomDoc->firstChild);
  91. }
  92. public function FromParams($aParams)
  93. {
  94. foreach ($this->aProperties as $sProperty => $value)
  95. {
  96. if (array_key_exists($sProperty, $aParams))
  97. {
  98. $this->aProperties[$sProperty] = $aParams[$sProperty];
  99. }
  100. }
  101. }
  102. public function DoRender($oPage, $bEditMode = false, $aExtraParams = array())
  103. {
  104. $sCSSClasses = implode(' ', $this->aCSSClasses);
  105. if ($bEditMode)
  106. {
  107. $sId = $this->GetID();
  108. $oPage->add('<div class="'.$sCSSClasses.'" id="dashlet_'.$sId.'">');
  109. }
  110. else
  111. {
  112. $oPage->add('<div class="'.$sCSSClasses.'">');
  113. }
  114. $this->Render($oPage, $bEditMode, $aExtraParams);
  115. $oPage->add('</div>');
  116. if ($bEditMode)
  117. {
  118. $sClass = get_class($this);
  119. $oPage->add_ready_script(
  120. <<<EOF
  121. $('#dashlet_$sId').dashlet({dashlet_id: '$sId', dashlet_class: '$sClass'});
  122. EOF
  123. );
  124. }
  125. }
  126. public function SetID($sId)
  127. {
  128. $this->sId = $sId;
  129. }
  130. public function GetID()
  131. {
  132. return $this->sId;
  133. }
  134. abstract public function Render($oPage, $bEditMode = false, $aExtraParams = array());
  135. abstract public function GetPropertiesFields(DesignerForm $oForm);
  136. public function ToXml(DOMNode $oContainerNode)
  137. {
  138. }
  139. public function Update($aValues, $aUpdatedFields)
  140. {
  141. foreach($aUpdatedFields as $sProp)
  142. {
  143. if (array_key_exists($sProp, $this->aProperties))
  144. {
  145. $this->aProperties[$sProp] = $aValues[$sProp];
  146. }
  147. }
  148. return $this;
  149. }
  150. public function IsRedrawNeeded()
  151. {
  152. return $this->bRedrawNeeded;
  153. }
  154. public function IsFormRedrawNeeded()
  155. {
  156. return $this->bFormRedrawNeeded;
  157. }
  158. static public function GetInfo()
  159. {
  160. return array(
  161. 'label' => '',
  162. 'icon' => '',
  163. 'description' => '',
  164. );
  165. }
  166. public function GetForm()
  167. {
  168. $oForm = new DesignerForm();
  169. $oForm->SetPrefix("dashlet_". $this->GetID());
  170. $oForm->SetParamsContainer('params');
  171. $this->GetPropertiesFields($oForm);
  172. $oDashletClassField = new DesignerHiddenField('dashlet_class', '', get_class($this));
  173. $oForm->AddField($oDashletClassField);
  174. $oDashletIdField = new DesignerHiddenField('dashlet_id', '', $this->GetID());
  175. $oForm->AddField($oDashletIdField);
  176. return $oForm;
  177. }
  178. static public function IsVisible()
  179. {
  180. return true;
  181. }
  182. static public function CanCreateFromOQL()
  183. {
  184. return false;
  185. }
  186. public function GetPropertiesFieldsFromOQL(DesignerForm $oForm, $sOQL)
  187. {
  188. // Default: do nothing since it's not supported
  189. }
  190. }
  191. class DashletEmptyCell extends Dashlet
  192. {
  193. public function __construct($sId)
  194. {
  195. parent::__construct($sId);
  196. }
  197. public function Render($oPage, $bEditMode = false, $aExtraParams = array())
  198. {
  199. $oPage->add('&nbsp;');
  200. }
  201. public function GetPropertiesFields(DesignerForm $oForm)
  202. {
  203. }
  204. static public function GetInfo()
  205. {
  206. return array(
  207. 'label' => 'Empty Cell',
  208. 'icon' => 'images/dashlet-text.png',
  209. 'description' => 'Empty Cell Dashlet Placeholder',
  210. );
  211. }
  212. static public function IsVisible()
  213. {
  214. return false;
  215. }
  216. }
  217. class DashletHelloWorld extends Dashlet
  218. {
  219. public function __construct($sId)
  220. {
  221. parent::__construct($sId);
  222. $this->aProperties['text'] = 'Hello World';
  223. }
  224. public function Render($oPage, $bEditMode = false, $aExtraParams = array())
  225. {
  226. $oPage->add('<div style="text-align:center; line-height:5em" class="dashlet-content"><span>'.$this->aProperties['text'].'</span></div>');
  227. }
  228. public function GetPropertiesFields(DesignerForm $oForm)
  229. {
  230. $oField = new DesignerTextField('text', 'Text', $this->aProperties['text']);
  231. $oForm->AddField($oField);
  232. }
  233. static public function GetInfo()
  234. {
  235. return array(
  236. 'label' => 'Hello World',
  237. 'icon' => 'images/dashlet-text.png',
  238. 'description' => 'Hello World test Dashlet',
  239. );
  240. }
  241. }
  242. class DashletObjectList extends Dashlet
  243. {
  244. public function __construct($sId)
  245. {
  246. parent::__construct($sId);
  247. $this->aProperties['title'] = 'Hardcoded list of "my requests"';
  248. $this->aProperties['query'] = 'SELECT UserRequest AS i WHERE i.caller_id = :current_contact_id AND status NOT IN ("closed", "resolved")';
  249. $this->aProperties['menu'] = false;
  250. }
  251. public function Render($oPage, $bEditMode = false, $aExtraParams = array())
  252. {
  253. $sTitle = $this->aProperties['title'];
  254. $sQuery = $this->aProperties['query'];
  255. $sShowMenu = $this->aProperties['menu'] ? '1' : '0';
  256. $oPage->add('<div style="text-align:center" class="dashlet-content">');
  257. // C'est quoi ce paramètre "menu" ?
  258. $sXML = '<itopblock BlockClass="DisplayBlock" type="list" asynchronous="false" encoding="text/oql" parameters="menu:'.$sShowMenu.'">'.$sQuery.'</itopblock>';
  259. $aParams = array();
  260. $sBlockId = 'block_'.$this->sId.($bEditMode ? '_edit' : ''); // make a unique id (edition occuring in the same DOM)
  261. $oBlock = DisplayBlock::FromTemplate($sXML);
  262. $oBlock->Display($oPage, $sBlockId, $aParams);
  263. $oPage->add('</div>');
  264. }
  265. public function GetPropertiesFields(DesignerForm $oForm)
  266. {
  267. $oField = new DesignerTextField('title', 'Title', $this->aProperties['title']);
  268. $oForm->AddField($oField);
  269. $oField = new DesignerLongTextField('query', 'Query', $this->aProperties['query']);
  270. $oForm->AddField($oField);
  271. $oField = new DesignerBooleanField('menu', 'Menu', $this->aProperties['menu']);
  272. $oForm->AddField($oField);
  273. }
  274. static public function GetInfo()
  275. {
  276. return array(
  277. 'label' => 'Object list',
  278. 'icon' => 'images/dashlet-object-list.png',
  279. 'description' => 'Object list dashlet',
  280. );
  281. }
  282. static public function CanCreateFromOQL()
  283. {
  284. return true;
  285. }
  286. public function GetPropertiesFieldsFromOQL(DesignerForm $oForm, $sOQL)
  287. {
  288. $oField = new DesignerTextField('title', 'Title', '');
  289. $oForm->AddField($oField);
  290. $oField = new DesignerHiddenField('query', 'Query', $sOQL);
  291. $oForm->AddField($oField);
  292. $oField = new DesignerBooleanField('menu', 'Menu', $this->aProperties['menu']);
  293. $oForm->AddField($oField);
  294. }
  295. }
  296. abstract class DashletGroupBy extends Dashlet
  297. {
  298. public function __construct($sId)
  299. {
  300. parent::__construct($sId);
  301. $this->aProperties['title'] = 'Hardcoded list of Contacts grouped by location';
  302. $this->aProperties['query'] = 'SELECT Contact';
  303. $this->aProperties['group_by'] = 'location_name';
  304. $this->aProperties['style'] = 'table';
  305. }
  306. public function Render($oPage, $bEditMode = false, $aExtraParams = array())
  307. {
  308. $sTitle = $this->aProperties['title'];
  309. $sQuery = $this->aProperties['query'];
  310. $sGroupBy = $this->aProperties['group_by'];
  311. $sStyle = $this->aProperties['style'];
  312. if ($sQuery == '')
  313. {
  314. $oPage->add('<p>Please enter a valid OQL query</p>');
  315. }
  316. elseif ($sGroupBy == '')
  317. {
  318. $oPage->add('<p>Please select the field on which the objects will be grouped together</p>');
  319. }
  320. else
  321. {
  322. switch($sStyle)
  323. {
  324. case 'bars':
  325. $sXML = '<itopblock BlockClass="DisplayBlock" type="open_flash_chart" parameters="chart_type:bars;chart_title:'.$sTitle.';group_by:'.$sGroupBy.'" asynchronous="false" encoding="text/oql">'.$sQuery.'</itopblock>';
  326. $sHtmlTitle = ''; // done in the itop block
  327. break;
  328. case 'pie':
  329. $sXML = '<itopblock BlockClass="DisplayBlock" type="open_flash_chart" parameters="chart_type:pie;chart_title:'.$sTitle.';group_by:'.$sGroupBy.'" asynchronous="false" encoding="text/oql">'.$sQuery.'</itopblock>';
  330. $sHtmlTitle = ''; // done in the itop block
  331. break;
  332. case 'table':
  333. default:
  334. $sHtmlTitle = htmlentities(Dict::S($sTitle), ENT_QUOTES, 'UTF-8'); // done in the itop block
  335. $sXML = '<itopblock BlockClass="DisplayBlock" type="count" parameters="group_by:'.$sGroupBy.'" asynchronous="false" encoding="text/oql">'.$sQuery.'</itopblock>';
  336. break;
  337. }
  338. $oPage->add('<div style="text-align:center" class="dashlet-content">');
  339. if ($sHtmlTitle != '')
  340. {
  341. $oPage->add('<h1>'.$sHtmlTitle.'</h1>');
  342. }
  343. $aParams = array();
  344. $sBlockId = 'block_'.$this->sId.($bEditMode ? '_edit' : ''); // make a unique id (edition occuring in the same DOM)
  345. $oBlock = DisplayBlock::FromTemplate($sXML);
  346. $oBlock->Display($oPage, $sBlockId, $aParams);
  347. $oPage->add('</div>');
  348. // TEST Group By as SQL!
  349. //$oSearch = DBObjectSearch::FromOQL($this->aProperties['query']);
  350. //$sSql = MetaModel::MakeSelectQuery($oSearch);
  351. //$sHtmlSql = htmlentities($sSql, ENT_QUOTES, 'UTF-8');
  352. //$oPage->p($sHtmlSql);
  353. }
  354. }
  355. public function GetPropertiesFields(DesignerForm $oForm)
  356. {
  357. $oField = new DesignerTextField('title', 'Title', $this->aProperties['title']);
  358. $oForm->AddField($oField);
  359. $oField = new DesignerLongTextField('query', 'Query', $this->aProperties['query']);
  360. $oForm->AddField($oField);
  361. // Group by field: build the list of possible values (attribute codes + ...)
  362. $oSearch = DBObjectSearch::FromOQL($this->aProperties['query']);
  363. $sClass = $oSearch->GetClass();
  364. $aGroupBy = array();
  365. foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef)
  366. {
  367. if (!$oAttDef->IsScalar()) continue; // skip link sets
  368. if ($oAttDef->IsExternalKey(EXTKEY_ABSOLUTE)) continue; // skip external keys
  369. $aGroupBy[$sAttCode] = $oAttDef->GetLabel();
  370. if ($oAttDef instanceof AttributeDateTime)
  371. {
  372. //date_format(start_date, '%d')
  373. $aGroupBy['date_of_'.$sAttCode] = 'Day of '.$oAttDef->GetLabel();
  374. }
  375. }
  376. $oField = new DesignerComboField('group_by', 'Group by', $this->aProperties['group_by']);
  377. $oField->SetAllowedValues($aGroupBy);
  378. $oForm->AddField($oField);
  379. $aStyles = array(
  380. 'pie' => 'Pie chart',
  381. 'bars' => 'Bar chart',
  382. 'table' => 'Table',
  383. );
  384. $oField = new DesignerComboField('style', 'Style', $this->aProperties['style']);
  385. $oField->SetAllowedValues($aStyles);
  386. $oForm->AddField($oField);
  387. }
  388. public function Update($aValues, $aUpdatedFields)
  389. {
  390. if (in_array('query', $aUpdatedFields))
  391. {
  392. $sCurrQuery = $aValues['query'];
  393. $oCurrSearch = DBObjectSearch::FromOQL($sCurrQuery);
  394. $sCurrClass = $oCurrSearch->GetClass();
  395. $sPrevQuery = $this->aProperties['query'];
  396. $oPrevSearch = DBObjectSearch::FromOQL($sPrevQuery);
  397. $sPrevClass = $oPrevSearch->GetClass();
  398. if ($sCurrClass != $sPrevClass)
  399. {
  400. $this->bFormRedrawNeeded = true;
  401. // wrong but not necessary - unset($aUpdatedFields['group_by']);
  402. $this->aProperties['group_by'] = '';
  403. }
  404. }
  405. $oDashlet = parent::Update($aValues, $aUpdatedFields);
  406. if (in_array('style', $aUpdatedFields))
  407. {
  408. switch($aValues['style'])
  409. {
  410. // Style changed, mutate to the specified type of chart
  411. case 'pie':
  412. $oDashlet = new DashletGroupByPie($this->sId);
  413. break;
  414. case 'bars':
  415. $oDashlet = new DashletGroupByBars($this->sId);
  416. break;
  417. case 'table':
  418. $oDashlet = new DashletGroupByTable($this->sId);
  419. break;
  420. }
  421. $oDashlet->FromParams($aValues);
  422. $oDashlet->bRedrawNeeded = true;
  423. $oDashlet->bFormRedrawNeeded = true;
  424. }
  425. return $oDashlet;
  426. }
  427. static public function GetInfo()
  428. {
  429. return array(
  430. 'label' => 'Objects grouped by...',
  431. 'icon' => 'images/dashlet-object-grouped.png',
  432. 'description' => 'Grouped objects dashlet',
  433. );
  434. }
  435. static public function CanCreateFromOQL()
  436. {
  437. return true;
  438. }
  439. public function GetPropertiesFieldsFromOQL(DesignerForm $oForm, $sOQL)
  440. {
  441. $oField = new DesignerTextField('title', 'Title', '');
  442. $oForm->AddField($oField);
  443. $oField = new DesignerHiddenField('query', 'Query', $sOQL);
  444. $oForm->AddField($oField);
  445. // Group by field: build the list of possible values (attribute codes + ...)
  446. $oSearch = DBObjectSearch::FromOQL($this->aProperties['query']);
  447. $sClass = $oSearch->GetClass();
  448. $aGroupBy = array();
  449. foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef)
  450. {
  451. if (!$oAttDef->IsScalar()) continue; // skip link sets
  452. if ($oAttDef->IsExternalKey(EXTKEY_ABSOLUTE)) continue; // skip external keys
  453. $aGroupBy[$sAttCode] = $oAttDef->GetLabel();
  454. if ($oAttDef instanceof AttributeDateTime)
  455. {
  456. //date_format(start_date, '%d')
  457. $aGroupBy['date_of_'.$sAttCode] = 'Day of '.$oAttDef->GetLabel();
  458. }
  459. }
  460. $oField = new DesignerComboField('group_by', 'Group by', $this->aProperties['group_by']);
  461. $oField->SetAllowedValues($aGroupBy);
  462. $oForm->AddField($oField);
  463. $oField = new DesignerHiddenField('style', '', $this->aProperties['style']);
  464. $oForm->AddField($oField);
  465. }
  466. }
  467. class DashletGroupByPie extends DashletGroupBy
  468. {
  469. public function __construct($sId)
  470. {
  471. parent::__construct($sId);
  472. $this->aProperties['style'] = 'pie';
  473. }
  474. static public function GetInfo()
  475. {
  476. return array(
  477. 'label' => 'Pie Chart',
  478. 'icon' => 'images/dashlet-pie-chart.png',
  479. 'description' => 'Pie Chart',
  480. );
  481. }
  482. }
  483. class DashletGroupByBars extends DashletGroupBy
  484. {
  485. public function __construct($sId)
  486. {
  487. parent::__construct($sId);
  488. $this->aProperties['style'] = 'bars';
  489. }
  490. static public function GetInfo()
  491. {
  492. return array(
  493. 'label' => 'Bar Chart',
  494. 'icon' => 'images/dashlet-bar-chart.png',
  495. 'description' => 'Bar Chart',
  496. );
  497. }
  498. }
  499. class DashletGroupByTable extends DashletGroupBy
  500. {
  501. public function __construct($sId)
  502. {
  503. parent::__construct($sId);
  504. $this->aProperties['style'] = 'table';
  505. }
  506. static public function GetInfo()
  507. {
  508. return array(
  509. 'label' => 'Group By (table)',
  510. 'icon' => 'images/dashlet-group-by-table.png',
  511. 'description' => 'List (Grouped by a field)',
  512. );
  513. }
  514. }
  515. class DashletHeader extends Dashlet
  516. {
  517. public function __construct($sId)
  518. {
  519. parent::__construct($sId);
  520. $this->aProperties['title'] = 'Hardcoded header of contacts';
  521. $this->aProperties['subtitle'] = 'Contacts';
  522. $this->aProperties['class'] = 'Contact';
  523. }
  524. public function Render($oPage, $bEditMode = false, $aExtraParams = array())
  525. {
  526. $sTitle = $this->aProperties['title'];
  527. $sSubtitle = $this->aProperties['subtitle'];
  528. $sClass = $this->aProperties['class'];
  529. $sTitleReady = str_replace(':', '_', $sTitle);
  530. $sSubtitleReady = str_replace(':', '_', $sSubtitle);
  531. $sStatusAttCode = MetaModel::GetStateAttributeCode($sClass);
  532. if (($sStatusAttCode == '') && MetaModel::IsValidAttCode($sClass, 'status'))
  533. {
  534. // Based on an enum
  535. $sStatusAttCode = 'status';
  536. $aStates = array_keys(MetaModel::GetAllowedValues_att($sClass, $sStatusAttCode));
  537. }
  538. else
  539. {
  540. // Based on a state variable
  541. $aStates = array_keys(MetaModel::EnumStates($sClass));
  542. }
  543. if ($sStatusAttCode == '')
  544. {
  545. // Simple stats
  546. $sXML = '<itopblock BlockClass="DisplayBlock" type="summary" asynchronous="false" encoding="text/oql" parameters="title[block]:'.$sTitleReady.';context_filter:1;label[block]:'.$sSubtitleReady.'">SELECT '.$sClass.'</itopblock>';
  547. }
  548. else
  549. {
  550. // Stats grouped by "status"
  551. $sStatusList = implode(',', $aStates);
  552. //$oPage->p('State: '.$sStatusAttCode.' states='.$sStatusList);
  553. $sXML = '<itopblock BlockClass="DisplayBlock" type="summary" asynchronous="false" encoding="text/oql" parameters="title[block]:'.$sTitleReady.';context_filter:1;label[block]:'.$sSubtitleReady.';status[block]:status;status_codes[block]:'.$sStatusList.'">SELECT '.$sClass.'</itopblock>';
  554. }
  555. $oPage->add('<div style="text-align:center" class="dashlet-content">');
  556. $oPage->add('<div class="main_header">');
  557. $aParams = array();
  558. $sBlockId = 'block_'.$this->sId.($bEditMode ? '_edit' : ''); // make a unique id (edition occuring in the same DOM)
  559. $oBlock = DisplayBlock::FromTemplate($sXML);
  560. $oBlock->Display($oPage, $sBlockId, $aParams);
  561. $oPage->add('</div>');
  562. $oPage->add('</div>');
  563. }
  564. public function GetPropertiesFields(DesignerForm $oForm)
  565. {
  566. $oField = new DesignerTextField('title', 'Title', $this->aProperties['title']);
  567. $oForm->AddField($oField);
  568. $oField = new DesignerTextField('subtitle', 'Subtitle', $this->aProperties['subtitle']);
  569. $oForm->AddField($oField);
  570. $oField = new DesignerTextField('class', 'Class', $this->aProperties['class']);
  571. $oForm->AddField($oField);
  572. }
  573. static public function GetInfo()
  574. {
  575. return array(
  576. 'label' => 'Header with stats',
  577. 'icon' => 'images/dashlet-header-stats.png',
  578. 'description' => 'Header with stats (grouped by...)',
  579. );
  580. }
  581. }
  582. class DashletBadge extends Dashlet
  583. {
  584. public function __construct($sId)
  585. {
  586. parent::__construct($sId);
  587. $this->aProperties['class'] = 'Contact';
  588. $this->aCSSClasses[] = 'dashlet-inline';
  589. $this->aCSSClasses[] = 'dashlet-badge';
  590. }
  591. public function Render($oPage, $bEditMode = false, $aExtraParams = array())
  592. {
  593. $sClass = $this->aProperties['class'];
  594. $oPage->add('<div style="text-align:center" class="dashlet-content">');
  595. $sXml = "<itopblock BlockClass=\"DisplayBlock\" type=\"actions\" asynchronous=\"false\" encoding=\"text/oql\" parameters=\"context_filter:1\">SELECT $sClass</itopblock>";
  596. $oBlock = DisplayBlock::FromTemplate($sXml);
  597. $sBlockId = 'block_'.$this->sId.($bEditMode ? '_edit' : ''); // make a unique id (edition occuring in the same DOM)
  598. $oBlock->Display($oPage, $sBlockId, $aExtraParams);
  599. $oPage->add('</div>');
  600. }
  601. public function GetPropertiesFields(DesignerForm $oForm)
  602. {
  603. $oField = new DesignerTextField('class', 'Class', $this->aProperties['class']);
  604. $oForm->AddField($oField);
  605. }
  606. static public function GetInfo()
  607. {
  608. return array(
  609. 'label' => 'Badge',
  610. 'icon' => 'images/dashlet-badge.png',
  611. 'description' => 'Object Icon with new/search',
  612. );
  613. }
  614. }