/**
	 * Returns all task templates
	 *
	 */
	static function getAllTaskTemplates($only_parent_task_templates = false, $archived = false) {
		if ($archived)
			$archived_cond = "AND `archived_on` <> 0";
		else
			$archived_cond = "AND `archived_on` = 0";
		
		$conditions = " `is_template` = true $archived_cond";
		if ($only_parent_task_templates)
			$conditions .= "  and `parent_id` = 0  ";
		$order_by = "`title` ASC";
		$tasks = ProjectTasks::find ( array ('conditions' => $conditions, 'order' => $order_by ) );
		if (! is_array ( $tasks ))
			$tasks = array ();
		return $tasks;
	}
 static function getProjectTasks($project = null, $order = null, $orderdir = 'ASC', $parent_id = null, $milestone_id = null, $tag = null, $assigned_to_company = null, $assigned_to_user = null, $assigned_by_user = null, $pending = false, $priority = "all", $is_template = false, $is_today = false, $is_late = false, $limit = null, $archived = false)
 {
     if ($order == self::ORDER_BY_STARTDATE) {
         $order_by = '`start_date` ' . $orderdir;
     } else {
         if ($order == self::ORDER_BY_DUEDATE) {
             $order_by = '`due_date` ' . $orderdir;
         } else {
             // default
             $order_by = '`order` ' . $orderdir;
         }
     }
     // if
     if ($project instanceof Project) {
         $pids = $project->getAllSubWorkspacesQuery(!$archived);
         $projectstr = " AND " . self::getWorkspaceString($pids);
     } else {
         $projectstr = "";
     }
     if ($parent_id === null) {
         $parentstr = "";
     } else {
         $parentstr = " AND `parent_id` = " . DB::escape($parent_id) . " ";
     }
     if ($milestone_id === null) {
         $milestonestr = "";
     } else {
         $milestonestr = " AND `milestone_id` = " . DB::escape($milestone_id) . " ";
     }
     if ($tag == '' || $tag == null) {
         $tagstr = "";
     } else {
         $tagstr = " AND (select count(*) from " . TABLE_PREFIX . "tags where " . TABLE_PREFIX . "project_tasks.id = " . TABLE_PREFIX . "tags.rel_object_id and " . TABLE_PREFIX . "tags.tag = " . DB::escape($tag) . " and " . TABLE_PREFIX . "tags.rel_object_manager ='ProjectTasks' ) > 0 ";
     }
     $assignedToStr = "";
     if ($assigned_to_company) {
         if ($assigned_to_company == -1) {
             $assigned_to_company = 0;
         }
         $assignedToStr .= " AND `assigned_to_company_id` = " . DB::escape($assigned_to_company) . " ";
     }
     if ($assigned_to_user) {
         if ($assigned_to_user == -1) {
             $assigned_to_user = 0;
         }
         $assignedToStr .= " AND `assigned_to_user_id` = " . DB::escape($assigned_to_user) . " ";
     }
     $assignedByStr = "";
     if ($assigned_by_user) {
         $assignedByStr .= " AND (`created_by_id` = " . DB::escape($assigned_by_user) . " OR `updated_by_id` = " . DB::escape($assigned_by_user) . ") ";
     }
     if ($pending) {
         $pendingstr = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " ";
     } else {
         $pendingstr = "";
     }
     if (is_numeric($priority)) {
         $priostr = " AND `priority` = " . DB::escape($priority);
     } else {
         $priostr = "";
     }
     if ($archived) {
         $archived_cond = " AND `archived_by_id` <> 0";
     } else {
         $archived_cond = " AND `archived_by_id` = 0";
     }
     $permissionstr = ' AND ( ' . permissions_sql_for_listings(ProjectTasks::instance(), ACCESS_LEVEL_READ, logged_user()) . ') ';
     $otherConditions = $milestonestr . $parentstr . $projectstr . $tagstr . $assignedToStr . $assignedByStr . $pendingstr . $priostr . $permissionstr . $archived_cond;
     $conditions = array(' `is_template` = ' . DB::escape($is_template) . $otherConditions);
     $tasks = ProjectTasks::find(array('conditions' => $conditions, 'order' => $order_by, 'limit' => $limit));
     if (!is_array($tasks)) {
         $tasks = array();
     }
     return $tasks;
 }