BP_Gifts

This function should include all classes and functions that access the database.

Defined (1)

The class is defined in the following location(s).

/includes/bp-gifts-classes.php  
  1. class BP_Gifts { 
  2.  
  3. var $id; 
  4.  
  5. var $gift_name; 
  6.  
  7. var $gift_image; 
  8.  
  9. var $category; 
  10.  
  11. var $point; 
  12.  
  13.  
  14.  
  15. /** 
  16.   
  17. * bp_gifts_item() 
  18.   
  19.   
  20. * This is the constructor, it is auto run when the class is instantiated. 
  21.   
  22. * It will either create a new empty object if no ID is set, or fill the object 
  23.   
  24. * with a row from the table if an ID is provided. 
  25.   
  26. */ 
  27.  
  28. function bp_gifts( $id = null ) { 
  29.  
  30. global $wpdb, $bp; 
  31.  
  32.  
  33.  
  34. if ( $id ) { 
  35.  
  36. $this->id = $id; 
  37.  
  38. $this->populate( $this->id ); 
  39.  
  40.  
  41.  
  42.  
  43.  
  44. /** 
  45.   
  46. * populate() 
  47.   
  48.   
  49. * This method will populate the object with a row from the database, based on the 
  50.   
  51. * ID passed to the constructor. 
  52.   
  53. */ 
  54.  
  55. function populate() { 
  56.  
  57. global $wpdb, $bp, $creds; 
  58.  
  59.  
  60.  
  61. if ( $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->gifts->table_name} WHERE id = %d", $this->id ) ) ) { 
  62.  
  63. $this->gift_name = $row->gift_name; 
  64.  
  65. $this->gift_image = $row->gift_image; 
  66.  
  67. $this->category = $row->category; 
  68.  
  69. $this->point = $row->point; 
  70.  
  71.  
  72.  
  73.  
  74.  
  75. /** 
  76.   
  77. * save() 
  78.   
  79.   
  80. * This method will save an object to the database. It will dynamically switch between 
  81.   
  82. * INSERT and UPDATE depending on whether or not the object already exists in the database. 
  83.   
  84. */ 
  85.  
  86.  
  87.  
  88. function save() { 
  89.  
  90. global $wpdb, $bp; 
  91.  
  92.  
  93.  
  94. /** Call a before save action here */ 
  95.  
  96. do_action( 'bp_gifts_data_before_save', $this ); 
  97.  
  98.  
  99.  
  100. if ( $this->id ) { 
  101.  
  102. // Update 
  103.  
  104. echo $this->gift_name; 
  105.  
  106. echo $this->gift_id; 
  107.  
  108. $result = $wpdb->query( $wpdb->prepare(  
  109.  
  110. "UPDATE {$bp->gifts->table_name} SET  
  111.  
  112. gift_name = %s,  
  113.  
  114. gift_image = %s,  
  115.  
  116. category = %s,  
  117.  
  118. point = %f 
  119.  
  120. WHERE id = %d",  
  121.  
  122. $this->gift_name,  
  123.  
  124. $this->gift_image,  
  125.  
  126. $this->category,  
  127.  
  128. $this->point,  
  129.  
  130. $this->id  
  131.  
  132. ) ); 
  133.  
  134. } else { 
  135.  
  136. // Save 
  137.  
  138. $result = $wpdb->query( $wpdb->prepare(  
  139.  
  140. "INSERT INTO {$bp->gifts->table_name} (  
  141.  
  142. gift_name,  
  143.  
  144. gift_image,  
  145.  
  146. category,  
  147.  
  148. point  
  149.  
  150. ) VALUES (  
  151.  
  152. %d, %d, %d, %f  
  153.  
  154. )",  
  155.  
  156. $this->gift_name,  
  157.  
  158. $this->gift_image,  
  159.  
  160. $this->category,  
  161.  
  162. $this->point 
  163.  
  164. ) ); 
  165.  
  166.  
  167.  
  168.  
  169. if ( !$result ) 
  170.  
  171. return false; 
  172.  
  173.  
  174.  
  175. if ( !$this->id ) { 
  176.  
  177. $this->id = $wpdb->insert_id; 
  178.  
  179. }  
  180.  
  181.  
  182.  
  183. /** Add an after save action here */ 
  184.  
  185. do_action( 'bp_gifts_data_after_save', $this );  
  186.  
  187. return $result; 
  188.  
  189.  
  190.  
  191.  
  192. /** 
  193.   
  194. * delete() 
  195.   
  196.   
  197. * This method will delete the corresponding row for an object from the database. 
  198.   
  199. */  
  200.  
  201. function delete() { 
  202.  
  203. global $wpdb, $bp; 
  204.  
  205.  
  206.  
  207. return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->gifts->table_name} WHERE id = %d", $this->id ) ); 
  208.  
  209.  
  210. /** Static Functions */ 
  211.  
  212.  
  213.  
  214. /** 
  215.   
  216. * Static functions can be used to bulk delete items in a table, or do something that 
  217.   
  218. * doesn't necessarily warrant the instantiation of the class. 
  219.   
  220.   
  221. * Look at bp-core-classes.php for giftss of mass delete. 
  222.   
  223. */ 
  224.  
  225.  
  226.  
  227. function delete_all() { 
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234. function delete_by_user_id() { 
  235.  
  236.  
  237.  
  238.