PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/library/Adapto/Recordlist/PrintableRecordList.php

http://github.com/egeniq/adapto
PHP | 144 lines | 66 code | 24 blank | 54 comment | 39 complexity | 6a30fe6af88b9170940607d43bc49c6b MD5 | raw file
  1. <?php
  2. /**
  3. * This file is part of the Adapto Toolkit.
  4. * Detailed copyright and licensing information can be found
  5. * in the doc/COPYRIGHT and doc/LICENSE files which should be
  6. * included in the distribution.
  7. *
  8. * @package adapto
  9. * @subpackage recordlist
  10. *
  11. * @copyright (c)2000-2004 Ivo Jansch
  12. * @license http://www.achievo.org/atk/licensing ATK Open Source License
  13. *
  14. */
  15. /** @internal include base class */
  16. /**
  17. * Recordlist implementation that renders a recordlist that is
  18. * 'printer-friendly'.
  19. *
  20. * It doesn't render any actions or links, and can only be used as a
  21. * readonly list of records.
  22. *
  23. * @author ijansch
  24. * @package adapto
  25. * @subpackage recordlist
  26. *
  27. */
  28. class Adapto_Recordlist_PrintableRecordList extends Adapto_RecordList
  29. {
  30. /**
  31. * Creates printableRecordlist
  32. * @param $suppresslist
  33. * obsolete by specialRecordList
  34. */
  35. /**
  36. * Creates printableRecordlist
  37. * obsolete by specialRecordList
  38. *
  39. * @param atkEntity $entity the entity
  40. * @param Array $recordset the list of records
  41. * @param Array $suppressList fields we don't display
  42. * @param int $flags The prefix for embeded fields
  43. * @return String The rendered recordlist
  44. */
  45. function render(&$entity, $recordset, $suppressList = "", $flags = 0)
  46. {
  47. $this->setEntity($entity);
  48. $this->m_flags = $flags;
  49. $output = '<table border="0" cellspacing="0" cellpadding="4">';
  50. $output .= "<tr>";
  51. // stuff for the totals row..
  52. $totalisable = false;
  53. $totals = array();
  54. // display a headerrow with titles.
  55. // Since we are looping the attriblist anyway, we also check if there
  56. // are totalisable collumns.
  57. foreach (array_keys($this->m_entity->m_attribList) as $attribname) {
  58. $p_attrib = &$this->m_entity->m_attribList[$attribname];
  59. $musthide = (is_array($suppressList) && count($suppressList) > 0 && in_array($attribname, $suppressList));
  60. if (($p_attrib->hasFlag(AF_HIDE_LIST) == false)
  61. && (($p_attrib->hasFlag(AF_HIDE_SELECT) == false) || ($this->m_entity->m_action != "select")) && $musthide == false) {
  62. $output .= '<td><b>' . atktext($p_attrib->fieldName(), $this->m_entity->m_module, $this->m_entity->m_type) . '</b></td>';
  63. // the totalisable check..
  64. if ($p_attrib->hasFlag(AF_TOTAL)) {
  65. $totalisable = true;
  66. }
  67. }
  68. }
  69. $output .= "</tr>";
  70. for ($i = 0, $_i = count($recordset); $i < $_i; $i++) {
  71. $output .= '<tr>';
  72. foreach (array_keys($this->m_entity->m_attribList) as $attribname) {
  73. $p_attrib = &$this->m_entity->m_attribList[$attribname];
  74. $musthide = (is_array($suppressList) && count($suppressList) > 0 && in_array($attribname, $suppressList));
  75. if (($p_attrib->hasFlag(AF_HIDE_LIST) == false)
  76. && (($p_attrib->hasFlag(AF_HIDE_SELECT) == false) || ($this->m_entity->m_action != "select")) && $musthide == false) {
  77. // An <attributename>_display function may be provided in a derived
  78. // class to display an attribute.
  79. $funcname = $p_attrib->m_name . "_display";
  80. if (method_exists($this->m_entity, $funcname)) {
  81. $value = $this->m_entity->$funcname($recordset[$i], "list");
  82. } else {
  83. // otherwise, the display function of the particular attribute
  84. // is called.
  85. $value = $p_attrib->display($recordset[$i], "list");
  86. }
  87. $output .= '<td>' . ($value == "" ? "&nbsp;" : $value) . '</td>';
  88. // Calculate totals..
  89. if ($p_attrib->hasFlag(AF_TOTAL)) {
  90. $totals[$attribname] = $p_attrib->sum($totals[$attribname], $recordset[$i]);
  91. }
  92. }
  93. }
  94. $output .= '</tr>';
  95. }
  96. // totalrow..
  97. if ($totalisable) {
  98. $totalRow = '<tr>';
  99. // Third loop.. this time for the totals row.
  100. foreach (array_keys($this->m_entity->m_attribList) as $attribname) {
  101. $p_attrib = &$this->m_entity->m_attribList[$attribname];
  102. $musthide = (is_array($suppressList) && count($suppressList) > 0 && in_array($attribname, $suppressList));
  103. if (($p_attrib->hasFlag(AF_HIDE_LIST) == false)
  104. && (($p_attrib->hasFlag(AF_HIDE_SELECT) == false) || ($this->m_entity->m_action != "select")) && $musthide == false) {
  105. if ($p_attrib->hasFlag(AF_TOTAL)) {
  106. $totalRow .= '<td><b>' . $p_attrib->display($totals[$attribname], "list") . '</b></td>';
  107. } else {
  108. $totalRow .= '<td>&nbsp;</td>';
  109. }
  110. }
  111. }
  112. $totalRow .= "</tr>";
  113. $output .= $totalRow;
  114. }
  115. $output .= '</table>';
  116. return $output;
  117. }
  118. }
  119. ?>