Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
Client_Portal_Endpoint
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 6
110
0.00% covered (danger)
0.00%
0 / 1
 register_endpoint
n/a
0 / 0
n/a
0 / 0
0
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 perform_endpoint_action
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
20
 output_html
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
6
 before_endpoint_actions
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 pre_content_action
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 post_content_action
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/*
3* Jetpack CRM
4* https://jetpackcrm.com
5*
6* Client Portal Endpoint
7*
8*/
9namespace Automattic\JetpackCRM;
10
11defined( 'ZEROBSCRM_PATH' ) || exit( 0 );
12
13/**
14 *
15 * This class represents a single Client Portal endpoint (e.g. Quotes)
16 */
17#[\AllowDynamicProperties]
18abstract class Client_Portal_Endpoint {
19    public $portal                       = null;
20    public $template_name                = null;
21    public $should_check_user_permission = true;
22    public $slug                         = null;
23    public $name                         = null;
24    public $icon                         = null;
25    public $hide_from_menu               = null;
26    public $hide_from_settings_page      = false;
27    public $add_rewrite_endpoint         = null;
28    public $menu_order                   = null;
29    public $template_args                = array();
30    public $template_path                = '';
31    public $default_template_path        = '';
32    /**
33     * Option param value used by some endpoints
34     *
35     * @var string
36     */
37    public $param_value;
38
39    abstract public static function register_endpoint( $endpoints, $client_portal );
40
41    public function __construct( $portal ) {
42        $this->portal = $portal;
43    }
44
45    /**
46     * This function will perform all actions from this endpoint, including
47     * the permission check.
48     */
49    public function perform_endpoint_action() {
50        // Some endpoints from the Client Portal bypass user permissions and
51        // allow users that are not logged in to see the content.
52        // e.g. Invoices with easy links.
53        if ( $this->should_check_user_permission ) {
54            if ( ! is_user_logged_in() ) {
55                return $this->portal->get_template( 'login.php' );
56            }
57
58            if ( ! $this->portal->is_user_enabled() ) {
59                return $this->portal->get_template( 'disabled.php' );
60            }
61        }
62
63        $this->pre_content_action();
64        $this->output_html();
65        $this->post_content_action();
66    }
67
68    public function output_html() {
69        if ( $this->template_name != '' ) {
70            $this->portal->get_template(
71                $this->template_name,
72                $this->template_args,
73                $this->template_path,
74                $this->default_template_path
75            );
76        }
77    }
78
79    /**
80     * This action gets called before any action (even permission checks)
81     * are performed by this endpoint.
82     */
83    public function before_endpoint_actions() {
84        // Do nothing. Should be overwritten by child classes if needed.
85    }
86
87    /**
88     * This action gets called before any rendering is made by the endpoint.
89     */
90    public function pre_content_action() {
91        // Do nothing. Should be overwritten by child classes if needed.
92    }
93
94    /**
95     * This action gets called after all rendering is finished.
96     */
97    public function post_content_action() {
98        // Do nothing. Should be overwritten by child classes if needed.
99    }
100}