PageRenderTime 36ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/umfrage/class.PollUser.inc.php

http://flaimo-php.googlecode.com/
PHP | 153 lines | 44 code | 12 blank | 97 comment | 7 complexity | 9cf7a82968ee787cd5599071f0848061 MD5 | raw file
  1. <?php
  2. /**
  3. * @package Polls
  4. */
  5. /**
  6. * Including the User class
  7. */
  8. require_once('class.User.inc.php');
  9. /**
  10. * Holds methods for manipulating user related informations
  11. *
  12. * Tested with WAMP (XP-SP1/1.3.24/4.0.12/4.3.0)
  13. * Last change: 2003-04-21
  14. *
  15. * @desc Holds methods for manipulating user related informations
  16. * @access public
  17. * @author Michael Wimmer <flaimo@gmx.net>
  18. * @copyright Michael Wimmer
  19. * @link http://www.flaimo.com/
  20. * @package Polls
  21. * @version 1.001
  22. */
  23. class PollUser extends User {
  24. /*-------------------*/
  25. /* V A R I A B L E S */
  26. /*-------------------*/
  27. /**
  28. * Prefix for all session/cookies when marking a poll voted
  29. *
  30. * @desc Prefix for all session/cookies when marking a poll voted
  31. * @var string
  32. * @access private
  33. */
  34. var $poll_varname;
  35. /**
  36. * Prefix for all session/cookies when marking a poll written (with a comment)
  37. *
  38. * @desc Prefix for all session/cookies when marking a poll written (with a comment)
  39. * @var string
  40. * @access private
  41. */
  42. var $commentwritten_varname;
  43. /*-----------------------*/
  44. /* C O N S T R U C T O R */
  45. /*-----------------------*/
  46. /**
  47. * Constructor
  48. *
  49. * @desc Constructor
  50. * @return (void)
  51. * @access private
  52. * @uses User::User()
  53. * @since 1.001 - 2003/04/21
  54. */
  55. function PollUser() {
  56. parent::User();
  57. $this->commentwritten_varname = (string) 'commentwritten_';
  58. $this->poll_varname = (string) 'abgestimmt_';
  59. } // end function
  60. /*-------------------*/
  61. /* F U N C T I O N S */
  62. /*-------------------*/
  63. /**
  64. * Sets a session/cookie to mark a poll written (with a comment)
  65. *
  66. * @desc Sets a session/cookie to mark a poll written (with a comment)
  67. * @param (int) $id The ID of the poll
  68. * @return (void)
  69. * @access public
  70. * @since 1.001 - 2003/04/21
  71. */
  72. function setCommentWritten($id) {
  73. $_COOKIE[$this->commentwritten_varname . $id] = time() + 360;
  74. setcookie($this->commentwritten_varname . $id, 1, time() + 360);
  75. $_SESSION[$this->commentwritten_varname . $id] = $GLOBALS[$this->commentwritten_varname . $id] = (int) time() +360;
  76. session_register($this->commentwritten_varname . $id);
  77. } // end function
  78. /**
  79. * Checks if the user has written a comment for that poll or not
  80. *
  81. * @desc Checks if the user has written a comment for that poll or not
  82. * @param (int) $id The ID of the poll
  83. * @return (boolean) $cookieset
  84. * @access public
  85. * @since 1.001 - 2003/04/21
  86. */
  87. function isCommentWritten($id) {
  88. $cookieset = (boolean) FALSE;
  89. if ((isset($_COOKIE[$this->commentwritten_varname . $id])) || (isset($_SESSION[$this->commentwritten_varname . $id]) && $_SESSION[$this->commentwritten_varname . $id] >= time())) {
  90. $cookieset = (boolean) TRUE;
  91. } elseif (isset($_SESSION[$this->commentwritten_varname . $id]) && $_SESSION[$this->commentwritten_varname . $id] < time()) {
  92. session_unregister($this->commentwritten_varname . $id);
  93. } // end if
  94. return (boolean) $cookieset;
  95. } // end function
  96. /**
  97. * Sets a session/cookie to mark a poll voted
  98. *
  99. * @desc Sets a session/cookie to mark a poll voted
  100. * @param (int) $id The ID of the poll
  101. * @param (array) $values Array with the coosen value(s)
  102. * @return (void)
  103. * @access public
  104. * @since 1.001 - 2003/04/21
  105. */
  106. function setPollVoted($id, $values) {
  107. $remember_choise = ((isset($values) && is_array($values)) ? implode(',', $values) : $values);
  108. $_COOKIE[$this->poll_varname . $id] = $remember_choise;
  109. setcookie($this->poll_varname . $id, $remember_choise, time()+31536000);
  110. $_SESSION[$this->poll_varname . $id] = $GLOBALS[$this->poll_varname . $id] = $remember_choise;
  111. session_register($this->poll_varname . $id);
  112. } // end function
  113. /**
  114. * Checks if the user has voted for that poll or not
  115. *
  116. * @desc Checks if the user has voted for that poll or not
  117. * @param (int) $id The ID of the poll
  118. * @return (boolean) $cookieset
  119. * @access public
  120. * @since 1.001 - 2003/04/21
  121. */
  122. function isPollVoted($id) {
  123. $cookieset = (boolean) FALSE;
  124. if ((isset($_COOKIE[$this->poll_varname . $id])) || (isset($_SESSION[$this->poll_varname . $id]))) {
  125. $cookieset = (boolean) TRUE;
  126. } // end if
  127. return (boolean) $cookieset;
  128. } // end function
  129. /**
  130. * Returns the prefix for poll cookies/sessions
  131. *
  132. * @desc Returns the prefix for poll cookies/sessions
  133. * @return (string) $poll_varname
  134. * @access public
  135. * @since 1.001 - 2003/04/21
  136. */
  137. function getPollVarname() {
  138. return (string) $this->poll_varname;
  139. }
  140. } // end class PollUser
  141. ?>