Esempio n. 1
0
 /**
  * Update todays date with the given work change. If todays date
  * is 2011-01-23 and the remaining work size left that day is
  * 10.0, and this function is called with $work_change set to 2.0,
  * then after this function call the stored remaining work would
  * be changed to 12.0.
  *
  * The user must be authenticated.
  */
 public static function update_todays_remaining_work_authed($project_id, $work_change)
 {
     // Our dates are always UTC
     $todays_date = date('Y-m-d');
     $query = new SqlQuery("SELECT remaining_size FROM Remaining WHERE remaining_projectid='%s' AND remaining_date='%s' LIMIT 1", $project_id, $todays_date);
     if ($query->select_was_successful()) {
         // We've updated todays date before
         $update_mode = 'update';
         $last_size = $query->get_next_row_column('remaining_size');
     } else {
         // First time we update the time for this day, use size
         // from yesterday (or rather, last day we made an update)
         $update_mode = 'insert';
         $query = new SqlQuery("SELECT remaining_size FROM Remaining WHERE remaining_projectid='%s' LIMIT 1", $project_id);
         if ($query->select_was_successful()) {
             $last_size = $query->get_next_row_column('remaining_size');
         } else {
             // First update ever for the project, start at zero
             $last_size = 0.0;
         }
     }
     $new_size = 0;
     $tasks = Sql::get_tasks_from_project_id($project_id);
     foreach ((array) $tasks as $task) {
         $new_size += $task->get_size();
     }
     if ($update_mode == 'update') {
         $query = new SqlQuery("UPDATE Remaining SET remaining_size='%s' WHERE remaining_projectid='%s' AND remaining_date='%s' LIMIT 1", $new_size, $project_id, $todays_date);
     } else {
         $query = new SqlQuery("INSERT INTO Remaining (remaining_projectid, remaining_size, remaining_date) VALUES ('%s', '%s', '%s')", $project_id, $new_size, $todays_date);
     }
 }