/src/class.event.php

https://github.com/nitcalicut/Sockmonkey · PHP · 229 lines · 159 code · 35 blank · 35 comment · 2 complexity · e181492037b7661c5c10c413c825c976 MD5 · raw file

  1. <?php
  2. /*
  3. This class contains functions to store, modify, access the event details.
  4. @author Rahul Raveendran VP <rahul.pmna@gmail.com>
  5. @author Mitaksh <mitakshg@gmail.com>
  6. */
  7. include_once 'database.php';
  8. class event {
  9. private $eno,$ename,$eid,$emgr,$econtact,$emin,$emax,$efee,$eprize1,$eprize2,$eprize3,$etype,$resourcevar;
  10. /**/
  11. public function __construct() {
  12. $a = func_get_args();
  13. $i = func_num_args();
  14. if($i==1)
  15. call_user_func_array(array($this,'viewEvent'),$a);
  16. if($i==10)
  17. call_user_func_array(array($this,'createEvent'),$a);
  18. }
  19. public function __destruct() {}
  20. /*
  21. this fuction helps you inserting a new event into database
  22. @param string ename: event name, string eid: event Id, string emgr: event manager,
  23. */
  24. protected function createEvent ($evname,$evid,$evmgr,$evcontact,$evmin,$evmax,$evfee,$evprize1,$evprize2,$evprize3) {
  25. $this->ename = pg_escape_string($evname);
  26. $this->eid = pg_escape_string($evid);
  27. $this->emgr = pg_escape_string($evmgr);
  28. $this->econtact = pg_escape_string($evcontact);
  29. $this->emin = pg_escape_string($evmin);
  30. $this->emax = pg_escape_string($evmax);
  31. $this->efee = pg_escape_string($evfee);
  32. $this->eprize1 = pg_escape_string($evprize1);
  33. $this->eprize2 = pg_escape_string($evprize2);
  34. $this->eprize3 = pg_escape_string($evprize3);
  35. $qry = "Insert into event(ev_name,ev_id,ev_mgr,ev_contact,ev_min,ev_max,ev_fee,ev_prize1,ev_prize2,ev_prize3)
  36. values ('".$this->ename."',
  37. '".$this->eid."',
  38. '".$this->emgr."',
  39. '".$this->econtact."',
  40. ".$this->emin.",
  41. ".$this->emax.",
  42. ".$this->efee.",
  43. '".$this->eprize1."',
  44. '".$this->eprize2."',
  45. '".$this->eprize3."') RETURNING ev_no";
  46. $eventNo=pg_fetch_assoc(dbquery($qry));
  47. $this->eno=$eventNo['ev_no'];
  48. }
  49. /* This function helps you viewing details for a particular event if the event number is given
  50. *
  51. */
  52. protected function viewEvent ($evid) {
  53. /* Bad practice. A change in DB design will screw up if we use * instead of specific col names */
  54. $qry = "select * from event where ev_id='".$evid."'";
  55. $res = dbquery($qry);
  56. $this->resourcevar = (resource2array($res));
  57. $res = dbquery($qry);
  58. $rec = pg_fetch_row($res);
  59. $this->eno = $rec[0];
  60. $this->ename = $rec[1];
  61. $this->eid = $rec[2];
  62. $this->emgr = $rec[3];
  63. $this->econtact = $rec[4];
  64. $this->emin = $rec[5];
  65. $this->emax = $rec[6];
  66. $this->efee = $rec[7];
  67. $this->eprize1 = $rec[8];
  68. $this->eprize2 = $rec[9];
  69. $this->eprize3 = $rec[10];
  70. $this->etype=$rec[11];
  71. }
  72. /*
  73. * This function helps you to search the events in the table using all possible combinations of fields.
  74. * @return: it returns a record set which contains the result of search.
  75. */
  76. public static function searchEvent($arg) {
  77. $arg='%'.$arg.'%';
  78. $qry = "select * from event where
  79. (ev_name like '".$arg."') OR
  80. (ev_id like '".$arg."') OR
  81. (ev_mgr like '".$arg."')";
  82. return (resource2array(dbquery($qry)));
  83. }
  84. /*
  85. * This is a function for updating an event's details'
  86. */
  87. public function updateEvent() {
  88. $qry = "update event set
  89. ev_name = '".$this->ename."' ,
  90. ev_id = '".$this->eid."' ,
  91. ev_mgr = '".$this->emgr."' ,
  92. ev_contact = '".$this->econtact."' ,
  93. ev_min = ".$this->emin." ,
  94. ev_max = ".$this->emax." ,
  95. ev_fee = ".$this->efee." ,
  96. ev_prize1 = '".$this->eprize1."' ,
  97. ev_prize2 = '".$this->eprize2."' ,
  98. ev_prize3 = '".$this->eprize3."'
  99. where ev_no=".$this->eno."";
  100. $res = dbquery($qry);
  101. }
  102. /*
  103. * List all EventIds
  104. * @returns all event ids
  105. */
  106. public static function listAllEventIds(){
  107. $qry = "select ev_id from event";
  108. $res = dbquery($qry);
  109. return(resource2array($res));
  110. }
  111. /*
  112. * the following functions helps you to get data from the Object.
  113. * they are 'get methods' :-)
  114. */
  115. public function getEventName() {
  116. return $this->ename;
  117. }
  118. public function getEventId() {
  119. return $this->eid;
  120. }
  121. public function getEventNo() {
  122. return $this->eno;
  123. }
  124. public function getManager() {
  125. return $this->emgr;
  126. }
  127. public function getContact() {
  128. return $this->econtact;
  129. }
  130. public function getMinimum() {
  131. return $this->emin;
  132. }
  133. public function getMaximum() {
  134. return $this->emax;
  135. }
  136. public function getFee() {
  137. return $this->efee;
  138. }
  139. public function getPrize1() {
  140. return $this->eprize1;
  141. }
  142. public function getPrize2() {
  143. return $this->eprize2;
  144. }
  145. public function getPrize3() {
  146. return $this->eprize3;
  147. }
  148. public function getEventType() {
  149. return $this->etype;
  150. }
  151. public function getResourceVar() {
  152. return $this->resourcevar;
  153. }
  154. /*
  155. * the following functions helps you to set data to the Object.
  156. * @Param $value is set correspondinlg to value-member of the class
  157. */
  158. public function setEventName($value) {
  159. $this->ename = $value;
  160. }
  161. public function setEventId($value) {
  162. $this->eid = $value;
  163. }
  164. public function setEventNo($value) {
  165. $this->eno = $value;
  166. }
  167. public function setManager($value) {
  168. $this->emgr = $value;
  169. }
  170. public function setContact($value) {
  171. $this->econtact = $value;
  172. }
  173. public function setMinimum($value) {
  174. $this->emin = $value;
  175. }
  176. public function setMaximum($value) {
  177. $this->emax = $value;
  178. }
  179. public function setFee($value) {
  180. $this->efee = $value;
  181. }
  182. public function setPrize1($value) {
  183. $this->eprize1 = $value;
  184. }
  185. public function setPrize2($value) {
  186. $this->eprize2 = $value;
  187. }
  188. public function setPrize3($value) {
  189. $this->eprize3 = $value;
  190. }
  191. }
  192. ?>