-
Notifications
You must be signed in to change notification settings - Fork 1
/
processing_dates.php
44 lines (43 loc) · 1.34 KB
/
processing_dates.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
class dateProcessing extends processing {
public function getDateActors($date) {
$date=$this->data['dates'][$date];
if (empty($date)) {
throw new Exception('The date you are searching for has no birthdays listed.', 1);
}
return $date;
}
public function getDateCommonBirthdays($date) {
$actors=$this->getDateActors($date);
$birthdays=$this->getActorsCommonFilms($actors);
$birthdays['date']=$date;
return $birthdays;
}
public function getActorsCommonFilms($actors) {
foreach ($actors as $actor => $films){
foreach ($films as $film) {
$film_counts[$film]++;
$film_actors[$film][]=$actor;
}
}
return $this->getMostCommonFilmBirthdays($film_counts,$film_actors);
}
public function getCommonBirthdays() {
$birthdays=$birthday_counts=array();
foreach ($this->data['dates'] as $date => $actors) {
$birthdays[$date]=$this->getActorsCommonFilms($actors);
$birthday_counts[$date]=is_array($birthdays[$date]['actors']) ? count($birthdays[$date]['actors']) : null;
}
arsort($birthday_counts);
if (reset($birthday_counts)>0) {
$max_birthdays_dates=array_keys($birthday_counts);
$max_birthdays_date=$max_birthdays_dates[0];
$birthdays=$birthdays[$max_birthdays_date];
$birthdays['date']=$max_birthdays_date;
return $birthdays;
}
else {
return array('date'=>'','actors'=>'','film'=>'');
}
}
}