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