Location: PHPKode > scripts > Prioritexter > TaskCategories.php
<?php
// dependencies:
// $db global must be declared
// db structure must be correct for tables task_category and category
class TaskCategories {

  var $task_categories;

  function TaskCategories() {
    global $db;
    $cats = array();

    $result = $db->joinQuery("task_category","category","category_id");
    while($myrow = mysql_fetch_array($result)) {
      if (!isset($task_cat[$myrow["task_id"]])) 
	$task_cat[$myrow["task_id"]] = array();
      array_push($task_cat[$myrow["task_id"]],$myrow["category_name"]);
    }
    $this->task_categories = $task_cat;
  }

  function insertTaskCategories($cats, $task_id) {
    global $db, $categories;

    foreach ($cats as $this_category) {
      $values = array();
      $values["task_id"] = $task_id;
      $values["category_id"] = array_search($this_category,
					    $categories->categories);
      Assert::assert(($values["category_id"] !== FALSE),
		     "Invalid category submitted");
      $db->insert("task_category", $values);
    }
  }
}
?>
Return current item: Prioritexter