diff --git a/README.md b/README.md
index da6e558..ea98b99 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@ have is:
require './shiftplanning.php';
- $shiftplanning = new shiftplanning(
+ $shiftplanning = new Shiftplanning(
array(
'key' => 'XXXXXXXXXXXXXXXXXX' // enter your developer key
)
diff --git a/examples/examples.php b/examples/examples.php
index f61fc34..1e3b97f 100644
--- a/examples/examples.php
+++ b/examples/examples.php
@@ -1,17 +1,17 @@
'XXXXXXXXXXXXXXXXXX' // enter your developer key
)
);
// or set the developer key using the setAppKey method
-//$shiftplanning->setAppKey( 'XXXXXXXXXXXXXXXXXX' );
+//$shiftplanning->setAppKey('XXXXXXXXXXXXXXXXXX');
/**
*
@@ -22,13 +22,14 @@
// check for a current active session
// if a session exists, $session will now hold the user's information
-$session = $shiftplanning->getSession( );
+$session = $shiftplanning->getSession();
echo "appKey: " . $shiftplanning->getAppKey( ) . "
"; // returns the developer key currently set
echo "appToken: " . $shiftplanning->getAppToken( ) . "
"; // returns the token for the current session, error if not yet set
-if( !$session )
-{// if a session hasn't been started, create one
+if (!$session)
+{
+ // if a session hasn't been started, create one
// perform a single API call to authenticate a user
$response = $shiftplanning->doLogin(
@@ -38,7 +39,7 @@
)
);
- if( $response['status']['code'] == 1 )
+ if ($response['status']['code'] == 1)
{// check to make sure that login was successful
$session = $shiftplanning->getSession( ); // return the session data after successful login
echo "Hi, " . $session['employee']['name'] . "
";
@@ -49,79 +50,80 @@
}
}
else
-{// session has been established
+{
+ // session has been established
// the $session variable now holds the currently logged in user's data
echo "Hi, " . $session['employee']['name'] . "
";
/**
* Quick Access ShiftPlanning SDK Methods:
- * doLogin( $array_of_user_data )
- * doLogout( )
- * getMessages( )
- * getMessageDetails( $message_id )
- * createMessage( $array_of_message_data )
- * deleteMessage( $message_id )
- * getWallMessages( )
- * createWallMessage( $array_of_message_data )
- * deleteWallMessage( $message_id, $array_of_other_message_data )
- * getEmployees( )
- * getEmployeeDetails( $employee_id_number )
- * updateEmployee( $employee_id, $array_of_updated_employee_data )
- * createEmployee( $array_of_employee_data )
- * deleteEmployee( $employee_id )
- * getStaffSkills( )
- * getStaffSkillDetails( $skill_id )
- * createStaffSkill( $array_of_skill_data )
- * updateStaffSkill( $skill_id, $array_of_skill_data )
- * deleteStaffSkill( $skill_id )
- * createPing( $array_of_ping_data )
- * getSchedules( )
- * getScheduleDetails( $schedule_id )
- * createSchedule( $array_of_schedule_data )
- * updateSchedule( $schedule_id, $array_of_schedule_data )
- * deleteSchedule( $schedule_id )
- * getShifts( )
- * getShiftDetails( $shift_id )
- * updateShift( $shift_id, $array_of_shift_data )
- * createShift( $array_of_shift_data )
- * deleteShift( $shift_id )
- * getVacationSchedules( $time_period_array ) // e.g. getVacationSchedules( array( 'start' => '', 'end' => '' ) );
- * getVacationScheduleDetails( $schedule_id )
- * createVacationSchedule( $array_of_schedule_data )
- * updateVacationSchedule( $schedule_id, $array_of_schedule_data )
- * deleteVacationSchedule( $schedule_id )
- * getScheduleConflicts( )
- * getAdminSettings( )
- * updateAdminSettings( $array_of_new_settings )
- * getAdminFiles( )
- * getAdminFileDetails( $file_id )
- * updateAdminFile( $file_id, $array_of_file_data )
- * createAdminFile( $array_of_file_data )
- * deleteAdminFile( $file_id )
- * getAdminBackups( )
- * getAdminBackupDetails( $backup_id )
- * createAdminBackup( $array_of_backup_data )
- * deleteAdminBackup( $backup_id )
- * getAPIConfig( )
- * getAPIMethods( )
+ * doLogin($array_of_user_data)
+ * doLogout()
+ * getMessages()
+ * getMessageDetails($message_id)
+ * createMessage($array_of_message_data)
+ * deleteMessage($message_id)
+ * getWallMessages()
+ * createWallMessage($array_of_message_data)
+ * deleteWallMessage($message_id, $array_of_other_message_data)
+ * getEmployees()
+ * getEmployeeDetails($employee_id_number)
+ * updateEmployee($employee_id, $array_of_updated_employee_data)
+ * createEmployee($array_of_employee_data)
+ * deleteEmployee($employee_id)
+ * getStaffSkills()
+ * getStaffSkillDetails($skill_id)
+ * createStaffSkill($array_of_skill_data)
+ * updateStaffSkill($skill_id, $array_of_skill_data)
+ * deleteStaffSkill($skill_id)
+ * createPing($array_of_ping_data)
+ * getSchedules()
+ * getScheduleDetails($schedule_id)
+ * createSchedule($array_of_schedule_data)
+ * updateSchedule($schedule_id, $array_of_schedule_data)
+ * deleteSchedule($schedule_id)
+ * getShifts()
+ * getShiftDetails($shift_id)
+ * updateShift($shift_id, $array_of_shift_data)
+ * createShift($array_of_shift_data)
+ * deleteShift($shift_id)
+ * getVacationSchedules($time_period_array) // e.g. getVacationSchedules(array('start' => '', 'end' => ''));
+ * getVacationScheduleDetails($schedule_id)
+ * createVacationSchedule($array_of_schedule_data)
+ * updateVacationSchedule($schedule_id, $array_of_schedule_data)
+ * deleteVacationSchedule($schedule_id)
+ * getScheduleConflicts()
+ * getAdminSettings()
+ * updateAdminSettings($array_of_new_settings)
+ * getAdminFiles()
+ * getAdminFileDetails($file_id)
+ * updateAdminFile($file_id, $array_of_file_data)
+ * createAdminFile($array_of_file_data)
+ * deleteAdminFile($file_id)
+ * getAdminBackups()
+ * getAdminBackupDetails($backup_id)
+ * createAdminBackup($array_of_backup_data)
+ * deleteAdminBackup($backup_id)
+ * getAPIConfig()
+ * getAPIMethods()
*/
/**
* All Quick-Access methods return a response like this:
* array(
- * 'status' => array( 'code' => '1', 'text' => 'Success', 'error' => 'Error message if any' ),
+ * 'status' => array('code' => '1', 'text' => 'Success', 'error' => 'Error message if any'),
* 'data' => array(
* 'field_name' => 'value'
* )
* )
*
- * For methods that return multiple objects (as in the case for the getMessages( ) method
+ * For methods that return multiple objects (as in the case for the getMessages() method
* responses will look like this, where the indexes [0], [1] would be replaced with the
* message you're looking to display
*
* array(
- * 'status' => array( 'code' => '1', 'text' => 'Success', 'error' => 'Error message if any' ),
+ * 'status' => array('code' => '1', 'text' => 'Success', 'error' => 'Error message if any'),
* 'data' => array(
* [0] => array (
* 'id' => 1,
@@ -136,7 +138,7 @@
*/
// Quick-Access Methods, to perform API calls more easily
- $employees = $shiftplanning->getEmployees( ); // returns all employees
+ $employees = $shiftplanning->getEmployees(); // returns all employees
$employee_1_wage = $employees['data'][0]['wage'];
echo "Employee 1 Wage: $" . $employee_1_wage . "
";
echo "Employee 1 Nick Name: " . $employees['data'][0]['nick_name'] . "
";
@@ -149,7 +151,7 @@
)
);
- if( $update_employee_record_response['status']['code'] == 1 )
+ if ($update_employee_record_response['status']['code'] == 1)
{// employee update successful
echo "Employee record updated.
";
}
@@ -216,16 +218,17 @@
}
- if( $get_schedules['status']['code'] == 1 )
- {// schedules were retrieved successfully
- print_r( $get_schedules['data'][0] ); // print data from first schedule returned
+ // schedules were retrieved successfully
+ if ($get_schedules['status']['code'] == 1)
+ {
+ print_r($get_schedules['data'][0]); // print data from first schedule returned
}
- if( $get_settings['status']['code'] == 1 )
- {// admin settings retrieved successfully
- print_r( $get_settings );
+ // admin settings retrieved successfully
+ if ($get_settings['status']['code'] == 1)
+ {
+ print_r($get_settings);
}
- //$shiftplanning->doLogout();
-}
-?>
\ No newline at end of file
+ $shiftplanning->doLogout();
+}
\ No newline at end of file
diff --git a/src/config/mimes.php b/src/config/mimes.php
new file mode 100644
index 0000000..fda283d
--- /dev/null
+++ b/src/config/mimes.php
@@ -0,0 +1,141 @@
+ "application/andrew-inset",
+ "hqx" => "application/mac-binhex40",
+ "cpt" => "application/mac-compactpro",
+ "doc" => "application/msword",
+ "bin" => "application/octet-stream",
+ "dms" => "application/octet-stream",
+ "lha" => "application/octet-stream",
+ "lzh" => "application/octet-stream",
+ "exe" => "application/octet-stream",
+ "class" => "application/octet-stream",
+ "so" => "application/octet-stream",
+ "dll" => "application/octet-stream",
+ "oda" => "application/oda",
+ "pdf" => "application/pdf",
+ "ai" => "application/postscript",
+ "eps" => "application/postscript",
+ "ps" => "application/postscript",
+ "smi" => "application/smil",
+ "smil" => "application/smil",
+ "wbxml" => "application/vnd.wap.wbxml",
+ "wmlc" => "application/vnd.wap.wmlc",
+ "wmlsc" => "application/vnd.wap.wmlscriptc",
+ "bcpio" => "application/x-bcpio",
+ "vcd" => "application/x-cdlink",
+ "pgn" => "application/x-chess-pgn",
+ "cpio" => "application/x-cpio",
+ "csh" => "application/x-csh",
+ "dcr" => "application/x-director",
+ "dir" => "application/x-director",
+ "dxr" => "application/x-director",
+ "dvi" => "application/x-dvi",
+ "spl" => "application/x-futuresplash",
+ "gtar" => "application/x-gtar",
+ "hdf" => "application/x-hdf",
+ "js" => "application/x-javascript",
+ "skp" => "application/x-koan",
+ "skd" => "application/x-koan",
+ "skt" => "application/x-koan",
+ "skm" => "application/x-koan",
+ "latex" => "application/x-latex",
+ "nc" => "application/x-netcdf",
+ "cdf" => "application/x-netcdf",
+ "sh" => "application/x-sh",
+ "shar" => "application/x-shar",
+ "swf" => "application/x-shockwave-flash",
+ "sit" => "application/x-stuffit",
+ "sv4cpio" => "application/x-sv4cpio",
+ "sv4crc" => "application/x-sv4crc",
+ "tar" => "application/x-tar",
+ "tcl" => "application/x-tcl",
+ "tex" => "application/x-tex",
+ "texinfo" => "application/x-texinfo",
+ "texi" => "application/x-texinfo",
+ "t" => "application/x-troff",
+ "tr" => "application/x-troff",
+ "roff" => "application/x-troff",
+ "man" => "application/x-troff-man",
+ "me" => "application/x-troff-me",
+ "ms" => "application/x-troff-ms",
+ "ustar" => "application/x-ustar",
+ "src" => "application/x-wais-source",
+ "xhtml" => "application/xhtml+xml",
+ "xht" => "application/xhtml+xml",
+ "zip" => "application/zip",
+ "au" => "audio/basic",
+ "snd" => "audio/basic",
+ "mid" => "audio/midi",
+ "midi" => "audio/midi",
+ "kar" => "audio/midi",
+ "mpga" => "audio/mpeg",
+ "mp2" => "audio/mpeg",
+ "mp3" => "audio/mpeg",
+ "aif" => "audio/x-aiff",
+ "aiff" => "audio/x-aiff",
+ "aifc" => "audio/x-aiff",
+ "m3u" => "audio/x-mpegurl",
+ "ram" => "audio/x-pn-realaudio",
+ "rm" => "audio/x-pn-realaudio",
+ "rpm" => "audio/x-pn-realaudio-plugin",
+ "ra" => "audio/x-realaudio",
+ "wav" => "audio/x-wav",
+ "pdb" => "chemical/x-pdb",
+ "xyz" => "chemical/x-xyz",
+ "bmp" => "image/bmp",
+ "gif" => "image/gif",
+ "ief" => "image/ief",
+ "jpeg" => "image/jpeg",
+ "jpg" => "image/jpeg",
+ "jpe" => "image/jpeg",
+ "png" => "image/png",
+ "tiff" => "image/tiff",
+ "tif" => "image/tif",
+ "djvu" => "image/vnd.djvu",
+ "djv" => "image/vnd.djvu",
+ "wbmp" => "image/vnd.wap.wbmp",
+ "ras" => "image/x-cmu-raster",
+ "pnm" => "image/x-portable-anymap",
+ "pbm" => "image/x-portable-bitmap",
+ "pgm" => "image/x-portable-graymap",
+ "ppm" => "image/x-portable-pixmap",
+ "rgb" => "image/x-rgb",
+ "xbm" => "image/x-xbitmap",
+ "xpm" => "image/x-xpixmap",
+ "xwd" => "image/x-windowdump",
+ "igs" => "model/iges",
+ "iges" => "model/iges",
+ "msh" => "model/mesh",
+ "mesh" => "model/mesh",
+ "silo" => "model/mesh",
+ "wrl" => "model/vrml",
+ "vrml" => "model/vrml",
+ "css" => "text/css",
+ "html" => "text/html",
+ "htm" => "text/html",
+ "asc" => "text/plain",
+ "txt" => "text/plain",
+ "rtx" => "text/richtext",
+ "rtf" => "text/rtf",
+ "sgml" => "text/sgml",
+ "sgm" => "text/sgml",
+ "tsv" => "text/tab-seperated-values",
+ "wml" => "text/vnd.wap.wml",
+ "wmls" => "text/vnd.wap.wmlscript",
+ "etx" => "text/x-setext",
+ "xml" => "text/xml",
+ "xsl" => "text/xml",
+ "mpeg" => "video/mpeg",
+ "mpg" => "video/mpeg",
+ "mpe" => "video/mpeg",
+ "qt" => "video/quicktime",
+ "mov" => "video/quicktime",
+ "mxu" => "video/vnd.mpegurl",
+ "avi" => "video/x-msvideo",
+ "movie" => "video/x-sgi-movie",
+ "ice" => "x-conference-xcooltalk",
+);
diff --git a/src/messages/internal_error.php b/src/messages/internal_error.php
new file mode 100644
index 0000000..8ec81f2
--- /dev/null
+++ b/src/messages/internal_error.php
@@ -0,0 +1,16 @@
+ 'Could not find the requested error message.',
+ 1 => 'The requested API method was not found in this SDK.',
+ 2 => 'The ShiftPlanning API is not responding.',
+ 3 => 'You must use the login method before accessing other modules of this API.',
+ 4 => 'A session has not yet been established.',
+ 5 => 'You must specify your Developer Key when using this SDK.',
+ 6 => 'The ShiftPlanning SDK needs the CURL PHP extension.',
+ 7 => 'The ShiftPlanning SDK needs the JSON PHP extension.',
+ 8 => "File doesn't exist.",
+ 9 => 'Could not find the correct mime for the file supplied.',
+);
diff --git a/src/messages/response.php b/src/messages/response.php
new file mode 100644
index 0000000..85f7da6
--- /dev/null
+++ b/src/messages/response.php
@@ -0,0 +1,28 @@
+ 'Error code not found',
+ '-3' => 'Flagged API Key - Pemanently Banned',
+ '-2' => 'Flagged API Key - Too Many invalid access attempts - contact us',
+ '-1' => 'Flagged API Key - Temporarily Disabled - contact us',
+ '1' => 'Success',
+ '2' => 'Invalid API key - App must be granted a valid key by ShiftPlanning',
+ '3' => 'Invalid token key - Please re-authenticate',
+ '4' => 'Invalid Method - No Method with that name exists in our API',
+ '5' => 'Invalid Module - No Module with that name exists in our API',
+ '6' => 'Invalid Action - No Action with that name exists in our API',
+ '7' => 'Authentication Failed - You do not have permissions to access the service',
+ '8' => 'Missing parameters - Your request is missing a required parameter',
+ '9' => 'Invalid parameters - Your request has an invalid parameter type',
+ '10' => 'Extra parameters - Your request has an extra/unallowed parameter type',
+ '12' => 'Create Failed - Your CREATE request failed',
+ '13' => 'Update Failed - Your UPDATE request failed',
+ '14' => 'Delete Failed - Your DELETE request failed',
+ '20' => 'Incorrect Permissions - You don\'t have the proper permissions to access this',
+ '90' => 'Suspended API key - Access for your account has been suspended, please contact ShiftPlanning',
+ '91' => 'Throttle exceeded - You have exceeded the max allowed requests. Try again later.',
+ '98' => 'Bad API Paramaters - Invalid POST request. See Manual.',
+ '99' => 'Service Offline - This service is temporarily offline. Try again later.',
+);
diff --git a/src/shiftplanning.php b/src/shiftplanning.php
index 9621d2c..d0abd98 100644
--- a/src/shiftplanning.php
+++ b/src/shiftplanning.php
@@ -8,72 +8,72 @@
/**
* Quick Access ShiftPlanning SDK Methods:
- * doLogin( $array_of_user_data )
- * doLogout( )
- * getMessages( )
- * getMessageDetails( $message_id )
- * createMessage( $array_of_message_data )
- * deleteMessage( $message_id )
- * getWallMessages( )
- * createWallMessage( $array_of_message_data )
- * deleteWallMessage( $message_id, $array_of_other_message_data )
- * getEmployees( )
- * getEmployeeDetails( $employee_id_number )
- * updateEmployee( $employee_id, $array_of_updated_employee_data )
- * createEmployee( $array_of_employee_data )
- * deleteEmployee( $employee_id )
- * getStaffSkills( )
- * getStaffSkillDetails( $skill_id )
- * createStaffSkill( $array_of_skill_data )
- * updateStaffSkill( $skill_id, $array_of_skill_data )
- * deleteStaffSkill( $skill_id )
- * createPing( $array_of_ping_data )
- * getSchedules( )
- * getScheduleDetails( $schedule_id )
- * createSchedule( $array_of_schedule_data )
- * updateSchedule( $schedule_id, $array_of_schedule_data )
- * deleteSchedule( $schedule_id )
- * getShifts( )
- * getShiftDetails( $shift_id )
- * updateShift( $shift_id, $array_of_shift_data )
- * createShift( $array_of_shift_data )
- * deleteShift( $shift_id )
- * getVacationSchedules( $time_period_array ) // e.g. getVacationSchedules( array( 'start' => '', 'end' => '' ) );
- * getVacationScheduleDetails( $schedule_id )
- * createVacationSchedule( $array_of_schedule_data )
- * updateVacationSchedule( $schedule_id, $array_of_schedule_data )
- * deleteVacationSchedule( $schedule_id )
- * getScheduleConflicts( )
- * getAdminSettings( )
- * updateAdminSettings( $array_of_new_settings )
- * getAdminFiles( )
- * getAdminFileDetails( $file_id )
- * updateAdminFile( $file_id, $array_of_file_data )
- * createAdminFile( $array_of_file_data )
- * deleteAdminFile( $file_id )
- * getAdminBackups( )
- * getAdminBackupDetails( $backup_id )
- * createAdminBackup( $array_of_backup_data )
- * deleteAdminBackup( $backup_id )
- * getAPIConfig( )
- * getAPIMethods( )
+ * doLogin($array_of_user_data)
+ * doLogout()
+ * getMessages()
+ * getMessageDetails($message_id)
+ * createMessage($array_of_message_data)
+ * deleteMessage($message_id)
+ * getWallMessages()
+ * createWallMessage($array_of_message_data)
+ * deleteWallMessage($message_id, $array_of_other_message_data)
+ * getEmployees()
+ * getEmployeeDetails($employee_id_number)
+ * updateEmployee($employee_id, $array_of_updated_employee_data)
+ * createEmployee($array_of_employee_data)
+ * deleteEmployee($employee_id)
+ * getStaffSkills()
+ * getStaffSkillDetails($skill_id)
+ * createStaffSkill($array_of_skill_data)
+ * updateStaffSkill($skill_id, $array_of_skill_data)
+ * deleteStaffSkill($skill_id)
+ * createPing($array_of_ping_data)
+ * getSchedules()
+ * getScheduleDetails($schedule_id)
+ * createSchedule($array_of_schedule_data)
+ * updateSchedule($schedule_id, $array_of_schedule_data)
+ * deleteSchedule($schedule_id)
+ * getShifts()
+ * getShiftDetails($shift_id)
+ * updateShift($shift_id, $array_of_shift_data)
+ * createShift($array_of_shift_data)
+ * deleteShift($shift_id)
+ * getVacationSchedules($time_period_array) // e.g. getVacationSchedules(array('start' => '', 'end' => ''));
+ * getVacationScheduleDetails($schedule_id)
+ * createVacationSchedule($array_of_schedule_data)
+ * updateVacationSchedule($schedule_id, $array_of_schedule_data)
+ * deleteVacationSchedule($schedule_id)
+ * getScheduleConflicts()
+ * getAdminSettings()
+ * updateAdminSettings($array_of_new_settings)
+ * getAdminFiles()
+ * getAdminFileDetails($file_id)
+ * updateAdminFile($file_id, $array_of_file_data)
+ * createAdminFile($array_of_file_data)
+ * deleteAdminFile($file_id)
+ * getAdminBackups()
+ * getAdminBackupDetails($backup_id)
+ * createAdminBackup($array_of_backup_data)
+ * deleteAdminBackup($backup_id)
+ * getAPIConfig()
+ * getAPIMethods()
*/
/**
* All Quick-Access methods return a response like this:
* array(
- * 'status' => array( 'code' => '1', 'text' => 'Success', 'error' => 'Error message if any' ),
+ * 'status' => array('code' => '1', 'text' => 'Success', 'error' => 'Error message if any'),
* 'data' => array(
* 'field_name' => 'value'
* )
* )
*
- * For methods that return multiple objects (as in the case for the getMessages( ) method
+ * For methods that return multiple objects (as in the case for the getMessages() method
* responses will look like this, where the indexes [0], [1] would be replaced with the
* message you're looking to display
*
* array(
- * 'status' => array( 'code' => '1', 'text' => 'Success', 'error' => 'Error message if any' ),
+ * 'status' => array('code' => '1', 'text' => 'Success', 'error' => 'Error message if any'),
* 'data' => array(
* [0] => array (
* 'id' => 1,
@@ -87,77 +87,137 @@
* )
*/
-class shiftplanning
-{//
+class Shiftplanning
+{
+
+ /**
+ * @var string AppKey
+ */
private $_key;
+
+ /**
+ * @var string Callback Method
+ */
private $_callback;
+
+ /**
+ * @var integer session initalization
+ */
private $_init;
- private $_debug;
- private $request = array( );
- private $requests = array( );
- private $response = array( );
- private $raw_response = array( );
+
+ /**
+ * @var boolean In debug mode
+ */
+ private $_debug = FALSE;
+
+ /**
+ * @var array
+ */
+ private $request = array();
+
+ /**
+ * @var array
+ */
+ private $requests = array();
+
+ /**
+ * @var array
+ */
+ private $response = array();
+
+ /**
+ * @var array
+ */
+ private $raw_response = array();
+
+ /**
+ * @var array cached storage of internal error messages
+ */
+ private $internal_errors = array();
+
+ /**
+ * @var array cached storage of response messages
+ */
+ private $response_messages = array();
+
// constants
- const session_identifier = 'SP';
- const api_endpoint = 'http://www.shiftplanning.com/api/';
- const output_type = 'json';
+ const SESSION_IDENTIFIER = 'SP';
+ const API_ENDPOINT = 'http://www.shiftplanning.com/api/';
+ const OUTPUT_TYPE = 'json';
- public function __construct( $config = array() )
- {// construct the SDK
+
+ /**
+ * Construct the SDK
+ * @param array $config [description]
+ */
+ public function __construct($config = array())
+ {
try
- {//
- $this->_debug = false;
- $this->startSession( );
+ {
+ $this->startSession();
// set the developer key
- $this->setAppKey( $config['key'] );
+ $this->setAppKey($config['key']);
- if( !function_exists( 'curl_init' ) )
- {// curl is not available
- throw new Exception( $this->internal_errors( 6 ) );
+ if (!function_exists('curl_init'))
+ {
+ // curl is not available
+ throw new Exception($this->internal_errors(6));
}
- if( !function_exists( 'json_decode' ) )
- {// json_decode is not available
- throw new Exception( $this->internal_errors( 7 ) );
+
+ if (!function_exists('json_decode'))
+ {
+ // json_decode is not available
+ throw new Exception($this->internal_errors(7));
}
}
- catch( Exception $e )
- {//
- echo $e->getMessage( ); exit;
+ catch(Exception $e)
+ {
+ echo $e->getMessage(); exit;
}
}
- public function setDebug( $switch = false )
- {// turn debug on
- if( file_exists('log.txt') )
- {// delete previous log file
- unlink( 'log.txt' );
+ /**
+ * Turn debug on
+ * @param boolean $switch [description]
+ */
+ public function setDebug($switch = FALSE)
+ {
+ // delete previous log file
+ if (file_exists('log.txt'))
+ {
+ unlink('log.txt');
}
- $this->_debug = true;
+ $this->_debug = TRUE;
}
- protected function startSession( )
- {// start the session
- session_name( self::session_identifier );
- session_start( );
+ // start the session
+ protected function startSession()
+ {
+ session_name(self::SESSION_IDENTIFIER);
+ session_start();
}
- private function setSession( )
- {// store the user data to this session
+ // store the user data to this session
+ private function setSession()
+ {
$_SESSION['token'] = $this->response['token'][0];
$_SESSION['data'] = $this->response['data'][0];
}
- private function destroySession( )
- {// destroy the currently active session
- $logout = $this->setRequest( array (
+ // destroy the currently active session
+ private function destroySession()
+ {
+ $logout = $this->setRequest(array(
'module' => 'staff.logout',
'method' => 'GET'
- ) );
- if( $logout['status']['code'] == 1 )
- {// logout successful, remove local session data
- unset( $_SESSION['token'] );
- unset( $_SESSION['data'] );
+ ));
+
+ // logout successful, remove local session data
+ if ($logout['status']['code'] == 1)
+ {
+ unset($_SESSION['token']);
+ unset($_SESSION['data']);
# REMOVE COOKIE
setcookie("mobile_token", $this->response['token'][0], time()-(30*86400), "/", ".shiftplanning.com");
@@ -165,132 +225,178 @@ private function destroySession( )
return $logout;
}
- public function getSession( )
- {// check whether a valid session has been established
- if( isset( $_SESSION['token'] ) )
- {// user is already authenticated
+ /**
+ * Check whether a valid session has been established
+ * @return [type] [description]
+ */
+ public function getSession()
+ {
+ // user is already authenticated
+ if (isset($_SESSION['token']))
+ {
return $_SESSION['data'];
}
else
- {// user has not authenticated
- return false;
+ {
+ // user has not authenticated
+ return FALSE;
}
}
- private function setCallback( $callback )
- {// set the method to call after successful api call
+ /**
+ * Set the method to call after successful api call
+ * @param [type] $callback [description]
+ */
+ private function setCallback($callback)
+ {
$this->_callback = $callback;
return $this->_callback;
}
- public function getRawResponse( )
- {// return the raw response data
+ /**
+ * Return the raw response data
+ * @return [type] [description]
+ */
+ public function getRawResponse()
+ {
return $this->raw_response;
}
- public function getAppKey( )
- {// return the developer key
+ /**
+ * Return the developer key
+ * @return [type] [description]
+ */
+ public function getAppKey()
+ {
return $this->_key;
}
- public function setAppKey( $key )
- {// set the developer key to use
+ /**
+ * Set the developer key to use
+ * @param [type] $key [description]
+ */
+ public function setAppKey($key)
+ {
$this->_key = $key;
return $this->_key;
}
- public function getAppToken( )
- {// return the token that's currently being used
+ /**
+ * Get the token that's currently being used
+ * @return [type] [description]
+ */
+ public function getAppToken()
+ {
try
- {//
- if( $this->getSession( ) )
- {// user authenticated, return the token
+ {
+ // user authenticated, return the token
+ if ($this->getSession())
+ {
return $_SESSION['token'];
}
else
- {// user not authenticated, return an error
- throw new Exception( $this->internal_errors( 4 ) );
+ {
+ // user not authenticated, return an error
+ throw new Exception($this->internal_errors(4));
}
}
- catch( Exception $e )
- {//
+ catch(Exception $e)
+ {
echo $e->getMessage();
}
}
- public function setRequest( $requests = array( ) )
- {// set the request parameters
+ /**
+ * Set the request parameters
+ * @param array $requests [description]
+ */
+ public function setRequest($requests = array())
+ {
// clear out previous request data
- unset( $this->requests );
+ unset($this->requests);
// set the default response type of JSON
- $this->request['output'] = self::output_type;
+ $this->request['output'] = self::OUTPUT_TYPE;
$this->_init = 0;
- foreach( $requests as $r => $v )
- {// loop through each request array
- if( is_array( $v ) )
- {//
+ foreach($requests as $r => $v)
+ {
+ // loop through each request array
+ if (is_array($v))
+ {
$this->requests[] = $v;
}
else
- {//
- if( $requests['module'] == 'staff.login' )
- {// automatically initialize session after this API call
+ {
+ // automatically initialize session after this API call
+ if ($requests['module'] == 'staff.login')
+ {
$this->_init = 1;
}
$this->requests[] = $requests; break;
}
}
- return $this->api( );
+ return $this->api();
}
- public function getRequest( )
- {// return the request parameters
- return array_merge( $this->request, array( 'request' => $this->requests ) );
+ /**
+ * Return the request parameters
+ * @return [type] [description]
+ */
+ public function getRequest()
+ {
+ return array_merge($this->request, array('request' => $this->requests));
}
- private function setResponse( $response )
- {// set the response data
+ /**
+ * Set the response data
+ * @param [type] $response [description]
+ */
+ private function setResponse($response)
+ {
// remove previous response data
- unset( $this->response );
+ unset($this->response);
// set new response data
- if( !is_array( $response[0] ) )
- {//
+ if (! isset($response[0]) || !is_array($response[0]))
+ {
$this->response['response'][0] = array(
'code' => $response['status'],
- 'text' => $this->getResponseText( &$response['status'] ),
- 'error' => $response['error']
+ 'text' => $this->getResponseText($response['status']),
+ 'error' => (isset($response['error']) ? $response['error'] : '')
);
$this->response['data'][0] = $response['data'];
$this->response['token'][0] = $response['token'];
}
else
- {//
- foreach( $response as $num => $data )
- {// loop through each response
+ {
+ // loop through each response
+ foreach($response as $num => $data)
+ {
+
$this->response['response'][$num] = array(
'code' => $data['status'],
- 'text' => $this->getResponseText( &$data['status'] ),
- 'error' => $data['error']
+ 'text' => $this->getResponseText($data['status']),
+ 'error' => (isset($data['error']) ? $data['error'] : '')
);
- $tmp = array( );
+ $tmp = array();
$id = 0;
- if( is_array( $data['data'] ) )
- {// is there an array returned
- foreach( $data['data'] as $n => $v )
- {//
- if( is_array( $v ) )
- {//
- foreach( $v as $key => $val )
- {//
+
+ // is there an array returned
+ if (is_array($data['data']))
+ {
+ foreach($data['data'] as $n => $v)
+ {
+ if (is_array($v))
+ {
+ foreach($v as $key => $val)
+ {
$tmp[$n][$key] = $val;
}
}
else
- {//
+ {
$tmp[$n] = $v;
}
}
@@ -298,299 +404,183 @@ private function setResponse( $response )
$this->response['data'][$num] = $tmp;
}
else
- {// the data response is text
+ {
+ // the data response is text
$this->response['data'][$num] = $data['data'];
}
}
}
}
- public function getResponse( $call_num = 0 )
- {// return the API response data to the calling method
+ /**
+ * Get the API response data to the calling method
+ * @param integer $call_num Calling method number
+ * @return array API Response Data
+ */
+ public function getResponse($call_num = 0)
+ {
return array(
'status' => $this->response['response'][$call_num],
'data' => $this->response['data'][$call_num],
- 'error' => $this->response['error'][$call_num]
+ 'error' => (isset($this->response['error'])) ? $this->response['error'][$call_num]: NULL,
);
}
- private function getResponseText( &$code )
- {// return a reason text for a response code
- switch( $code )
- {// select a response code to display
- case '-3' : $reason = 'Flagged API Key - Pemanently Banned'; break;
- case '-2' : $reason = 'Flagged API Key - Too Many invalid access attempts - contact us'; break;
- case '-1' : $reason = 'Flagged API Key - Temporarily Disabled - contact us'; break;
- case '1' : $reason = 'Success -'; break;
- case '2' : $reason = 'Invalid API key - App must be granted a valid key by ShiftPlanning'; break;
- case '3' : $reason = 'Invalid token key - Please re-authenticate'; break;
- case '4' : $reason = 'Invalid Method - No Method with that name exists in our API'; break;
- case '5' : $reason = 'Invalid Module - No Module with that name exists in our API'; break;
- case '6' : $reason = 'Invalid Action - No Action with that name exists in our API'; break;
- case '7' : $reason = 'Authentication Failed - You do not have permissions to access the service'; break;
- case '8' : $reason = 'Missing parameters - Your request is missing a required parameter'; break;
- case '9' : $reason = 'Invalid parameters - Your request has an invalid parameter type'; break;
- case '10' : $reason = 'Extra parameters - Your request has an extra/unallowed parameter type'; break;
- case '12' : $reason = 'Create Failed - Your CREATE request failed'; break;
- case '13' : $reason = 'Update Failed - Your UPDATE request failed'; break;
- case '14' : $reason = 'Delete Failed - Your DELETE request failed'; break;
- case '20' : $reason = 'Incorrect Permissions - You don\'t have the proper permissions to access this'; break;
- case '90' : $reason = 'Suspended API key - Access for your account has been suspended, please contact ShiftPlanning'; break;
- case '91' : $reason = 'Throttle exceeded - You have exceeded the max allowed requests. Try again later.'; break;
- case '98' : $reason = 'Bad API Paramaters - Invalid POST request. See Manual.'; break;
- case '99' : $reason = 'Service Offline - This service is temporarily offline. Try again later.'; break;
- default : $reason = 'Error code not found'; break;
+ /**
+ * Get a reason text for a response code
+ * @param int $code [description]
+ * @return string Response
+ */
+ private function getResponseText(&$code)
+ {
+ // Check internal cache or get array from file
+ if (empty($this->response_messages))
+ {
+ // Load response messages array
+ $response_messages = include 'messages/response.php';
+ }
+ else
+ {
+ $response_messages = $this->response_messages;
+ }
+
+ // select a response code to display
+ if (array_key_exists($code, $response_messages))
+ {
+ $message = $response_messages[$code];
+ }
+ else
+ {
+ $message = $response_messages[0];
+ }
+
+ return $message;
+ }
+
+ /**
+ * Errors internal to the ShiftPlanning SDK
+ * @param [type] $errno [description]
+ * @return [type] [description]
+ */
+ private function internal_errors($errno = 0)
+ {
+ // Check internal cache or get array from file
+ if (empty($this->internal_errors))
+ {
+ $internal_error_messages = include 'messages/internal_error.php';
+ }
+ else
+ {
+ $internal_error_messages = $this->internal_errors;
+ }
+
+ // internal error message
+ if (array_key_exists($errno, $internal_error_messages))
+ {
+ $message = $internal_error_messages[$errno];
}
- // return the reason text
- return $reason;
- }
-
- private function internal_errors( $errno )
- {// errors internal to the ShiftPlanning SDK
- switch( $errno )
- {// internal error messages
- case 1 :
- $message = 'The requested API method was not found in this SDK.';
- break;
- case 2 :
- $message = 'The ShiftPlanning API is not responding.';
- break;
- case 3 :
- $message = 'You must use the login method before accessing other modules of this API.';
- break;
- case 4 :
- $message = 'A session has not yet been established.';
- break;
- case 5 :
- $message = 'You must specify your Developer Key when using this SDK.';
- break;
- case 6 :
- $message = 'The ShiftPlanning SDK needs the CURL PHP extension.';
- break;
- case 7 :
- $message = 'The ShiftPlanning SDK needs the JSON PHP extension.';
- break;
- case 8 :
- $message = 'File doesn\'t exist.';
- break;
- case 9 :
- $message = 'Could not find the correct mime for the file supplied.';
- break;
- default :
- $message = 'Could not find the requested error message.';
- break;
+ else
+ {
+ $message = $internal_error_messages[0];
}
+
return $message; exit;
}
- private function api( )
- {// create the api call
- if( $this->_callback == null )
- {// method to call after successful api request
- $this->setCallback( 'getResponse' );
+ /**
+ * Create the api call
+ * @return [type] [description]
+ */
+ private function api()
+ {
+ if ($this->_callback == null)
+ {
+ // method to call after successful api request
+ $this->setCallback('getResponse');
}
- if( $this->getSession( ) )
- {// session already established, use token
+
+ // session already established, use token
+ if ($this->getSession())
+ {
// remove the developer key from the request, since it's not necessary
- unset( $this->request['key'] );
+ unset($this->request['key']);
// set the token for this request, since the user is already authenticated
$this->request['token'] = $_SESSION['token'];
}
else
- {// session has not been established, use developer key to access API
+ {
+ // session has not been established, use developer key to access API
try
- {//
- if( isset( $this->_key ) )
- {// developer key is set
+ {
+ if (isset($this->_key))
+ {
+ // developer key is set
$this->request['key'] = $this->_key;
}
else
- {// developer key is not set
- throw new Exception( $this->internal_errors( 5 ) );
+ {
+ // developer key is not set
+ throw new Exception($this->internal_errors(5));
}
}
- catch( Exception $e )
- {//
- echo $e->getMessage( );
+ catch(Exception $e)
+ {
+ echo $e->getMessage();
}
}
// make the api request
- return $this->perform_request( );
- }
-
- private function getFileMimeType( $extension )
- {//
- $mimes = array(
- "ez" => "application/andrew-inset",
- "hqx" => "application/mac-binhex40",
- "cpt" => "application/mac-compactpro",
- "doc" => "application/msword",
- "bin" => "application/octet-stream",
- "dms" => "application/octet-stream",
- "lha" => "application/octet-stream",
- "lzh" => "application/octet-stream",
- "exe" => "application/octet-stream",
- "class" => "application/octet-stream",
- "so" => "application/octet-stream",
- "dll" => "application/octet-stream",
- "oda" => "application/oda",
- "pdf" => "application/pdf",
- "ai" => "application/postscript",
- "eps" => "application/postscript",
- "ps" => "application/postscript",
- "smi" => "application/smil",
- "smil" => "application/smil",
- "wbxml" => "application/vnd.wap.wbxml",
- "wmlc" => "application/vnd.wap.wmlc",
- "wmlsc" => "application/vnd.wap.wmlscriptc",
- "bcpio" => "application/x-bcpio",
- "vcd" => "application/x-cdlink",
- "pgn" => "application/x-chess-pgn",
- "cpio" => "application/x-cpio",
- "csh" => "application/x-csh",
- "dcr" => "application/x-director",
- "dir" => "application/x-director",
- "dxr" => "application/x-director",
- "dvi" => "application/x-dvi",
- "spl" => "application/x-futuresplash",
- "gtar" => "application/x-gtar",
- "hdf" => "application/x-hdf",
- "js" => "application/x-javascript",
- "skp" => "application/x-koan",
- "skd" => "application/x-koan",
- "skt" => "application/x-koan",
- "skm" => "application/x-koan",
- "latex" => "application/x-latex",
- "nc" => "application/x-netcdf",
- "cdf" => "application/x-netcdf",
- "sh" => "application/x-sh",
- "shar" => "application/x-shar",
- "swf" => "application/x-shockwave-flash",
- "sit" => "application/x-stuffit",
- "sv4cpio" => "application/x-sv4cpio",
- "sv4crc" => "application/x-sv4crc",
- "tar" => "application/x-tar",
- "tcl" => "application/x-tcl",
- "tex" => "application/x-tex",
- "texinfo" => "application/x-texinfo",
- "texi" => "application/x-texinfo",
- "t" => "application/x-troff",
- "tr" => "application/x-troff",
- "roff" => "application/x-troff",
- "man" => "application/x-troff-man",
- "me" => "application/x-troff-me",
- "ms" => "application/x-troff-ms",
- "ustar" => "application/x-ustar",
- "src" => "application/x-wais-source",
- "xhtml" => "application/xhtml+xml",
- "xht" => "application/xhtml+xml",
- "zip" => "application/zip",
- "au" => "audio/basic",
- "snd" => "audio/basic",
- "mid" => "audio/midi",
- "midi" => "audio/midi",
- "kar" => "audio/midi",
- "mpga" => "audio/mpeg",
- "mp2" => "audio/mpeg",
- "mp3" => "audio/mpeg",
- "aif" => "audio/x-aiff",
- "aiff" => "audio/x-aiff",
- "aifc" => "audio/x-aiff",
- "m3u" => "audio/x-mpegurl",
- "ram" => "audio/x-pn-realaudio",
- "rm" => "audio/x-pn-realaudio",
- "rpm" => "audio/x-pn-realaudio-plugin",
- "ra" => "audio/x-realaudio",
- "wav" => "audio/x-wav",
- "pdb" => "chemical/x-pdb",
- "xyz" => "chemical/x-xyz",
- "bmp" => "image/bmp",
- "gif" => "image/gif",
- "ief" => "image/ief",
- "jpeg" => "image/jpeg",
- "jpg" => "image/jpeg",
- "jpe" => "image/jpeg",
- "png" => "image/png",
- "tiff" => "image/tiff",
- "tif" => "image/tif",
- "djvu" => "image/vnd.djvu",
- "djv" => "image/vnd.djvu",
- "wbmp" => "image/vnd.wap.wbmp",
- "ras" => "image/x-cmu-raster",
- "pnm" => "image/x-portable-anymap",
- "pbm" => "image/x-portable-bitmap",
- "pgm" => "image/x-portable-graymap",
- "ppm" => "image/x-portable-pixmap",
- "rgb" => "image/x-rgb",
- "xbm" => "image/x-xbitmap",
- "xpm" => "image/x-xpixmap",
- "xwd" => "image/x-windowdump",
- "igs" => "model/iges",
- "iges" => "model/iges",
- "msh" => "model/mesh",
- "mesh" => "model/mesh",
- "silo" => "model/mesh",
- "wrl" => "model/vrml",
- "vrml" => "model/vrml",
- "css" => "text/css",
- "html" => "text/html",
- "htm" => "text/html",
- "asc" => "text/plain",
- "txt" => "text/plain",
- "rtx" => "text/richtext",
- "rtf" => "text/rtf",
- "sgml" => "text/sgml",
- "sgm" => "text/sgml",
- "tsv" => "text/tab-seperated-values",
- "wml" => "text/vnd.wap.wml",
- "wmls" => "text/vnd.wap.wmlscript",
- "etx" => "text/x-setext",
- "xml" => "text/xml",
- "xsl" => "text/xml",
- "mpeg" => "video/mpeg",
- "mpg" => "video/mpeg",
- "mpe" => "video/mpeg",
- "qt" => "video/quicktime",
- "mov" => "video/quicktime",
- "mxu" => "video/vnd.mpegurl",
- "avi" => "video/x-msvideo",
- "movie" => "video/x-sgi-movie",
- "ice" => "x-conference-xcooltalk"
- );
+ return $this->perform_request();
+ }
+
+ /**
+ * Get the mime type by file extension
+ * @param [type] $extension File extension without leading dot
+ * @return string Mime Type
+ */
+ private function getFileMimeType($extension)
+ {
try
- {//
- if( $mimes[ $extension ] )
- {// mime found
- return $mimes[ $extension ];
+ {
+ $mimes = include 'config/mimes.php';
+ if ($mimes[$extension])
+ {
+ return $mimes[$extension];
}
else
- {// mime not found
- throw new Exception( 'Mime for .' . $extension . ' not found' );
+ {
+ throw new Exception('Mime for .' . $extension . ' not found');
}
}
- catch( Exception $e )
- {//
- echo $e->getMessage( );
+ catch(Exception $e)
+ {
+ echo $e->getMessage();
}
}
- private function getFileData( $file )
- {// get file details, (data, length, mimetype)
+ /**
+ * Get file details, (data, length, mimetype)
+ * @param [type] $file [description]
+ * @return [type] [description]
+ */
+ private function getFileData($file)
+ {
try
- {//
- if( file_exists( $file ) )
- {// file
- $file_data['filedata'] = file_get_contents( $file );
- $file_data['filelength'] = strlen( $file_data['filedata'] );
- if( function_exists( 'mime_content_type' ) )
- {// mime_content_type function is available
- $file_data['mimetype'] = mime_content_type( $file );
+ {
+ if (file_exists($file))
+ {
+ // file
+ $file_data['filedata'] = file_get_contents($file);
+ $file_data['filelength'] = strlen($file_data['filedata']);
+ if (function_exists('mime_content_type'))
+ {
+ // mime_content_type function is available
+ $file_data['mimetype'] = mime_content_type($file);
}
else
- {//
- $parts = explode( '.', $file );
- $extension = strtolower( $parts[ sizeOf( $parts ) - 1 ] );
- $file_data['mimetype'] = $this->getFileMimeType( $extension );
+ {
+ $parts = explode('.', $file);
+ $extension = strtolower($parts[ sizeOf($parts) - 1 ]);
+ $file_data['mimetype'] = $this->getFileMimeType($extension);
}
return array(
@@ -600,108 +590,124 @@ private function getFileData( $file )
);
}
else
- {//
- throw new Exception( $this->internal_errors( 8 ) );
+ {
+ throw new Exception($this->internal_errors(8));
}
}
- catch( Exception $e )
- {//
- echo $e->getMessage( ); exit;
+ catch(Exception $e)
+ {
+ echo $e->getMessage(); exit;
}
}
- private function perform_request( )
- {// perform the api request
+ /**
+ * Perform the api request
+ * @return [type] [description]
+ */
+ private function perform_request()
+ {
try
- {//
- $ch = curl_init( self::api_endpoint );
+ {
+ $ch = curl_init(self::API_ENDPOINT);
$filedata = '';
- if( is_array( $this->requests ) )
- {//
- foreach( $this->requests as $key => $request )
- {//
- if( $request['filedata'] )
- {//
+ if (is_array($this->requests))
+ {
+ foreach($this->requests as $key => $request)
+ {
+ if (isset($request['filedata']))
+ {
$filedata = $request['filedata'];
- unset( $this->requests[$key]['filedata'] );
+ unset($this->requests[$key]['filedata']);
}
}
}
- $post = $filedata ? array( 'data'=> json_encode( $this->getRequest( ) ),
- 'filedata' => $filedata ) : array( 'data' => json_encode( $this->getRequest( ) ) );
+ $post = $filedata ? array('data'=> json_encode($this->getRequest()),
+ 'filedata' => $filedata) : array('data' => json_encode($this->getRequest()));
- curl_setopt( $ch, CURLOPT_URL, self::api_endpoint );
- curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 0 );
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
- curl_setopt( $ch, CURLOPT_POST, 1 );
- curl_setopt( $ch, CURLOPT_POSTFIELDS, $post );
+ curl_setopt($ch, CURLOPT_URL, self::API_ENDPOINT);
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_POST, 1);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
// return the response from the api
- $response = curl_exec( $ch );
- $http_response_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
- curl_close( $ch );
-
- if( $http_response_code == 200 )
- {// response from API was a successful
- $temp = json_decode( $response, true );
+ $response = curl_exec($ch);
+ $http_response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+ curl_close($ch);
+
+ // response from API was a successful
+ if ($http_response_code == 200)
+ {
+ $temp = json_decode($response, TRUE);
// decode the response and store each call response in its own array
- $this->setResponse( $temp );
- if( $this->_init == 1 )
- {// initialize a session
- $this->setSession( );
+ $this->setResponse($temp);
+
+ // initialize a session
+ if ($this->_init == 1)
+ {
+ $this->setSession();
}
+
// raw response call
$this->raw_response = $temp;
- if( $this->_debug == true )
- {// debug mode is on
- $request = json_encode( $this->getRequest( ) );
+ if ($this->_debug == TRUE)
+ {
+ // debug mode is on
+ $request = json_encode($this->getRequest());
$db = fopen('log.txt', 'a');
- $tmp_vals = array( );
- if( is_array( $this->response['data'][0] ) )
- {//
- foreach( $this->response['data'] as $n => $v )
- {//
- foreach( $v as $key => $val )
- {//
+ $tmp_vals = array();
+ if (is_array($this->response['data'][0]))
+ {
+ foreach($this->response['data'] as $n => $v)
+ {
+ foreach($v as $key => $val)
+ {
$tmp_vals[$n][$key] = $val;
}
}
}
else
- {//
- foreach( $this->response['data'] as $n => $v )
- {//
+ {
+ foreach($this->response['data'] as $n => $v)
+ {
$tmp_vals[$n] = $v;
}
}
- fwrite( $db, date('m-d-Y h:i a'). "\n" . 'REQUEST: ' . $request . "\n"
+ fwrite($db, date('m-d-Y h:i a'). "\n" . 'REQUEST: ' . $request . "\n"
. 'RESPONSE STATUS: (' . $this->response['response'][0]['code']
. ') ' . $this->response['response'][0]['text'] . " -- " . $this->response['response'][0]['error'] . "\n"
- . 'RESPONSE DATA: ' . json_encode( $tmp_vals ) . "\n\n" );
- fclose( $db );
+ . 'RESPONSE DATA: ' . json_encode($tmp_vals) . "\n\n");
+ fclose($db);
}
+
// perform the callback method
- return $this->{ $this->_callback }( );
+ return $this->{ $this->_callback }();
}
else
- {// response from API was unsuccessful
- throw new Exception( $this->internal_errors( 2 ) );
+ {
+ // response from API was unsuccessful
+ throw new Exception($this->internal_errors(2));
}
}
- catch( Exception $e )
- {//
+ catch(Exception $e)
+ {
echo $e->getMessage();
}
}
- /*
+ /**
* User Authentication Methods
- *
*/
- public function doLogin( $user = array( ) )
- {// perform a login api call
+
+ /**
+ * Perform a login api call
+ * @param array $user [description]
+ * @return [type] [description]
+ */
+ public function doLogin($user = array())
+ {
return $this->setRequest(
array(
'module' => 'staff.login',
@@ -712,17 +718,25 @@ public function doLogin( $user = array( ) )
);
}
- public function doLogout( )
- {// erase token and user data from current session
- $this->destroySession( );
+ /**
+ * Erase token and user data from current session
+ */
+ public function doLogout()
+ {
+ $this->destroySession();
}
- /*
+
+ /**
* Message Methods
- *
*/
- public function getMessages( )
- {// get messages for the currently logged in user
+
+ /**
+ * Get messages for the currently logged in user
+ * @return [type] [description]
+ */
+ public function getMessages()
+ {
return $this->setRequest(
array(
'module' => 'messaging.messages',
@@ -731,8 +745,13 @@ public function getMessages( )
);
}
- public function getMessageDetails( $id )
- {// get message details for a specific message
+ /**
+ * Get message details for a specific message
+ * @param [type] $id [description]
+ * @return [type] [description]
+ */
+ public function getMessageDetails($id)
+ {
return $this->setRequest(
array(
'module' => 'messaging.message',
@@ -742,8 +761,13 @@ public function getMessageDetails( $id )
);
}
- public function createMessage( $message = array( ) )
- {// create a new message
+ /**
+ * Create a new message
+ * @param array $message [description]
+ * @return [type] [description]
+ */
+ public function createMessage($message = array())
+ {
return $this->setRequest(
array_merge(
array(
@@ -755,8 +779,13 @@ public function createMessage( $message = array( ) )
);
}
- public function deleteMessage( $id )
- {// delete a message
+ /**
+ * Delete a message
+ * @param [type] $id [description]
+ * @return [type] [description]
+ */
+ public function deleteMessage($id)
+ {
return $this->setRequest(
array(
'module' => 'messaging.message',
@@ -766,8 +795,12 @@ public function deleteMessage( $id )
);
}
- public function getWallMessages( )
- {// get message wall
+ /**
+ * Get message wall
+ * @return [type] [description]
+ */
+ public function getWallMessages()
+ {
return $this->setRequest(
array(
'module' => 'messaging.wall',
@@ -776,8 +809,13 @@ public function getWallMessages( )
);
}
- public function createWallMessage( $message = array( ) )
- {// create a wall message
+ /**
+ * Create a wall message
+ * @param array $message [description]
+ * @return [type] [description]
+ */
+ public function createWallMessage($message = array())
+ {
return $this->setRequest(
array_merge(
array(
@@ -789,8 +827,14 @@ public function createWallMessage( $message = array( ) )
);
}
- public function deleteWallMessage( $id, $details = array( ) )
- {// delete a wall message
+ /**
+ * Delete a wall message
+ * @param [type] $id [description]
+ * @param array $details [description]
+ * @return [type] [description]
+ */
+ public function deleteWallMessage($id, $details = array())
+ {
return $this->setRequest(
array_merge(
array(
@@ -807,8 +851,14 @@ public function deleteWallMessage( $id, $details = array( ) )
* Staff Methods
*
*/
- public function getEmployees( )
- {// get a list of employees
+
+
+ /**
+ * Get a list of employees
+ * @return [type] [description]
+ */
+ public function getEmployees()
+ {
return $this->setRequest(
array(
'module' => 'staff.employees',
@@ -817,8 +867,13 @@ public function getEmployees( )
);
}
- public function getEmployeeDetails( $id )
- {// get details for a specific employee
+ /**
+ * Get details for a specific employee
+ * @param [type] $id [description]
+ * @return [type] [description]
+ */
+ public function getEmployeeDetails($id)
+ {
return $this->setRequest(
array(
'module' => 'staff.employee',
@@ -828,8 +883,14 @@ public function getEmployeeDetails( $id )
);
}
- public function updateEmployee( $id, $new_data = array( ) )
- {// update an employee record
+ /**
+ * Update an employee record
+ * @param [type] $id [description]
+ * @param array $new_data [description]
+ * @return [type] [description]
+ */
+ public function updateEmployee($id, $new_data = array())
+ {
return $this->setRequest(
array_merge(
array(
@@ -842,8 +903,13 @@ public function updateEmployee( $id, $new_data = array( ) )
);
}
- public function createEmployee( $data )
- {// create a new employee record
+ /**
+ * Create a new employee record
+ * @param [type] $data [description]
+ * @return [type] [description]
+ */
+ public function createEmployee($data)
+ {
return $this->setRequest(
array_merge(
array(
@@ -855,8 +921,13 @@ public function createEmployee( $data )
);
}
- public function deleteEmployee( $id )
- {// delete an employee
+ /**
+ * Delete an employee
+ * @param [type] $id [description]
+ * @return [type] [description]
+ */
+ public function deleteEmployee($id)
+ {
return $this->setRequest(
array(
'module' => 'staff.employee',
@@ -866,8 +937,12 @@ public function deleteEmployee( $id )
);
}
- public function getStaffSkills( )
- {// get staff skills
+ /**
+ * Get staff skills
+ * @return [type] [description]
+ */
+ public function getStaffSkills()
+ {
return $this->setRequest(
array(
'module' => 'staff.skills',
@@ -876,8 +951,13 @@ public function getStaffSkills( )
);
}
- public function getStaffSkillDetails( $id )
- {// get staff skill details
+ /**
+ * Get staff skill details
+ * @param [type] $id [description]
+ * @return [type] [description]
+ */
+ public function getStaffSkillDetails($id)
+ {
return $this->setRequest(
array(
'module' => 'staff.skill',
@@ -887,8 +967,13 @@ public function getStaffSkillDetails( $id )
);
}
- public function createStaffSkill( $skill_details = array( ) )
- {// create staff skill
+ /**
+ * Create staff skill
+ * @param array $skill_details [description]
+ * @return [type] [description]
+ */
+ public function createStaffSkill($skill_details = array())
+ {
return $this->setRequest(
array_merge(
array(
@@ -900,8 +985,14 @@ public function createStaffSkill( $skill_details = array( ) )
);
}
- public function updateStaffSkill( $id, $skill_details = array( ) )
- {// update staff skill
+ /**
+ * Update staff skill
+ * @param [type] $id [description]
+ * @param array $skill_details [description]
+ * @return [type] [description]
+ */
+ public function updateStaffSkill($id, $skill_details = array())
+ {
return $this->setRequest(
array_merge(
array(
@@ -914,8 +1005,13 @@ public function updateStaffSkill( $id, $skill_details = array( ) )
);
}
- public function deleteStaffSkill( $id )
- {// delete staff skill
+ /**
+ * Delete staff skill
+ * @param [type] $id [description]
+ * @return [type] [description]
+ */
+ public function deleteStaffSkill($id)
+ {
return $this->setRequest(
array(
'module' => 'staff.skill',
@@ -925,8 +1021,13 @@ public function deleteStaffSkill( $id )
);
}
- public function createPing( $ping_data = array( ) )
- {// create a ping
+ /**
+ * Create a ping
+ * @param array $ping_data [description]
+ * @return [type] [description]
+ */
+ public function createPing($ping_data = array())
+ {
return $this->setRequest(
array_merge(
array(
@@ -938,12 +1039,16 @@ public function createPing( $ping_data = array( ) )
);
}
- /*
+ /**
* Schedule Methods
- *
*/
- public function getSchedules( )
- {// get schedules
+
+ /**
+ * Get schedules
+ * @return [type] [description]
+ */
+ public function getSchedules()
+ {
return $this->setRequest(
array(
'module' => 'schedule.schedules',
@@ -952,8 +1057,13 @@ public function getSchedules( )
);
}
- public function getScheduleDetails( $id )
- {// get schedule details
+ /**
+ * Get schedule details
+ * @param [type] $id [description]
+ * @return [type] [description]
+ */
+ public function getScheduleDetails($id)
+ {
return $this->setRequest(
array(
'module' => 'schedule.schedule',
@@ -963,8 +1073,13 @@ public function getScheduleDetails( $id )
);
}
- public function createSchedule( $schedule_details = array( ) )
- {// create a new schedule
+ /**
+ * Create a new schedule
+ * @param array $schedule_details [description]
+ * @return [type] [description]
+ */
+ public function createSchedule($schedule_details = array())
+ {
return $this->setRequest(
array_merge(
array(
@@ -976,8 +1091,14 @@ public function createSchedule( $schedule_details = array( ) )
);
}
- public function updateSchedule( $id, $schedule_details = array( ) )
- {// update an existing schedule
+ /**
+ * Update an existing schedule
+ * @param [type] $id [description]
+ * @param array $schedule_details [description]
+ * @return [type] [description]
+ */
+ public function updateSchedule($id, $schedule_details = array())
+ {
return $this->setRequest(
array_merge(
array(
@@ -990,8 +1111,13 @@ public function updateSchedule( $id, $schedule_details = array( ) )
);
}
- public function deleteSchedule( $id )
- {// delete an existing schedule
+ /**
+ * Delete an existing schedule
+ * @param [type] $id [description]
+ * @return [type] [description]
+ */
+ public function deleteSchedule($id)
+ {
return $this->setRequest(
array(
'module' => 'schedule.schedule',
@@ -1001,8 +1127,12 @@ public function deleteSchedule( $id )
);
}
- public function getShifts( )
- {// get shifts
+ /**
+ * Get shifts
+ * @return [type] [description]
+ */
+ public function getShifts()
+ {
return $this->setRequest(
array(
'module' => 'schedule.shifts',
@@ -1011,8 +1141,13 @@ public function getShifts( )
);
}
- public function getShiftDetails( $id )
- {// get shift details
+ /**
+ * Get shift details
+ * @param [type] $id [description]
+ * @return [type] [description]
+ */
+ public function getShiftDetails($id)
+ {
return $this->setRequest(
array(
'module' => 'schedule.shift',
@@ -1022,8 +1157,14 @@ public function getShiftDetails( $id )
);
}
- public function updateShift( $id, $shift_details = array( ) )
- {// update shift details
+ /**
+ * Update shift details
+ * @param [type] $id [description]
+ * @param array $shift_details [description]
+ * @return [type] [description]
+ */
+ public function updateShift($id, $shift_details = array())
+ {
return $this->setRequest(
array_merge(
array(
@@ -1036,8 +1177,13 @@ public function updateShift( $id, $shift_details = array( ) )
);
}
- public function createShift( $shift_details = array( ) )
- {// create a new shift
+ /**
+ * Create a new shift
+ * @param array $shift_details [description]
+ * @return [type] [description]
+ */
+ public function createShift($shift_details = array())
+ {
return $this->setRequest(
array_merge(
array(
@@ -1049,8 +1195,13 @@ public function createShift( $shift_details = array( ) )
);
}
- public function deleteShift( $id )
- {// delete a shift
+ /**
+ * Delete a shift
+ * @param [type] $id [description]
+ * @return [type] [description]
+ */
+ public function deleteShift($id)
+ {
return $this->setRequest(
array(
'module' => 'schedule.shift',
@@ -1060,8 +1211,13 @@ public function deleteShift( $id )
);
}
- public function getVacationSchedules( $time_period = array( ) )
- {// get schedule vacations, pass start and end params to get vacations within a certian time-period
+ /**
+ * Get schedule vacations, pass start and end params to get vacations within a certian time-period
+ * @param array $time_period [description]
+ * @return [type] [description]
+ */
+ public function getVacationSchedules($time_period = array())
+ {
return $this->setRequest(
array_merge(
array(
@@ -1073,8 +1229,13 @@ public function getVacationSchedules( $time_period = array( ) )
);
}
- public function getVacationScheduleDetails( $id )
- {// get vacation schedule details
+ /**
+ * Get vacation schedule details
+ * @param [type] $id [description]
+ * @return [type] [description]
+ */
+ public function getVacationScheduleDetails($id)
+ {
return $this->setRequest(
array(
'module' => 'schedule.vacation',
@@ -1084,8 +1245,13 @@ public function getVacationScheduleDetails( $id )
);
}
- public function createVacationSchedule( $vacation_details = array( ) )
- {// create a vacation schedule
+ /**
+ * Create a vacation schedule
+ * @param array $vacation_details [description]
+ * @return [type] [description]
+ */
+ public function createVacationSchedule($vacation_details = array())
+ {
return $this->setRequest(
array_merge(
array(
@@ -1097,8 +1263,14 @@ public function createVacationSchedule( $vacation_details = array( ) )
);
}
- public function updateVacationSchedule( $id, $vacation_details = array( ) )
- {// update a vacation schedule
+ /**
+ * Update a vacation schedule
+ * @param [type] $id [description]
+ * @param array $vacation_details [description]
+ * @return [type] [description]
+ */
+ public function updateVacationSchedule($id, $vacation_details = array())
+ {
return $this->setRequest(
array_merge(
array(
@@ -1111,8 +1283,13 @@ public function updateVacationSchedule( $id, $vacation_details = array( ) )
);
}
- public function deleteVacationSchedule( $id )
- {// delete a vacation schedule
+ /**
+ * Delete a vacation schedule
+ * @param [type] $id [description]
+ * @return [type] [description]
+ */
+ public function deleteVacationSchedule($id)
+ {
return $this->setRequest(
array(
'module' => 'schedule.vacation',
@@ -1122,8 +1299,13 @@ public function deleteVacationSchedule( $id )
);
}
- public function getScheduleConflicts( $time_period = array( ) )
- {// get schedule conflicts
+ /**
+ * Get schedule conflicts
+ * @param array $time_period [description]
+ * @return [type] [description]
+ */
+ public function getScheduleConflicts($time_period = array())
+ {
return $this->setRequest(
array_merge(
array(
@@ -1135,12 +1317,16 @@ public function getScheduleConflicts( $time_period = array( ) )
);
}
- /*
+ /**
* Administration Methods
- *
*/
- public function getAdminSettings( )
- {// get admin settings
+
+ /**
+ * Get admin settings
+ * @return [type] [description]
+ */
+ public function getAdminSettings()
+ {
return $this->setRequest(
array(
'module' => 'admin.settings',
@@ -1149,8 +1335,13 @@ public function getAdminSettings( )
);
}
- public function updateAdminSettings( $settings = array( ) )
- {// update admin settings
+ /**
+ * Update admin settings
+ * @param array $settings [description]
+ * @return [type] [description]
+ */
+ public function updateAdminSettings($settings = array())
+ {
return $this->setRequest(
array_merge(
array(
@@ -1162,8 +1353,12 @@ public function updateAdminSettings( $settings = array( ) )
);
}
- public function getAdminFiles( )
- {// get administrator file listing
+ /**
+ * Get administrator file listing
+ * @return [type] [description]
+ */
+ public function getAdminFiles()
+ {
return $this->setRequest(
array(
'module' => 'admin.files',
@@ -1172,8 +1367,13 @@ public function getAdminFiles( )
);
}
- public function getAdminFileDetails( $id )
- {// get admin file details
+ /**
+ * Get admin file details
+ * @param [type] $id [description]
+ * @return [type] [description]
+ */
+ public function getAdminFileDetails($id)
+ {
return $this->setRequest(
array(
'module' => 'admin.file',
@@ -1183,8 +1383,14 @@ public function getAdminFileDetails( $id )
);
}
- public function updateAdminFile( $id, $details = array( ) )
- {// update admin file details
+ /**
+ * Update admin file details
+ * @param [type] $id [description]
+ * @param array $details [description]
+ * @return [type] [description]
+ */
+ public function updateAdminFile($id, $details = array())
+ {
return $this->setRequest(
array_merge(
array(
@@ -1197,9 +1403,14 @@ public function updateAdminFile( $id, $details = array( ) )
);
}
- public function createAdminFile( $file_details = array( ) )
- {// create new admin file
- $file_details = array_merge( $file_details, $this->getFileData( $file_details['filename'] ) );
+ /**
+ * Create new admin file
+ * @param array $file_details [description]
+ * @return [type] [description]
+ */
+ public function createAdminFile($file_details = array())
+ {
+ $file_details = array_merge($file_details, $this->getFileData($file_details['filename']));
return $this->setRequest(
array_merge(
array(
@@ -1211,8 +1422,13 @@ public function createAdminFile( $file_details = array( ) )
);
}
- public function deleteAdminFile( $id )
- {// delete admin file
+ /**
+ * Delete admin file
+ * @param [type] $id [description]
+ * @return [type] [description]
+ */
+ public function deleteAdminFile($id)
+ {
return $this->setRequest(
array(
'module' => 'admin.file',
@@ -1222,8 +1438,12 @@ public function deleteAdminFile( $id )
);
}
- public function getAdminBackups( )
- {// get admin backups
+ /**
+ * Get admin backups
+ * @return [type] [description]
+ */
+ public function getAdminBackups()
+ {
return $this->setRequest(
array(
'module' => 'admin.backups',
@@ -1232,8 +1452,13 @@ public function getAdminBackups( )
);
}
- public function getAdminBackupDetails( $id )
- {// get admin backup details
+ /**
+ * Get admin backup details
+ * @param [type] $id [description]
+ * @return [type] [description]
+ */
+ public function getAdminBackupDetails($id)
+ {
return $this->setRequest(
array(
'module' => 'admin.backup',
@@ -1243,9 +1468,14 @@ public function getAdminBackupDetails( $id )
);
}
- public function createAdminBackup( $backup_details = array( ) )
- {// create an admin backup
- $backup_details = array_merge( $backup_details, $this->getFileData( $backup_details['filename'] ) );
+ /**
+ * Create an admin backup
+ * @param array $backup_details [description]
+ * @return [type] [description]
+ */
+ public function createAdminBackup($backup_details = array())
+ {
+ $backup_details = array_merge($backup_details, $this->getFileData($backup_details['filename']));
return $this->setRequest(
array_merge(
array(
@@ -1257,8 +1487,13 @@ public function createAdminBackup( $backup_details = array( ) )
);
}
- public function deleteAdminBackup( $id )
- {// delete an admin backup
+ /**
+ * Delete an admin backup
+ * @param [type] $id [description]
+ * @return [type] [description]
+ */
+ public function deleteAdminBackup($id)
+ {
return $this->setRequest(
array(
'module' => 'admin.backup',
@@ -1268,12 +1503,16 @@ public function deleteAdminBackup( $id )
);
}
- /*
+ /**
* API Methods
- *
*/
- public function getAPIConfig( )
- {// get api config
+
+ /**
+ * Get api config
+ * @return [type] [description]
+ */
+ public function getAPIConfig()
+ {
return $this->setRequest(
array(
'module' => 'api.config',
@@ -1282,8 +1521,12 @@ public function getAPIConfig( )
);
}
- public function getAPIMethods( )
- {// get all available api methods
+ /**
+ * Get all available api methods
+ * @return [type] [description]
+ */
+ public function getAPIMethods()
+ {
return $this->setRequest(
array(
'module' => 'api.methods',
@@ -1292,4 +1535,3 @@ public function getAPIMethods( )
);
}
}
-?>
\ No newline at end of file