CodeIgniter 3 app for dinbestehjelper.no. Excludes vendor/, local backup folders (new/, archive/, archived/) and DB dumps (*.sql) via .gitignore. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01P16ttGUge8zj91dm6WrmEb
228 lines
7.2 KiB
PHP
228 lines
7.2 KiB
PHP
<?php
|
|
class Group_model extends CI_Model {
|
|
|
|
function __construct(){
|
|
parent::__construct();
|
|
}
|
|
|
|
public function createGroup($groupArray){
|
|
$this->load->database();
|
|
$query = $this->db->query("INSERT INTO workgroups(
|
|
group_name,
|
|
group_info,
|
|
skills,
|
|
group_notes,
|
|
is_active
|
|
) VALUES(
|
|
'".$groupArray['group_name']."',
|
|
'".$groupArray['group_info']."',
|
|
'".$groupArray['skills']."',
|
|
'".$groupArray['group_notes']."',
|
|
'".$groupArray['is_active']."'
|
|
);");
|
|
}
|
|
|
|
public function getAllGroups(){
|
|
$this->load->database();
|
|
$this->load->model('Group_model');
|
|
$this->load->model('Service_model');
|
|
|
|
$query = $this->db->query('SELECT * FROM workgroups ORDER BY group_name DESC;');
|
|
|
|
if($query->num_rows() > 0){
|
|
$resultArray = array();
|
|
foreach($query->result() as $resultItem){
|
|
$resultItemTmp = (array)$resultItem;
|
|
|
|
if($resultItem->skills != ''){
|
|
$serviceArray = array();
|
|
$serviceIds = unserialize($resultItem->skills);
|
|
foreach($serviceIds as $serviceItem){
|
|
$serviceArray[] = $this->Service_model->getServiceById($serviceItem);
|
|
}
|
|
$resultItemTmp['skillList'] = $serviceArray;
|
|
}
|
|
$resultArray[] = (object)$resultItemTmp;
|
|
}
|
|
return $resultArray;
|
|
}
|
|
else{
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public function getAllActiveGroups(){
|
|
$this->load->database();
|
|
$this->load->model('Group_model');
|
|
$this->load->model('Service_model');
|
|
|
|
$query = $this->db->query('SELECT * FROM workgroups WHERE is_active = "1" && is_deleted != "1" ORDER BY group_id ASC;');
|
|
|
|
if($query->num_rows() > 0){
|
|
$resultArray = array();
|
|
foreach($query->result() as $resultItem){
|
|
$resultItemTmp = (array)$resultItem;
|
|
|
|
if($resultItem->skills != ''){
|
|
$serviceArray = array();
|
|
$serviceIds = unserialize($resultItem->skills);
|
|
foreach($serviceIds as $serviceItem){
|
|
$serviceArray[] = $this->Service_model->getServiceById($serviceItem);
|
|
}
|
|
$resultItemTmp['skillList'] = $serviceArray;
|
|
}
|
|
$resultArray[] = (object)$resultItemTmp;
|
|
}
|
|
return $resultArray;
|
|
}
|
|
else{
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public function getGroupById($group_id){
|
|
$this->load->database();
|
|
$query = $this->db->query('SELECT * FROM workgroups WHERE group_id = "'.$group_id.'" LIMIT 1;');
|
|
|
|
if($query->num_rows() == 1){
|
|
return $query->result()[0];
|
|
}
|
|
else{
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function updateGroup($group_id, $groupArray){
|
|
$this->load->database();
|
|
|
|
foreach($groupArray as $propertyKey => $propertyValue){
|
|
$query = $this->db->query("UPDATE workgroups SET ".$propertyKey." = '".$propertyValue."' WHERE group_id = '".$group_id."';");
|
|
}
|
|
}
|
|
|
|
public function availableGroupsByServiceId($serviceCategory){
|
|
$this->load->database();
|
|
$this->load->model('Group_model');
|
|
$this->load->model('Service_model');
|
|
|
|
$groupArray = array();
|
|
|
|
$activeGroups = $this->Group_model->getAllActiveGroups();
|
|
$selectedServiceCategory = 0;
|
|
|
|
if(is_array($activeGroups)){
|
|
foreach($activeGroups as $activeGroupItem){
|
|
$serviceIds = unserialize($activeGroupItem->skills);
|
|
foreach($serviceIds as $serviceIdItem){
|
|
$selectedService = $this->Service_model->getServiceById($serviceIdItem);
|
|
$selectedServiceCategory = $selectedService->service_group;
|
|
if($selectedServiceCategory == $serviceCategory){
|
|
$groupArray[] = $activeGroupItem->group_id;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $groupArray;
|
|
}
|
|
|
|
|
|
public function getAvailableGroup($bookingDate, $serviceCategory){
|
|
$this->load->database();
|
|
$this->load->model('Group_model');
|
|
|
|
$activeServiceGroupArray = $this->Group_model->availableGroupsByServiceId($serviceCategory);
|
|
|
|
$activeServiceGroupString = '';
|
|
if(!empty($activeServiceGroupArray)){
|
|
$arrayIndex = 1;
|
|
$collectedServiceGroupArrayTmp = array();
|
|
foreach($activeServiceGroupArray as $activeServiceGroupArrayItem){
|
|
if($arrayIndex != sizeof($activeServiceGroupArray)){
|
|
if(!in_array($activeServiceGroupArrayItem, $collectedServiceGroupArrayTmp)){
|
|
$collectedServiceGroupArrayTmp[] = $activeServiceGroupArrayItem;
|
|
}
|
|
}
|
|
else{
|
|
if(!in_array($activeServiceGroupArrayItem, $collectedServiceGroupArrayTmp)){
|
|
$collectedServiceGroupArrayTmp[] = $activeServiceGroupArrayItem;
|
|
}
|
|
}
|
|
$arrayIndex++;
|
|
}
|
|
|
|
}
|
|
$activeServiceGroupString .= implode(', ', $collectedServiceGroupArrayTmp);
|
|
|
|
$query = $this->db->query('
|
|
SELECT * FROM
|
|
(SELECT
|
|
results.group_id,
|
|
SEC_TO_TIME( SUM( TIME_TO_SEC( TIME(results.difference) ) ) ) AS diff FROM
|
|
(SELECT
|
|
booking_id,
|
|
guest_name,
|
|
guest_email,
|
|
guest_phone,
|
|
bookings.group_id,
|
|
booking_date,
|
|
booking_start_time,
|
|
booking_finish_time,
|
|
service_ids,
|
|
guest_confirmed,
|
|
guest_confirm_code,
|
|
group_name,
|
|
group_info,
|
|
group_profile_img,
|
|
skills,
|
|
group_notes,
|
|
is_active,
|
|
is_deleted,
|
|
TIMEDIFF(booking_finish_time, booking_start_time) AS difference
|
|
FROM bookings JOIN workgroups ON bookings.group_id = workgroups.group_id
|
|
WHERE is_active = 1 AND is_deleted = 0
|
|
AND booking_date = "'.$bookingDate.'"
|
|
AND bookings.group_id IN ('.$activeServiceGroupString.')
|
|
) as results
|
|
GROUP BY results.group_id
|
|
ORDER BY SEC_TO_TIME( SUM( TIME_TO_SEC( TIME(results.difference) ) ) ) DESC
|
|
) AS groupedResults
|
|
JOIN workgroups ON groupedResults.group_id = workgroups.group_id
|
|
;');
|
|
if($query->num_rows() > 0){
|
|
return $query->result()[0];
|
|
}
|
|
else{
|
|
$activeGroups = $this->Group_model->getAllActiveGroups();
|
|
$firstGroup = $activeGroups[0];
|
|
return $firstGroup;
|
|
}
|
|
|
|
return $isServiceActive;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
?>
|