Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // get customers
- public function getCustomers($user, $skip=0, $search=false, $asearch=false, $sort=false, $order=false){
- if($this->authorized){
- $this->user_affiliation = $user->affiliation();
- $customers = [];
- $collection = $this->db->Customer;
- $collection1 = $this->db->Customers;
- // criteria
- $criteria = $this->initializeCustomersCriteria();
- // New Criteria for getting student recently registered from past 48 hrs ('Added By: Ron Ivin Gregorio - 02/20/2023')
- if(!$search && !$asearch){
- array_push($criteria,['UDateCreated' => [ '$gte' => strtotime('-48 hours') , '$lt' => time()]]);
- }
- // include search criteria if available
- if($search){
- array_push($criteria, $this->searchCustomers($search));
- // include advanced search criteria if available
- } else if($asearch){
- $criteria = array_merge($criteria, $this->advancedSearchCustomers($asearch));
- }
- if(!$user->super){
- $user_states = $user->states;
- if(in_array('zz', $user_states)){
- array_push($user_states, 'generic');
- }
- array_push($criteria, array("CustomerCoursesStates" => array('$in' => $user_states)));
- if($user->isCourtAdmin()){
- $courts_assigned = $user->getCourtsAssigned();
- if($courts_assigned){
- array_push($criteria, array("DLNumber" => array('$in' => $this->getCustomersByCourts($courts_assigned))));
- } else {
- array_push($criteria, array("DLNumber" => "no_courts"));
- }
- } else {
- if($user->isFleet()){
- $this->fleet_courses = $this->getFleetCourses($user);
- array_push($criteria, array("DLNumber" => array('$in' => $this->getFleetStudents())));
- } else {
- array_push($criteria, array("CoursesAffiliates" => array('$in' => [$this->user_affiliation['affiliate']])));
- if($this->user_affiliation['company'] != ''){
- array_push($criteria, array("CourseCompanies" => array('$in' => [$this->user_affiliation['company']])));
- }
- }
- }
- }
- // finalize criteria
- $criteria = array('$and' => $criteria);
- // include sorting if available
- $sort = $this->sortCustomers($sort, $order);
- // select fields
- $select = ["_id" => 0, "ID" => 1, "DLNumber" => 1, "FirstName" => 1, "MiddleName" => 1, "LastName" => 1,
- "RecentRegUDate" => 1, "RecentRegDate" => 1, "Status" => 1];
- // get records
- $cursor = $collection->find($criteria, $select);
- $this->total_count = $cursor->count() - 0;
- $this->total_pages = ceil($this->total_count / $this->page_size);
- // Getting the total length of the customers in first iteration ('Added By: Ron Ivin Gregorio - 02/20/2023')
- $customer_length = 0;
- if($skip == 0){
- $customer_length = $this->total_count;
- }
- // Limit into 20 students only per load ('Added By: Ron Ivin Gregorio - 02/20/2023')
- $cursor->sort($sort)->skip($skip)->limit(20);
- foreach($cursor as $document){
- $registration = $this->getCustomerRegistrationDate($document);
- $registration_date = $registration ? $registration['date'] : false;
- $registration_time = $registration ? $registration['time'] : '';
- $student_ids = $this->getCustomerStudentIDs($document['DLNumber']);
- $customer_courses = implode(", ", $this->getCustomerCourses($student_ids));
- $customer_classes = $this->getCustomerClasses($student_ids);
- $affiliations = $this->getCustomerCourseAffiliations($student_ids);
- $affiliates = implode(", ", $affiliations['affiliates']);
- $companies = count($affiliations['companies']) > 0 ? $affiliations['companies'] : false;
- $companies = $companies ? implode(", ", $companies) : '-';
- $customer = [
- "id" => $document['ID'],
- "registration_date" => $registration_date,
- "registration_time" => $registration_time,
- "name" => $this->getCustomerFullnameLastFirst($document),
- "dlnum" => strstr($document['DLNumber'], "TEMP") ? '-' : $document['DLNumber'],
- "student_ids" => implode(", ", $student_ids),
- "courses" => $customer_courses,
- "classes" => $customer_classes ? implode(', ', $customer_classes) : '-',
- "affiliates" => $affiliates,
- "companies" => $companies,
- "status" => implode(", ", $this->getCustomerCoursesStatus($student_ids, $document['Status']))
- ];
- array_push($customers, $customer);
- }
- // Adding customer length when returning data ('Added By: Ron Ivin Gregorio - 02/20/2023')
- $data = [
- 'customers' => $customers,
- 'customer_length' => $customer_length
- ];
- return $data;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment