MS_View_Membership_Overview_Simple

The Membership 2 MS View Membership Overview Simple class.

Defined (1)

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

/app/view/membership/overview/class-ms-view-membership-overview-simple.php  
  1. class MS_View_Membership_Overview_Simple extends MS_View { 
  2.  
  3. public function to_html() { 
  4. $this->check_simulation(); 
  5.  
  6. $membership = $this->data['membership']; 
  7.  
  8. $toggle = array( 
  9. 'id' => 'ms-toggle-' . $membership->id,  
  10. 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER,  
  11. 'value' => $membership->active,  
  12. 'class' => '',  
  13. 'data_ms' => array( 
  14. 'action' => MS_Controller_Membership::AJAX_ACTION_TOGGLE_MEMBERSHIP,  
  15. 'field' => 'active',  
  16. 'membership_id' => $membership->id,  
  17. ),  
  18. ); 
  19.  
  20. $status_class = ''; 
  21. if ( $membership->active ) { 
  22. $status_class = 'ms-active'; 
  23.  
  24. $edit_args = array( 
  25. 'membership_id' => $membership->id,  
  26. ); 
  27.  
  28. $edit_button = sprintf( 
  29. '<a href="?page=%1$s&step=%2$s&tab=%3$s&membership_id=%4$s" class="button">%5$s</a>',  
  30. esc_attr( $_REQUEST['page'] ),  
  31. MS_Controller_Membership::STEP_EDIT,  
  32. MS_Controller_Membership::TAB_DETAILS,  
  33. esc_attr( $membership->id ),  
  34. '<i class="wpmui-fa wpmui-fa-pencil"></i> ' . __( 'Edit', 'membership2' ) 
  35. ); 
  36.  
  37. ob_start(); 
  38. ?> 
  39. <div class="wrap ms-wrap ms-membership-overview"> 
  40. <div class="ms-wrap-top ms-group"> 
  41. <div class="ms-membership-status-wrapper"> 
  42. <?php MS_Helper_Html::html_element( $toggle ); ?> 
  43. <div id="ms-membership-status" class="ms-membership-status <?php echo esc_attr( $status_class ); ?>"> 
  44. <?php 
  45. printf( 
  46. '<div class="ms-active">%s</div>',  
  47. sprintf( 
  48. __( 'Membership is %s', 'membership2' ),  
  49. '<span id="ms-membership-status-text" class="ms-ok">' . 
  50. __( 'Active', 'membership2' ) . 
  51. '</span>' 
  52. ); 
  53. printf( 
  54. '<div>%s</div>',  
  55. sprintf( 
  56. __( 'Membership is %s', 'membership2' ),  
  57. '<span id="ms-membership-status-text" class="ms-nok">' . 
  58. __( 'Inactive', 'membership2' ) . 
  59. '</span>' 
  60. ); 
  61. ?> 
  62. </div> 
  63. </div> 
  64. <div class="ms-membership-edit-wrapper"> 
  65. <?php echo $edit_button; ?> 
  66. </div> 
  67. <?php 
  68.  
  69. $title = sprintf( 
  70. __( '%s Overview', 'membership2' ),  
  71. $membership->get_name_tag() 
  72. ); 
  73. $desc = array( 
  74. __( 'Here you find a summary of this membership, and alter any of its details.', 'membership2' ),  
  75. sprintf( 
  76. __( 'This is a %s', 'membership2' ),  
  77. $membership->get_type_description() 
  78. ),  
  79. ); 
  80.  
  81. MS_Helper_Html::settings_header( 
  82. array( 
  83. 'title' => $title,  
  84. 'desc' => $desc,  
  85. 'title_icon_class' => 'wpmui-fa wpmui-fa-dashboard',  
  86. ); 
  87. ?> 
  88. <div class="clear"></div> 
  89. </div> 
  90. <?php $this->available_content_panel(); ?> 
  91. <div class="clear"></div> 
  92. </div> 
  93.  
  94. <?php 
  95. $html = ob_get_clean(); 
  96.  
  97. return $html; 
  98.  
  99. public function news_panel() { 
  100. ?> 
  101. <div class="ms-half ms-settings-box"> 
  102. <h3> 
  103. <i class="ms-low wpmui-fa wpmui-fa-globe"></i> 
  104. <?php _e( 'Recent News', 'membership2' ); ?> 
  105. </h3> 
  106.  
  107. <?php if ( ! empty( $this->data['events'] ) ) : ?> 
  108. <div class="inside group"> 
  109. <?php $this->news_panel_data( $this->data['events'] ); ?> 
  110. </div> 
  111.  
  112. <div class="ms-news-view-wrapper"> 
  113. <?php 
  114. $url = esc_url_raw( 
  115. add_query_arg( array( 'step' => MS_Controller_Membership::STEP_NEWS ) ) 
  116. ); 
  117. MS_Helper_Html::html_element( 
  118. array( 
  119. 'id' => 'view_news',  
  120. 'type' => MS_Helper_Html::TYPE_HTML_LINK,  
  121. 'value' => __( 'View More News', 'membership2' ),  
  122. 'url' => $url,  
  123. 'class' => 'wpmui-field-button button',  
  124. ); 
  125. ?> 
  126. </div> 
  127. <?php else : ?> 
  128. <div class="inside group"> 
  129. <p class="ms-italic"> 
  130. <?php _e( 'There will be some interesting news here when your site gets going.', 'membership2' ); ?> 
  131. </p> 
  132. </div> 
  133. <?php endif; ?> 
  134. </div> 
  135. <?php 
  136.  
  137. /** 
  138. * Renders the Members panel 
  139. * @since 1.0.0 
  140. */ 
  141. public function members_panel() { 
  142. $count = count( $this->data['members'] ); 
  143. $membership_id = $this->data['membership']->id; 
  144. ?> 
  145. <div class="ms-half ms-settings-box"> 
  146. <h3> 
  147. <i class="ms-low wpmui-fa wpmui-fa-user"></i> 
  148. <?php printf( __( 'New Members (%s)', 'membership2' ), $count ); ?> 
  149. </h3> 
  150.  
  151. <?php if ( $count > 0 ) : ?> 
  152. <div class="inside group"> 
  153. <?php 
  154. $this->members_panel_data( 
  155. $this->data['members'],  
  156. $membership_id 
  157. ); 
  158. ?> 
  159. </div> 
  160.  
  161. <div class="ms-member-edit-wrapper"> 
  162. <?php 
  163. $url = MS_Controller_Plugin::get_admin_url( 
  164. 'members',  
  165. array( 'membership_id' => $membership_id ) 
  166. ); 
  167. MS_Helper_Html::html_element( 
  168. array( 
  169. 'id' => 'edit_members',  
  170. 'type' => MS_Helper_Html::TYPE_HTML_LINK,  
  171. 'value' => __( 'All Members', 'membership2' ),  
  172. 'url' => $url,  
  173. 'class' => 'wpmui-field-button button',  
  174. ); 
  175. ?> 
  176. </div> 
  177. <?php else : ?> 
  178. <div class="inside group"> 
  179. <p class="ms-italic"> 
  180. <?php _e( 'No members yet.', 'membership2' ); ?> 
  181. </p> 
  182. </div> 
  183. <?php endif; ?> 
  184. </div> 
  185. <?php 
  186.  
  187. /** 
  188. * Echo the news-contents. This function can be overwritten by other views 
  189. * to customize the list. 
  190. * @since 1.0.0 
  191. * @param array $items List of news to display. 
  192. */ 
  193. protected function news_panel_data( $items ) { 
  194. $item = 0; 
  195. $max_items = 10; 
  196. $class = ''; 
  197. ?> 
  198. <table class="ms-list-table widefat"> 
  199. <thead> 
  200. <tr> 
  201. <th><?php _e( 'Date', 'membership2' ); ?></th> 
  202. <th><?php _e( 'Member', 'membership2' ); ?></th> 
  203. <th><?php _e( 'Event', 'membership2' ); ?></th> 
  204. </tr> 
  205. </thead> 
  206. <tbody> 
  207. <?php foreach ( $this->data['events'] as $event ) : 
  208. $item += 1; 
  209. if ( $item > $max_items ) { break; } 
  210. $class = ($class == 'alternate' ? '' : 'alternate' ); 
  211. ?> 
  212. <tr class="<?php echo esc_attr( $class ); ?>"> 
  213. <td><?php 
  214. echo esc_html( 
  215. MS_Helper_Period::format_date( $event->post_modified ) 
  216. ); 
  217. ?></td> 
  218. <td><?php echo esc_html( MS_Model_Member::get_username( $event->user_id ) ); ?></td> 
  219. <td><?php echo esc_html( $event->description ); ?></td> 
  220. </tr> 
  221. <?php endforeach;?> 
  222. </tbody> 
  223. </table> 
  224. <?php 
  225.  
  226. /** 
  227. * Echo a member-list. This function can be overwritten by other views 
  228. * to customize the list. 
  229. * @since 1.0.0 
  230. * @param array $members List of members to display. 
  231. */ 
  232. protected function members_panel_data( $members, $membership_id ) { 
  233. $item = 0; 
  234. $max_items = 10; 
  235. $class = ''; 
  236. $status_types = MS_Model_Relationship::get_status_types(); 
  237. ?> 
  238. <table class="ms-list-table widefat"> 
  239. <thead> 
  240. <th><?php _e( 'Member', 'membership2' ); ?></th> 
  241. <th><?php _e( 'Since', 'membership2' ); ?></th> 
  242. <th><?php _e( 'Status', 'membership2' ); ?></th> 
  243. </thead> 
  244. <tbody> 
  245. <?php foreach ( $this->data['members'] as $member ) : 
  246. $item += 1; 
  247. if ( $item > $max_items ) { break; } 
  248. $class = ($class == 'alternate' ? '' : 'alternate' ); 
  249. $subscription = $member->get_subscription( $membership_id ); 
  250. ?> 
  251. <tr class="<?php echo esc_attr( $class ); ?>"> 
  252. <td><?php echo esc_html( $member->username ); ?></td> 
  253. <td><?php 
  254. echo esc_html( 
  255. MS_Helper_Period::format_date( $subscription->start_date ) 
  256. ); 
  257. ?></td> 
  258. <td><?php echo esc_html( $status_types[ $subscription->status ] ); ?></td> 
  259. </tr> 
  260. <?php endforeach; ?> 
  261. </tbody> 
  262. </table> 
  263. <?php 
  264.  
  265. public function available_content_panel() { 
  266. $membership = $this->data['membership']; 
  267.  
  268. $desc = $membership->get_description(); 
  269. $desc_empty_class = (empty( $desc ) ? '' : 'hidden'); 
  270.  
  271. ?> 
  272. <div class="ms-overview-container"> 
  273. <div class="ms-settings"> 
  274. <div class="ms-overview-top"> 
  275. <div class="ms-settings-desc ms-description membership-description"> 
  276. <?php echo '' . $desc; ?> 
  277. </div> 
  278. <?php 
  279. MS_Helper_Html::html_separator(); 
  280. $this->news_panel(); 
  281. $this->members_panel(); 
  282. ?> 
  283. <div class="clear"></div> 
  284. </div> 
  285. <div class="ms-overview-available-content-wrapper ms-overview-bottom"> 
  286. <h3><i class="ms-img-unlock"></i> <?php _e( 'Available Content', 'membership2' ); ?></h3> 
  287. <div class="ms-description ms-indented-description"> 
  288. <?php 
  289. printf( 
  290. __( 'This is Membership2 which <span class="ms-bold">%s</span> members has access to.', 'membership2' ),  
  291. esc_html( $this->data['membership']->name ) 
  292. ); 
  293. ?> 
  294. </div> 
  295. <div class="inside"> 
  296. <?php $this->available_content_panel_data(); ?> 
  297. </div> 
  298. </div> 
  299. </div> 
  300. </div> 
  301. <?php 
  302.  
  303. protected function available_content_panel_data() { 
  304. $membership = $this->data['membership']; 
  305. $rule_types = MS_Model_Rule::get_rule_types(); 
  306.  
  307. ?> 
  308. <div class="ms-settings ms-group"> 
  309. <div class="ms-group"> 
  310. <?php 
  311. foreach ( $rule_types as $rule_type ) { 
  312. $rule = $membership->get_rule( $rule_type ); 
  313. if ( ! $rule->is_active() ) { continue; } 
  314.  
  315. if ( $rule->has_rules() ) { 
  316. $this->content_box( $rule ); 
  317. ?> 
  318. </div> 
  319. </div> 
  320. <?php 
  321.  
  322. if ( ! $membership->is_free ) { 
  323. $payment_url = esc_url_raw( 
  324. add_query_arg( 
  325. array( 
  326. 'step' => MS_Controller_Membership::STEP_PAYMENT,  
  327. 'edit' => 1,  
  328. ); 
  329.  
  330. MS_Helper_Html::html_element( 
  331. array( 
  332. 'id' => 'setup_payment',  
  333. 'type' => MS_Helper_Html::TYPE_HTML_LINK,  
  334. 'value' => __( 'Payment Options', 'membership2' ),  
  335. 'url' => $payment_url,  
  336. 'class' => 'wpmui-field-button button',  
  337. ); 
  338.  
  339. /** 
  340. * Echo a content list as tag-list. 
  341. * @since 1.0.0 
  342. * @param array $contents List of content items to display. 
  343. */ 
  344. protected function content_box( $rule ) { 
  345. static $row_items = 0; 
  346.  
  347. $rule_titles = MS_Model_Rule::get_rule_type_titles(); 
  348. $title = $rule_titles[ $rule->rule_type ]; 
  349. $contents = (array) $rule->get_contents( null, true ); 
  350.  
  351. $membership_id = $this->data['membership']->id; 
  352.  
  353. $row_items += 1; 
  354. $new_row = ($row_items % 4 === 0); 
  355. $show_sep = (($row_items - 1) % 4 === 0); 
  356.  
  357. if ( $show_sep && $row_items > 1 ) { 
  358. MS_Helper_Html::html_separator(); 
  359. ?> 
  360. <div class="ms-part-4 ms-min-height"> 
  361. <?php if ( ! $new_row ) { MS_Helper_Html::html_separator( 'vertical' ); } ?> 
  362. <div class="ms-bold"> 
  363. <?php printf( '%s (%s):', $title, $rule->count_rules() ); ?> 
  364. </div> 
  365.  
  366. <div class="inside"> 
  367. <ul class="ms-content-tag-list ms-group"> 
  368. <?php 
  369. foreach ( $contents as $content ) { 
  370. if ( $content->access ) { 
  371. MS_Helper_Html::content_tag( $content ); 
  372. ?> 
  373. </ul> 
  374.  
  375. <div class="ms-protection-edit-wrapper"> 
  376. <?php 
  377. $edit_url = MS_Controller_Plugin::get_admin_url( 
  378. 'protection',  
  379. array( 
  380. 'tab' => $rule->rule_type,  
  381. 'membership_id' => $membership_id,  
  382. ); 
  383.  
  384. MS_Helper_Html::html_element( 
  385. array( 
  386. 'id' => 'edit_' . $rule->rule_type,  
  387. 'type' => MS_Helper_Html::TYPE_HTML_LINK,  
  388. 'title' => $title,  
  389. 'value' => sprintf( __( 'Edit %s Access', 'membership2' ), $title ),  
  390. 'url' => $edit_url,  
  391. 'class' => 'wpmui-field-button button',  
  392. ); 
  393. ?> 
  394. </div> 
  395. </div> 
  396. </div> 
  397. <?php 
  398. if ( $new_row ) { 
  399. echo '</div><div class="ms-group">';