| <?php |
| // EXAMPLE: AUTO-APPROVE TIME OFF REQUESTS |
| // |
| // This code example illustrates how to listen for newly created requests for time off, then |
| // automatically approve them (this is great for organizations that have a more flexible time |
| // off policy). This script listens for a WebHook event, then connects to the site via the REST |
| // API to get the details and modify the details of the request. |
| // |
| // More on WebHooks: http://developers.tribehr.com/api/webhook-event-notification/ |
| // More on the REST Api: http://developers.tribehr.com/api/api-introduction/ |
| // |
| // PHP API Wrapper: https://github.com/TribeHR/TribeHR-PHP-Client |
| // Set your TribeHR credentials |
| define('SUBDOMAIN', ''); // Your TribeHR Sub Domain |
| define('USER', ''); // The username of an Administrator |
| define('KEY', ''); // The API KEY of the administrator above |
| // Include the API Wrapper |
| require('./TribeHR-PHP-Client/TribeHR.php'); |
| // Let's only process the payload if we're going to actually be getting |
| // a LeaveRequest. Note - this logic can be easily extende to create a script that |
| // can handle multiple different WebHook types. |
| if(isset($_POST['object_id']) && isset($_POST['object']) && $_POST['object'] == 'LeaveRequest') |
| { |
| // Create my connection to the site using the API Wrapper |
| $TribeHRConnection = new TribeHRConnector(SUBDOMAIN, USER, KEY); |
| // Get the specific Leave Request, as specified by the WebHook data |
| $id = intval($_POST['object_id']); |
| $tc = $TribeHRConnection->sendRequest('/leave_requests/'.$id.'.xml', 'GET'); |
| // Create the new request data, based on the old request. Some interesting constraints |
| // caused by the current API version: |
| // - date_start and date_end exped m/d/Y format, but the API returns Y-m-d |
| // - the API requires a complete data object, so all fields must be specified |
| // - the status APPROVED == 1 |
| $old_request = simplexml_load_string($tc->response); |
| $new_request = array( |
| 'id' => (string) $old_request->leave_request['id'], |
| 'comments' => (string) $old_request->leave_request['comments'] . "\nAuto-Approved", |
| 'date_start' => date('m/d/Y', strtotime($old_request->leave_request['date_start'])), |
| 'date_end' => date('m/d/Y', strtotime($old_request->leave_request['date_end'])), |
| 'days' => (string) $old_request->leave_request['days'], |
| 'leave_type_id' => (string) $old_request->leave_request['leave_type_id'], |
| 'user_id' => (string) $old_request->leave_request['user_id'], |
| 'status' => 1, |
| ); |
| // Submit the new data |
| $tc = $TribeHRConnection->sendRequest('/leave_requests/'.$id.'.xml', 'PUT', $new_request); |
| // Let's echo our the response for good measure |
| echo htmlentities($tc->response); |
| } |
| else |
| { |
| // Since there wasn't a valid payload, let's echo a message out |
| echo 'This script listens for TribeHR WebHooks to auto-approve vacation requests'; |
| } |
| ?> |
.
Thursday, 28 August 2014
Subscribe to:
Post Comments (Atom)
.
Popular Posts
-
List of Free and Open Source CMS List of CMS (Content Management System), free and open source, written in PHP or other languages. Click on ...
-
Types of Encryption - Conventional Methods Encryption - Decryption: To carry sensitive information, such as military or financial data, a sy...
-
As a popular open source solution, Joomla has a very flexible architecture and ever more developers build various components and modules f...
-
To add a new menu which can hold menu items do the following: Log in to the Joomla! Administrator Back-end. Click Menus > Menu Manager ...
-
Joomla is the popular CMS which helps you create website easily. If you use Joomla as long enough to say you know everything about J...
-
In this SMF introductory installation tutorial, we will demonstrate how to install the Simple Machine Forums (SMF) program manually. A man...
-
photo by Castles, Capes & Clones/Flickr If you're doing custom design and development with Joomla! you need all of the tips an...
-
Installation CakePHP is simple and easy to install. The minimum requirements are a web server and a copy of CakePHP, that’s it! While this c...
-
Introduction This article provides detailed instructions for configuring a LAMPP server, not only for Joomla! it also should work fine for ...
-
Simple Login logout system using php Login and logout system is the most important thing for the user management, session management is on...
Powered by Blogger.
0 comments:
Post a Comment