timesheet source code
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

72 lines
2.3KB

  1. <?php
  2. namespace Biukop;
  3. class Apiv1{
  4. private $office;
  5. private $job_table;
  6. public function __construct($office, $job_table){
  7. $this->office = $office;
  8. $this->job_table = $job_table;
  9. add_shortcode( 'bts_jobv1_item', array($this, 'bts_jobv1_item'));
  10. add_action('wp_ajax_list_jobv1', array($this,'list_job' ));
  11. }
  12. public function bts_jobv1_item($attr){
  13. $html =$this->template('jobv1_item', 'jobv1.html');
  14. //$html = str_replace('[bts-tos-options]', $this->bts_tos_options([]), $html);
  15. $html = do_shortcode($html);
  16. return $html;
  17. }
  18. //generate template based on html file
  19. private function template($id, $file)
  20. {
  21. $text = '<script id="' . $id .'" type="text/x-biukop-template">';
  22. $text .= file_get_contents(plugin_dir_path(__FILE__) . "/html/$file");
  23. $text .= '</script>';
  24. return $text;
  25. }
  26. //ajax browse job with different filters
  27. function list_job(){
  28. global $wpdb;
  29. check_ajax_referer('acaresydney');
  30. $start = $_POST['start'] . " 00:00:00";
  31. $finish = $_POST['finish']. " 23:59:59";
  32. $response = array(
  33. 'status'=>'success',
  34. 'jobs' => [],
  35. 'job_maps' =>[],
  36. );
  37. $sql = "SELECT * FROM $this->job_table WHERE start>='%s' and start <='%s' order by start ASC ,staff ASC";
  38. //$sql = "SELECT * FROM $this->job_table order by start ASC ,staff ASC";
  39. $query = $wpdb->prepare ($sql, array($start, $finish));
  40. $response['sql'] = $query;
  41. $jobs = $wpdb->get_results($query);
  42. if (! empty($jobs)){
  43. $response['status'] = 'success';
  44. foreach( $jobs as $s){
  45. $data = array(
  46. 'id' => $s->id,
  47. 'tos' => $s->tos,
  48. 'start'=> $s->start,
  49. 'finish'=> $s->finish,
  50. 'rate'=> $s->rate,
  51. 'staff'=> $s->staff,
  52. 'client'=> $s->client,
  53. 'ack' => $s->ack,
  54. 'rating' =>$s->rating,
  55. );
  56. $response['jobs'][] = $data;
  57. $response['jobs_maps'][$s->id] = $data;
  58. }
  59. }
  60. wp_send_json($response);
  61. }
  62. }