split the stuff into different files
[GitHub/Stricted/speedport-hybrid-php-api.git] / Phone.class.php
1 <?php
2 /**
3 * @author Jan Altensen (Stricted)
4 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
5 * @copyright 2015 Jan Altensen (Stricted)
6 */
7 trait Phone {
8 /**
9 * get phone book entrys
10 *
11 * @return array
12 */
13 public function getPhoneBookEntrys () {
14 $data = $this->getData('PhoneBook');
15 $data = $this->getValues($data);
16
17 if (isset($data['addbookentry'])) {
18 return $data['addbookentry'];
19 }
20 else {
21 return array();
22 }
23 }
24
25 /**
26 * add Phone Book Entry
27 *
28 * @param string $name
29 * @param string $firstname
30 * @param string $private
31 * @param string $work
32 * @param string $mobile
33 * @param integer $id
34 *
35 * @return array
36 */
37 public function addPhoneBookEntry ($name, $firstname, $private, $work, $mobile, $id = -1) {
38 $this->checkLogin();
39
40 $path = 'data/PhoneBook.json';
41 $fields = array(
42 'csrf_token' => $this->token,
43 'id' => $id,
44 'search' => '',
45 'phonebook_name' => $name,
46 'phonebook_vorname' => $firstname,
47 'phonebook_number_p' => $private,
48 'phonebook_number_a' => $work,
49 'phonebook_number_m' => $mobile
50 );
51
52 $data = $this->sentRequest($path, $fields, true);
53 $data = $this->getValues($data['body']);
54
55 if ($data['status'] == 'ok') {
56 return $data;
57 }
58 else {
59 throw new RouterException('can not add/edit Phone Book Entry');
60 }
61 }
62
63 /**
64 * edit Phone Book Entry
65 *
66 * @param integer $id
67 * @param string $name
68 * @param string $firstname
69 * @param string $private
70 * @param string $work
71 * @param string $mobile
72 *
73 * @return array
74 */
75 public function changePhoneBookEntry ($id, $name, $firstname, $private, $work, $mobile) {
76 return $this->addPhoneBookEntry($name, $firstname, $private, $work, $private, $id);
77 }
78
79 /**
80 * delete Phone Book Entry
81 *
82 * @param integer $id
83 *
84 * @return array
85 */
86 public function deletePhoneBookEntry ($id) {
87 $this->checkLogin();
88
89 $path = 'data/PhoneBook.json';
90 $fields = array(
91 'csrf_token' => $this->token,
92 'id' => $id,
93 'deleteEntry' => 'delete'
94 );
95
96 $data = $this->sentRequest($path, $fields, true);
97 $data = $this->getValues($data['body']);
98
99 if ($data['status'] == 'ok') {
100 return $data;
101 }
102 else {
103 throw new RouterException('can not delete Phone Book Entry');
104 }
105 }
106
107 /**
108 * get the Missed Calls from router
109 *
110 * @return array
111 */
112 public function getMissedCalls() {
113 $data = $this->getData('PhoneCalls');
114 $data = $this->getValues($data);
115
116 if (isset($data['addmissedcalls'])) {
117 return $data['addmissedcalls'];
118 }
119 else {
120 return array();
121 }
122 }
123
124 /**
125 * get the Taken Calls from router
126 *
127 * @return array
128 */
129 public function getTakenCalls() {
130 $data = $this->getData('PhoneCalls');
131 $data = $this->getValues($data);
132
133 if (isset($data['addtakencalls'])) {
134 return $data['addtakencalls'];
135 }
136 else {
137 return array();
138 }
139 }
140
141 /**
142 * get the Dialed Calls from router
143 *
144 * @return array
145 */
146 public function getDialedCalls() {
147 $data = $this->getData('PhoneCalls');
148 $data = $this->getValues($data);
149
150 if (isset($data['adddialedcalls'])) {
151 return $data['adddialedcalls'];
152 }
153 else {
154 return array();
155 }
156 }
157 }