AJAX_Locking
[ class tree: AJAX_Locking ] [ index: AJAX_Locking ] [ all elements ]

Source for file Driver.php

Documentation is available at Driver.php

  1. <?php
  2.  
  3. define('AJAX_LOCKING_LOCKED', 'locked');
  4. define('AJAX_LOCKING_UNLOCKED', 'unlocked');
  5. define('AJAX_LOCKING_OWNED', 'owned');
  6. define('AJAX_LOCKING_TIMEOUT', 'timeout');
  7.  
  8. define('AJAX_LOCKING_PREFIX', 'ajaxlock');
  9.  
  10. /**
  11. * This class implements a base class for AJAX_Locking drivers.
  12. */
  13. class AJAX_Locking_Driver
  14. {
  15. var $timeout = 3600;
  16.  
  17. /**
  18. * Constructor
  19. *
  20. * @return AJAX_Locking_Driver
  21. */
  22. function AJAX_Locking_Driver($timeout = 3600)
  23. {
  24. if ($timeout) $this->timeout = $timeout;
  25. }
  26.  
  27. /**
  28. * Locks an object
  29. *
  30. * @param mixed $user id of the user who wants to lock
  31. * @param string $type type/classname of the object
  32. * @param mixed $id id of the object
  33. * @return boolean true if the lock was successfull or the user is the owner
  34. * false otherwise
  35. */
  36. function lock($user, $type, $id)
  37. {
  38. return true;
  39. }
  40.  
  41. /**
  42. * Unlocks an object
  43. *
  44. * @param mixed $user id of the user who wants to unlock
  45. * @param string $type type/classname of the object
  46. * @param mixed $id id of the object
  47. * @return boolean true if the unlock was successfull, false otherwise
  48. */
  49. function unlock($user, $type, $id)
  50. {
  51. return true;
  52. }
  53.  
  54. /**
  55. * Returns the status of the object (lock or unlocked)
  56. *
  57. * @param mixed $user id of the user who wants to know the object's status
  58. * @param string $type type/classname of the object
  59. * @param mixed $id id of the object
  60. * @return string the status and the owner of the object
  61. */
  62. function status($user, $type, $id)
  63. {
  64. return AJAX_LOCKING_UNLOCKED . "~";
  65. }
  66.  
  67. /**
  68. * Returns the list of all active locks for administration purpose
  69. *
  70. * @return array of locks (owner, type, id), false if not implemented
  71. */
  72. function getLocks()
  73. {
  74. return false;
  75. }
  76.  
  77. /**
  78. * Administrately delete lock
  79. *
  80. * @param string $type
  81. * @param mixed $id
  82. *
  83. * @return true if the lock is deleted successfully, false otherwise
  84. */
  85. function delete($type, $id)
  86. {
  87. return false;
  88. }
  89.  
  90. function _getKey($type, $id)
  91. {
  92. return AJAX_LOCKING_PREFIX . '.' . $type . '.' . $id;
  93. }
  94.  
  95. function _getValue($user, $type, $id)
  96. {
  97. return implode('~', array($user, $type, $id, time()));
  98. }
  99.  
  100. function _parseValue($value)
  101. {
  102. return explode('~', $value);
  103. }
  104. }
  105. ?>

Documentation generated on Tue, 13 Feb 2007 21:42:44 +0100 by phpDocumentor 1.3.0RC3