|
- <?php
- namespace Biukop;
-
- class UserJob{
- private $user;
- private $db;
- private $table_name;
- private $jobs;
- private $options;
- public function __construct($login){
- if ($login == null || $login == "")
- $this->user = wp_get_current_user();
- else{
- $this->user = get_user_by('login', $login);
- }
-
- global $wpdb;
- $this->db = $wpdb;
- $this->table_name = $wpdb->prefix . 'acare_ts';
-
- $this->jobs = $this->list_jobs("2019-07-01", "2019-07-14");
- }
-
- private function is_staff()
- {
- $roles = get_userdata($this->user->ID)->roles;
- return $roles == 'staff';
- }
-
- public function list_jobs($start, $finish){
- $response = array(
- 'status'=>'success',
- 'jobs' => [],
- 'staff_name'=>$this->user->display_name,
- 'job_count' => 0.
- );
- $sql = "SELECT * FROM $this->table_name WHERE start>='%s' and start <='%s' and staff='%s' order by start ASC";
- $query = $this->db->prepare ($sql, array($start, $finish, $this->user->user_login));
- $jobs = $this->db->get_results($query);
- $response['job_count'] = count($jobs);
- //$response['sql'] = $query;
- if ($this->db->last_error == ""){
- $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,
- //descriptions
- 'rate_str'=> $this->get_rate_str($s->rate),
- 'tos_str'=> $this->get_tos_str($s->tos),
- 'client_name' => $this->get_display_name($s->client),
- 'client_addr' => $this->get_client_addr($s->client),
- );
- }
-
- }else{
- $response['status'] = 'error';
- $response['err'] = $this->db->last_error;
- }
- return $response;
- }
-
-
- private function get_rate_str($earnings_rate_id)
- {
- if ($this->options == NULL){
- $this->options = get_option('bts_payitem_earnings_rate');
- }
- foreach($this->options as $o){
- if ($o['EarningsRateID'] == $earnings_rate_id)
- return $o['Name'];
- }
- return "";
- }
-
- private function get_tos_str($ndis_code)
- {
- if ($this->ndis == null){
- $this->ndis = new NdisPrice(2019);
- }
- return $this->ndis->get_tos_str($ndis_code);
- }
-
- private function get_client_addr($login)
- {
- $user = get_user_by('login', $login);
- return get_user_meta($user->ID, 'address', true);
- }
-
- private function get_display_name($login)
- {
- $user = get_user_by('login', $login);
- return $user->display_name;
- }
- }
-
-
- ?>
|