Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 35 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| zeroBS__Metabox_ExtSource | |
0.00% |
0 / 34 |
|
0.00% |
0 / 2 |
210 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 29 |
|
0.00% |
0 / 1 |
110 | |||
| html | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | /* |
| 3 | * Jetpack CRM |
| 4 | * https://jetpackcrm.com |
| 5 | * V3.0 |
| 6 | * |
| 7 | * Copyright 2020 Automattic |
| 8 | * |
| 9 | * Date: 20/02/2019 |
| 10 | */ |
| 11 | |
| 12 | defined( 'ZEROBSCRM_PATH' ) || exit( 0 ); |
| 13 | |
| 14 | /* |
| 15 | ====================================================== |
| 16 | Create External Source Metabox |
| 17 | ====================================================== */ |
| 18 | class zeroBS__Metabox_ExtSource extends zeroBS__Metabox { |
| 19 | |
| 20 | private $acceptableTypes = array( 'contact', 'company', 'transaction', 'invoice' ); |
| 21 | |
| 22 | /** |
| 23 | * The object type ID using this metabox. |
| 24 | * |
| 25 | * @since 6.2.0 |
| 26 | * @var int |
| 27 | */ |
| 28 | private $objTypeID; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.PropertyNotSnakeCase |
| 29 | |
| 30 | public function __construct( $plugin_file, $objType = 'contact', $metaboxScreen = 'zbs-add-edit-contact-edit' ) { |
| 31 | |
| 32 | global $zbs; |
| 33 | |
| 34 | // set these |
| 35 | // DAL3 switched for objType $this->postType = 'zerobs_customer'; |
| 36 | $this->objType = 'contact'; |
| 37 | $this->objTypeID = ZBS_TYPE_CONTACT; |
| 38 | $this->metaboxID = 'zerobs-externalsource'; |
| 39 | $this->metaboxTitle = __( 'External Source', 'zero-bs-crm' ); |
| 40 | $this->metaboxScreen = 'zbs-add-edit-contact-edit'; // DEFAULT (overriden by metaboxScreens below) |
| 41 | // Better than this, is initiating multiple of this class with diff screens/objtypes |
| 42 | // ... because that presevers obj type unlike this solution: $this->metaboxScreens = array('zbs-add-edit-contact-edit','zbs-add-edit-company-edit'); // (since v3.0 we can add multiple, overrides metaboxScreen) |
| 43 | $this->metaboxArea = 'side'; |
| 44 | $this->metaboxLocation = 'low'; |
| 45 | $this->saveOrder = 1; |
| 46 | $this->capabilities = array( |
| 47 | |
| 48 | 'can_hide' => false, // can be hidden |
| 49 | 'areas' => array( 'side' ), // areas can be dragged to - normal side = only areas currently |
| 50 | 'can_accept_tabs' => true, // can/can't accept tabs onto it |
| 51 | 'can_become_tab' => false, // can be added as tab |
| 52 | 'can_minimise' => true, // can be minimised |
| 53 | 'can_move' => true, // can be moved |
| 54 | |
| 55 | ); |
| 56 | |
| 57 | // Catch any passed params as overrides |
| 58 | // (this allows us to have multiple initialised (e.g. one for contacts, one co's)) |
| 59 | if ( isset( $objType ) ) { |
| 60 | $this->objType = $objType; |
| 61 | } |
| 62 | if ( isset( $objType ) ) { |
| 63 | $this->objTypeID = $zbs->DAL->objTypeID( $this->objType ); |
| 64 | } |
| 65 | if ( isset( $metaboxScreen ) ) { |
| 66 | $this->metaboxScreen = $metaboxScreen; |
| 67 | } |
| 68 | |
| 69 | // set typeint based on type |
| 70 | $this->typeInt = $zbs->DAL->objTypeID( $this->objType ); // contact -> ZBS_TYPE_CONTACT = 1 |
| 71 | |
| 72 | #} Only load if is legit. |
| 73 | |
| 74 | // also hide if "new" (not edit) - as defies point of extsource |
| 75 | $isEdit = false; |
| 76 | if ( isset( $_GET['action'] ) && $_GET['action'] == 'edit' && isset( $_GET['zbsid'] ) && ! empty( $_GET['zbsid'] ) ) { |
| 77 | $isEdit = true; |
| 78 | } |
| 79 | |
| 80 | if ( in_array( $this->objType, $this->acceptableTypes ) && $isEdit ) { |
| 81 | // call this |
| 82 | $this->initMetabox(); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | public function html( $obj, $metabox ) { |
| 87 | |
| 88 | global $zbs; |
| 89 | |
| 90 | // Only load if is legit. |
| 91 | if ( in_array( $this->objType, $this->acceptableTypes ) ) { |
| 92 | |
| 93 | $object_id = -1; if ( is_array( $obj ) && isset( $obj['id'] ) ) { |
| 94 | $object_id = (int) $obj['id']; |
| 95 | } |
| 96 | |
| 97 | // use centralised function to draw |
| 98 | jpcrm_render_external_sources_by_id( $object_id, $this->objTypeID ); |
| 99 | |
| 100 | } // / only load if post type |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * End of Create External Source Metabox |
| 106 | */ |