PageAbleResult.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * PageAbleResult is an AMFPHP service class which is used internally by AMFPHP
  4. * to provide support for pageable recordsets. The methods of PageAbleResult
  5. * are called automatically by the Flash player when implementing pageable
  6. * recordsets. To use pageable recordsets the developer need only
  7. * include the pagesize value in the service class method table and use
  8. * setDeliveryMode in the Flash client.
  9. *
  10. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  11. * @copyright (c) 2003 amfphp.org
  12. * @package flashservices
  13. * @subpackage sql
  14. * @version $Id: PageAbleResult.php,v 1.2 2005/07/05 07:40:53 pmineault Exp $
  15. */
  16. class PageAbleResult {
  17. /**
  18. * Constructor function.
  19. *
  20. * Contains the methodTable data and sets getRecords to return a record set page
  21. * instead of a normal array.
  22. */
  23. function PageAbleResult() {
  24. $this->methodTable = array("getRecords" => array("access" => "remote",
  25. "returns" => "__RECORDSETPAGE__"
  26. ),
  27. "release" => array("access" => "remote"
  28. )
  29. );
  30. }
  31. /**
  32. * Collects the page of the recordset from the session and returns it along
  33. * with the cursor position of the first record.
  34. *
  35. * @param string $id The session id
  36. * @param int $c The cursor position
  37. * @param int $ps The page size
  38. * @return array Contains the cursor position of the first record and the page data
  39. */
  40. function getRecords($id, $c, $ps) {
  41. $keys = explode("=", $id);
  42. $currset = intval($keys[1]);
  43. session_id($keys[0]);
  44. session_start();
  45. $pageData = array();
  46. $pageData['Cursor'] = $c;
  47. $pageData['Page'] = array_slice($_SESSION['amfphp_recordsets'][$currset]['data'], $c - 1, $ps);
  48. for($i = 0; $i < $ps; $i++)
  49. {
  50. $_SESSION['amfphp_recordsets'][$currset]['indexes'][$c + $i] = true;
  51. }
  52. return $pageData;
  53. }
  54. /**
  55. * Unsets the recordset data from the session
  56. * Flash, for some reason does not give back the recordid, so it's difficult to see
  57. * what exactly is going on, this is why we store sent data in another session var
  58. *
  59. */
  60. function release() {
  61. foreach($_SESSION['amfphp_recordsets'] as $key => $value)
  62. {
  63. $found = false;
  64. foreach($value['indexes'] as $recordid => $recordsent)
  65. {
  66. if(!$recordsent)
  67. {
  68. $found = true;
  69. break;
  70. }
  71. }
  72. if(!$found)
  73. {
  74. //Release recordset
  75. unset($_SESSION['amfphp_recordsets'][$key]);
  76. }
  77. }
  78. return;
  79. }
  80. }
  81. ?>