Location: PHPKode > scripts > Prioritexter > Task.php
<?php
class Task {

  var $task_id, $urgency, $name, 
    $notes, $priority, $created, $due, $adjustment,
    $type, $categories, $active, $finished;

  function Task ($task_id, $urgency="", $name="", $priority="",
		 $created="", $due="", $adjustment="", $notes="",
		 $type="", $active="", $finished="", $categories=array()) {
    global $db, $task_categories;

    if (strlen($name)>0) {
      $this->task_id = $task_id;
      $this->urgency = $urgency;
      $this->name = $name;
      $this->priority = $priority;
      $this->created = $created;
      $this->due = $due;
      $this->adjustment = $adjustment;
      $this->notes = $notes;
      $this->type = $type;
      $this->active = $active;
      $this->finished = $finished;

      if(!is_array($categories)) Debug::debug("Categories NOT array in Task");
      $this->categories = $categories;
    } else { // if basically ONLY the task_id was given... we need to 
      // query the database for the info!
      $myrow = $db->getOneRecord("task", "task_id=$task_id");
      Assert::assert(sizeof($myrow),"task id was invalid for "
		     ."finding existing task");
      
     
      $this->task_id = $task_id;
      $this->name = $myrow["name"];
      $this->priority = $myrow["priority"];
      $this->created = $myrow["created"];
      $this->due = $myrow["due"];
      $this->adjustment = $myrow["adjustment"];
      $this->notes = $myrow["notes"];
      $this->type = $myrow["type"];
      $this->active = $myrow["active"];
      $this->finished = $myrow["finished"];

      $this->categories = $task_categories->task_categories[$task_id];
    }
  }

  function postponeAdjustment($created, $due, $old_adj) {
    Debug::debug("ready to postpone. created is $created ; due is $due;"
		 . " old adjustment is $old_adj ; time is ".time());

    // we need to know old adjusted period -- created date to
    // adjusted due date -- to know how much we should be increasing
    // the adjustment by!
    $old_total = $old_adj + $due - $created;
    // editing task can put its due date BEFORE its creation date,
    // resulting in NEGATIVE total start-end period! sto pthis nonsense.
    if ($old_total < 0) $old_total=0;

    // had to redo this logic because of problem scenario --
    // what if user waited until long after due date to hit postpone?
    // with old logic, adjustment would be a few days bigger-- but
    // that might still not bring new adjusted due date up to the present!
    // it doesn't make much sense to hit postpone and then have the task
    // still be overdue...

    $time_past_due = (time()-$due-$old_adj);
    if ($time_past_due>0) {
      $catch_up_time = $time_past_due+$old_adj;
      Debug::debug("adjusted time is past due");
    }
    else {
      $catch_up_time = $old_adj;
      Debug::debug("adjusted time is NOT past due.");
    }

    // so at this point catch_up_time is at LEAST big enough to bring
    // the adjustment to the current day.

    // take 5% of old total time
    $portion_of_old_total = $old_total*.1;

    // a few constant days to add, in case % of prev period is very small
    $constant_time = .5*86400; 

    // new adjustment is 150% of old one, plus a standard 10% of period
    // and a day or two constant.
    Debug::debug("new adj is $catch_up_time + "
		 . " $portion_of_old_total + $constant_time .");
    $new_adj = $catch_up_time+$old_adj*.35+
       $portion_of_old_total+$constant_time;
    Debug::debug("almost done postponing. new adj is $new_adj");
    // round new_adj to nearest whole day amount
    //    $new_adj = round($new_adj/86400)*86400;

    Debug::debug("done postponing. new adj is $new_adj");
    return $new_adj;
  }

}
?>
Return current item: Prioritexter