/**
  * Prepare list items.
  *
  * @since  1.0.0
  */
 public function prepare_items()
 {
     $this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns());
     $per_page = apply_filters('ms_helper_listtable_member_items_per_page', self::DEFAULT_PAGE_SIZE);
     $current_page = $this->get_pagenum();
     $args = array('posts_per_page' => $per_page, 'offset' => ($current_page - 1) * $per_page);
     if (isset($_REQUEST['membership_id'])) {
         $args['membership_id'] = $_REQUEST['membership_id'];
     }
     if (!empty($_REQUEST['s'])) {
         $args['s'] = $_REQUEST['s'];
         $this->search_string = $args['s'];
         $args['posts_per_page'] = -1;
         $args['number'] = false;
         $args['offset'] = 0;
     }
     // Prepare order by statement.
     if (!empty($_REQUEST['orderby']) && !empty($_REQUEST['order'])) {
         $args['orderby'] = $_REQUEST['orderby'];
         $args['order'] = $_REQUEST['order'];
     }
     $total_items = MS_Model_Event::get_event_count($args);
     $this->items = MS_Model_Event::get_events($args);
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page));
     do_action('ms_helper_listtable_event_prepare_items', $args, $this);
 }
    /**
     * Returns the contens of the dialog
     *
     * @since  1.0.0
     *
     * @return object
     */
    public function get_contents($data)
    {
        $subscription = $data['model'];
        $gateways = MS_Model_Gateway::get_gateway_names(false, true);
        if (isset($gateways[$subscription->gateway_id])) {
            $gateway = $gateways[$subscription->gateway_id];
        } elseif (empty($subscription->gateway_id)) {
            $gateway = __('- No Gateway -', 'membership2');
        } else {
            $gateway = '(' . $subscription->gateway_id . ')';
        }
        $events = MS_Model_Event::get_events(array('topic' => 'membership', 'nopaging' => true, 'relationship_id' => $subscription->id));
        $sub_details = array('title' => __('Subscription Details', 'membership2'), 'type' => MS_Helper_Html::TYPE_HTML_TABLE, 'value' => array(array('Subscription ID', $subscription->id), array('Membership', $subscription->get_membership()->name), array('Payment Gateway', $gateway), array('Payment Type', $subscription->get_payment_description(null, true)), array('Subscription Start', $subscription->start_date), array('Subscription End', $subscription->expire_date), array('Status', $subscription->status)), 'field_options' => array('head_col' => true));
        $evt_details = array();
        foreach ($events as $event) {
            $evt_details[] = array('title' => __('Event Details', 'membership2'), 'type' => MS_Helper_Html::TYPE_HTML_TABLE, 'value' => array(array('Event ID', $event->id), array('Date', $event->date), array('Description', $event->description)), 'field_options' => array('head_col' => true));
        }
        ob_start();
        ?>
		<div>
			<?php 
        MS_Helper_Html::html_element($sub_details);
        MS_Helper_Html::html_separator();
        foreach ($evt_details as $detail) {
            MS_Helper_Html::html_element($detail);
        }
        ?>
		</div>
		<?php 
        $html = ob_get_clean();
        return apply_filters('ms_view_member_subscription_to_html', $html);
    }
 /**
  * Display Membership News page.
  *
  * @since  1.0.0
  */
 public function page_news()
 {
     $data = array();
     $data['step'] = $this->get_step();
     $data['action'] = '';
     $data['membership'] = $this->load_membership();
     $args = apply_filters('ms_controller_membership_page_news_event_args', array('posts_per_page' => -1));
     $data['events'] = MS_Model_Event::get_events($args);
     $view = MS_Factory::create('MS_View_Membership_News');
     $view->data = apply_filters('ms_view_membership_news_data', $data, $this);
     $view->render();
 }
 /**
  * Manage user account actions.
  *
  * @since  1.0.0
  * @internal
  */
 public function user_account_manager()
 {
     $action = $this->get_action();
     $member = MS_Model_Member::get_current_member();
     /**
      * These actions are always executed when any user account page loads.
      *
      * @since  1.0.1.0
      */
     do_action('ms_frontend_user_account_manager-' . $action, $this);
     do_action('ms_frontend_user_account_manager', $action, $this);
     if ($this->verify_nonce()) {
         /**
          * The following two actions are only executed when a form was
          * submitted on a user account page.
          *
          * @since  1.0.1.0
          */
         do_action('ms_frontend_user_account_manager_submit-' . $action, $this);
         do_action('ms_frontend_user_account_manager_submit', $action, $this);
     }
     switch ($action) {
         case self::ACTION_EDIT_PROFILE:
             $data = array();
             if ($this->verify_nonce()) {
                 if (is_array($_POST)) {
                     foreach ($_POST as $field => $value) {
                         $member->{$field} = $value;
                     }
                 }
                 try {
                     $member->validate_member_info();
                     $member->save();
                     wp_safe_redirect(esc_url_raw(remove_query_arg('action')));
                     exit;
                 } catch (Exception $e) {
                     $data['errors'] = $e->getMessage();
                 }
             }
             $view = MS_Factory::create('MS_View_Frontend_Profile');
             $data['member'] = $member;
             $data['action'] = $action;
             $view->data = apply_filters('ms_view_frontend_profile_data', $data, $this);
             $view->add_filter('the_content', 'to_html', 1);
             break;
         case self::ACTION_VIEW_INVOICES:
             $data['invoices'] = MS_Model_Invoice::get_public_invoices($member->id);
             $view = MS_Factory::create('MS_View_Frontend_Invoices');
             $view->data = apply_filters('ms_view_frontend_frontend_invoices', $data, $this);
             $view->add_filter('the_content', 'to_html', 1);
             break;
         case self::ACTION_VIEW_ACTIVITIES:
             $data['events'] = MS_Model_Event::get_events(array('author' => $member->id, 'posts_per_page' => -1));
             $view = MS_Factory::create('MS_View_Frontend_Activities');
             $view->data = apply_filters('ms_view_frontend_frontend_activities', $data, $this);
             $view->add_filter('the_content', 'to_html', 1);
             break;
         case self::ACTION_VIEW_RESETPASS:
             /**
              * Reset password action.
              * This action is accessed via the password-reset email
              * @see  class-ms-controller-dialog.php
              *
              * The action is targeted to the Account-page but actually calls
              * the Login-Shortcode.
              */
             $view = MS_Factory::create('MS_View_Shortcode_Login');
             $view->data = array('action' => 'resetpass');
             $view->add_filter('the_content', 'to_html', 1);
             break;
         default:
             // Do nothing...
             break;
     }
 }
 /**
  * Membership account page shortcode callback function.
  *
  * @since  1.0.0
  *
  * @param mixed[] $atts Shortcode attributes.
  */
 public function membership_account($atts)
 {
     MS_Helper_Shortcode::did_shortcode(MS_Helper_Shortcode::SCODE_MS_ACCOUNT);
     $data = apply_filters('ms_controller_shortcode_membership_account_atts', shortcode_atts(array('show_membership' => true, 'show_membership_change' => true, 'membership_title' => __('Your Membership', 'membership2'), 'membership_change_label' => __('Change', 'membership2'), 'show_profile' => true, 'show_profile_change' => true, 'profile_title' => __('Personal details', 'membership2'), 'profile_change_label' => __('Edit', 'membership2'), 'show_invoices' => true, 'limit_invoices' => 10, 'show_all_invoices' => true, 'invoices_title' => __('Invoices', 'membership2'), 'invoices_details_label' => __('View all', 'membership2'), 'show_activity' => true, 'limit_activities' => 10, 'show_all_activities' => true, 'activity_title' => __('Activities', 'membership2'), 'activity_details_label' => __('View all', 'membership2')), $atts));
     $data['show_membership'] = lib3()->is_true($data['show_membership']);
     $data['show_membership_change'] = lib3()->is_true($data['show_membership_change']);
     $data['show_profile'] = lib3()->is_true($data['show_profile']);
     $data['show_profile_change'] = lib3()->is_true($data['show_profile_change']);
     $data['show_invoices'] = lib3()->is_true($data['show_invoices']);
     $data['show_all_invoices'] = lib3()->is_true($data['show_all_invoices']);
     $data['show_activity'] = lib3()->is_true($data['show_activity']);
     $data['show_all_activities'] = lib3()->is_true($data['show_all_activities']);
     $data['limit_invoices'] = absint($data['limit_invoices']);
     $data['limit_activities'] = absint($data['limit_activities']);
     $data['member'] = MS_Model_Member::get_current_member();
     $data['membership'] = array();
     $subscriptions = MS_Model_Relationship::get_subscriptions(array('user_id' => $data['member']->id, 'status' => 'all'));
     if (is_array($subscriptions)) {
         foreach ($subscriptions as $subscription) {
             // Do not display system-memberships in Account
             if ($subscription->is_system()) {
                 continue;
             }
             // Do not display deactivated memberships in Account
             if ($subscription->get_status() == MS_Model_Relationship::STATUS_DEACTIVATED) {
                 continue;
             }
             $data['subscription'][] = $subscription;
         }
     }
     $data['invoices'] = MS_Model_Invoice::get_public_invoices($data['member']->id, $data['limit_invoices']);
     $data['events'] = MS_Model_Event::get_events(array('author' => $data['member']->id, 'posts_per_page' => $data['limit_activities']));
     $view = MS_Factory::create('MS_View_Shortcode_Account');
     $view->data = apply_filters('ms_view_shortcode_account_data', $data, $this);
     return $view->to_html();
 }