Skip to content

Instantly share code, notes, and snippets.

@orloffv
Created June 21, 2012 13:29
Show Gist options
  • Save orloffv/2965736 to your computer and use it in GitHub Desktop.
Save orloffv/2965736 to your computer and use it in GitHub Desktop.
<?php
$startDate = \DateTime::createFromFormat('d.m.Y H:i:s', $request->get('startDate').' 00:00:00');
$endDate = \DateTime::createFromFormat('d.m.Y H:i:s', $request->get('endDate').' 23:59:59');
$projects = $request->get('project', []);
$applicants = $this->applicantService->findByProjects($projects);
$research = [];
$researchResult = [];
$do = function($key, $state) use(&$research) {
if (!isset($research[$key])) {
$research[$key] = null;
}
if ($research[$key] != null) {
if ($state == false) {
$research[$key] = $state;
}
} else {
$research[$key] = $state;
}
};
foreach ($applicants as $applicant) {
$research = [];
$projectId = $applicant->getProject()->getId();
$states = $applicant->getStates();
if (count($states)) {
foreach ($states as $state) {
if ($startDate <= $state->getCreatedAt() && $endDate >= $state->getCreatedAt()) {
if ($state->getState() == 'call') {
$do('calls', false);
} else {
$do('calls', true);
}
if ($state->getState() == 'didntcome') {
$do('doshlo', false);
$do('interview_complete', false);
$do('odobreno', false);
$do('doshlo_do_klienta', false);
$do('odobreno_u_klienta', false);
}
if ($state->getState() == 'candidate') {
$do('welcomeAncor', true);
$do('doshlo', true);
$do('interview_complete', true);
$do('odobreno', true);
}
if ($state->getState() == 'left') {
$do('interview_complete', false);
$do('odobreno', false);
$do('odobreno_u_klienta', false);
}
if ($state->getState() == 'rejected') {
$do('odobreno', false);
}
if ($state->getState() == 'finalist') {
$do('doshlo_do_klienta', true);
$do('odobreno_u_klienta', true);
}
if ($state->getState() == 'rejected_client') {
$do('odobreno_u_klienta', false);
}
if ($state->getState() == 'probationer') {
$do('trudoystroeno', true);
}
}
if ($state->getState() == 'finalist' || $state->getState() == 'job') {
if ($startDate <= $state->getDate() && $endDate >= $state->getDate()) {
if ($state->getState() == 'finalist') {
$do('napravleny_k_klientu', true);
}
if ($state->getState() == 'job') {
$do('trudoystroeno', true);
}
}
}
}
if (!isset($researchResult[$projectId])) {
$researchResult[$projectId] = [];
}
foreach ($research as $key => $state) {
if (!isset($researchResult[$projectId][$key])) {
$researchResult[$projectId][$key] = 0;
}
$researchResult[$projectId][$key] += ($state == true) ? 1 : 0;
}
}
}
var_dump($researchResult);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment