Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 23 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| zeroBSCRM_segmentCondition | |
0.00% |
0 / 22 |
|
0.00% |
0 / 5 |
240 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| init | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
90 | |||
| condition | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
| conditionArg | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| condition_arg_superseded | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /* |
| 3 | * Jetpack CRM |
| 4 | * https://jetpackcrm.com |
| 5 | * V4.5 |
| 6 | */ |
| 7 | |
| 8 | defined( 'ZEROBSCRM_PATH' ) || exit( 0 ); |
| 9 | |
| 10 | /* |
| 11 | * This Parent class allows us to simplify what's needed of each condition into a class below |
| 12 | */ |
| 13 | class zeroBSCRM_segmentCondition { |
| 14 | |
| 15 | public $key = false; |
| 16 | public $condition = false; |
| 17 | public $superseded_keys = array(); |
| 18 | |
| 19 | // killswitch |
| 20 | private $addFilters = true; |
| 21 | |
| 22 | /** |
| 23 | * Jetpack CRM Segment Argument Constructor. |
| 24 | */ |
| 25 | public function __construct( $constructionArgs = array() ) { |
| 26 | |
| 27 | // in children we play with the order here (preConstructor) |
| 28 | // so it's separated into an init func |
| 29 | $this->init( $constructionArgs ); |
| 30 | } |
| 31 | |
| 32 | public function init( $constructionArgs = array() ) { |
| 33 | |
| 34 | global $zbs; |
| 35 | |
| 36 | if ( $this->addFilters && $this->key !== false && is_array( $this->condition ) ) { |
| 37 | |
| 38 | // __ name, category, description etc. |
| 39 | if ( isset( $this->condition['name'] ) ) { |
| 40 | $this->condition['name'] = __( $this->condition['name'], 'zero-bs-crm' ); |
| 41 | } |
| 42 | if ( isset( $this->condition['category'] ) ) { |
| 43 | $this->condition['category'] = __( $this->condition['category'], 'zero-bs-crm' ); |
| 44 | } |
| 45 | if ( isset( $this->condition['description'] ) ) { |
| 46 | $this->condition['description'] = __( $this->condition['description'], 'zero-bs-crm' ); |
| 47 | } |
| 48 | |
| 49 | // add the condition |
| 50 | add_filter( 'zbs_segment_conditions', array( $this, 'condition' ) ); |
| 51 | |
| 52 | // add the query arg builder |
| 53 | add_filter( $zbs->DAL->makeSlug( $this->key ) . '_zbsSegmentArgumentBuild', array( $this, 'conditionArg' ), 10, 3 ); |
| 54 | |
| 55 | // any conditions that this supersedes get filters added too, to ensure backward compatibility (though these should be migrated too) |
| 56 | if ( is_array( $this->superseded_keys ) ) { |
| 57 | |
| 58 | foreach ( $this->superseded_keys as $key ) { |
| 59 | |
| 60 | // add filter |
| 61 | add_filter( $key . '_zbsSegmentArgumentBuild', array( $this, 'condition_arg_superseded' ), 10, 3 ); |
| 62 | |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | public function condition( $conditions = array() ) { |
| 69 | |
| 70 | if ( $this->key !== false && is_array( $this->condition ) ) { |
| 71 | |
| 72 | return array_merge( $conditions, array( $this->key => $this->condition ) ); |
| 73 | |
| 74 | } |
| 75 | |
| 76 | // else don't add |
| 77 | return $conditions; |
| 78 | } |
| 79 | |
| 80 | // note starting arg is ignored (should not have been called multiple times) |
| 81 | public function conditionArg( $startingArg = false, $condition = false, $conditionKeySuffix = false ) { |
| 82 | |
| 83 | global $zbs, $wpdb, $ZBSCRM_t; |
| 84 | |
| 85 | return $startingArg; |
| 86 | } |
| 87 | |
| 88 | /* |
| 89 | * This fires when a superseded condition key has been used |
| 90 | * It'll migrate the key in the db then return as `conditionArg()` |
| 91 | */ |
| 92 | public function condition_arg_superseded( $startingArg = false, $condition = false, $conditionKeySuffix = false ) { |
| 93 | |
| 94 | global $zbs; |
| 95 | |
| 96 | // migrate to avoid future reoccurances |
| 97 | $zbs->DAL->segments->migrate_superseded_condition( $condition['type'], $this->key ); |
| 98 | |
| 99 | // return conditionArg as if normal |
| 100 | return $this->conditionArg( $startingArg, $condition, $conditionKeySuffix ); |
| 101 | } |
| 102 | } |