Exemple #1
0
 public function all_get($token)
 {
     $token_entry = new Token();
     $token_entry->get_by_valid_token($token)->get();
     if ($token_entry->exists()) {
         $settings = new Setting();
         $settings->get();
         $response = new stdClass();
         $response->status = true;
         $response->settings = new stdClass();
         foreach ($settings as $setting) {
             $response->settings->{$setting->setting_key} = $setting->setting_value;
         }
         $this->response($response);
     } else {
         $response = new stdClass();
         $response->status = false;
         $response->error = 'Token not found or session expired';
         $this->response($response);
     }
 }
Exemple #2
0
 public function weekTotal_get($token)
 {
     //YEARWEEK(FROM_UNIXTIME(stop_time)) = YEARWEEK(CURRENT_DATE)
     $token_entry = new Token();
     $token_entry->get_by_valid_token($token)->get();
     $response = new stdClass();
     if ($token_entry->exists()) {
         //TODO
         $timer_entries = new Timer_entry();
         //Selecting the entry
         $timer_entries->getThisWeek()->where('active', 0)->select_sum('(stop_time - start_time)', 'totalTime')->get();
         $response->status = true;
         $response->totalThisWeek = 0;
         if ($timer_entries->exists()) {
             if (!$timer_entries->totalTime) {
                 $response->totalThisWeek = from_unix_timespan_to_string(0);
             }
             $response->totalThisWeek = from_unix_timespan_to_string($timer_entries->totalTime);
         }
     } else {
         $response->status = false;
         $response->error = 'Token not found or session expired';
     }
     $this->response($response);
 }
Exemple #3
0
 public function user_delete($id, $token)
 {
     $token_entry = new Token();
     $token_entry->get_by_valid_token($token)->get();
     $response = new stdClass();
     if ($token_entry->exists() && $token_entry->user->get()->is_admin) {
         if ($token_entry->user_id != $id) {
             $user = new User();
             $user->get_by_id($id);
             $user->delete();
             $response->status = TRUE;
             $this->response($response);
         } else {
             $response->status = FALSE;
             $response->error = 'Cannot delete active user!';
             $this->response($response);
         }
     } else {
         $response->status = FALSE;
         $response->error = 'Token not found, not an admin or session expired';
         $this->response($response);
     }
 }
Exemple #4
0
 /**
  * Create a new project
  * @route POST projects/
  */
 public function index_post()
 {
     $token_entry = new Token();
     $token_entry->get_by_valid_token($this->post('token'))->get();
     $response = new stdClass();
     if ($token_entry->exists()) {
         $project = new Project();
         $project->name = $this->post('name');
         $project->customer_id = $this->post('customer_id');
         if ($project->save()) {
             $response->status = true;
         } else {
             $response->status = false;
             $response->error = 'Project not saved!';
         }
     } else {
         $response->status = false;
         $response->error = 'Token not found or session expired';
     }
     $this->response($response);
 }