zenapply /
php-bamboohr
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Zenapply\BambooHR\Api; |
||
| 4 | |||
| 5 | /* |
||
| 6 | |||
| 7 | Copyright (c) 2013, Bamboo HR LLC |
||
| 8 | All rights reserved. |
||
| 9 | |||
| 10 | Redistribution and use in source and binary forms, with or without modification, |
||
| 11 | are permitted provided that the following conditions are met: |
||
| 12 | |||
| 13 | * Redistributions of source code must retain the above copyright notice, this |
||
| 14 | list of conditions and the following disclaimer. |
||
| 15 | |||
| 16 | * Redistributions in binary form must reproduce the above copyright notice, |
||
| 17 | this list of conditions and the following disclaimer in the documentation |
||
| 18 | and/or other materials provided with the distribution. |
||
| 19 | |||
| 20 | * Neither the name of Bamboo HR nor the names of its contributors may be used |
||
| 21 | to endorse or promote products derived from this software without specific |
||
| 22 | prior written permission. |
||
| 23 | |||
| 24 | |||
| 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
||
| 26 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||
| 27 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
| 28 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
||
| 29 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||
| 30 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
||
| 31 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||
| 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
||
| 33 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||
| 34 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
| 35 | |||
| 36 | */ |
||
| 37 | |||
| 38 | class BambooHTTPRequest |
||
| 39 | { |
||
| 40 | public $method="GET"; |
||
| 41 | public $headers=array(); |
||
| 42 | public $url; |
||
| 43 | public $content=""; // Use raw text for most requests, or arrays for multipart/form-data |
||
| 44 | public $multiPart=false; |
||
| 45 | } |
||
| 46 | |||
| 47 | class BambooHTTPResponse |
||
| 48 | { |
||
| 49 | public $statusCode; |
||
| 50 | public $headers=array(); |
||
| 51 | public $content; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * If HTTP response indicates error, return true. |
||
| 55 | * @return bool |
||
| 56 | */ |
||
| 57 | public function isError() { |
||
| 58 | return $this->statusCode < 200 || $this->statusCode > 299; |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * If the request is a success and is xml, return a SimpleXmlElement of the response content. |
||
| 63 | * |
||
| 64 | * @return \SimpleXMLElement|null |
||
| 65 | */ |
||
| 66 | public function getContentXML() { |
||
| 67 | View Code Duplication | if(!$this->isError() && strpos($this->headers['Content-Type'], 'text/xml') !== false) { |
|
| 68 | return new \SimpleXMLElement($this->content); |
||
| 69 | } |
||
| 70 | return null; |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * If the request is a success and is json, return an object from the response content. |
||
| 75 | * |
||
| 76 | * @return stdclass|null |
||
| 77 | */ |
||
| 78 | public function getContentJSON() { |
||
| 79 | View Code Duplication | if(!$this->isError() && strpos($this->headers['Content-Type'], 'application/json') !== false) { |
|
| 80 | return json_decode($this->content); |
||
| 81 | } |
||
| 82 | return null; |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Return an object representing the content of the response. Mostly just a shortcut to {@see getContentJSON()} and {@see getContentXML()} |
||
| 87 | * |
||
| 88 | * @return \SimpleXMLElement|stdclass|null |
||
| 89 | */ |
||
| 90 | public function getContent() { |
||
| 91 | View Code Duplication | if(!$this->isError() && strpos($this->headers['Content-Type'], 'application/json') !== false) { |
|
| 92 | return $this->getContentJSON(); |
||
| 93 | } |
||
| 94 | View Code Duplication | if(!$this->isError() && strpos($this->headers['Content-Type'], 'text/xml') !== false) { |
|
| 95 | return $this->getContentXML(); |
||
| 96 | } |
||
| 97 | return $this->content; |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * If the API returns an error, it may also send a message to describe the |
||
| 102 | * error. This message is only suitable for debugging purposes, not for |
||
| 103 | * displaying errors to the user. While we will endeavor to avoid changing these messages, |
||
| 104 | * you should be prepared for them to change. (in other words, avoid comparing |
||
| 105 | * the content of the error message to determine behavior). |
||
| 106 | * |
||
| 107 | * @return string |
||
| 108 | */ |
||
| 109 | public function getErrorMessage() { |
||
| 110 | if($this->isError()) |
||
| 111 | return $this->headers['X-BambooHR-Error-Messsage']; |
||
| 112 | return null; |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | interface BambooHTTP { |
||
| 117 | function setBasicAuth($username, $password); |
||
| 118 | function sendRequest(BambooHTTPRequest $request); |
||
| 119 | } |
||
| 120 | |||
| 121 | define('BAMBOOHR_MULTIPART_BOUNDARY', "----BambooHR-MultiPart-Mime-Boundary----"); |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Utility function for creating a valid multipart POST body. Mostly useful for uploading files. |
||
| 125 | * |
||
| 126 | * @param type $boundary |
||
| 127 | * @param type $postFields |
||
| 128 | * @param type $name |
||
| 129 | * @param type $fileName |
||
| 130 | * @param type $contentType |
||
| 131 | * @param type $fileData |
||
| 132 | * @return string |
||
| 133 | */ |
||
| 134 | function buildMultipart($boundary, $postFields, $name, $fileName, $contentType, $fileData ) { |
||
| 135 | |||
| 136 | $data = ''; |
||
| 137 | |||
| 138 | // populate normal fields first (simpler) |
||
| 139 | foreach ($postFields as $key => $content) { |
||
| 140 | $data .= "--".$boundary. "\r\n"; |
||
| 141 | $data .= 'Content-Disposition: form-data; name="' . $key . '"'; |
||
| 142 | // note: double endline |
||
| 143 | $data .= "\r\n\r\n"; |
||
| 144 | $data.= $content."\r\n"; |
||
| 145 | } |
||
| 146 | $data.="--".$boundary."\r\n"; |
||
| 147 | $data .= 'Content-Disposition: form-data; name="' . $name . '";' . |
||
| 148 | ' filename="' . $fileName . '"' . "\r\n"; |
||
| 149 | |||
| 150 | $data .= 'Content-Type: ' . $contentType . "\r\n"; |
||
| 151 | $data .= "\r\n"; |
||
| 152 | // the file itself (note: there's no encoding of any kind) |
||
| 153 | |||
| 154 | $data .= $fileData . "\r\n"; |
||
| 155 | // last delimiter |
||
| 156 | $data .= "--" . $boundary . "--\r\n"; |
||
| 157 | return $data; |
||
| 158 | } |
||
| 159 | |||
| 160 | |||
| 161 | class BambooCurlHTTP implements BambooHTTP { |
||
| 162 | private $basicAuthUsername; |
||
| 163 | private $basicAuthPassword; |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Set the username and password used in HTTP basic Authentication. |
||
| 167 | * @param string $username |
||
| 168 | * @param string $password |
||
| 169 | */ |
||
| 170 | function setBasicAuth($username, $password) { |
||
|
0 ignored issues
–
show
|
|||
| 171 | $this->basicAuthUsername=$username; |
||
| 172 | $this->basicAuthPassword=$password; |
||
| 173 | } |
||
| 174 | |||
| 175 | /** |
||
| 176 | * Given a string with HTTP headers, return an array like array('Header' => 'Value') |
||
| 177 | * |
||
| 178 | * @param string $headerString |
||
| 179 | * @return array |
||
| 180 | */ |
||
| 181 | function parseHeaders( $headerString ) { |
||
|
0 ignored issues
–
show
|
|||
| 182 | $retVal = array(); |
||
| 183 | $fields = explode("\r\n", preg_replace('/\x0D\x0A[\x09\x20]+/', ' ', $headerString )); |
||
| 184 | foreach( $fields as $field ) { |
||
| 185 | if( preg_match('/([^:]+): (.+)/m', $field, $match) ) { |
||
| 186 | $retVal[$match[1]] = trim($match[2]); |
||
| 187 | } |
||
| 188 | } |
||
| 189 | return $retVal; |
||
| 190 | } |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Perform the request described by the BambooHTTPRequest. Return a |
||
| 194 | * BambooHTTPResponse describing the response. |
||
| 195 | * |
||
| 196 | * @param \BambooHR\API\BambooHTTPRequest $request |
||
| 197 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 198 | */ |
||
| 199 | function sendRequest(BambooHTTPRequest $request) { |
||
|
0 ignored issues
–
show
|
|||
| 200 | $response=new BambooHTTPResponse(); |
||
| 201 | |||
| 202 | $http=curl_init(); |
||
| 203 | curl_setopt($http, CURLOPT_URL, $request->url ); |
||
| 204 | curl_setopt($http, CURLOPT_CUSTOMREQUEST, $request->method ); |
||
| 205 | curl_setopt($http, CURLOPT_HTTPHEADER, $request->headers ); |
||
| 206 | curl_setopt($http, CURLOPT_POSTFIELDS, $request->content); |
||
| 207 | |||
| 208 | curl_setopt($http, CURLOPT_HEADER, true ); |
||
| 209 | curl_setopt($http, CURLOPT_SSL_VERIFYHOST, 2); |
||
| 210 | curl_setopt($http, CURLOPT_SSL_VERIFYPEER, 1); |
||
| 211 | curl_setopt($http, CURLOPT_RETURNTRANSFER, 1); |
||
| 212 | |||
| 213 | curl_setopt($http, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ); |
||
| 214 | curl_setopt($http, CURLOPT_USERPWD, $this->basicAuthUsername.':'.$this->basicAuthPassword); |
||
| 215 | |||
| 216 | $response->content=curl_exec($http); |
||
| 217 | |||
| 218 | if($response->content!==false) { |
||
| 219 | $response->statusCode = curl_getinfo($http, CURLINFO_HTTP_CODE); |
||
| 220 | $headerSize = curl_getinfo($http,CURLINFO_HEADER_SIZE); |
||
| 221 | $response->headers= $this->parseHeaders( substr($response->content, 0, $headerSize) ); |
||
| 222 | $response->content= substr($response->content, $headerSize ); |
||
| 223 | } else { |
||
| 224 | $response->statusCode=0; |
||
| 225 | $response->content="Connection error"; |
||
| 226 | } |
||
| 227 | return $response; |
||
| 228 | } |
||
| 229 | } |
||
| 230 | |||
| 231 | /** |
||
| 232 | * The main class. |
||
| 233 | * |
||
| 234 | * Common usage: |
||
| 235 | * <code> |
||
| 236 | * <?php |
||
| 237 | * $bhr = new BambooAPI("foo"); |
||
| 238 | * $bhr->setSecretKey("bar"); |
||
| 239 | * $response = $bhr->getDirectory(); |
||
| 240 | * if($response->isError()) { |
||
| 241 | * trigger_error("Error communicating with BambooHR"); |
||
| 242 | * } |
||
| 243 | * $xml = new SimpleXmlElement($response->content); |
||
| 244 | * ... |
||
| 245 | * ?> |
||
| 246 | * </code> |
||
| 247 | */ |
||
| 248 | class BambooHR { |
||
| 249 | protected $companyDomain; |
||
| 250 | protected $httpHandler; |
||
| 251 | protected $baseUrl="https://api.bamboohr.com/api/gateway.php"; |
||
| 252 | |||
| 253 | /** |
||
| 254 | * |
||
| 255 | * |
||
| 256 | * @param string $companyDomain Either the subdomain of a BambooHR account ("example.bamboohr.com" => "example") or the full domain ("example.bamboohr.com") |
||
| 257 | * @param BambooHTTP $http |
||
| 258 | * @param string $baseUrl |
||
| 259 | */ |
||
| 260 | function __construct($companyDomain, BambooHTTP $http=null, $baseUrl=null) { |
||
|
0 ignored issues
–
show
|
|||
| 261 | if($http) { |
||
| 262 | $this->httpHandler=$http; |
||
| 263 | } else { |
||
| 264 | $this->httpHandler=new BambooCurlHTTP(); |
||
| 265 | } |
||
| 266 | if($baseUrl) { |
||
|
0 ignored issues
–
show
The expression
$baseUrl of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
Loading history...
|
|||
| 267 | $this->baseUrl=$baseUrl; |
||
| 268 | } |
||
| 269 | $this->companyDomain = $companyDomain; |
||
| 270 | $this->baseUrl=$this->baseUrl.="/$companyDomain"; |
||
| 271 | } |
||
| 272 | |||
| 273 | /** |
||
| 274 | * Set the api key to use. |
||
| 275 | * |
||
| 276 | * @param string $key |
||
| 277 | */ |
||
| 278 | function setSecretKey($key){ |
||
|
0 ignored issues
–
show
|
|||
| 279 | $this->httpHandler->setBasicAuth($key, 'x'); |
||
| 280 | } |
||
| 281 | |||
| 282 | /** |
||
| 283 | * Use the Login API to get a key for use in later API requests. |
||
| 284 | * To set the secretKey, you will need to parse the |
||
| 285 | * {@see \BambooHR\API\BambooHTTPResponse::$content} returned from this function and call |
||
| 286 | * {@see setSecretKey()} |
||
| 287 | * |
||
| 288 | * Use the {@see login()} as an alternative to this function that |
||
| 289 | * will do this work for you. |
||
| 290 | * |
||
| 291 | * @param string $applicationKey To ask about an applicationKey, email [email protected] |
||
| 292 | * @param string $email |
||
| 293 | * @param string $password |
||
| 294 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 295 | * @link http://www.bamboohr.com/api/documentation/login.php |
||
| 296 | */ |
||
| 297 | View Code Duplication | function requestSecretKey($applicationKey, $email, $password) { |
|
|
0 ignored issues
–
show
|
|||
| 298 | $request=new BambooHTTPRequest(); |
||
| 299 | $request->method="POST"; |
||
| 300 | $request->url=$this->baseUrl."/v1/login"; |
||
| 301 | $request->content="applicationKey=".urlencode($applicationKey)."&user=".urlencode($email)."&password=".urlencode($password); |
||
| 302 | return $this->httpHandler->sendRequest( $request ); |
||
| 303 | } |
||
| 304 | |||
| 305 | /** |
||
| 306 | * Use the Login API to get a key for use in later API requests. Also use the |
||
| 307 | * response to set up the authentication for future requests. Using this API |
||
| 308 | * requires you to contact BambooHR to get an applicationKey. |
||
| 309 | * |
||
| 310 | * @param string $applicationKey To ask about an applicationKey, email [email protected] |
||
| 311 | * @param string $email |
||
| 312 | * @param string $password |
||
| 313 | * @return bool |
||
| 314 | * @link http://www.bamboohr.com/api/documentation/login.php |
||
| 315 | */ |
||
| 316 | function login($applicationKey, $email, $password) { |
||
|
0 ignored issues
–
show
|
|||
| 317 | $response = $this->requestSecretKey($applicationKey, $email, $password); |
||
| 318 | if($response->isError()) { |
||
| 319 | return false; |
||
| 320 | } |
||
| 321 | $xml = new \SimpleXMLElement($response->content); |
||
| 322 | if($xml->response != 'authenticated') { |
||
| 323 | return false; |
||
| 324 | } |
||
| 325 | $this->setSecretKey($xml->key); |
||
| 326 | $this->baseUrl = $xml->apiUrl . $this->companyDomain; |
||
| 327 | return true; |
||
| 328 | } |
||
| 329 | |||
| 330 | /** |
||
| 331 | * |
||
| 332 | * |
||
| 333 | * @param int $employeeId |
||
| 334 | * @param array $fields an array of field aliases or ids |
||
| 335 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 336 | * @link http://www.bamboohr.com/api/documentation/employees.php#getEmployee |
||
| 337 | */ |
||
| 338 | View Code Duplication | function getEmployee($employeeId, $fields=array()) { |
|
|
0 ignored issues
–
show
|
|||
| 339 | $request=new BambooHTTPRequest(); |
||
| 340 | $request->method="GET"; |
||
| 341 | $request->url=$this->baseUrl."/v1/employees/".intval($employeeId)."/?fields=".implode(",",$fields); |
||
| 342 | |||
| 343 | return $this->httpHandler->sendRequest( $request ); |
||
| 344 | } |
||
| 345 | |||
| 346 | /** |
||
| 347 | * |
||
| 348 | * @param int $reportId |
||
| 349 | * @param string $format one of xml, csv, xls, json, pdf |
||
| 350 | * @param bool $filterDuplicates |
||
| 351 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 352 | * @link http://www.bamboohr.com/api/documentation/employees.php#requestCompanyReport |
||
| 353 | */ |
||
| 354 | function getReport($reportId, $format, $filterDuplicates=true) { |
||
|
0 ignored issues
–
show
|
|||
| 355 | $request=new BambooHTTPRequest(); |
||
| 356 | $request->method="GET"; |
||
| 357 | $request->url=$this->baseUrl."/v1/reports/".intval($reportId)."/?format=".$format; |
||
| 358 | if(!$filterDuplicates) { |
||
| 359 | $request->url.="&fd=no"; |
||
| 360 | } |
||
| 361 | return $this->httpHandler->sendRequest( $request ); |
||
| 362 | } |
||
| 363 | |||
| 364 | |||
| 365 | private function prepareKeyValues($values) { |
||
| 366 | $xml=""; |
||
| 367 | foreach($values as $key=>$value) { |
||
| 368 | if(is_array($value)) { |
||
| 369 | $extraAttr=$value['extra']; |
||
| 370 | $value=$value['value']; |
||
| 371 | } else { |
||
| 372 | $extraAttr=array(); |
||
| 373 | } |
||
| 374 | $xml.=sprintf("<field id=\"%s\" ", htmlspecialchars($key,ENT_COMPAT)); |
||
| 375 | foreach($extraAttr as $name=>$attValue) { |
||
| 376 | $xml.=sprintf("%s=\"%s\"",$name, htmlspecialchars($attValue,ENT_COMPAT)); |
||
| 377 | } |
||
| 378 | |||
| 379 | $xml.=">".htmlspecialchars($value,ENT_COMPAT )."</field>"; |
||
| 380 | } |
||
| 381 | return $xml; |
||
| 382 | } |
||
| 383 | |||
| 384 | /** |
||
| 385 | * Update an employee. pass a map of "fieldId" => "value". Does not work for table fields. |
||
| 386 | * |
||
| 387 | * @param int $employeeId |
||
| 388 | * @param array $fieldValues |
||
| 389 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 390 | * @link http://www.bamboohr.com/api/documentation/employees.php#updateEmployee |
||
| 391 | */ |
||
| 392 | function updateEmployee($employeeId, $fieldValues=array()) { |
||
|
0 ignored issues
–
show
|
|||
| 393 | $request=new BambooHTTPRequest(); |
||
| 394 | $request->method="POST"; |
||
| 395 | $request->url=$this->baseUrl."/v1/employees/".intval($employeeId); |
||
| 396 | $request->headers=array("Content-type:"=>"text/xml"); |
||
| 397 | |||
| 398 | $xml=sprintf('<employee id="%d">', $employeeId); |
||
| 399 | $xml.=$this->prepareKeyValues($fieldValues); |
||
| 400 | $xml.="</employee>"; |
||
| 401 | $request->content=$xml; |
||
| 402 | return $this->httpHandler->sendRequest( $request ); |
||
| 403 | } |
||
| 404 | |||
| 405 | /** |
||
| 406 | * |
||
| 407 | * @param int $employeeId |
||
| 408 | * @param array $fieldValues |
||
| 409 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 410 | * @link http://www.bamboohr.com/api/documentation/employees.php#addEmployee |
||
| 411 | */ |
||
| 412 | function addEmployee($initialFieldValues=array()) { |
||
|
0 ignored issues
–
show
|
|||
| 413 | $request=new BambooHTTPRequest(); |
||
| 414 | $request->method="POST"; |
||
| 415 | $request->url=$this->baseUrl."/v1/employees/"; |
||
| 416 | $request->headers=array("Content-type"=>"text/xml"); |
||
| 417 | |||
| 418 | $xml='<employee>'.$this->prepareKeyValues($initialFieldValues)."</employee>"; |
||
| 419 | $request->content=$xml; |
||
| 420 | return $this->httpHandler->sendRequest( $request ); |
||
| 421 | } |
||
| 422 | |||
| 423 | /** |
||
| 424 | * |
||
| 425 | * @param string $format one of xml, csv, xls, json, pdf |
||
| 426 | * @param array $fields |
||
| 427 | * @param bool $filterDuplicates |
||
| 428 | * @param string $title |
||
| 429 | * @param string $lastChanged Date in ISO 8601 format, like: 2012-10-17T16:00:00Z |
||
| 430 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 431 | * @link http://www.bamboohr.com/api/documentation/employees.php#requestCustomReport |
||
| 432 | */ |
||
| 433 | function getCustomReport($format, $fields, $filterDuplicates=true,$title="", $lastChanged="") { |
||
|
0 ignored issues
–
show
|
|||
| 434 | $request=new BambooHTTPRequest(); |
||
| 435 | $request->method="POST"; |
||
| 436 | $request->url=$this->baseUrl."/v1/reports/custom/?format=".$format; |
||
| 437 | $request->headers=array("Content-type", "text/xml"); |
||
| 438 | $xml='<report>'; |
||
| 439 | if($title!="") $xml.="<title>".htmlentities($title)."</title>"; |
||
| 440 | |||
| 441 | if($lastChanged!="") { |
||
| 442 | $xml.="<filters><lastChanged includeNull=\"no\" >".htmlentities($lastChanged)."</lastChanged></filters>"; |
||
| 443 | } |
||
| 444 | |||
| 445 | $xml.='<fields>'; |
||
| 446 | if(!$filterDuplicates) $xml.="<filterDuplicates>no</filterDuplicates>"; |
||
| 447 | foreach($fields as $field) { |
||
| 448 | $xml.=sprintf('<field id="%s" />', $field ); |
||
| 449 | } |
||
| 450 | $xml.='</fields></report>'; |
||
| 451 | $request->content=$xml; |
||
| 452 | echo $xml; |
||
| 453 | return $this->httpHandler->sendRequest( $request ); |
||
| 454 | } |
||
| 455 | |||
| 456 | /** |
||
| 457 | * |
||
| 458 | * @param int $employeeId |
||
| 459 | * @param string $tableName {@link http://www.bamboohr.com/api/documentation/tables.php#tables List of valid tables} |
||
| 460 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 461 | * @link http://www.bamboohr.com/api/documentation/tables.php#getTable |
||
| 462 | */ |
||
| 463 | View Code Duplication | function getTable($employeeId, $tableName) { |
|
|
0 ignored issues
–
show
|
|||
| 464 | if($employeeId!="all") $employeeId=intval($employeeId); |
||
| 465 | $request=new BambooHTTPRequest(); |
||
| 466 | $request->method="GET"; |
||
| 467 | $request->url=$this->baseUrl."/v1/employees/".$employeeId."/tables/".urlencode($tableName)."/"; |
||
| 468 | return $this->httpHandler->sendRequest( $request ); |
||
| 469 | } |
||
| 470 | |||
| 471 | /** |
||
| 472 | * |
||
| 473 | * @param string $since Date in ISO 8601 format, like: 2012-10-17T16:00:00Z |
||
| 474 | * @param string $type |
||
| 475 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 476 | * @link http://www.bamboohr.com/api/documentation/changes.php#description |
||
| 477 | */ |
||
| 478 | View Code Duplication | function getChangedEmployees($since, $type="all") { |
|
|
0 ignored issues
–
show
|
|||
| 479 | $request=new BambooHTTPRequest(); |
||
| 480 | $request->method="GET"; |
||
| 481 | $request->url=$this->baseUrl."/v1/employees/changed/?since=".urlencode($since)."&type=".urlencode($type); |
||
| 482 | return $this->httpHandler->sendRequest( $request ); |
||
| 483 | } |
||
| 484 | |||
| 485 | /** |
||
| 486 | * |
||
| 487 | * @param string $type |
||
| 488 | * @param Array $params |
||
| 489 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 490 | * @link http://www.bamboohr.com/api/documentation/metadata.php |
||
| 491 | */ |
||
| 492 | View Code Duplication | function getMetaData($type, $params=array()) { |
|
|
0 ignored issues
–
show
|
|||
| 493 | $request=new BambooHTTPRequest(); |
||
| 494 | $request->method="GET"; |
||
| 495 | $request->url=$this->baseUrl."/v1/meta/$type/"; |
||
| 496 | return $this->httpHandler->sendRequest( $request ); |
||
| 497 | } |
||
| 498 | |||
| 499 | /** |
||
| 500 | * |
||
| 501 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 502 | * @link http://www.bamboohr.com/api/documentation/metadata.php#users |
||
| 503 | */ |
||
| 504 | function getUsers() { |
||
|
0 ignored issues
–
show
|
|||
| 505 | return $this->getMetaData('users'); |
||
| 506 | } |
||
| 507 | |||
| 508 | /** |
||
| 509 | * |
||
| 510 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 511 | * @link http://www.bamboohr.com/api/documentation/metadata.php#lists |
||
| 512 | */ |
||
| 513 | function getLists() { |
||
|
0 ignored issues
–
show
|
|||
| 514 | return $this->getMetaData('lists'); |
||
| 515 | } |
||
| 516 | |||
| 517 | /** |
||
| 518 | * |
||
| 519 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 520 | * @link http://www.bamboohr.com/api/documentation/metadata.php#fields |
||
| 521 | */ |
||
| 522 | function getFields() { |
||
|
0 ignored issues
–
show
|
|||
| 523 | return $this->getMetaData('fields'); |
||
| 524 | } |
||
| 525 | |||
| 526 | /** |
||
| 527 | * |
||
| 528 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 529 | * @link http://www.bamboohr.com/api/documentation/metadata.php#tables |
||
| 530 | */ |
||
| 531 | function getTables() { |
||
|
0 ignored issues
–
show
|
|||
| 532 | return $this->getMetaData('tables'); |
||
| 533 | } |
||
| 534 | |||
| 535 | /** |
||
| 536 | * |
||
| 537 | * @param int $employeeId |
||
| 538 | * @param string $date (date in the format YYYY-mm-dd) |
||
| 539 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 540 | * @link http://www.dev5.bamboohr.com/api/documentation/time_off.php#estimateFutureBalance |
||
| 541 | */ |
||
| 542 | function getTimeOffBalances($employeeId,$date) { |
||
|
0 ignored issues
–
show
|
|||
| 543 | $request=new BambooHTTPRequest(); |
||
| 544 | $request->method="GET"; |
||
| 545 | $request->url=$this->baseUrl."/v1/employees/".intval($employeeId)."/time_off/calculator?end=".$date; |
||
| 546 | return $this->httpHandler->sendRequest( $request ); |
||
| 547 | } |
||
| 548 | |||
| 549 | /** |
||
| 550 | * |
||
| 551 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 552 | * @link http://www.dev5.bamboohr.com/api/documentation/metadata.php#timeOffTypes |
||
| 553 | */ |
||
| 554 | function getTimeOffTypes() { |
||
|
0 ignored issues
–
show
|
|||
| 555 | return $this->getMetaData('time_off/types'); |
||
| 556 | } |
||
| 557 | |||
| 558 | /** |
||
| 559 | * |
||
| 560 | * @param type $arr array(["id" => int], ["action" => "(view|approve)"], ["type" => "id,id"],["status" => "(approved|denied|superceded|requested|canceled)"], ["start" => "YYYY-mm-dd"], ["end" => "YYYY-mm-dd"], ["employeeId" => "id"]) |
||
| 561 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 562 | * @link http://www.dev5.bamboohr.com/api/documentation/time_off.php#requests |
||
| 563 | */ |
||
| 564 | function getTimeOffRequestsArr($arr) { |
||
|
0 ignored issues
–
show
|
|||
| 565 | $request=new BambooHTTPRequest(); |
||
| 566 | $request->method="GET"; |
||
| 567 | $request->url=$this->baseUrl."/v1/time_off/requests/?"; |
||
| 568 | View Code Duplication | if(isset($arr['id'])) $request->url.="id=".urlencode($arr['id'])."&"; |
|
| 569 | View Code Duplication | if(isset($arr['action'])) $request->url.="action=".urlencode($arr['action'])."&"; |
|
| 570 | View Code Duplication | if(isset($arr['type'])) $request->url.="type=".urlencode($arr['type'])."&"; |
|
| 571 | View Code Duplication | if(isset($arr['status'])) $request->url.="status=".urlencode($arr['status'])."&"; |
|
| 572 | View Code Duplication | if(isset($arr['start'])) $request->url.="start=".urlencode($arr['start'])."&"; |
|
| 573 | View Code Duplication | if(isset($arr['end'])) $request->url.="end=".urlencode($arr['end'])."&"; |
|
| 574 | View Code Duplication | if(isset($arr['employeeId'])) $request->url.="employeeId=".urlencode($arr['employeeId'])."&"; |
|
| 575 | return $this->httpHandler->sendRequest( $request ); |
||
| 576 | } |
||
| 577 | |||
| 578 | /** |
||
| 579 | * |
||
| 580 | * @param string $start format: "YYYY-mm-dd" |
||
| 581 | * @param string $end format "YYYY-mm-dd" |
||
| 582 | * @param string $status (approved|denied|superceded|requested|canceled) |
||
| 583 | * @param int $type A time off type id |
||
| 584 | * @param int $employeeId An employee id |
||
| 585 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 586 | * @see getTimeOffTypes() |
||
| 587 | * @link http://www.bamboohr.com/api/documentation/time_off.php#requests |
||
| 588 | */ |
||
| 589 | function getTimeOffRequests($start="", $end="", $status="", $type="", $employeeId=0) { |
||
|
0 ignored issues
–
show
|
|||
| 590 | $arr=array(); |
||
| 591 | if($type!="") $arr["type"]=$type; |
||
| 592 | if($status!="") $arr["status"]=$status; |
||
| 593 | if($start!="") $arr["start"]=$start; |
||
| 594 | if($end!="") $arr["end"]=$end; |
||
| 595 | if($employeeId!=0) $arr["employeeId"]=$employeeId; |
||
| 596 | return $this->getTimeOffRequestsArr($arr); |
||
| 597 | } |
||
| 598 | |||
| 599 | /** |
||
| 600 | * |
||
| 601 | * @param int $employeeId An employee id |
||
| 602 | * @param string $tableName A table alias. Check out function |
||
| 603 | * @param array $values |
||
| 604 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 605 | * @see getTables() |
||
| 606 | * @link http://www.bamboohr.com/api/documentation/tables.php#addRow |
||
| 607 | */ |
||
| 608 | View Code Duplication | function addTableRow($employeeId, $tableName, $values) { |
|
|
0 ignored issues
–
show
|
|||
| 609 | $request=new BambooHTTPRequest(); |
||
| 610 | $request->method="POST"; |
||
| 611 | $request->url=$this->baseUrl."/v1/employees/".intval($employeeId)."/tables/".$tableName."/"; |
||
| 612 | |||
| 613 | $xml="<row>".$this->prepareKeyValues($values)."</row>"; |
||
| 614 | $request->content=$xml; |
||
| 615 | |||
| 616 | return $this->httpHandler->sendRequest( $request ); |
||
| 617 | } |
||
| 618 | |||
| 619 | /** |
||
| 620 | * |
||
| 621 | * @param int $employeeId |
||
| 622 | * @param string $start format: YYYY-mm-dd |
||
| 623 | * @param string $end format: YYYY-mm-dd |
||
| 624 | * @param int $timeOffTypeId |
||
| 625 | * @param float $amount |
||
| 626 | * @param string $status (approved|denied|superceded|requested|canceled) |
||
| 627 | * @param string $employeeNote |
||
| 628 | * @param string $managerNote |
||
| 629 | * @param int $previous |
||
| 630 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 631 | * @link http://www.bamboohr.com/api/documentation/time_off.php#addrequest |
||
| 632 | */ |
||
| 633 | function addTimeOffRequest($employeeId, $start, $end, $timeOffTypeId, $amount, $status, $employeeNote, $managerNote,$previous=0) { |
||
|
0 ignored issues
–
show
|
|||
| 634 | $request=new BambooHTTPRequest(); |
||
| 635 | $request->method="PUT"; |
||
| 636 | $request->url=$this->baseUrl."/v1/employees/".intval($employeeId)."/time_off/request/"; |
||
| 637 | |||
| 638 | $values=array( |
||
| 639 | "start"=>$start, |
||
| 640 | "end"=>$end, |
||
| 641 | "timeOffTypeId"=>intval($timeOffTypeId), |
||
| 642 | "status"=>$status, |
||
| 643 | "amount"=>$amount |
||
| 644 | ); |
||
| 645 | if($previous!=0) $values["previousRequest"]=intval($previous); |
||
| 646 | $xml="<history>\n"; |
||
| 647 | View Code Duplication | foreach($values as $tag=>$value) { |
|
| 648 | $xml.=sprintf("<%s>%s</%s>\n",$tag, htmlspecialchars($value, ENT_COMPAT),$tag); |
||
| 649 | } |
||
| 650 | |||
| 651 | $xml.="<notes>"; |
||
| 652 | if($employeeNote!="") { |
||
| 653 | $xml.=sprintf('<note from="employee">%s</note>'."\n", $employeeNote ); |
||
| 654 | } |
||
| 655 | if($managerNote!="") { |
||
| 656 | $xml.=sprintf('<note from="manager">%s</note>'."\n", $managerNote ); |
||
| 657 | } |
||
| 658 | $xml.="</notes>\n"; |
||
| 659 | $xml.="</history>"; |
||
| 660 | $request->content=$xml; |
||
| 661 | return $this->httpHandler->sendRequest( $request ); |
||
| 662 | } |
||
| 663 | |||
| 664 | /** |
||
| 665 | * |
||
| 666 | * @param int $employeeId |
||
| 667 | * @param string $ymd format: "YYYY-m-d" |
||
| 668 | * @param int $requestId |
||
| 669 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 670 | * @link http://www.bamboohr.com/api/documentation/time_off.php#addhistory |
||
| 671 | */ |
||
| 672 | function addTimeOffHistoryFromRequest($employeeId, $ymd, $requestId) { |
||
|
0 ignored issues
–
show
|
|||
| 673 | $request=new BambooHTTPRequest(); |
||
| 674 | $request->method="PUT"; |
||
| 675 | $request->url=$this->baseUrl."/v1/employees/".intval($employeeId)."/time_off/history/"; |
||
| 676 | |||
| 677 | $values=array( |
||
| 678 | "date"=>$ymd, |
||
| 679 | "timeOffRequestId"=>intval($requestId), |
||
| 680 | "eventType"=>"used", |
||
| 681 | ); |
||
| 682 | $xml="<history>\n"; |
||
| 683 | View Code Duplication | foreach($values as $tag=>$value) { |
|
| 684 | $xml.=sprintf("<%s>%s</%s>\n",$tag, htmlspecialchars($value, ENT_COMPAT),$tag); |
||
| 685 | } |
||
| 686 | $xml.="</history>"; |
||
| 687 | $request->content=$xml; |
||
| 688 | echo $xml; |
||
| 689 | return $this->httpHandler->sendRequest( $request ); |
||
| 690 | } |
||
| 691 | |||
| 692 | /** |
||
| 693 | * |
||
| 694 | * @param int $employeeId |
||
| 695 | * @param string $ymd format: "YYYY-mm-dd" |
||
| 696 | * @param int $timeOffTypeId |
||
| 697 | * @param string $note |
||
| 698 | * @param float $amount |
||
| 699 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 700 | * @link http://www.bamboohr.com/api/documentation/time_off.php#addhistory |
||
| 701 | * @see getTimeOffTypes() |
||
| 702 | */ |
||
| 703 | function recordTimeOffOverride($employeeId, $ymd, $timeOffTypeId, $note, $amount) { |
||
|
0 ignored issues
–
show
|
|||
| 704 | $request=new BambooHTTPRequest(); |
||
| 705 | $request->method="PUT"; |
||
| 706 | $request->url=$this->baseUrl."/v1/employees/".intval($employeeId)."/time_off/history/"; |
||
| 707 | |||
| 708 | $values=array( |
||
| 709 | "date"=>$ymd, |
||
| 710 | "timeOffTypeId"=>intval($requestId), |
||
| 711 | "eventType"=>"override", |
||
| 712 | "note"=>$note, |
||
| 713 | "amount"=>$amount |
||
| 714 | ); |
||
| 715 | $xml="<history>\n"; |
||
| 716 | View Code Duplication | foreach($values as $tag=>$value) { |
|
| 717 | $xml.=sprintf("<%s>%s</%s>\n",$tag, htmlspecialchars($value, ENT_COMPAT),$tag); |
||
| 718 | } |
||
| 719 | $xml.="</history>"; |
||
| 720 | $request->content=$xml; |
||
| 721 | return $this->httpHandler->sendRequest( $request ); |
||
| 722 | } |
||
| 723 | |||
| 724 | /** |
||
| 725 | * |
||
| 726 | * @param int $employeeId |
||
| 727 | * @param string $tableName |
||
| 728 | * @param int $rowId |
||
| 729 | * @param array $values |
||
| 730 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 731 | * @link http://www.bamboohr.com/api/documentation/tables.php#updateRow |
||
| 732 | * @see getTables() |
||
| 733 | */ |
||
| 734 | View Code Duplication | function updateTableRow($employeeId, $tableName, $rowId, $values) { |
|
|
0 ignored issues
–
show
|
|||
| 735 | $request=new BambooHTTPRequest(); |
||
| 736 | $request->method="POST"; |
||
| 737 | $request->url=$this->baseUrl."/v1/employees/".intval($employeeId)."/tables/".$tableName."/".intval($rowId); |
||
| 738 | |||
| 739 | $xml="<row>".$this->prepareKeyValues($values)."</row>"; |
||
| 740 | $request->content=$xml; |
||
| 741 | |||
| 742 | return $this->httpHandler->sendRequest( $request ); |
||
| 743 | } |
||
| 744 | |||
| 745 | /** |
||
| 746 | * |
||
| 747 | * @param int $employeeId |
||
| 748 | * @param int $categoryId |
||
| 749 | * @param string $fileName |
||
| 750 | * @param string $contentType |
||
| 751 | * @param string $fileData |
||
| 752 | * @param string $shareWithEmployees (yes|no) |
||
| 753 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 754 | * @link http://www.bamboohr.com/api/documentation/employees.php#uploadEmployeeFile |
||
| 755 | * @see listEmployeeFiles() |
||
| 756 | */ |
||
| 757 | View Code Duplication | function uploadEmployeeFile($employeeId, $categoryId, $fileName, $contentType, $fileData, $shareWithEmployees = 'no') { |
|
|
0 ignored issues
–
show
|
|||
| 758 | $request=new BambooHttpRequest(); |
||
| 759 | $request->url=$this->baseUrl."/v1/employees/".intval($employeeId)."/files/"; |
||
| 760 | $request->method="POST"; |
||
| 761 | |||
| 762 | $params=array( |
||
| 763 | "category"=>$categoryId, |
||
| 764 | "fileName"=>$fileName, |
||
| 765 | "share"=>$shareWithEmployees |
||
| 766 | ); |
||
| 767 | $request->content=buildMultipart( BAMBOOHR_MULTIPART_BOUNDARY, $params, "file",$fileName,$contentType, $fileData); |
||
| 768 | $request->headers[]="Content-Type: multipart/form-data; boundary=".BAMBOOHR_MULTIPART_BOUNDARY; |
||
| 769 | $request->headers[]="Content-Length: ".strlen( $request->content ); |
||
| 770 | |||
| 771 | return $this->httpHandler->sendRequest( $request ); |
||
| 772 | } |
||
| 773 | |||
| 774 | /** |
||
| 775 | * |
||
| 776 | * @param int $requestId |
||
| 777 | * @param string $status (approved|denied|superceded|requested|canceled) |
||
| 778 | * @param string $note |
||
| 779 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 780 | * @link http://www.bamboohr.com/api/documentation/time_off.php#updateRequestStatus |
||
| 781 | */ |
||
| 782 | function updateTimeOffRequestStatus($requestId, $status, $note) { |
||
|
0 ignored issues
–
show
|
|||
| 783 | $request=new BambooHTTPRequest(); |
||
| 784 | $request->url=$this->baseUrl."/v1/time_off/requests/".intval($requestId)."/status/"; |
||
| 785 | $request->method="POST"; |
||
| 786 | $request->content="<request><status>".htmlentities($status,ENT_COMPAT)."</status><note>".htmlentities($note,ENT_COMPAT)."</note></request>"; |
||
| 787 | return $this->httpHandler->sendRequest( $request ); |
||
| 788 | } |
||
| 789 | |||
| 790 | /** |
||
| 791 | * |
||
| 792 | * @param int $categoryId |
||
| 793 | * @param string $fileName |
||
| 794 | * @param string $contentType |
||
| 795 | * @param string $fileData |
||
| 796 | * @param string $shareWithEmployees (yes|no) |
||
| 797 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 798 | * @link http://www.bamboohr.com/api/documentation/employees.php#uploadCompanyFile |
||
| 799 | * @see getCompanyFiles() |
||
| 800 | */ |
||
| 801 | View Code Duplication | function uploadCompanyFile($categoryId, $fileName, $contentType, $fileData, $shareWithEmployees = 'no') { |
|
|
0 ignored issues
–
show
|
|||
| 802 | $request=new BambooHttpRequest(); |
||
| 803 | $request->url=$this->baseUrl."/v1/files/"; |
||
| 804 | $request->method="POST"; |
||
| 805 | |||
| 806 | $params=array( |
||
| 807 | "category"=>$categoryId, |
||
| 808 | "fileName"=>$fileName, |
||
| 809 | "share"=>$shareWithEmployees |
||
| 810 | ); |
||
| 811 | $request->content=buildMultipart( BAMBOOHR_MULTIPART_BOUNDARY, $params, "file",$fileName,$contentType, $fileData); |
||
| 812 | $request->headers[]="Content-Type: multipart/form-data; boundary=".BAMBOOHR_MULTIPART_BOUNDARY; |
||
| 813 | $request->headers[]="Content-Length: ".strlen( $request->content ); |
||
| 814 | |||
| 815 | return $this->httpHandler->sendRequest( $request ); |
||
| 816 | } |
||
| 817 | |||
| 818 | /** |
||
| 819 | * |
||
| 820 | * @param int $employeeId |
||
| 821 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 822 | * @link http://www.bamboohr.com/api/documentation/employees.php#listEmployeeFiles |
||
| 823 | */ |
||
| 824 | View Code Duplication | function listEmployeeFiles($employeeId){ |
|
|
0 ignored issues
–
show
|
|||
| 825 | $request=new BambooHTTPRequest(); |
||
| 826 | $request->method="GET"; |
||
| 827 | $request->url=$this->baseUrl."/v1/employees/".intval($employeeId)."/files/view/"; |
||
| 828 | return $this->httpHandler->sendRequest( $request ); |
||
| 829 | } |
||
| 830 | |||
| 831 | /** |
||
| 832 | * |
||
| 833 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 834 | * @link http://www.bamboohr.com/api/documentation/employees.php#listCompanyFiles |
||
| 835 | */ |
||
| 836 | View Code Duplication | function listCompanyFiles(){ |
|
|
0 ignored issues
–
show
|
|||
| 837 | $request=new BambooHTTPRequest(); |
||
| 838 | $request->method="GET"; |
||
| 839 | $request->url=$this->baseUrl."/v1/files/view/"; |
||
| 840 | return $this->httpHandler->sendRequest( $request ); |
||
| 841 | } |
||
| 842 | |||
| 843 | /** |
||
| 844 | * |
||
| 845 | * @param string $categoryName |
||
| 846 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 847 | * @link http://www.bamboohr.com/api/documentation/employees.php#addEmployeeCategory |
||
| 848 | */ |
||
| 849 | View Code Duplication | function addEmployeeFileCategory($categoryName){ |
|
|
0 ignored issues
–
show
|
|||
| 850 | $request=new BambooHTTPRequest(); |
||
| 851 | $request->method="POST"; |
||
| 852 | $request->url=$this->baseUrl."/v1/employees/files/categories/"; |
||
| 853 | |||
| 854 | $xml='<employee>'; |
||
| 855 | $xml.='<category>'.htmlspecialchars($categoryName).'</category>'; |
||
| 856 | $xml.='</employee>'; |
||
| 857 | $request->content=$xml; |
||
| 858 | |||
| 859 | return $this->httpHandler->sendRequest($request); |
||
| 860 | } |
||
| 861 | |||
| 862 | /** |
||
| 863 | * |
||
| 864 | * @param string $categoryName |
||
| 865 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 866 | * @link http://www.bamboohr.com/api/documentation/employees.php#addCompanyCategory |
||
| 867 | */ |
||
| 868 | View Code Duplication | function addCompanyFileCategory($categoryName){ |
|
|
0 ignored issues
–
show
|
|||
| 869 | $request=new BambooHTTPRequest(); |
||
| 870 | $request->method="POST"; |
||
| 871 | $request->url=$this->baseUrl."/v1/files/categories/"; |
||
| 872 | |||
| 873 | $xml='<files>'; |
||
| 874 | $xml.='<category>'.htmlspecialchars($categoryName).'</category>'; |
||
| 875 | $xml.='</files>'; |
||
| 876 | $request->content=$xml; |
||
| 877 | |||
| 878 | return $this->httpHandler->sendRequest($request); |
||
| 879 | } |
||
| 880 | |||
| 881 | /** |
||
| 882 | * |
||
| 883 | * @param int $employeeId |
||
| 884 | * @param int $fileId |
||
| 885 | * @param array $values array(["name" => "new name"],["categoryId" => 1],["shareWithEmployee" => "(yes|no)"]); |
||
| 886 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 887 | * @link http://www.bamboohr.com/api/documentation/employees.php#updateEmployeeFile |
||
| 888 | */ |
||
| 889 | View Code Duplication | function updateEmployeeFile($employeeId, $fileId, $values){ |
|
|
0 ignored issues
–
show
|
|||
| 890 | $request=new BambooHTTPRequest(); |
||
| 891 | $request->method="POST"; |
||
| 892 | $request->url=$this->baseUrl."/v1/employees/".intval($employeeId)."/files/".intval($fileId)."/"; |
||
| 893 | |||
| 894 | $xml = "<file>"; |
||
| 895 | foreach($values as $name=>$value){ |
||
| 896 | $xml.="<".htmlspecialchars($name).">".htmlspecialchars($value)."</".htmlspecialchars($name).">"; |
||
| 897 | } |
||
| 898 | $xml.="</file>"; |
||
| 899 | $request->content=$xml; |
||
| 900 | |||
| 901 | return $this->httpHandler->sendRequest($request); |
||
| 902 | } |
||
| 903 | |||
| 904 | /** |
||
| 905 | * |
||
| 906 | * @param int $fileId |
||
| 907 | * @param array $values array(["name" => "new name"],["categoryId" => 1],["shareWithEmployees" => "(yes|no)"]) |
||
| 908 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 909 | * @link http://www.bamboohr.com/api/documentation/employees.php#updateCompanyFile |
||
| 910 | */ |
||
| 911 | View Code Duplication | function updateCompanyFile($fileId, $values){ |
|
|
0 ignored issues
–
show
|
|||
| 912 | $request=new BambooHTTPRequest(); |
||
| 913 | $request->method="POST"; |
||
| 914 | $request->url=$this->baseUrl."/v1/files/".intval($fileId)."/"; |
||
| 915 | |||
| 916 | $xml = "<file>"; |
||
| 917 | foreach($values as $name=>$value){ |
||
| 918 | $xml.="<".htmlspecialchars($name).">".htmlspecialchars($value)."</".htmlspecialchars($name).">"; |
||
| 919 | } |
||
| 920 | $xml.="</file>"; |
||
| 921 | $request->content=$xml; |
||
| 922 | |||
| 923 | return $this->httpHandler->sendRequest($request); |
||
| 924 | } |
||
| 925 | |||
| 926 | /** |
||
| 927 | * |
||
| 928 | * @param int $employeeId |
||
| 929 | * @param int $fileId |
||
| 930 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 931 | * @link http://www.bamboohr.com/api/documentation/employees.php#downloadEmployeeFile |
||
| 932 | */ |
||
| 933 | View Code Duplication | function downloadEmployeeFile($employeeId, $fileId) { |
|
|
0 ignored issues
–
show
|
|||
| 934 | $request=new BambooHTTPRequest(); |
||
| 935 | $request->method="GET"; |
||
| 936 | $request->url=$this->baseUrl."/v1/employees/".intval($employeeId)."/files/".intval($fileId)."/"; |
||
| 937 | |||
| 938 | return $this->httpHandler->sendRequest( $request ); |
||
| 939 | } |
||
| 940 | |||
| 941 | /** |
||
| 942 | * |
||
| 943 | * @param int $fileId |
||
| 944 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 945 | * @link http://www.bamboohr.com/api/documentation/employees.php#downloadCompanyFile |
||
| 946 | */ |
||
| 947 | View Code Duplication | function downloadCompanyFile($fileId){ |
|
|
0 ignored issues
–
show
|
|||
| 948 | $request=new BambooHTTPRequest(); |
||
| 949 | $request->method="GET"; |
||
| 950 | $request->url=$this->baseUrl."/v1/files/".intval($fileId)."/"; |
||
| 951 | return $this->httpHandler->sendRequest( $request ); |
||
| 952 | } |
||
| 953 | |||
| 954 | /** |
||
| 955 | * This api is undocumented. It is only useful for importing large numbers of |
||
| 956 | * employees. Look at the test_import.xml file for an example import. |
||
| 957 | * |
||
| 958 | * @param string $xml |
||
| 959 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 960 | */ |
||
| 961 | View Code Duplication | function importEmployees($xml){ |
|
|
0 ignored issues
–
show
|
|||
| 962 | $request=new BambooHTTPRequest(); |
||
| 963 | $request->method="POST"; |
||
| 964 | $request->url=$this->baseUrl."/v1/employees/import"; |
||
| 965 | $request->content=$xml; |
||
| 966 | |||
| 967 | return $this->httpHandler->sendRequest($request); |
||
| 968 | } |
||
| 969 | |||
| 970 | /** |
||
| 971 | * |
||
| 972 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 973 | * @link http://www.dev5.bamboohr.com/api/documentation/employees.php#getEmployeeDirectory |
||
| 974 | */ |
||
| 975 | View Code Duplication | function getDirectory() { |
|
|
0 ignored issues
–
show
|
|||
| 976 | $request=new BambooHTTPRequest(); |
||
| 977 | $request->method="GET"; |
||
| 978 | $request->url=$this->baseUrl."/v1/employees/directory"; |
||
| 979 | return $this->httpHandler->sendRequest( $request ); |
||
| 980 | } |
||
| 981 | |||
| 982 | /** |
||
| 983 | * |
||
| 984 | * @param int |
||
| 985 | * @param int|string (1|2|small|tiny) |
||
| 986 | * @param array array(["width" => 100], ["height" => 100]) |
||
| 987 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 988 | */ |
||
| 989 | View Code Duplication | function downloadEmployeePhoto($employeeId, $size, $params=array()) { |
|
|
0 ignored issues
–
show
|
|||
| 990 | $request=new BambooHTTPRequest(); |
||
| 991 | $request->method="GET"; |
||
| 992 | $request->url=$this->baseUrl."/v1/employees/".intval($employeeId)."/photo/".urlencode($size); |
||
| 993 | if(count($params)>0) { |
||
| 994 | $request->url.="?".http_build_query($params); |
||
| 995 | } |
||
| 996 | return $this->httpHandler->sendRequest( $request ); |
||
| 997 | } |
||
| 998 | |||
| 999 | /** |
||
| 1000 | * |
||
| 1001 | * @param string an alias from {@see getTables()} |
||
| 1002 | * @param string format: 2012-19-29T11:53:05Z |
||
| 1003 | * @return \BambooHR\API\BambooHTTPResponse |
||
| 1004 | * @link http://www.bamboohr.com/api/documentation/tables.php#changedEmployeeTables |
||
| 1005 | */ |
||
| 1006 | function getChangedEmployeeTable($table,$since) { |
||
|
0 ignored issues
–
show
|
|||
| 1007 | $request=new BambooHTTPRequest(); |
||
| 1008 | $request->method="GET"; |
||
| 1009 | $request->url=$this->baseUrl."/v1/employees/changed/tables/".urlencode($table)."?since=".urlencode($since); |
||
| 1010 | return $this->httpHandler->sendRequest( $request ); |
||
| 1011 | } |
||
| 1012 | } |
||
| 1013 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.