MS_View_Member_Dialog

Dialog: Member Profile.

Defined (1)

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

/app/view/member/class-ms-view-member-dialog.php  
  1. class MS_View_Member_Dialog extends MS_Dialog { 
  2.  
  3. const ACTION_SAVE = 'ms_save_member'; 
  4.  
  5. /** 
  6. * Generate/Prepare the dialog attributes. 
  7. * @since 1.0.0 
  8. */ 
  9. public function prepare() { 
  10. $member_id = $_POST['member_id']; 
  11. $member = MS_Factory::load( 'MS_Model_Member', $member_id ); 
  12.  
  13. $data = array( 
  14. 'model' => $member,  
  15. ); 
  16.  
  17. $data = apply_filters( 'ms_view_member_dialog_data', $data ); 
  18.  
  19. // Dialog Title 
  20. $this->title = sprintf( 
  21. __( 'Profile: %1$s %2$s', 'membership2' ),  
  22. esc_html( $member->first_name ),  
  23. esc_html( $member->last_name ) 
  24. ); 
  25.  
  26. // Dialog Size 
  27. $this->width = 940; 
  28. $this->height = 500; 
  29.  
  30. // Contents 
  31. $this->content = $this->get_contents( $data ); 
  32.  
  33. // Make the dialog modal 
  34. $this->modal = true; 
  35.  
  36. /** 
  37. * Save the gateway details. 
  38. * @since 1.0.0 
  39. * @return string 
  40. */ 
  41. public function submit() { 
  42. $data = $_POST; 
  43. $res = MS_Helper_Member::MEMBER_MSG_NOT_UPDATED; 
  44.  
  45. unset( $data['action'] ); 
  46. unset( $data['dialog'] ); 
  47.  
  48. // Update the memberships 
  49. if ( isset( $_POST['dialog_action'] ) 
  50. && $this->verify_nonce( $_POST['dialog_action'] ) 
  51. && isset( $_POST['member_id'] ) 
  52. ) { 
  53. // No input fields, so we cannot save anything... 
  54. $res = MS_Helper_Member::MEMBER_MSG_UPDATED; 
  55.  
  56. return $res; 
  57.  
  58. /** 
  59. * Returns the contens of the dialog 
  60. * @since 1.0.0 
  61. * @return object 
  62. */ 
  63. public function get_contents( $data ) { 
  64. $member = $data['model']; 
  65.  
  66. $currency = MS_Plugin::instance()->settings->currency; 
  67. $show_trial = MS_Model_Addon::is_enabled( MS_Model_Addon::ADDON_TRIAL ); 
  68.  
  69. $all_subscriptions = MS_Model_Relationship::get_subscriptions( 
  70. array( 
  71. 'user_id' => $member->id,  
  72. 'status' => 'all',  
  73. 'meta_key' => 'expire_date',  
  74. 'orderby' => 'meta_value',  
  75. 'order' => 'DESC',  
  76. ); 
  77.  
  78. // Prepare the form fields. 
  79. $inp_dialog = array( 
  80. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  81. 'name' => 'dialog',  
  82. 'value' => 'View_Member_Dialog',  
  83. ); 
  84.  
  85. $inp_id = array( 
  86. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  87. 'name' => 'member_id',  
  88. 'value' => $member->id,  
  89. ); 
  90.  
  91. $inp_nonce = array( 
  92. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  93. 'name' => '_wpnonce',  
  94. 'value' => wp_create_nonce( self::ACTION_SAVE ),  
  95. ); 
  96.  
  97. $inp_action = array( 
  98. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  99. 'name' => 'dialog_action',  
  100. 'value' => self::ACTION_SAVE,  
  101. ); 
  102.  
  103. $inp_save = array( 
  104. 'type' => MS_Helper_Html::INPUT_TYPE_SUBMIT,  
  105. 'value' => __( 'Save', 'membership2' ),  
  106. 'class' => 'ms-submit-form',  
  107. 'data' => array( 
  108. 'form' => 'ms-edit-member',  
  109. ); 
  110.  
  111. $inp_cancel = array( 
  112. 'type' => MS_Helper_Html::INPUT_TYPE_BUTTON,  
  113. 'value' => __( 'Close', 'membership2' ),  
  114. 'class' => 'close',  
  115. ); 
  116.  
  117. ob_start(); 
  118. ?> 
  119. <div> 
  120. <form class="ms-form wpmui-ajax-update ms-edit-member" data-wpmui-ajax="<?php echo esc_attr( 'save' ); ?>"> 
  121. <div class="ms-form wpmui-form wpmui-grid-8"> 
  122. <table class="widefat"> 
  123. <thead> 
  124. <tr> 
  125. <th class="column-membership"> 
  126. <?php _e( 'Membership', 'membership2' ); ?> 
  127. </th> 
  128. <th class="column-status"> 
  129. <?php _e( 'Status', 'membership2' ); ?> 
  130. </th> 
  131. <th class="column-start"> 
  132. <?php _e( 'Subscribed on', 'membership2' ); ?> 
  133. </th> 
  134. <th class="column-expire"> 
  135. <?php _e( 'Expires on', 'membership2' ); ?> 
  136. </th> 
  137. <?php if ( $show_trial ) : ?> 
  138. <th class="column-trialexpire"> 
  139. <?php _e( 'Trial until', 'membership2' ); ?> 
  140. </th> 
  141. <?php endif; ?> 
  142. <th class="column-payments"> 
  143. <?php _e( 'Payments', 'membership2' ); ?> 
  144. </th> 
  145. </tr> 
  146. </thead> 
  147. <tbody> 
  148. <?php 
  149. foreach ( $all_subscriptions as $subscription ) : 
  150. $membership = $subscription->get_membership(); 
  151. $payments = $subscription->get_payments(); 
  152.  
  153. $num_payments = count( $payments ); 
  154. $amount_payments = 0; 
  155. foreach ( $payments as $payment ) { 
  156. $amount_payments += $payment['amount']; 
  157.  
  158. $subscription_info = array( 
  159. 'subscription_id' => $subscription->id,  
  160. ); 
  161. $update_info = array( 
  162. 'subscription_id' => $subscription->id,  
  163. 'statuscheck' => 'yes',  
  164. ); 
  165. ?> 
  166. <tr> 
  167. <td class="column-membership"> 
  168. <?php $membership->name_tag(); ?> 
  169. </td> 
  170. <td class="column-status"> 
  171. <?php 
  172. printf( 
  173. '<a href="#" data-ms-dialog="View_Member_Subscription" data-ms-data="%2$s">%1$s</a> 
  174. <a href="#" data-ms-dialog="View_Member_Subscription" data-ms-data="%3$s" title="%5$s">%4$s</a>',  
  175. $subscription->status,  
  176. esc_attr( json_encode( $subscription_info ) ),  
  177. esc_attr( json_encode( $update_info ) ),  
  178. '<i class="dashicons dashicons-update"></i>',  
  179. __( 'Check and update subscription status', 'membership2' ) 
  180. ); 
  181. ?> 
  182. </td> 
  183. <td class="column-start"> 
  184. <?php echo $subscription->start_date; ?> 
  185. </td> 
  186. <td class="column-expire"> 
  187. <?php echo $subscription->expire_date; ?> 
  188. </td> 
  189. <?php if ( $show_trial ) : ?> 
  190. <td class="column-trialexpire"> 
  191. <?php 
  192. if ( $subscription->start_date == $subscription->trial_expire_date ) { 
  193. echo '-'; 
  194. } else { 
  195. echo $subscription->trial_expire_date; 
  196. ?> 
  197. </td> 
  198. <?php endif; ?> 
  199. <td class="column-payments"> 
  200. <?php 
  201. $total = sprintf( 
  202. '<b>%1$s</b> (%3$s %2$s)',  
  203. $num_payments,  
  204. MS_Helper_Billing::format_price( $amount_payments ),  
  205. $currency 
  206. ); 
  207.  
  208. printf( 
  209. '<a href="#" data-ms-dialog="View_Member_Payment" data-ms-data="%1$s">%2$s</a>',  
  210. esc_attr( json_encode( $subscription_info ) ),  
  211. $total 
  212. ); 
  213. ?> 
  214. </td> 
  215. </tr> 
  216. <?php endforeach; ?> 
  217. </tbody> 
  218. </table> 
  219. </div> 
  220. <?php 
  221. MS_Helper_Html::html_element( $inp_id ); 
  222. MS_Helper_Html::html_element( $inp_dialog ); 
  223. MS_Helper_Html::html_element( $inp_nonce ); 
  224. MS_Helper_Html::html_element( $inp_action ); 
  225. ?> 
  226. </form> 
  227. <div class="buttons"> 
  228. <?php 
  229. MS_Helper_Html::html_element( $inp_cancel ); 
  230. // MS_Helper_Html::html_element( $inp_save ); 
  231. ?> 
  232. </div> 
  233. </div> 
  234. <?php 
  235. $html = ob_get_clean(); 
  236. return apply_filters( 'ms_view_member_dialog_to_html', $html ); 
  237.  
  238. };