-
Notifications
You must be signed in to change notification settings - Fork 1
/
compiling.php
73 lines (64 loc) · 1.83 KB
/
compiling.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
class Controller {
public $output;
public $data=array();
function __construct($request) {
switch (true) {
case isset($request['date']):
$this->getBirthdaysByDate($request['date']);
break;
case isset($request['actor']):
$this->getBirthdaysByActor($request['actor']);
break;
case isset($request['film']):
$this->getBirthdaysByFilm($request['film']);
break;
default:
$output=false;
}
}
private function getBirthdaysByActor($actor) {
$this->output='actor';
}
private function getBirthdaysByDate($date) {
$this->output='date';
$db=new Database();
$this->data['actors']=$db->getBirthdaysByDate($date);
$this->data['actors_films']=$db->getFilmsByActors($this->data['actors']);
}
private function getBirthdaysByFilm($film) {
$this->output='film';
return;
}
}
class Database {
private $db;
function __construct() {
$this->db = new Mongo();
}
public function getDBActorBirthdays() {
return $this->db->actor_birthdays->actor_birthdays->actor_birthdays;
}
public function getActorBirthday($actor) {
$actors = $this->getDBActorBirthdays();
$actor = $actors->findOne(array('name' => $actor));
$day = substr($actor['date'], 0, 2);
$month = (int) substr($actor['date'], 3, 2);
return "$day-$month";
}
public function getBirthdaysByDate($date) {
$actors = $this->getDBActorBirthdays();
$actors = $actors->find(array('date' => $date));
$actors=iterator_to_array($actors);
return $actors;
}
public function getFilmsByActors($search_actors) {
$actors = $this->getDBActorBirthdays();
$actor_films=array();
foreach ($search_actors as $actor) {
$actor = $actors->findOne(array('name' => $actor));
$actor_films[$actor['name']]=$actor['films'];
}
return $actor_films;
}
}