activity_model.php
1 year ago
agent_meta_model.php
1 year ago
agent_model.php
1 year ago
booking_meta_model.php
1 year ago
booking_model.php
1 year ago
bundle_meta_model.php
1 year ago
bundle_model.php
1 year ago
cart_item_model.php
1 year ago
cart_meta_model.php
1 year ago
cart_model.php
1 year ago
connector_model.php
1 year ago
customer_meta_model.php
1 year ago
customer_model.php
9 months ago
invoice_model.php
1 year ago
join_bundles_services_model.php
1 year ago
location_category_model.php
9 months ago
location_model.php
1 year ago
meta_model.php
1 year ago
model.php
9 months ago
off_period_model.php
1 year ago
order_intent_meta_model.php
1 year ago
order_intent_model.php
9 months ago
order_item_model.php
1 year ago
order_meta_model.php
1 year ago
order_model.php
1 year ago
otp_model.php
9 months ago
payment_request_model.php
1 year ago
process_job_model.php
1 year ago
process_model.php
1 year ago
recurrence_model.php
1 year ago
service_category_model.php
9 months ago
service_meta_model.php
1 year ago
service_model.php
9 months ago
session_model.php
1 year ago
settings_model.php
1 year ago
step_settings_model.php
1 year ago
transaction_intent_model.php
1 year ago
transaction_model.php
1 year ago
transaction_refund_model.php
1 year ago
work_period_model.php
1 year ago
service_category_model.php
117 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 | if($id){ |
| 22 | $this->load_by_id($id); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | public function count_services(){ |
| 27 | $services = new OsServiceModel(); |
| 28 | $total_services = $services->where(['category_id' => $this->id])->should_be_active()->count(); |
| 29 | $child_categories = new OsServiceCategoryModel(); |
| 30 | $child_categories = $child_categories->where(['parent_id' => $this->id])->get_results_as_models(); |
| 31 | if($child_categories){ |
| 32 | foreach($child_categories as $child_category){ |
| 33 | $total_services = $total_services + $child_category->count_services(); |
| 34 | } |
| 35 | } |
| 36 | return $total_services; |
| 37 | } |
| 38 | |
| 39 | public function delete($id = false){ |
| 40 | if(!$id && isset($this->id)){ |
| 41 | $id = $this->id; |
| 42 | } |
| 43 | if($id && $this->db->delete( $this->table_name, array('id' => $id), array( '%d' ))){ |
| 44 | $this->db->update(LATEPOINT_TABLE_SERVICES, array('category_id' => 0), array( 'category_id' => $id ), array( '%d' ) ); |
| 45 | $this->db->update($this->table_name, array('parent_id' => NULL), array( 'parent_id' => $id ), array( '%d' ) ); |
| 46 | return true; |
| 47 | }else{ |
| 48 | return false; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | public function get_selection_image_url(){ |
| 53 | $default_service_image_url = LATEPOINT_IMAGES_URL . 'service-image.png'; |
| 54 | return OsImageHelper::get_image_url_by_id($this->selection_image_id, 'thumbnail', $default_service_image_url); |
| 55 | } |
| 56 | |
| 57 | protected function properties_to_validate(){ |
| 58 | $validations = array( |
| 59 | 'name' => array('presence', 'uniqueness'), |
| 60 | ); |
| 61 | return $validations; |
| 62 | } |
| 63 | |
| 64 | public function index_for_select(){ |
| 65 | $categories = $this->db->get_results("SELECT id, name FROM ".$this->table_name); |
| 66 | $categories_for_select = array(); |
| 67 | |
| 68 | $categories_for_select[] = array('value' => 0, 'label' => __('Uncategorized', 'latepoint')); |
| 69 | foreach($categories as $category){ |
| 70 | $categories_for_select[] = array('value' => $category->id, 'label' => $category->name); |
| 71 | } |
| 72 | |
| 73 | return $categories_for_select; |
| 74 | } |
| 75 | |
| 76 | protected function allowed_params($role = 'admin'){ |
| 77 | $allowed_params = array('id', |
| 78 | 'name', |
| 79 | 'short_description', |
| 80 | 'selection_image_id', |
| 81 | 'parent_id', |
| 82 | 'order_number'); |
| 83 | return $allowed_params; |
| 84 | } |
| 85 | |
| 86 | |
| 87 | protected function params_to_save($role = 'admin'){ |
| 88 | $params_to_save = array('id', |
| 89 | 'name', |
| 90 | 'short_description', |
| 91 | 'selection_image_id', |
| 92 | 'parent_id', |
| 93 | 'order_number'); |
| 94 | return $params_to_save; |
| 95 | } |
| 96 | |
| 97 | public function get_active_services($show_hidden = false, $filtered = false){ |
| 98 | if(!isset($this->active_services)){ |
| 99 | $services = new OsServiceModel(); |
| 100 | $services->should_be_active()->where(array('category_id'=> $this->id))->order_by('order_number asc'); |
| 101 | if($filtered) $services->filter_allowed_records(); |
| 102 | if(!$show_hidden) $services->should_not_be_hidden(); |
| 103 | $this->active_services = $services->get_results_as_models(); |
| 104 | } |
| 105 | return $this->active_services; |
| 106 | } |
| 107 | |
| 108 | public function get_services($filtered = false){ |
| 109 | if(!isset($this->services)){ |
| 110 | $services = new OsServiceModel(); |
| 111 | if($filtered) $services->filter_allowed_records(); |
| 112 | $this->services = $services->where(array('category_id'=> $this->id))->order_by('order_number asc')->get_results_as_models(); |
| 113 | } |
| 114 | return $this->services; |
| 115 | } |
| 116 | |
| 117 | } |