Вот настройка:
У меня есть два набора кода для получения сервисов:
A.
Код: Выделить всё
$services_internal = Service::join('offices', 'services.office_id', '=', 'offices.id')
->where('offices.cluster_id', $cluster_id)
->where('service_type', 'internal')
->get();
$services_external = Service::join('offices', 'services.office_id', '=', 'offices.id')
->where('offices.cluster_id', $cluster_id)
->where('service_type', 'external')
->get();
Код: Выделить всё
$services_internal = Service::where('office_id', 5)
->where('service_type', 'internal')
->get();
$services_external = Service::where('office_id', 5)
->where('service_type', 'external')
->get();
Код: Выделить всё
public function rating($academic_year, $semester)
{
$sqd_results = Response::selectRaw('COUNT(responses.respondent_id) as total_respondents')
->selectRaw('COUNT(CASE WHEN responses.rate = 5 THEN 1 END) as strongly_agree')
->selectRaw('COUNT(CASE WHEN responses.rate = 4 THEN 1 END) as agree')
->selectRaw('COUNT(CASE WHEN responses.rate = 0 THEN 1 END) as na_scores')
->join('respondents', 'responses.respondent_id', '=', 'respondents.id')
->join('questionnaires', 'responses.questionnaire_id', '=', 'questionnaires.id')
->join('questionnaire_types', 'questionnaires.questionnaire_type_id', '=', 'questionnaire_types.id')
->where('respondents.academic_year', $academic_year)
->where('respondents.semester', $semester)
->where('respondents.service_id', $this->id)
->where('questionnaires.questionnaire_type_id', 2)
->get()->first();
// Accessing data
$totalRespondents = $sqd_results->total_respondents;
$strongly_agree = $sqd_results->strongly_agree;
$agree = $sqd_results->agree;
$naScores = $sqd_results->na_scores;
if (($totalRespondents - $naScores) array:4 [▼
"Service X" => array:1 [▼
"rating" => 0
]
"Service Y" => array:1 [▼
"rating" => 0
]
"Service Z" => array:1 [▼
"rating" => 0
]
"Service A" => array:1 [▼
"rating" => 0
]
]
"external" => array:2 [▼
"Service M" => array:1 [▼
"rating" => 0
]
"Service N" => array:1 [▼
"rating" => 0
]
]
Код: Выделить всё
"internal" => array:4 [▼
"Service X" => array:1 [▼
"rating" => "94.4"
]
"Service Y" => array:1 [▼
"rating" => 0
]
"Service Z" => array:1 [▼
"rating" => 0
]
"Service A" => array:1 [▼
"rating" => 0
]
]
"external" => array:2 [▼
"Service M" => array:1 [▼
"rating" => "100.0"
]
"Service N" => array:1 [▼
"rating" => 0
]
]
Может ли кто-нибудь объяснить, почему я могу получать такие противоречивые результаты и как я могу обеспечить точные оценки для всех услуг?
Любая помощь быть очень оценены. Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/784 ... in-laravel
Мобильная версия