Skip to content

Commit df09828

Browse files
committed
add resume and experience for use of type hinting
1 parent 4ca1a09 commit df09828

File tree

1 file changed

+192
-0
lines changed

1 file changed

+192
-0
lines changed

Diff for: intro3.php

+192
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
<?php
2+
error_reporting(E_ALL);
3+
ini_set('display_errors', 1);
4+
5+
interface UserInterface {
6+
public function getFormattedSalutation();
7+
public function getName();
8+
public function setName($name);
9+
public function getTitle();
10+
public function setTitle($title);
11+
}
12+
13+
class User implements UserInterface {
14+
15+
protected $name;
16+
protected $title;
17+
public $phone;
18+
public $email;
19+
20+
public function __construct($name, $title) {
21+
$this->name = $name;
22+
$this->title = $title;
23+
}
24+
25+
public function __toString() {
26+
return $this->getFormattedSalutation();
27+
}
28+
29+
public function getFormattedSalutation() {
30+
return $this->getSalutation();
31+
}
32+
33+
protected function getSalutation() {
34+
return $this->title . " " . $this->name;
35+
}
36+
37+
public function getPhone() {
38+
return preg_replace('/(\d\d\d)(\d{3})(\d*)/','($1) $2-$3',$this->phone);
39+
}
40+
41+
public function setPhone($phone) {
42+
$this->phone = preg_replace("/[^0-9]/", "", $phone);
43+
}
44+
45+
public function getName() {
46+
return $this->name;
47+
}
48+
49+
public function setName($name) {
50+
$this->name = $name;
51+
}
52+
53+
public function getTitle() {
54+
return $this->title;
55+
}
56+
57+
public function setTitle($title) {
58+
$this->title = $title;
59+
}
60+
61+
public function setExperience($company, $title, array $tasks, $start_date, $end_date = null) {
62+
$this->experience[] = new Experience($company, $title, $tasks, $start_date, $end_date);
63+
}
64+
65+
public function getExperience($display_number = 10)
66+
{
67+
$string = "";
68+
$count = 0;
69+
70+
foreach ($this->experience as $exp) {
71+
$count++;
72+
if ($count > $display_number){
73+
break;
74+
}
75+
$string .= $this->name . $exp->showExperience().'<br />';
76+
}
77+
return $string;
78+
}
79+
}
80+
81+
class Developer extends User {
82+
public $skills = array();
83+
84+
public function getSalutation() {
85+
return $this->title . " " . $this->name.", Developer";
86+
}
87+
88+
public function getSkillsString() {
89+
echo implode(", ",$this->skills);
90+
}
91+
}
92+
93+
class Experience {
94+
public $company;
95+
public $title;
96+
public $tasks = array();
97+
public $start_date;
98+
public $end_date;
99+
100+
public function showExperience() {
101+
$string = ' worked at ' . $this->company;
102+
$string .= ' as ' . $this->title;
103+
$string .= ' from ' . formatDate($this->start_date) . ' to ' . formatDate($this->end_date);
104+
return $string;
105+
}
106+
107+
public function __construct($company, $title, array $tasks, $start_date, $end_date = null) {
108+
$this->addItem($company, $title, $tasks, $start_date, $end_date);
109+
}
110+
111+
public function addItem($company, $title, array $tasks, $start_date, $end_date = null) {
112+
$this->company = $company;
113+
$this->title = $title;
114+
$this->tasks = $tasks;
115+
$this->start_date = $start_date;
116+
$this->end_date = $end_date;
117+
}
118+
}
119+
120+
121+
function formatDate($date) {
122+
if (empty($date)) {
123+
return 'Present';
124+
}
125+
return date('m/d/Y', strtotime($date));
126+
}
127+
128+
class Resume {
129+
public $template;
130+
public $user;
131+
132+
public function __construct(User $user, $template = "default") {
133+
$this->user = $user;
134+
$this->template = $template;
135+
}
136+
137+
public function formatHTML() {
138+
$string = "<table style='width:800px'><tr><td>".$this->user->getName()."</td>";
139+
$string .= "<td style='text-align: right;'>".$this->user->getPhone()."</td></tr>";
140+
foreach ($this->user->experience as $experience) {
141+
$string .= "<tr><td><strong>" . $experience->company . "</strong><br />".$experience->title."</td>";
142+
$string .= "<td style='text-align: right;'>" . $this->formatDate($experience->start_date);
143+
$string .= " - " . $this->formatDate($experience->end_date) . "</td></tr>";
144+
$string .= "<tr><td colspan='2'><ul><li>";
145+
$string .= implode("</li><li>",$experience->tasks);
146+
$string .= "</li></ul></td></tr>";
147+
}
148+
$string .= "</table>";
149+
return $string;
150+
}
151+
152+
public function formatDate($date) {
153+
if (empty($date)) {
154+
return 'Present';
155+
}
156+
return date('d F Y', strtotime($date));
157+
}
158+
}
159+
160+
$user = new User("Jane Smith","Ms");
161+
echo $user;
162+
echo "<br />";
163+
164+
$developer = new Developer("Jane Smith", "Ms");
165+
$developer->setPhone('928-486-5172');
166+
echo $developer;
167+
echo "<br />";
168+
$developer->skills = array("JavasScript", "HTML", "CSS");
169+
$developer->skills[] = "PHP";
170+
$developer->getSkillsString();
171+
echo "<br />";
172+
173+
$tasks[0][] = "Implemented a continuing program of research in the laboratory and in the field";
174+
$tasks[0][] = "";
175+
176+
$tasks[1][] = "";
177+
$tasks[1][] = "Multi-tasking in a high pressure environment";
178+
179+
180+
$tasks[2][] = "Working for my Masters with 3 credits";
181+
$tasks[2][] = "Managed the dismantling of one facility and transporting and reassembly of all equipment to new location";
182+
183+
$developer->setExperience('Child Development and Human Relations', 'Research Associate', $tasks[0], '2011-06-16','2012-12-13');
184+
$developer->setExperience('Child Development and Human Relations', 'SR Research Associate', $tasks[1], '2012-12-13', '2014-02-12');
185+
$developer->setExperience('Child Development and Human Relations', 'SR Research Associate', $tasks[2], '2014-02-12');
186+
echo $developer->getExperience(1);
187+
188+
$resume = new Resume($developer);
189+
echo $resume->formatHTML();
190+
191+
//$experience = new Experience();
192+
//var_dump($experience);

0 commit comments

Comments
 (0)