-
Notifications
You must be signed in to change notification settings - Fork 1
/
processing_films.php
53 lines (52 loc) · 1.63 KB
/
processing_films.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
45
46
47
48
49
50
51
52
53
<?php
class filmProcessing extends processing {
public function getFilmActors($film) {
$film=$this->data['films'][$film];
if (empty($film)) {
throw new Exception('The film you are searching for does not exist.', 1);
}
return $film;
}
public function getFilmCommonBirthdays($film) {
$actors=$this->getFilmActors($film);
$birthday=$this->getActorsCommonBirthdays($actors);
$birthday['film']=$film;
return $birthday;
}
public function getActorsCommonBirthdays($actors) {
$birthdays=$birthday_actors=array();
foreach ($actors as $actor) {
$actor['birthday']=$this->_removeYear($actor['birthday']);
$birthdays[$actor['birthday']]++;
$birthday_actors[$actor['birthday']][]=$actor['name'];
}
arsort($birthdays);
if (reset($birthdays)>1) {
$birthdays=array_keys($birthdays);
$date=$birthdays[0];
$birthday_actors=$birthday_actors[$date];
return array('date'=>$date,'actors'=>$birthday_actors);
}
else {
return array('date'=>'','actors'=>'');
}
}
public function getCommonBirthdays() {
$birthdays=$birthday_counts=array();
foreach ($this->data['films'] as $film => $actors) {
$birthdays[$film]=$this->getActorsCommonBirthdays($actors);
$birthday_counts[$film]=is_array($birthdays[$film]['actors']) ? count($birthdays[$film]['actors']) : null;
}
arsort($birthday_counts);
if (reset($birthday_counts)>0) {
$max_birthdays_films=array_keys($birthday_counts);
$max_birthdays_film=$max_birthdays_films[0];
$birthdays=$birthdays[$max_birthdays_film];
$birthdays['film']=$max_birthdays_film;
return $birthdays;
}
else {
return array('date'=>'','actors'=>'','film'=>'');
}
}
}