Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.36 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. */
  5. public function get_closed(){
  6.  
  7. if(isset( $_GET['start'] ) && !empty( $_GET['start'] )){
  8.  
  9. $StartClassDateTime = new DateTime($_GET['start']);
  10. $EndClassDateTime = new DateTime($_GET['end']);
  11.  
  12. }else{
  13. $StartClassDateTime = NULL;
  14. $EndClassDateTime = NULL;
  15. }
  16. $indexnumber = 0;
  17. $resultafter = array();
  18.  
  19. /**
  20. * Get closed dates
  21. */
  22.  
  23. $args = array(
  24.  
  25. 'post_type' => 'cal-day',
  26. 'posts_per_page' => -1,
  27. 'orderby' => 'meta_value',
  28. 'order' => 'ASC',
  29. 'meta_key' => 'wpcf-time-start',
  30. 'meta_query' => array(
  31. array(
  32. 'key' => 'wpcf-time-start',
  33. 'value' => array( $StartClassDateTime->getTimestamp(), $EndClassDateTime->getTimestamp() ),
  34. 'compare' => 'BETWEEN',
  35. 'type' => 'NUMERIC'
  36. )
  37. )
  38.  
  39.  
  40. );
  41. // The Query
  42. $the_query = new WP_Query( $args );
  43.  
  44. // The Loop
  45.  
  46. if ( $the_query->have_posts() ) {
  47. foreach($the_query->posts as $keypost => $valuepost){
  48.  
  49. $starttime = get_post_meta( $valuepost->ID, 'wpcf-time-start', true );
  50. $endtime = get_post_meta( $valuepost->ID, 'wpcf-time-end', true );
  51.  
  52. $resultafter[$indexnumber] = new StdClass;
  53. $resultafter[$indexnumber]->title = $valuepost->post_title;
  54. $resultafter[$indexnumber]->description = $valuepost->post_content;
  55. $resultafter[$indexnumber]->start = gmdate("Y-m-d\TH:i:s\Z", $starttime);
  56. $resultafter[$indexnumber]->end = gmdate("Y-m-d\TH:i:s\Z", $endtime);
  57. $resultafter[$indexnumber]->permalink = get_permalink($valuepost->ID);
  58. $resultafter[$indexnumber]->className = 'closedclass';
  59.  
  60. $indexnumber ++;
  61.  
  62.  
  63. }
  64.  
  65. }
  66.  
  67. /**
  68. * End Closed dates
  69. */
  70.  
  71. /****
  72. *
  73. *Convert our returned array
  74. *to json ready for angularJS...
  75. *
  76. ****/
  77. $jsonitfull = json_encode($resultafter);
  78.  
  79. echo $jsonitfull;
  80. die();
  81. }
  82. /**
  83. *
  84. */
  85. public function get_events(){
  86.  
  87. if(isset( $_GET['start'] ) && !empty( $_GET['start'] )){
  88. $StartClassDateTime = new DateTime($_GET['start']);
  89. $EndClassDateTime = new DateTime($_GET['end']);
  90.  
  91. }else{
  92. $StartClassDateTime = NULL;
  93. $EndClassDateTime = NULL;
  94. }
  95. /**
  96. * Get closed dates
  97. */
  98. $indexnumber = 0;
  99. $resultafter = array();
  100. $args_events = array(
  101.  
  102. 'post_type' => 'product',
  103. 'posts_per_page' => -1,
  104. 'orderby' => 'meta_value',
  105. 'meta_key' => 'wpcf-event-start-date',
  106. 'order' => 'ASC',
  107. 'meta_query' => array(
  108. array(
  109. 'key' => 'wpcf-event-start-date',
  110. 'value' => array( $StartClassDateTime->getTimestamp(), $EndClassDateTime->getTimestamp() ),
  111. 'compare' => 'BETWEEN',
  112. 'type' => 'NUMERIC'
  113. ),
  114. array(
  115. 'key' => 'wpcf-eventtype',
  116. 'value' => 'yes'
  117. )
  118. )
  119.  
  120.  
  121. );
  122. // The Query
  123. $the_query_events = new WP_Query( $args_events );
  124.  
  125. // The Loop
  126.  
  127. if ( $the_query_events->have_posts() ) {
  128. foreach($the_query_events->posts as $keypost => $valuepost){
  129. $startdate = date("Y-m-d",get_post_meta( $valuepost->ID, 'wpcf-event-start-date', true ) );
  130. $enddate = date("Y-m-d",get_post_meta( $valuepost->ID, 'wpcf-event-start-date', true ) );
  131. $starttime = get_post_meta( $valuepost->ID, 'wpcf-event-start-time', true );
  132. $endtime = get_post_meta( $valuepost->ID, 'wpcf-event-end-time', true );
  133.  
  134. $resultafter[$indexnumber] = new StdClass;
  135. $resultafter[$indexnumber]->title = $valuepost->post_title;
  136. $resultafter[$indexnumber]->description = $valuepost->post_content;
  137. $resultafter[$indexnumber]->start = $startdate .'T'. $starttime;
  138. $resultafter[$indexnumber]->end = $enddate .'T'. $endtime;
  139. $resultafter[$indexnumber]->className = 'eventsclass';
  140. $resultafter[$indexnumber]->permalink = get_permalink($valuepost->ID);
  141.  
  142. $indexnumber ++;
  143.  
  144.  
  145. }
  146.  
  147. }
  148.  
  149. /****
  150. *
  151. *Convert our returned array
  152. *to json ready for angularJS...
  153. *
  154. ****/
  155. $jsonitfull = json_encode($resultafter);
  156.  
  157. echo $jsonitfull;
  158. die();
  159. }
  160. public function get_appoints(){
  161. //ini_set('max_execution_time', 300); //300 seconds = 5 minutes
  162.  
  163. require_once(dirname(__FILE__). "/includes/appointmentService.php");
  164. require_once(dirname(__FILE__). "/includes/classService.php");
  165.  
  166. $no_exists_value = get_option( 'mind_body_options' );
  167. $sourcename = $no_exists_value['sourcename'];
  168. $password = $no_exists_value['password'];
  169. $siteID = $no_exists_value['siteID'];
  170.  
  171. $Username = $no_exists_value['Username'];
  172. $Passworduser = $no_exists_value['Passworduser'];
  173.  
  174. // initialize default credentials
  175. $creds = new SourceCredentials($sourcename, $password, array($siteID));
  176. $user = new UserCredentials($Username, $Passworduser, array($siteID));
  177. //Services
  178. $classService = new MBClassService();
  179. $appointmentServcie = new MBAppointmentService();
  180. $indexnumber = 0;
  181.  
  182.  
  183.  
  184. if(isset( $_GET['start'] ) && !empty( $_GET['start'] )){
  185. $StartClassDateTime = new DateTime($_GET['start']);
  186. $EndClassDateTime = new DateTime($_GET['end']);
  187.  
  188. }else{
  189. $StartClassDateTime = NULL;
  190. $EndClassDateTime = NULL;
  191. }
  192.  
  193.  
  194.  
  195. /**
  196. * Classes loop
  197. */
  198. // initialize default credentials
  199. $classService->SetDefaultCredentials($creds);
  200. $classService->SetDefaultUserCredentials($user);
  201. //Class's get
  202. $resultclass = $classService->GetClasses(array(), array(), array(), $StartClassDateTime, $EndClassDateTime, NULL, 400, 1);
  203. $resultget = $resultclass->GetClassesResult->Classes->Class;
  204.  
  205.  
  206. $staffids = array();
  207.  
  208.  
  209.  
  210. /*
  211. *
  212. *Traverse array using shortcode level variable if it's set!
  213. *
  214. *
  215. */
  216.  
  217.  
  218.  
  219. $index = 0;
  220. foreach ($resultget as $class) {
  221. if(!$class->IsCanceled){
  222. $resultafter[$indexnumber] = new StdClass;
  223. $staffids[$index] = $class->Staff->ID;
  224. $index ++;
  225. }
  226. }
  227.  
  228. /**
  229. * End classes services
  230. */
  231.  
  232. /**
  233. * Appointsments service
  234. */
  235. // initialize default credentials
  236.  
  237.  
  238. $appointmentServcie->SetDefaultCredentials($creds);
  239. $appointmentServcie->SetDefaultUserCredentials($user);
  240.  
  241.  
  242.  
  243.  
  244. $uniqueids = array_values( array_unique($staffids) );
  245. $date_sub = array();
  246.  
  247. $getschedules = $appointmentServcie->GetScheduleItems( array(), $uniqueids, $StartClassDateTime, $EndClassDateTime, true, 1500 );
  248. $k = 0;
  249. foreach($getschedules->GetScheduleItemsResult->StaffMembers->Staff as $staffkey => $valuestaff){
  250.  
  251. if(isset($valuestaff->Availabilities->Availability)){
  252.  
  253. //$shift = new Ranges(new DateTime('12:30:00'), new DateTime('22:00:00'));
  254. //Check for availability set
  255. $date_sub[$k] = new StdClass;
  256. $date_sub[$k]->FirstName = $valuestaff->FirstName;
  257. $date_sub[$k]->LastName = $valuestaff->LastName;
  258.  
  259.  
  260. $i = 0;
  261. foreach($valuestaff->Availabilities->Availability as $keysub => $subvalue){
  262.  
  263. $daymonthyear = new DateTime($subvalue->StartDateTime);
  264.  
  265. $daymonthyearend = new DateTime($subvalue->EndDateTime);
  266.  
  267.  
  268. $date_sub[$k]->dates[$i] = new StdClass;
  269. $date_sub[$k]->dates[$i]->availday = $daymonthyear->format('Y-m-d');
  270. $date_sub[$k]->dates[$i]->availhoursstart = $daymonthyear->format('Y-m-d H:i');
  271. $date_sub[$k]->dates[$i]->availhoursend = $daymonthyearend->format('Y-m-d H:i');
  272.  
  273. $y = 0;
  274. if(isset($valuestaff->Appointments->Appointment)){
  275.  
  276. foreach($valuestaff->Appointments->Appointment as $blah => $blahblah){
  277.  
  278. $daymonthyearunavail = new DateTime($blahblah->StartDateTime);
  279.  
  280. if($daymonthyearunavail->format('Y-m-d') == $daymonthyear->format('Y-m-d') ){
  281.  
  282. $start = new DateTime($blahblah->StartDateTime);
  283. $end = new DateTime($blahblah->EndDateTime);
  284.  
  285.  
  286. $date_sub[$k]->dates[$i]->unavail[$y] = new StdClass;
  287. $date_sub[$k]->dates[$i]->unavail[$y]->start = $start->format('Y-m-d H:i');
  288. $date_sub[$k]->dates[$i]->unavail[$y]->end = $end->format('Y-m-d H:i');
  289. $date_sub[$k]->dates[$i]->unavail[$y]->Description = $blahblah->Program->Name;
  290. //Not in use all the data$date_sub[$k]->dates[$i]->unavail[$y]->all = $valueunavail;
  291.  
  292. $y++;
  293. }
  294. }
  295. }
  296. foreach($valuestaff->Unavailabilities->Unavailability as $keyunavil => $valueunavail){
  297.  
  298.  
  299. $daymonthyearunavail = new DateTime($valueunavail->StartDateTime);
  300.  
  301. if($daymonthyearunavail->format('Y-m-d') == $daymonthyear->format('Y-m-d') ){
  302.  
  303. $start = new DateTime($valueunavail->StartDateTime);
  304. $end = new DateTime($valueunavail->EndDateTime);
  305.  
  306.  
  307.  
  308. $date_sub[$k]->dates[$i]->unavail[$y] = new StdClass;
  309. $date_sub[$k]->dates[$i]->unavail[$y]->start = $start->format('Y-m-d H:i');
  310. $date_sub[$k]->dates[$i]->unavail[$y]->end = $end->format('Y-m-d H:i');
  311. $date_sub[$k]->dates[$i]->unavail[$y]->Description = $valueunavail->Description;
  312. //Not in use all the data$date_sub[$k]->dates[$i]->unavail[$y]->all = $valueunavail;
  313.  
  314. $y++;
  315. }
  316.  
  317. }
  318. $i++;
  319.  
  320. }
  321.  
  322. }
  323. $k++;
  324. }
  325. foreach($date_sub as $keydates => $valuedates){
  326.  
  327. foreach($valuedates->dates as $key => $value){
  328. $shift = new Ranges(new DateTime($value->availhoursstart), new DateTime($value->availhoursend));
  329.  
  330.  
  331. if(isset($value->unavail)){
  332.  
  333. $igh = 0;
  334. foreach($value->unavail as $keysubsub => $valuesubsub){
  335.  
  336. $unavails[$igh] = new Range(new DateTime($valuesubsub->start), new DateTime($valuesubsub->end));
  337.  
  338. $igh++;
  339.  
  340. }
  341.  
  342. }else{
  343. $unavails[$igh] = new Range(new DateTime("11:00"), new DateTime('12:00'));
  344.  
  345. }
  346. $unavailables = new Ranges($unavails);
  347.  
  348.  
  349.  
  350.  
  351. $shift->substract($unavailables);
  352. $x = 0;
  353. foreach ($shift as $range) {
  354.  
  355. $valuedates->dates[$key]->avail[$x] = $range->format('H:i');
  356.  
  357.  
  358. $x++;
  359.  
  360. }
  361. }
  362.  
  363. }
  364. foreach ($date_sub as $keylast => $valuelast) {
  365.  
  366. foreach($valuelast->dates as $keylastsub => $valuelastsub){
  367.  
  368. if(isset($valuelastsub->avail)){
  369. foreach($valuelastsub->avail as $keylastsubsub => $valuelastsubsub ){
  370.  
  371.  
  372. $resultafter[$indexnumber] = new StdClass;
  373. $resultafter[$indexnumber]->title = $valuelast->FirstName . ' ' . $valuelast->LastName;
  374. $resultafter[$indexnumber]->description = $valuelast->FirstName . ' has free time from:'. $valuelastsubsub[0] . ' untill:' .$valuelastsubsub[1] ;
  375. $resultafter[$indexnumber]->start = $valuelastsub->availday . 'T' . $valuelastsubsub[0]. ':00';
  376. $resultafter[$indexnumber]->end = $valuelastsub->availday . 'T' . $valuelastsubsub[1]. ':00';
  377. $resultafter[$indexnumber]->className = 'instructorsclass';
  378.  
  379. $indexnumber ++;
  380. }
  381. }
  382.  
  383. }
  384. }
  385. /**
  386. * End appointment service
  387. */
  388.  
  389.  
  390. /****
  391. *
  392. *Convert our returned array
  393. *to json ready for angularJS...
  394. *
  395. ****/
  396. $jsonitfull = json_encode($resultafter);
  397.  
  398. echo $jsonitfull;
  399. die();
  400. }
  401. /**
  402. *
  403. */
  404. public function get_classes(){
  405. //ini_set('max_execution_time', 300); //300 seconds = 5 minutes
  406.  
  407. require_once(dirname(__FILE__). "/includes/classService.php");
  408.  
  409. $no_exists_value = get_option( 'mind_body_options' );
  410. $sourcename = $no_exists_value['sourcename'];
  411. $password = $no_exists_value['password'];
  412. $siteID = $no_exists_value['siteID'];
  413.  
  414. $Username = $no_exists_value['Username'];
  415. $Passworduser = $no_exists_value['Passworduser'];
  416.  
  417. // initialize default credentials
  418. $creds = new SourceCredentials($sourcename, $password, array($siteID));
  419. $user = new UserCredentials($Username, $Passworduser, array($siteID));
  420. //Services
  421. $classService = new MBClassService();
  422. $indexnumber = 0;
  423.  
  424.  
  425.  
  426. if(isset( $_GET['start'] ) && !empty( $_GET['start'] )){
  427. $StartClassDateTime = new DateTime($_GET['start']);
  428. $EndClassDateTime = new DateTime($_GET['end']);
  429.  
  430. }else{
  431. $StartClassDateTime = NULL;
  432. $EndClassDateTime = NULL;
  433. }
  434.  
  435.  
  436.  
  437. /**
  438. * Classes loop
  439. */
  440. // initialize default credentials
  441. $classService->SetDefaultCredentials($creds);
  442. $classService->SetDefaultUserCredentials($user);
  443. //Class's get
  444. $resultclass = $classService->GetClasses(array(), array(), array(), $StartClassDateTime, $EndClassDateTime, NULL, 400, 1);
  445. $resultget = $resultclass->GetClassesResult->Classes->Class;
  446.  
  447.  
  448. $resultafter = array();
  449.  
  450. /*
  451. *
  452. *Traverse array using shortcode level variable if it's set!
  453. *
  454. *
  455. */
  456.  
  457.  
  458.  
  459.  
  460. foreach ($resultget as $class) {
  461. if(!$class->IsCanceled){
  462.  
  463. $resultafter[$indexnumber] = new StdClass;
  464. $resultafter[$indexnumber]->title = $class->ClassDescription->Name;
  465. $resultafter[$indexnumber]->description = $class->ClassDescription->Description;
  466. $resultafter[$indexnumber]->id = $class->ID;
  467. $resultafter[$indexnumber]->start = $class->StartDateTime;
  468. $resultafter[$indexnumber]->end = $class->EndDateTime;
  469. $resultafter[$indexnumber]->className = 'classclass';
  470.  
  471. $indexnumber ++;
  472.  
  473. }
  474. }
  475.  
  476. /**
  477. * End classes services
  478. */
  479. /****
  480. *
  481. *Convert our returned array
  482. *to json ready for angularJS...
  483. *
  484. ****/
  485. $jsonitfull = json_encode($resultafter);
  486.  
  487. echo $jsonitfull;
  488. die();
  489. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement