db->select('SessionName'); $this->db->where('SessionName', $arrayDetails['SessionName']); $this->db->where('BranchCode', $arrayDetails['BranchCode']); if($this->db->get(SESSIONMASTER)->first_row()){ $result['sessionStatus'] = false; $result['message'] ="This sessions is already exist."; } else{ $insertMaster['SessionName']=$arrayDetails['SessionName']; $insertMaster['SessionDate']=$arrayDetails['SessionDate']; $insertMaster['CreatedBy']=$arrayDetails['CreatedBy']; $insertMaster['IsActive']=$arrayDetails['IsActive']; $insertMaster['CreatedOn']=$arrayDetails['CreatedOn']; $insertMaster['BranchCode']=$arrayDetails['BranchCode']; $this->db->insert(SESSIONMASTER, $insertMaster); if ($this->db->affected_rows() == '1') { $insertDetails['SessionID']=$this->db->insert_id(); foreach ($university['UniversityID'] as $row1){ $insertDetails['UniversityID']=$row1['UniversityID']; $insertDetails['CreatedBy']=$arrayDetails['CreatedBy']; $insertDetails['IsActive']=$arrayDetails['IsActive']; $insertDetails['CreatedOn']=$arrayDetails['CreatedOn']; $insertDetails['BranchID']=$arrayDetails['BranchCode']; $this->db->insert(SESSIONDETAILS, $insertDetails); } $result['sessionStatus'] = true; $result['message'] = "Sessions added successfully"; } else { $result['sessionStatus'] = false; $result['message'] = "Something went wrong.please try again"; } } return $result; } /* * Get session master details * created by kms * */ public function getSession($requestedBy=null,$branchCode=null) { $this->db->select('SM.SessionID,SM.SessionDate,SM.SessionName,GROUP_CONCAT(SD.UniversityID) as UniversityID,GROUP_CONCAT(SM.SessionID) as GrpID,SM.IsActive,GROUP_CONCAT(US.UniversityName) as UniversityName'); $this->db->from(SESSIONMASTER.' as SM'); $this->db->join(SESSIONDETAILS.' as SD', 'SM.SessionID = SD.SessionID'); $this->db->join(UNIVERSITY.' as US', 'US.UniversityID = SD.UniversityID'); $this->db->where('SD.IsActive','1'); $this->db->where('SM.BranchCode',$branchCode); $this->db->where('US.BranchCode',$branchCode); $this->db->order_by('SM.SessionID','DESC'); $this->db->group_by('SM.SessionID','DESC'); $sessionDetails = $this->db->get(); if($sessionDetails->result()){ $result['sessionStatus'] = true; $result['details'] = $sessionDetails->result(); } else { $result['sessionStatus'] = false; $result['message'] = "No records found!"; } // load batch model for get university details $this->load->model('Batch_model', 'batch'); $result['universityDetails'] = $this->batch->getUniversityDetails($requestedBy,$branchCode); return $result; } /* * update session master details * created by kms * */ public function updateSession($arrayDetails=null,$universityDetails=null) { $this->db->select('SessionName'); $this->db->where('SessionName', $arrayDetails['SessionName']); $this->db->where('BranchCode', $arrayDetails['BranchCode']); $this->db->where('SessionID !=', $arrayDetails['SessionID']); if($this->db->get(SESSIONMASTER)->first_row()){ $result['sessionStatus'] = false; $result['message'] ="This sessions is already exist."; } else{ $this->db->where('SessionID', $arrayDetails['SessionID']); $this->db->where('BranchCode', $arrayDetails['BranchCode']); $upateStatus=$this->db->update(SESSIONMASTER, $arrayDetails); if($upateStatus){ $deactiveStatus['IsActive']=false; $deactiveStatus['UpdatedBy']=$arrayDetails['UpdatedBy']; $deactiveStatus['UpdatedOn']=$arrayDetails['UpdatedOn']; $this->db->where('SessionID ',$arrayDetails['SessionID']); $updateActivityStatusDeactive = $this->db->update(SESSIONDETAILS, $deactiveStatus); if($updateActivityStatusDeactive){ if($universityDetails['University']){ foreach ($universityDetails['University'] as $urow){ $this->db->select('ID'); $this->db->where('SessionID',$arrayDetails['SessionID']); $this->db->where('UniversityID',$urow); if($this->db->get(SESSIONDETAILS)->first_row()){ $existStatusUpdate['IsActive']=true; $existStatusUpdate['UpdatedBy']=$arrayDetails['UpdatedBy']; $existStatusUpdate['UpdatedOn']=$arrayDetails['UpdatedOn']; $this->db->where('SessionID',$arrayDetails['SessionID']); $this->db->where('UniversityID',$urow); $this->db->update(SESSIONDETAILS, $existStatusUpdate); } else{ $update_array["UniversityID"]=$urow; $update_array["SessionID"]=$arrayDetails['SessionID']; $update_array["IsActive"]=true; $update_array["CreatedBy"]=$arrayDetails['UpdatedBy']; $update_array["CreatedOn"]=$arrayDetails['UpdatedOn']; $this->db->insert(SESSIONDETAILS, $update_array); } } } else{ $activateStatus['IsActive']=true; $this->db->where('SessionID ',$arrayDetails['SessionID']); $this->db->update(SESSIONMASTER, $activateStatus); } $result['sessionStatus'] = true; $result['message'] = "Sessions updated successfully"; } } else { $result['sessionStatus'] = false; $result['message'] = "Something went wrong.please try again"; } } return $result; } /* * Get university details * created by kms * */ public function getUniversityDetails($requestedBy,$branchCode) { $this->db->select('UniversityID,UniversityName'); $this->db->order_by('UniversityID','ASC'); $this->db->where('IsActive','1'); $this->db->where('BranchCode',$branchCode); // $this->db->where_not_in('ID', $id); $universityDetails = $this->db->get(UNIVERSITY); return $universityDetails->result(); } }