|
- <?php
- namespace Biukop;
-
- class Apiv1{
- private $office;
- private $job_table;
- public function __construct($office, $job_table){
- $this->office = $office;
- $this->job_table = $job_table;
- add_shortcode( 'bts_jobv1_item', array($this, 'bts_jobv1_item'));
- add_action('wp_ajax_list_jobv1', array($this,'list_job' ));
- }
-
-
- public function bts_jobv1_item($attr){
- $html =$this->template('jobv1_item', 'jobv1.html');
- //$html = str_replace('[bts-tos-options]', $this->bts_tos_options([]), $html);
- $html = do_shortcode($html);
- return $html;
- }
-
- //generate template based on html file
- private function template($id, $file)
- {
- $text = '<script id="' . $id .'" type="text/x-biukop-template">';
- $text .= file_get_contents(plugin_dir_path(__FILE__) . "/html/$file");
- $text .= '</script>';
- return $text;
- }
-
-
- //ajax browse job with different filters
- function list_job(){
- global $wpdb;
- check_ajax_referer('acaresydney');
- $start = $_POST['start'] . " 00:00:00";
- $finish = $_POST['finish']. " 23:59:59";
-
- $response = array(
- 'status'=>'success',
- 'jobs' => [],
- );
-
- //$sql = "SELECT * FROM $this->table_name WHERE start>='%s' and start <='%s' order by start ASC ,staff ASC";
- $sql = "SELECT * FROM $this->job_table order by start ASC ,staff ASC";
- $query = $wpdb->prepare ($sql, array($start, $finish));
- $response['sql'] = $query;
- $jobs = $wpdb->get_results($query);
-
- if (! empty($jobs)){
- $response['status'] = 'success';
- foreach( $jobs as $s){
- $response['jobs'][] = array(
- 'id' => $s->id,
- 'tos' => $s->tos,
- 'start'=> $s->start,
- 'finish'=> $s->finish,
- 'rate'=> $s->rate,
- 'staff'=> $s->staff,
- 'client'=> $s->client,
- 'ack' => $s->ack,
- 'rating' =>$s->rating,
- );
- }
- }
- wp_send_json($response);
- wp_die();
- }
- }
|