PageRenderTime 43ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/recordlist/class.atkprintablerecordlist.inc

https://github.com/ibuildingsnl/ATK
PHP | 182 lines | 104 code | 23 blank | 55 comment | 9 complexity | c190df9644d97ab0455f29cacbf163f7 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, LGPL-3.0
  1. <?php
  2. /**
  3. * This file is part of the Achievo ATK distribution.
  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 atk
  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. * @version $Revision: 6320 $
  15. * $Id$
  16. */
  17. /** @internal include base class */
  18. atkimport("atk.recordlist.atkrecordlist");
  19. /**
  20. * Recordlist implementation that renders a recordlist that is
  21. * 'printer-friendly'.
  22. *
  23. * It doesn't render any actions or links, and can only be used as a
  24. * readonly list of records.
  25. *
  26. * @author Ivo Jansch <ivo@achievo.org>
  27. * @package atk
  28. * @subpackage recordlist
  29. *
  30. */
  31. class atkPrintableRecordList extends atkRecordList
  32. {
  33. /**
  34. * Creates printableRecordlist
  35. * @param $suppresslist
  36. * obsolete by specialRecordList
  37. */
  38. /**
  39. * Creates printableRecordlist
  40. * obsolete by specialRecordList
  41. *
  42. * @param atkNode $node the node
  43. * @param Array $recordset the list of records
  44. * @param Array $suppressList fields we don't display
  45. * @param int $flags The prefix for embeded fields
  46. * @return String The rendered recordlist
  47. */
  48. function render(&$node, $recordset, $suppressList="", $flags=0)
  49. {
  50. $this->setNode($node);
  51. $this->m_flags = $flags;
  52. $output='<table border="0" cellspacing="0" cellpadding="4">';
  53. $output.="<tr>";
  54. // stuff for the totals row..
  55. $totalisable = false;
  56. $totals = array();
  57. // display a headerrow with titles.
  58. // Since we are looping the attriblist anyway, we also check if there
  59. // are totalisable collumns.
  60. foreach (array_keys($this->m_node->m_attribList) as $attribname)
  61. {
  62. $p_attrib = &$this->m_node->m_attribList[$attribname];
  63. $musthide=(is_array($suppressList)&&count($suppressList)>0&&in_array($attribname,$suppressList));
  64. if (
  65. ($p_attrib->hasFlag(AF_HIDE_LIST)==false)
  66. &&
  67. (
  68. ($p_attrib->hasFlag(AF_HIDE_SELECT)==false)
  69. ||($this->m_node->m_action!="select")
  70. )
  71. &&$musthide==false
  72. )
  73. {
  74. $output.='<td><b>'.atktext($p_attrib->fieldName(),$this->m_node->m_module, $this->m_node->m_type).'</b></td>';
  75. // the totalisable check..
  76. if ($p_attrib->hasFlag(AF_TOTAL))
  77. {
  78. $totalisable = true;
  79. }
  80. }
  81. }
  82. $output.="</tr>";
  83. for ($i = 0, $_i = count($recordset); $i < $_i; $i++)
  84. {
  85. $output.='<tr>';
  86. foreach (array_keys($this->m_node->m_attribList) as $attribname)
  87. {
  88. $p_attrib = &$this->m_node->m_attribList[$attribname];
  89. $musthide=(is_array($suppressList)&&count($suppressList)>0&&in_array($attribname,$suppressList));
  90. if (
  91. ($p_attrib->hasFlag(AF_HIDE_LIST)==false)
  92. &&
  93. (
  94. ($p_attrib->hasFlag(AF_HIDE_SELECT)==false)
  95. ||($this->m_node->m_action!="select")
  96. )
  97. &&$musthide==false
  98. )
  99. {
  100. // An <attributename>_display function may be provided in a derived
  101. // class to display an attribute.
  102. $funcname = $p_attrib->m_name."_display";
  103. if (method_exists($this->m_node,$funcname))
  104. {
  105. $value=$this->m_node->$funcname($recordset[$i], "list");
  106. }
  107. else
  108. {
  109. // otherwise, the display function of the particular attribute
  110. // is called.
  111. $value=$p_attrib->display($recordset[$i], "list");
  112. }
  113. $output.='<td>'.($value==""?"&nbsp;":$value).'</td>';
  114. // Calculate totals..
  115. if ($p_attrib->hasFlag(AF_TOTAL))
  116. {
  117. $totals[$attribname] = $p_attrib->sum($totals[$attribname], $recordset[$i]);
  118. }
  119. }
  120. }
  121. $output.='</tr>';
  122. }
  123. // totalrow..
  124. if ($totalisable)
  125. {
  126. $totalRow = '<tr>';
  127. // Third loop.. this time for the totals row.
  128. foreach (array_keys($this->m_node->m_attribList) as $attribname)
  129. {
  130. $p_attrib = &$this->m_node->m_attribList[$attribname];
  131. $musthide=(is_array($suppressList)&&count($suppressList)>0&&in_array($attribname,$suppressList));
  132. if (
  133. ($p_attrib->hasFlag(AF_HIDE_LIST)==false)
  134. &&
  135. (
  136. ($p_attrib->hasFlag(AF_HIDE_SELECT)==false)
  137. ||($this->m_node->m_action!="select")
  138. )
  139. &&$musthide==false
  140. )
  141. {
  142. if ($p_attrib->hasFlag(AF_TOTAL))
  143. {
  144. $totalRow.='<td><b>'.$p_attrib->display($totals[$attribname], "list").'</b></td>';
  145. }
  146. else
  147. {
  148. $totalRow.='<td>&nbsp;</td>';
  149. }
  150. }
  151. }
  152. $totalRow.="</tr>";
  153. $output.=$totalRow;
  154. }
  155. $output.='</table>';
  156. return $output;
  157. }
  158. }
  159. ?>