Skip to content

Instantly share code, notes, and snippets.

@vimes1984
Last active August 29, 2015 14:19
Show Gist options
  • Select an option

  • Save vimes1984/8f206a6f48e50d2ae16a to your computer and use it in GitHub Desktop.

Select an option

Save vimes1984/8f206a6f48e50d2ae16a to your computer and use it in GitHub Desktop.
Mindbody api calls for cal
<?php
/**
*
*/
public function get_closed(){
if(isset( $_GET['start'] ) && !empty( $_GET['start'] )){
$StartClassDateTime = new DateTime($_GET['start']);
$EndClassDateTime = new DateTime($_GET['end']);
}else{
$StartClassDateTime = NULL;
$EndClassDateTime = NULL;
}
$indexnumber = 0;
$resultafter = array();
/**
* Get closed dates
*/
$args = array(
'post_type' => 'cal-day',
'posts_per_page' => -1,
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_key' => 'wpcf-time-start',
'meta_query' => array(
array(
'key' => 'wpcf-time-start',
'value' => array( $StartClassDateTime->getTimestamp(), $EndClassDateTime->getTimestamp() ),
'compare' => 'BETWEEN',
'type' => 'NUMERIC'
)
)
);
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
foreach($the_query->posts as $keypost => $valuepost){
$starttime = get_post_meta( $valuepost->ID, 'wpcf-time-start', true );
$endtime = get_post_meta( $valuepost->ID, 'wpcf-time-end', true );
$resultafter[$indexnumber] = new StdClass;
$resultafter[$indexnumber]->title = $valuepost->post_title;
$resultafter[$indexnumber]->description = $valuepost->post_content;
$resultafter[$indexnumber]->start = gmdate("Y-m-d\TH:i:s\Z", $starttime);
$resultafter[$indexnumber]->end = gmdate("Y-m-d\TH:i:s\Z", $endtime);
$resultafter[$indexnumber]->permalink = get_permalink($valuepost->ID);
$resultafter[$indexnumber]->className = 'closedclass';
$indexnumber ++;
}
}
/**
* End Closed dates
*/
/****
*
*Convert our returned array
*to json ready for angularJS...
*
****/
$jsonitfull = json_encode($resultafter);
echo $jsonitfull;
die();
}
/**
*
*/
public function get_events(){
if(isset( $_GET['start'] ) && !empty( $_GET['start'] )){
$StartClassDateTime = new DateTime($_GET['start']);
$EndClassDateTime = new DateTime($_GET['end']);
}else{
$StartClassDateTime = NULL;
$EndClassDateTime = NULL;
}
/**
* Get closed dates
*/
$indexnumber = 0;
$resultafter = array();
$args_events = array(
'post_type' => 'product',
'posts_per_page' => -1,
'orderby' => 'meta_value',
'meta_key' => 'wpcf-event-start-date',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'wpcf-event-start-date',
'value' => array( $StartClassDateTime->getTimestamp(), $EndClassDateTime->getTimestamp() ),
'compare' => 'BETWEEN',
'type' => 'NUMERIC'
),
array(
'key' => 'wpcf-eventtype',
'value' => 'yes'
)
)
);
// The Query
$the_query_events = new WP_Query( $args_events );
// The Loop
if ( $the_query_events->have_posts() ) {
foreach($the_query_events->posts as $keypost => $valuepost){
$startdate = date("Y-m-d",get_post_meta( $valuepost->ID, 'wpcf-event-start-date', true ) );
$enddate = date("Y-m-d",get_post_meta( $valuepost->ID, 'wpcf-event-start-date', true ) );
$starttime = get_post_meta( $valuepost->ID, 'wpcf-event-start-time', true );
$endtime = get_post_meta( $valuepost->ID, 'wpcf-event-end-time', true );
$resultafter[$indexnumber] = new StdClass;
$resultafter[$indexnumber]->title = $valuepost->post_title;
$resultafter[$indexnumber]->description = $valuepost->post_content;
$resultafter[$indexnumber]->start = $startdate .'T'. $starttime;
$resultafter[$indexnumber]->end = $enddate .'T'. $endtime;
$resultafter[$indexnumber]->className = 'eventsclass';
$resultafter[$indexnumber]->permalink = get_permalink($valuepost->ID);
$indexnumber ++;
}
}
/****
*
*Convert our returned array
*to json ready for angularJS...
*
****/
$jsonitfull = json_encode($resultafter);
echo $jsonitfull;
die();
}
public function get_appoints(){
//ini_set('max_execution_time', 300); //300 seconds = 5 minutes
require_once(dirname(__FILE__). "/includes/appointmentService.php");
require_once(dirname(__FILE__). "/includes/classService.php");
$no_exists_value = get_option( 'mind_body_options' );
$sourcename = $no_exists_value['sourcename'];
$password = $no_exists_value['password'];
$siteID = $no_exists_value['siteID'];
$Username = $no_exists_value['Username'];
$Passworduser = $no_exists_value['Passworduser'];
// initialize default credentials
$creds = new SourceCredentials($sourcename, $password, array($siteID));
$user = new UserCredentials($Username, $Passworduser, array($siteID));
//Services
$classService = new MBClassService();
$appointmentServcie = new MBAppointmentService();
$indexnumber = 0;
if(isset( $_GET['start'] ) && !empty( $_GET['start'] )){
$StartClassDateTime = new DateTime($_GET['start']);
$EndClassDateTime = new DateTime($_GET['end']);
}else{
$StartClassDateTime = NULL;
$EndClassDateTime = NULL;
}
/**
* Classes loop
*/
// initialize default credentials
$classService->SetDefaultCredentials($creds);
$classService->SetDefaultUserCredentials($user);
//Class's get
$resultclass = $classService->GetClasses(array(), array(), array(), $StartClassDateTime, $EndClassDateTime, NULL, 400, 1);
$resultget = $resultclass->GetClassesResult->Classes->Class;
$staffids = array();
/*
*
*Traverse array using shortcode level variable if it's set!
*
*
*/
$index = 0;
foreach ($resultget as $class) {
if(!$class->IsCanceled){
$resultafter[$indexnumber] = new StdClass;
$staffids[$index] = $class->Staff->ID;
$index ++;
}
}
/**
* End classes services
*/
/**
* Appointsments service
*/
// initialize default credentials
$appointmentServcie->SetDefaultCredentials($creds);
$appointmentServcie->SetDefaultUserCredentials($user);
$uniqueids = array_values( array_unique($staffids) );
$date_sub = array();
$getschedules = $appointmentServcie->GetScheduleItems( array(), $uniqueids, $StartClassDateTime, $EndClassDateTime, true, 1500 );
$k = 0;
foreach($getschedules->GetScheduleItemsResult->StaffMembers->Staff as $staffkey => $valuestaff){
if(isset($valuestaff->Availabilities->Availability)){
//$shift = new Ranges(new DateTime('12:30:00'), new DateTime('22:00:00'));
//Check for availability set
$date_sub[$k] = new StdClass;
$date_sub[$k]->FirstName = $valuestaff->FirstName;
$date_sub[$k]->LastName = $valuestaff->LastName;
$i = 0;
foreach($valuestaff->Availabilities->Availability as $keysub => $subvalue){
$daymonthyear = new DateTime($subvalue->StartDateTime);
$daymonthyearend = new DateTime($subvalue->EndDateTime);
$date_sub[$k]->dates[$i] = new StdClass;
$date_sub[$k]->dates[$i]->availday = $daymonthyear->format('Y-m-d');
$date_sub[$k]->dates[$i]->availhoursstart = $daymonthyear->format('Y-m-d H:i');
$date_sub[$k]->dates[$i]->availhoursend = $daymonthyearend->format('Y-m-d H:i');
$y = 0;
if(isset($valuestaff->Appointments->Appointment)){
foreach($valuestaff->Appointments->Appointment as $blah => $blahblah){
$daymonthyearunavail = new DateTime($blahblah->StartDateTime);
if($daymonthyearunavail->format('Y-m-d') == $daymonthyear->format('Y-m-d') ){
$start = new DateTime($blahblah->StartDateTime);
$end = new DateTime($blahblah->EndDateTime);
$date_sub[$k]->dates[$i]->unavail[$y] = new StdClass;
$date_sub[$k]->dates[$i]->unavail[$y]->start = $start->format('Y-m-d H:i');
$date_sub[$k]->dates[$i]->unavail[$y]->end = $end->format('Y-m-d H:i');
$date_sub[$k]->dates[$i]->unavail[$y]->Description = $blahblah->Program->Name;
//Not in use all the data$date_sub[$k]->dates[$i]->unavail[$y]->all = $valueunavail;
$y++;
}
}
}
foreach($valuestaff->Unavailabilities->Unavailability as $keyunavil => $valueunavail){
$daymonthyearunavail = new DateTime($valueunavail->StartDateTime);
if($daymonthyearunavail->format('Y-m-d') == $daymonthyear->format('Y-m-d') ){
$start = new DateTime($valueunavail->StartDateTime);
$end = new DateTime($valueunavail->EndDateTime);
$date_sub[$k]->dates[$i]->unavail[$y] = new StdClass;
$date_sub[$k]->dates[$i]->unavail[$y]->start = $start->format('Y-m-d H:i');
$date_sub[$k]->dates[$i]->unavail[$y]->end = $end->format('Y-m-d H:i');
$date_sub[$k]->dates[$i]->unavail[$y]->Description = $valueunavail->Description;
//Not in use all the data$date_sub[$k]->dates[$i]->unavail[$y]->all = $valueunavail;
$y++;
}
}
$i++;
}
}
$k++;
}
foreach($date_sub as $keydates => $valuedates){
foreach($valuedates->dates as $key => $value){
$shift = new Ranges(new DateTime($value->availhoursstart), new DateTime($value->availhoursend));
if(isset($value->unavail)){
$igh = 0;
foreach($value->unavail as $keysubsub => $valuesubsub){
$unavails[$igh] = new Range(new DateTime($valuesubsub->start), new DateTime($valuesubsub->end));
$igh++;
}
}else{
$unavails[$igh] = new Range(new DateTime("11:00"), new DateTime('12:00'));
}
$unavailables = new Ranges($unavails);
$shift->substract($unavailables);
$x = 0;
foreach ($shift as $range) {
$valuedates->dates[$key]->avail[$x] = $range->format('H:i');
$x++;
}
}
}
foreach ($date_sub as $keylast => $valuelast) {
foreach($valuelast->dates as $keylastsub => $valuelastsub){
if(isset($valuelastsub->avail)){
foreach($valuelastsub->avail as $keylastsubsub => $valuelastsubsub ){
$resultafter[$indexnumber] = new StdClass;
$resultafter[$indexnumber]->title = $valuelast->FirstName . ' ' . $valuelast->LastName;
$resultafter[$indexnumber]->description = $valuelast->FirstName . ' has free time from:'. $valuelastsubsub[0] . ' untill:' .$valuelastsubsub[1] ;
$resultafter[$indexnumber]->start = $valuelastsub->availday . 'T' . $valuelastsubsub[0]. ':00';
$resultafter[$indexnumber]->end = $valuelastsub->availday . 'T' . $valuelastsubsub[1]. ':00';
$resultafter[$indexnumber]->className = 'instructorsclass';
$indexnumber ++;
}
}
}
}
/**
* End appointment service
*/
/****
*
*Convert our returned array
*to json ready for angularJS...
*
****/
$jsonitfull = json_encode($resultafter);
echo $jsonitfull;
die();
}
/**
*
*/
public function get_classes(){
//ini_set('max_execution_time', 300); //300 seconds = 5 minutes
require_once(dirname(__FILE__). "/includes/classService.php");
$no_exists_value = get_option( 'mind_body_options' );
$sourcename = $no_exists_value['sourcename'];
$password = $no_exists_value['password'];
$siteID = $no_exists_value['siteID'];
$Username = $no_exists_value['Username'];
$Passworduser = $no_exists_value['Passworduser'];
// initialize default credentials
$creds = new SourceCredentials($sourcename, $password, array($siteID));
$user = new UserCredentials($Username, $Passworduser, array($siteID));
//Services
$classService = new MBClassService();
$indexnumber = 0;
if(isset( $_GET['start'] ) && !empty( $_GET['start'] )){
$StartClassDateTime = new DateTime($_GET['start']);
$EndClassDateTime = new DateTime($_GET['end']);
}else{
$StartClassDateTime = NULL;
$EndClassDateTime = NULL;
}
/**
* Classes loop
*/
// initialize default credentials
$classService->SetDefaultCredentials($creds);
$classService->SetDefaultUserCredentials($user);
//Class's get
$resultclass = $classService->GetClasses(array(), array(), array(), $StartClassDateTime, $EndClassDateTime, NULL, 400, 1);
$resultget = $resultclass->GetClassesResult->Classes->Class;
$resultafter = array();
/*
*
*Traverse array using shortcode level variable if it's set!
*
*
*/
foreach ($resultget as $class) {
if(!$class->IsCanceled){
$resultafter[$indexnumber] = new StdClass;
$resultafter[$indexnumber]->title = $class->ClassDescription->Name;
$resultafter[$indexnumber]->description = $class->ClassDescription->Description;
$resultafter[$indexnumber]->id = $class->ID;
$resultafter[$indexnumber]->start = $class->StartDateTime;
$resultafter[$indexnumber]->end = $class->EndDateTime;
$resultafter[$indexnumber]->className = 'classclass';
$indexnumber ++;
}
}
/**
* End classes services
*/
/****
*
*Convert our returned array
*to json ready for angularJS...
*
****/
$jsonitfull = json_encode($resultafter);
echo $jsonitfull;
die();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment