db->select('SCDate'); $this->db->where('SCDate', $arrayDetails['SCDate']); $this->db->where('SessionID', $arrayDetails['SessionID']); if($this->db->get(SESSIONSCHEDULE)->first_row()){ $result['sessionStatus'] = false; $result['message'] ="This same session/date is already exist."; } else{ $insertMaster['SCDate']=$arrayDetails['SCDate']; $insertMaster['SessionID']=$arrayDetails['SessionID']; $insertMaster['CreatedBy']=$arrayDetails['CreatedBy']; $insertMaster['IsActive']=$arrayDetails['IsActive']; $insertMaster['CreatedOn']=$arrayDetails['CreatedOn']; $this->db->insert(SESSIONSCHEDULE, $insertMaster); if ($this->db->affected_rows() == '1') { $insertDetails['SessionID']=$this->db->insert_id(); foreach ($Timings['Timings'] as $row1){ $insertDetails['StartTime']=$row1['startTime']; $insertDetails['EndTime']=$row1['endTime']; $insertDetails['CreatedBy']=$arrayDetails['CreatedBy']; $insertDetails['IsActive']=$arrayDetails['IsActive']; $insertDetails['CreatedOn']=$arrayDetails['CreatedOn']; $this->db->insert(SESSIONSCHEDULEDETAILS, $insertDetails); } $result['sessionStatus'] = true; $result['message'] = "Schedules added successfully"; } else { $result['sessionStatus'] = false; $result['message'] = "Something went wrong.please try again"; } } return $result; } /* * Get session schedule master details * created by kms * */ public function getSessionSchedule() { $this->db->select('SS.SCID,SM.SessionName,SM.SessionID,SS.IsActive,SS.SCDate'); $this->db->from(SESSIONSCHEDULE.' as SS'); $this->db->join(SESSIONMASTER.' as SM', 'SS.SessionID = SM.SessionID'); // $this->db->where('SM.IsActive','1'); $this->db->order_by('SS.SCID','DESC'); $sessionDetails = $this->db->get(); $result_array = array(); if($sessionDetails->result()){ foreach ($sessionDetails->result() as $row) { $scheduleDetails['SCID'] = $row->SCID; $scheduleDetails['SessionName'] = $row->SessionName; $scheduleDetails['SessionID'] = $row->SessionID; $scheduleDetails['SCDate'] = $row->SCDate; // $scheduleDetails['ScheduleDate'] = $row->SCDate; $scheduleDetails['IsActive'] = $row->IsActive; $scheduleDetails['ScheduleDetails'] = $this->getSessionScheduleDetails($row->SCID); $result[]=$scheduleDetails; } $result_array['sessionStatus'] = true; $result_array['details'] = $result; } else { $result_array['sessionStatus'] = false; $result_array['message'] = "No records found!"; } $result_array['sessionMaster'] = $this->getSessionMasterDetails(); return $result_array; } /* * get schedule details * created by kms * */ public function getSessionScheduleDetails($scheduleID=null) { $this->db->select('SD.StartTime,SD.EndTime,SD.SSD as ScheduleID'); $this->db->from(SESSIONSCHEDULEDETAILS.' as SD'); $this->db->join(SESSIONSCHEDULE.' as SS', 'SS.SCID = SD.SessionID'); $this->db->where('SD.SessionID',$scheduleID); $this->db->group_by('SD.SSD','ASC'); $sessionDetails = $this->db->get(); return $sessionDetails->result(); } /* * update session schedule details * created by kms * */ public function updateSessionSchedule($arrayDetails=null,$Timings=null) { $this->db->select('SessionID'); $this->db->where('SessionID', $arrayDetails['SessionID']); $this->db->where('SCDate', $arrayDetails['SCDate']); $this->db->where('SCID !=', $arrayDetails['SCID']); if($this->db->get(SESSIONSCHEDULE)->first_row()){ $result['sessionStatus'] = false; $result['message'] ="This same session/date is already exist."; } else{ $this->db->where('SCID', $arrayDetails['SCID']); $upateStatus=$this->db->update(SESSIONSCHEDULE, $arrayDetails); if($upateStatus){ if($Timings['Timings']){ foreach ($Timings['Timings'] as $urow){ if($urow['scheduleID']==''){ $insertDetails['SessionID']=$arrayDetails['SCID']; $insertDetails['StartTime']=$urow['startTime']; $insertDetails['EndTime']=$urow['endTime']; $insertDetails['IsActive']=$arrayDetails['IsActive']; $insertDetails['CreatedBy']=$arrayDetails['UpdatedBy']; $insertDetails['CreatedOn']=$arrayDetails['UpdatedOn']; $this->db->insert(SESSIONSCHEDULEDETAILS, $insertDetails); } else{ $updateDetails['SessionID']=$arrayDetails['SCID']; $updateDetails['StartTime']=$urow['startTime']; $updateDetails['EndTime']=$urow['endTime']; $updateDetails['IsActive']=$arrayDetails['IsActive']; $updateDetails['UpdatedBy']=$arrayDetails['UpdatedBy']; $updateDetails['UpdatedOn']=$arrayDetails['UpdatedOn']; $this->db->where('SSD',$urow['scheduleID']); $this->db->where('SessionID',$arrayDetails['SCID']); $this->db->update(SESSIONSCHEDULEDETAILS, $updateDetails); } } } $result['sessionStatus'] = true; $result['message'] = "Schedules updated successfully"; } else { $result['sessionStatus'] = false; $result['message'] = "Something went wrong.please try again"; } } return $result; } /* * Get session master details * created by kms * */ public function getSessionMasterDetails()//doubt { $this->db->select('SessionID,SessionName'); $this->db->order_by('SessionID','DESC'); $this->db->where('IsActive','1'); $sessionDetails = $this->db->get(SESSIONMASTER); return $sessionDetails->result(); } }