PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.5.2
LatePoint – Calendar Booking Plugin for Appointments and Events v5.5.2
5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / models / service_category_model.php
latepoint / lib / models Last commit date
activity_model.php 3 months ago agent_meta_model.php 3 months ago agent_model.php 3 months ago booking_meta_model.php 3 months ago booking_model.php 3 months ago bundle_meta_model.php 3 months ago bundle_model.php 3 months ago cart_item_model.php 3 months ago cart_meta_model.php 3 months ago cart_model.php 3 months ago connector_model.php 3 months ago customer_meta_model.php 3 months ago customer_model.php 1 month ago invoice_model.php 3 months ago join_bundles_services_model.php 3 months ago location_category_model.php 3 months ago location_model.php 3 months ago meta_model.php 3 months ago model.php 3 months ago off_period_model.php 3 months ago order_intent_meta_model.php 3 months ago order_intent_model.php 3 months ago order_item_model.php 3 months ago order_meta_model.php 3 months ago order_model.php 3 months ago otp_model.php 3 months ago payment_request_model.php 3 months ago process_job_model.php 3 months ago process_model.php 3 months ago recurrence_model.php 3 months ago service_category_model.php 3 months ago service_meta_model.php 3 months ago service_model.php 3 months ago session_model.php 3 months ago settings_model.php 3 months ago step_settings_model.php 3 months ago transaction_intent_model.php 3 months ago transaction_model.php 3 months ago transaction_refund_model.php 3 months ago work_period_model.php 3 months ago
service_category_model.php
134 lines
1 <?php
2
3 class OsServiceCategoryModel extends OsModel {
4 public $id,
5 $name,
6 $parent_id,
7 $selection_image_id,
8 $order_number,
9 $short_description,
10 $updated_at,
11 $created_at;
12
13 function __construct( $id = false ) {
14 parent::__construct();
15 $this->table_name = LATEPOINT_TABLE_SERVICE_CATEGORIES;
16 $this->nice_names = array(
17 'name' => __( 'Service Category Name', 'latepoint' ),
18 'short_description' => __( 'Service Category Short Description', 'latepoint' ),
19 'selection_image_id' => __( 'Service Category Selection Image', 'latepoint' ),
20 );
21
22 if ( $id ) {
23 $this->load_by_id( $id );
24 }
25 }
26
27 public function count_services() {
28 $services = new OsServiceModel();
29 $total_services = $services->where( [ 'category_id' => $this->id ] )->should_be_active()->count();
30 $child_categories = new OsServiceCategoryModel();
31 $child_categories = $child_categories->where( [ 'parent_id' => $this->id ] )->get_results_as_models();
32 if ( $child_categories ) {
33 foreach ( $child_categories as $child_category ) {
34 $total_services = $total_services + $child_category->count_services();
35 }
36 }
37 return $total_services;
38 }
39
40 public function delete( $id = false ) {
41 if ( ! $id && isset( $this->id ) ) {
42 $id = $this->id;
43 }
44 if ( $id && $this->db->delete( $this->table_name, array( 'id' => $id ), array( '%d' ) ) ) {
45 $this->db->update( LATEPOINT_TABLE_SERVICES, array( 'category_id' => 0 ), array( 'category_id' => $id ), array( '%d' ) );
46 $this->db->update( $this->table_name, array( 'parent_id' => null ), array( 'parent_id' => $id ), array( '%d' ) );
47 return true;
48 } else {
49 return false;
50 }
51 }
52
53 public function get_selection_image_url() {
54 $default_service_image_url = LATEPOINT_IMAGES_URL . 'service-image.png';
55 return OsImageHelper::get_image_url_by_id( $this->selection_image_id, 'thumbnail', $default_service_image_url );
56 }
57
58 protected function properties_to_validate() {
59 $validations = array(
60 'name' => array( 'presence', 'uniqueness' ),
61 );
62 return $validations;
63 }
64
65 public function index_for_select() {
66 $categories = $this->db->get_results( 'SELECT id, name FROM ' . $this->table_name );
67 $categories_for_select = array();
68
69 $categories_for_select[] = array(
70 'value' => 0,
71 'label' => __( 'Uncategorized', 'latepoint' ),
72 );
73 foreach ( $categories as $category ) {
74 $categories_for_select[] = array(
75 'value' => $category->id,
76 'label' => $category->name,
77 );
78 }
79
80 return $categories_for_select;
81 }
82
83 protected function allowed_params( $role = 'admin' ) {
84 $allowed_params = array(
85 'id',
86 'name',
87 'short_description',
88 'selection_image_id',
89 'parent_id',
90 'order_number',
91 );
92 return $allowed_params;
93 }
94
95
96 protected function params_to_save( $role = 'admin' ) {
97 $params_to_save = array(
98 'id',
99 'name',
100 'short_description',
101 'selection_image_id',
102 'parent_id',
103 'order_number',
104 );
105 return $params_to_save;
106 }
107
108 public function get_active_services( $show_hidden = false, $filtered = false ) {
109 if ( ! isset( $this->active_services ) ) {
110 $services = new OsServiceModel();
111 $services->should_be_active()->where( array( 'category_id' => $this->id ) )->order_by( 'order_number asc' );
112 if ( $filtered ) {
113 $services->filter_allowed_records();
114 }
115 if ( ! $show_hidden ) {
116 $services->should_not_be_hidden();
117 }
118 $this->active_services = $services->get_results_as_models();
119 }
120 return $this->active_services;
121 }
122
123 public function get_services( $filtered = false ) {
124 if ( ! isset( $this->services ) ) {
125 $services = new OsServiceModel();
126 if ( $filtered ) {
127 $services->filter_allowed_records();
128 }
129 $this->services = $services->where( array( 'category_id' => $this->id ) )->order_by( 'order_number asc' )->get_results_as_models();
130 }
131 return $this->services;
132 }
133 }
134