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
1 year 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
location_category_model.php
121 lines
| 1 | <?php |
| 2 | |
| 3 | class OsLocationCategoryModel extends OsModel{ |
| 4 | public $id, |
| 5 | $name, |
| 6 | $parent_id, |
| 7 | $selection_image_id, |
| 8 | $order_number, |
| 9 | $short_description; |
| 10 | |
| 11 | function __construct($id = false){ |
| 12 | parent::__construct(); |
| 13 | $this->table_name = LATEPOINT_TABLE_LOCATION_CATEGORIES; |
| 14 | $this->nice_names = array( |
| 15 | 'name' => __('Location Category Name', 'latepoint'), |
| 16 | 'short_description' => __('Location Category Short Description', 'latepoint'), |
| 17 | 'selection_image_id' => __('Location Category Selection Image', 'latepoint')); |
| 18 | |
| 19 | if($id){ |
| 20 | $this->load_by_id($id); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | public function generate_data_vars(): array { |
| 25 | return [ |
| 26 | 'id' => $this->id, |
| 27 | 'name' => $this->name |
| 28 | ]; |
| 29 | } |
| 30 | |
| 31 | public function count_locations(){ |
| 32 | $location = new OsLocationModel(); |
| 33 | $total_location = $location->filter_allowed_records()->where(['category_id' => $this->id])->should_be_active()->count(); |
| 34 | $child_categories = new OsLocationCategoryModel(); |
| 35 | $child_categories = $child_categories->where(['parent_id' => $this->id])->get_results_as_models(); |
| 36 | if($child_categories){ |
| 37 | foreach($child_categories as $child_category){ |
| 38 | $total_location = $total_location + $child_category->count_locations(); |
| 39 | } |
| 40 | } |
| 41 | return $total_location; |
| 42 | } |
| 43 | |
| 44 | public function delete($id = false){ |
| 45 | if(!$id && isset($this->id)){ |
| 46 | $id = $this->id; |
| 47 | } |
| 48 | if($id && $this->db->delete( $this->table_name, array('id' => $id), array( '%d' ))){ |
| 49 | $this->db->update(LATEPOINT_TABLE_SERVICES, array('category_id' => 0), array( 'category_id' => $id ), array( '%d' ) ); |
| 50 | $this->db->update($this->table_name, array('parent_id' => NULL), array( 'parent_id' => $id ), array( '%d' ) ); |
| 51 | return true; |
| 52 | }else{ |
| 53 | return false; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | public function get_selection_image_url(){ |
| 58 | $default_location_image_url = LATEPOINT_IMAGES_URL . 'location-image.png'; |
| 59 | return OsImageHelper::get_image_url_by_id($this->selection_image_id, 'thumbnail', $default_location_image_url); |
| 60 | } |
| 61 | |
| 62 | protected function properties_to_validate(){ |
| 63 | $validations = array( |
| 64 | 'name' => array('presence', 'uniqueness'), |
| 65 | ); |
| 66 | return $validations; |
| 67 | } |
| 68 | |
| 69 | public function index_for_select(){ |
| 70 | $categories = $this->db->get_results("SELECT id, name FROM ".$this->table_name); |
| 71 | $categories_for_select = array(); |
| 72 | |
| 73 | $categories_for_select[] = array('value' => 0, 'label' => __('Not categorized', 'latepoint')); |
| 74 | foreach($categories as $category){ |
| 75 | $categories_for_select[] = array('value' => $category->id, 'label' => $category->name); |
| 76 | } |
| 77 | |
| 78 | return $categories_for_select; |
| 79 | } |
| 80 | |
| 81 | protected function allowed_params($role = 'admin'){ |
| 82 | $allowed_params = array('id', |
| 83 | 'name', |
| 84 | 'short_description', |
| 85 | 'selection_image_id', |
| 86 | 'parent_id', |
| 87 | 'order_number'); |
| 88 | return $allowed_params; |
| 89 | } |
| 90 | |
| 91 | |
| 92 | protected function params_to_save($role = 'admin'){ |
| 93 | $params_to_save = array('id', |
| 94 | 'name', |
| 95 | 'short_description', |
| 96 | 'selection_image_id', |
| 97 | 'parent_id', |
| 98 | 'order_number'); |
| 99 | return $params_to_save; |
| 100 | } |
| 101 | |
| 102 | public function get_active_locations($filter_allowed_records = false){ |
| 103 | if(!isset($this->active_locations)){ |
| 104 | $location = new OsLocationModel(); |
| 105 | if($filter_allowed_records) $location->filter_allowed_records(); |
| 106 | $location->should_be_active()->where(array('category_id'=> $this->id))->order_by('order_number asc'); |
| 107 | $this->active_locations = $location->get_results_as_models(); |
| 108 | } |
| 109 | return $this->active_locations; |
| 110 | } |
| 111 | |
| 112 | protected function get_locations($filter_allowed_records = false){ |
| 113 | if(!isset($this->locations)){ |
| 114 | $location = new OsLocationModel(); |
| 115 | if($filter_allowed_records) $location->filter_allowed_records(); |
| 116 | $this->locations = $location->where(array('category_id'=> $this->id))->order_by('order_number asc')->get_results_as_models(); |
| 117 | } |
| 118 | return $this->locations; |
| 119 | } |
| 120 | |
| 121 | } |