| 1 |
<?php |
| 2 |
|
| 3 |
namespace Templately\Builder\Conditions; |
| 4 |
|
| 5 |
use Templately\Builder\ThemeBuilder; |
| 6 |
|
| 7 |
/** |
| 8 |
* Code Inspiration from Elementor |
| 9 |
*/ |
| 10 |
abstract class Condition { |
| 11 |
/** |
| 12 |
* @var ThemeBuilder |
| 13 |
*/ |
| 14 |
protected $builder; |
| 15 |
|
| 16 |
protected $controls = []; |
| 17 |
protected $sub_conditions = []; |
| 18 |
|
| 19 |
public function __construct( $args = [] ) { |
| 20 |
$this->builder = templately()->theme_builder; |
| 21 |
|
| 22 |
$this->register_sub_conditions(); |
| 23 |
$this->register_controls(); |
| 24 |
} |
| 25 |
|
| 26 |
protected function register_sub_conditions() { |
| 27 |
} |
| 28 |
|
| 29 |
protected function register_controls() { |
| 30 |
} |
| 31 |
|
| 32 |
public function get_priority(): int { |
| 33 |
return 100; |
| 34 |
} |
| 35 |
|
| 36 |
public function get_config(): array { |
| 37 |
$config = []; |
| 38 |
|
| 39 |
$config['label'] = $this->get_label(); |
| 40 |
$config['plural_label'] = $this->get_all_label(); |
| 41 |
$config['sub_conditions'] = $this->get_sub_conditions(); |
| 42 |
$config['type'] = $this->get_type(); |
| 43 |
$config['name'] = $this->get_name(); |
| 44 |
|
| 45 |
if ( ! empty( $this->get_controls() ) ) { |
| 46 |
$config['controls'] = $this->get_controls(); |
| 47 |
} |
| 48 |
|
| 49 |
return $config; |
| 50 |
} |
| 51 |
|
| 52 |
abstract public function get_label(): string; |
| 53 |
|
| 54 |
public function get_all_label(): string { |
| 55 |
return $this->get_label(); |
| 56 |
} |
| 57 |
|
| 58 |
public function get_sub_conditions() { |
| 59 |
return $this->sub_conditions; |
| 60 |
} |
| 61 |
|
| 62 |
abstract public function get_type(): string; |
| 63 |
|
| 64 |
abstract public function get_name(): string; |
| 65 |
|
| 66 |
private function get_controls() { |
| 67 |
return $this->controls; |
| 68 |
} |
| 69 |
|
| 70 |
public function check( $args = [] ): bool { |
| 71 |
return true; |
| 72 |
} |
| 73 |
|
| 74 |
public function add_control( $control_name, $control ) { |
| 75 |
$this->controls[ $control_name ] = $control; |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* @param Condition $condition |
| 80 |
*/ |
| 81 |
public function register_sub_condition( Condition $condition ) { |
| 82 |
$this->sub_conditions[] = $condition->get_name(); |
| 83 |
$this->builder::$conditions_manager->register_condition_instance( $condition ); |
| 84 |
} |
| 85 |
} |