/**
  * Return project tickets
  *
  * @access public
  * @param void
  * @return array
  */
 function index()
 {
     $page = (int) array_var($_GET, 'page', 1);
     if ($page < 0) {
         $page = 1;
     }
     $closed = (bool) array_var($_GET, 'closed', false);
     $conditions = DB::prepareString('`closed_on` ' . ($closed ? '>' : '=') . ' ? and `project_id` = ?', array(EMPTY_DATETIME, active_project()->getId()));
     if (!logged_user()->isMemberOfOwnerCompany()) {
         $conditions .= DB::prepareString(' AND `is_private` = ?', array(0));
     }
     // if
     if ($closed) {
         $order = '`closed_on` DESC';
     } else {
         $order = '`created_on` DESC';
     }
     // if
     list($tickets, $pagination) = ProjectTickets::paginate(array('conditions' => $conditions, 'order' => $order), config_option('tickets_per_page', 25), $page);
     // paginate
     tpl_assign('closed', $closed);
     tpl_assign('tickets', $tickets);
     tpl_assign('tickets_pagination', $pagination);
     $this->setSidebar(get_template_path('index_sidebar', 'tickets'));
 }
 /**
  * Prepare search conditions string based on input params
  *
  * @param string $search_for Search string
  * @param Project $project Search in this project
  * @return array
  */
 function getSearchConditions($search_for, Project $project, $include_private = false)
 {
     if ($include_private) {
         return DB::prepareString('MATCH (`content`) AGAINST (? IN BOOLEAN MODE) AND `project_id` = ?', array($search_for, $project->getId()));
     } else {
         return DB::prepareString('MATCH (`content`) AGAINST (? IN BOOLEAN MODE) AND `project_id` = ? AND `is_private` = ?', array($search_for, $project->getId(), false));
     }
     // if
 }
 /**
  * Return all file revisions
  *
  * @param void
  * @return array
  */
 function getRevisions($exclude_last = false, $asc = false)
 {
     if ($exclude_last) {
         $last_revision = $this->getLastRevision();
         if ($last_revision instanceof ProjectFileRevision) {
             $conditions = DB::prepareString('`object_id` <> ? AND `file_id` = ?', array($last_revision->getId(), $this->getId()));
         }
     }
     // if
     $dir = $asc ? 'ASC' : 'DESC';
     if (!isset($conditions)) {
         $conditions = DB::prepareString("`file_id` = ? AND `trashed_on` = '0000-00-00 00:00:00'", array($this->getId()));
     }
     return ProjectFileRevisions::find(array('conditions' => $conditions, 'order' => '`created_on` ' . $dir));
     // find
 }
Example #4
0
 /**
  * Execute query and return all rows
  *
  * @access public
  * @param string $sql
  * @return array
  * @throws DBQueryError
  */
 static function executeAll($sql)
 {
     $arguments = func_get_args();
     array_shift($arguments);
     $arguments = count($arguments) ? array_flat($arguments) : null;
     try {
         $start = microtime(true);
         $result = self::connection()->executeAll($sql, $arguments);
         $end = microtime(true);
         if (Env::isDebuggingDB()) {
             Logger::log(number_format($end - $start, 4) . " - " . DB::prepareString($sql, $arguments));
         }
         if (Env::isDebuggingTime()) {
             TimeIt::add("DB", $end - $start, $start, $end);
         }
     } catch (Exception $e) {
         Logger::log("SQL ERROR: " . $e->getMessage() . " - " . DB::prepareString($sql, $arguments));
         throw $e;
     }
     return $result;
 }
 /**
  * Return Day milestones
  *
  * @access public
  * @param DateTimeValue $date_start in user gmt
  * @param DateTimeValue $date_end	in user gmt	 * 
  */
 function getRangeMilestones(DateTimeValue $date_start, DateTimeValue $date_end, $archived = false)
 {
     $from_date = new DateTimeValue($date_start->getTimestamp());
     $from_date = $from_date->beginningOfDay();
     $to_date = new DateTimeValue($date_end->getTimestamp());
     $to_date = $to_date->endOfDay();
     //set dates to gmt 0 for sql
     $from_date->advance(-logged_user()->getTimezone() * 3600);
     $to_date->advance(-logged_user()->getTimezone() * 3600);
     $archived_cond = " AND `archived_on` " . ($archived ? "<>" : "=") . " 0";
     $conditions = DB::prepareString(' AND `is_template` = false AND `completed_on` = ? AND (`due_date` >= ? AND `due_date` < ?) ' . $archived_cond, array(EMPTY_DATETIME, $from_date, $to_date));
     $result = self::instance()->listing(array("extra_conditions" => $conditions));
     return $result->objects;
 }
	/**
	 * Return Day tasks this user have access on
	 *
	 * @access public
	 * @param void
	 * @return array
	 */
	function getRangeTasksByUser(DateTimeValue $date_start, DateTimeValue $date_end, $assignedUser, $task_filter = null, $archived = false) {
		
		$from_date = new DateTimeValue ( $date_start->getTimestamp () - logged_user()->getTimezone() * 3600 );
		$from_date = $from_date->beginningOfDay ();
		$to_date = new DateTimeValue ( $date_end->getTimestamp () - logged_user()->getTimezone() * 3600);
		$to_date = $to_date->endOfDay ();
		
		$assignedFilter = '';
		if ($assignedUser instanceof Contact) {
			$assignedFilter = ' AND (`assigned_to_contact_id` = ' . $assignedUser->getId () . ' OR `assigned_to_contact_id` = \'' . $assignedUser->getCompanyId () . '\') ';
		}
		$rep_condition = " (`repeat_forever` = 1 OR `repeat_num` > 0 OR (`repeat_end` > 0 AND `repeat_end` >= '" . $from_date->toMySQL () . "')) ";
		
		if ($archived)
			$archived_cond = " AND `archived_on` <> 0";
		else
			$archived_cond = " AND `archived_on` = 0";
		
		switch($task_filter){
			case 'complete':
				$conditions = DB::prepareString(' AND `completed_on` <> ?', array(EMPTY_DATETIME));
				break;
			case 'pending':
			default:
				$conditions = DB::prepareString(' AND `is_template` = false AND `completed_on` = ? AND (IF(due_date>0,(`due_date` >= ? AND `due_date` < ?),false) OR IF(start_date>0,(`start_date` >= ? AND `start_date` < ?),false) OR ' . $rep_condition . ') ' . $archived_cond . $assignedFilter, array(EMPTY_DATETIME,$from_date, $to_date, $from_date, $to_date));
				break;
		}
                
		$result = self::instance()->listing(array(
			"extra_conditions" => $conditions
		));
		
		return $result->objects;
	} // getDayTasksByUser
Example #7
0
 /**
 * Get conditions as argument and return them in the string (if array walk through and escape values)
 *
 * @param mixed $conditions
 * @return string
 */
 function prepareConditions($conditions) {
   if(is_array($conditions)) {
     $conditions_sql = array_shift($conditions);
     $conditions_arguments = count($conditions) ? $conditions : null;
     return DB::prepareString($conditions_sql, $conditions_arguments);
   } // if
   return $conditions;
 } // prepareConditions
 /**
  * Returns timeslots based on the set query parameters
  *
  * @param User $user
  * @param string $workspacesCSV
  * @param DateTimeValue $start_date
  * @param DateTimeValue $end_date
  * @param string $object_manager
  * @param string $object_id
  * @param array $group_by
  * @param array $order_by
  * @return array
  */
 static function getTaskTimeslots($workspace = null, $user = null, $workspacesCSV = null, $start_date = null, $end_date = null, $object_id = 0, $group_by = null, $order_by = null, $limit = 0, $offset = 0, $timeslot_type = 0, $custom_conditions = null, $object_subtype = null)
 {
     $wslevels = 0;
     foreach ($group_by as $gb) {
         if ($gb == "project_id") {
             $wslevels++;
         }
     }
     $wsDepth = 0;
     if ($workspace instanceof Project) {
         $wsDepth = $workspace->getDepth();
     }
     $wslevels = min(array($wslevels, 10 - $wsDepth));
     if ($wslevels < 0) {
         $wslevels = 0;
     }
     $select = "SELECT `ts`.*";
     for ($i = 0; $i < $wslevels; $i++) {
         $select .= ", `ws" . $i . "`.`name` AS `wsName" . $i . "`, `ws" . $i . "`.`id` AS `wsId" . $i . "`";
     }
     $preFrom = " FROM ";
     for ($i = 0; $i < $wslevels; $i++) {
         $preFrom .= "(";
     }
     $postFrom = "";
     for ($i = 0; $i < $wslevels; $i++) {
         $postFrom .= ") LEFT OUTER JOIN `" . TABLE_PREFIX . "projects` AS `ws" . $i . "` ON `pr`.`p" . ($wsDepth + $i + 1) . "` = `ws" . $i . "`.`id`";
     }
     $commonConditions = "";
     if ($start_date) {
         $commonConditions .= DB::prepareString(' AND `ts`.`start_time` >= ? ', array($start_date));
     }
     if ($end_date) {
         $commonConditions .= DB::prepareString(' AND (`ts`.`paused_on` <> 0 OR `ts`.`end_time` <> 0) AND `ts`.`end_time` < ? ', array($end_date));
     }
     //$commonConditions .= DB::prepareString(' AND (`ts`.`paused_on` <> 0 OR `ts`.`end_time` <> 0) AND `ts`.`end_time` > 0 AND `ts`.`end_time` < ? ', array($end_date));  -- another fix reported by a user, but we have to test it yet
     //User condition
     $commonConditions .= $user ? ' AND `ts`.`user_id` = ' . $user->getId() : '';
     //Object condition
     $commonConditions .= $object_id > 0 ? ' AND `ts`.`object_manager` = "ProjectTasks" AND `ts`.`object_id` = ' . $object_id : '';
     //Only applies to tasks
     $sql = '';
     //Custom properties conditions
     $custom_cond = '';
     $custom = false;
     if (count($custom_conditions) > 0) {
         $custom = true;
         foreach ($custom_conditions as $condCp) {
             //array_var($condCp, 'custom_property_id');
             $cp = CustomProperties::getCustomProperty(array_var($condCp, 'custom_property_id'));
             //$skip_condition = false;
             $dateFormat = 'm/d/Y';
             if (isset($params[array_var($condCp, 'id') . "_" . $cp->getName()])) {
                 $value = $params[array_var($condCp, 'id') . "_" . $cp->getName()];
                 if ($cp->getType() == 'date') {
                     $dateFormat = user_config_option('date_format');
                 }
             } else {
                 $value = array_var($condCp, 'value');
             }
             $custom_cond .= ' AND `pt`.id IN ( SELECT object_id as id FROM ' . TABLE_PREFIX . 'custom_property_values cpv WHERE ';
             $custom_cond .= ' cpv.custom_property_id = ' . array_var($condCp, 'custom_property_id');
             if (array_var($condCp, 'condition') == 'like' || array_var($condCp, 'condition') == 'not like') {
                 $value = '%' . $value . '%';
             }
             if ($cp->getType() == 'date') {
                 $dtValue = DateTimeValueLib::dateFromFormatAndString($dateFormat, $value);
                 $value = $dtValue->format('Y-m-d H:i:s');
             }
             if (array_var($condCp, 'condition') != '%') {
                 if ($cp->getType() == 'numeric') {
                     $custom_cond .= ' AND cpv.value ' . array_var($condCp, 'condition') . ' ' . mysql_real_escape_string($value);
                 } else {
                     $custom_cond .= ' AND cpv.value ' . array_var($condCp, 'condition') . ' "' . mysql_real_escape_string($value) . '"';
                 }
             } else {
                 $custom_cond .= ' AND cpv.value like "%' . mysql_real_escape_string($value) . '"';
             }
             $custom_cond .= ')';
         }
     }
     switch ($timeslot_type) {
         case 0:
             //Task timeslots
             $from = "`" . TABLE_PREFIX . "timeslots` AS `ts`, `" . TABLE_PREFIX . "project_tasks` AS `pt`, `" . TABLE_PREFIX . "projects` AS `pr`, `" . TABLE_PREFIX . "workspace_objects` AS `wo`";
             $conditions = " WHERE `ts`.`object_manager` = 'ProjectTasks'  AND `pt`.`id` = `ts`.`object_id` AND `pt`.`trashed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `pt`.`archived_by_id` = 0 AND `wo`.`object_manager` = 'ProjectTasks' AND `wo`.`object_id` = `ts`.`object_id` AND `wo`.`workspace_id` = `pr`.`id`";
             //Project condition
             $conditions .= $workspacesCSV ? ' AND `pr`.`id` IN (' . $workspacesCSV . ')' : '';
             if ($custom) {
                 $commonConditions .= $custom_cond;
             }
             if ($object_subtype) {
                 $conditions .= " AND `pt`.`object_subtype`={$object_subtype}";
             }
             $sql = $select . $preFrom . $from . $postFrom . $conditions . $commonConditions;
             break;
         case 1:
             //Time timeslots
             $from = "`" . TABLE_PREFIX . "timeslots` AS `ts`, `" . TABLE_PREFIX . "projects` AS `pr`";
             $conditions = " WHERE `ts`.`object_manager` = 'Projects'";
             $conditions .= $workspacesCSV ? ' AND `ts`.`object_id` IN (' . $workspacesCSV . ") AND `ts`.`object_id` = `pr`.`id`" : " AND `ts`.`object_id` = `pr`.`id`";
             $sql = $select . $preFrom . $from . $postFrom . $conditions . $commonConditions;
             break;
         case 2:
             //All timeslots
             $from1 = "`" . TABLE_PREFIX . "timeslots` AS `ts`, `" . TABLE_PREFIX . "project_tasks` AS `pt`, `" . TABLE_PREFIX . "projects` AS `pr`, `" . TABLE_PREFIX . "workspace_objects` AS `wo`";
             $from2 = "`" . TABLE_PREFIX . "timeslots` AS `ts`, `" . TABLE_PREFIX . "projects` AS `pr`";
             $conditions1 = " WHERE `ts`.`object_manager` = 'ProjectTasks'  AND `pt`.`id` = `ts`.`object_id` AND `pt`.`trashed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `pt`.`archived_by_id` = 0 AND `wo`.`object_manager` = 'ProjectTasks' AND `wo`.`object_id` = `ts`.`object_id` AND `wo`.`workspace_id` = `pr`.`id`";
             //Project condition
             $conditions1 .= $workspacesCSV ? ' AND `pr`.`id` IN (' . $workspacesCSV . ')' : '';
             if ($object_subtype) {
                 $conditions1 .= " AND `pt`.`object_subtype`={$object_subtype}";
             }
             $conditions2 = " WHERE `object_manager` = 'Projects'";
             $conditions2 .= $workspacesCSV ? ' AND `ts`.`object_id` IN (' . $workspacesCSV . ") AND `ts`.`object_id` = `pr`.`id`" : " AND `ts`.`object_id` = `pr`.`id`";
             $sql = $select . $preFrom . $from1 . $postFrom . $conditions1 . $commonConditions . $custom_cond . ' UNION ' . $select . $preFrom . $from2 . $postFrom . $conditions2 . $commonConditions;
             break;
         default:
             throw new Error("Timeslot type not recognised: " . $timeslot_type);
     }
     //Group by
     $wsCount = 0;
     $sql .= ' ORDER BY ';
     if (is_array($group_by)) {
         foreach ($group_by as $gb) {
             switch ($gb) {
                 case 'project_id':
                     $sql .= "`wsName" . $wsCount . "` ASC, ";
                     $wsCount++;
                     break;
                 case 'id':
                 case 'priority':
                 case 'milestone_id':
                 case 'state':
                     if ($timeslot_type == 0) {
                         $sql .= "`pt`.`{$gb}` ASC, ";
                     }
                     break;
                 default:
                     if (is_string($gb) && trim($gb) != '') {
                         $sql .= "`{$gb}` ASC, ";
                     }
                     break;
             }
         }
     }
     //Order by
     if (is_array($order_by)) {
         foreach ($order_by as $ob) {
             if (is_string($ob) && trim($ob) != '') {
                 $sql .= "`{$ob}` ASC, ";
             }
         }
     }
     $sql .= " `start_time`";
     if ($limit > 0 && $offset > 0) {
         $sql .= " LIMIT {$offset}, {$limit}";
     }
     $timeslots = array();
     $rows = DB::executeAll($sql);
     if (is_array($rows)) {
         foreach ($rows as $row) {
             $tsRow = array("ts" => Timeslots::instance()->loadFromRow($row));
             for ($i = 0; $i < $wslevels; $i++) {
                 $tsRow["wsId" . $i] = $row["wsId" . $i];
             }
             $timeslots[] = $tsRow;
         }
         // foreach
     }
     // if
     return count($timeslots) ? $timeslots : null;
 }
 /**
  * Return all file revisions
  *
  * @param void
  * @return array
  */
 function getRevisions($exclude_last = false)
 {
     if ($exclude_last) {
         $last_revision = $this->getLastRevision();
         if ($last_revision instanceof ProjectFileRevision) {
             $conditions = DB::prepareString('`id` <> ? AND `file_id` = ?', array($last_revision->getId(), $this->getId()));
         }
     }
     // if
     if (!isset($conditions)) {
         $conditions = DB::prepareString('`file_id` = ?', array($this->getId()));
     }
     return ProjectFileRevisions::find(array('conditions' => $conditions, 'order' => '`created_on` DESC'));
     // find
 }
 /** Prepare search conditions string based on input params
  *
  * @param string $search_for Search string
  * @param string $project_csvs Search in this project
  * @return array
  */
 function getTagSearchConditions($search_for, $project_csvs)
 {
     return DB::prepareString(" tag = '{$search_for}' ");
 }
 /**
  * Prepare SQL and execute it...
  *
  * @access protected
  * @param string $sql
  * @return DBResult
  * @throws DBQueryError
  */
 protected function prepareAndExecute($sql, $arguments = null)
 {
     if (is_array($arguments)) {
         $sql = DB::prepareString($sql, $arguments);
     }
     // if
     $query_result = $this->executeQuery($sql, $this->link);
     DB::addToSQLLog($sql);
     if ($query_result === false) {
         throw new DBQueryError($sql, $this->lastErrorCode(), $this->lastError());
     }
     // if
     return $query_result === true ? true : new DBResult($this, $query_result);
 }
Example #12
0
 /**
  * Returns timeslots based on the set query parameters
  *
  * @param User $user
  * @param string $workspacesCSV
  * @param DateTimeValue $start_date
  * @param DateTimeValue $end_date
  * @param string $object_id
  * @param array $group_by
  * @param array $order_by
  * @return array
  */
 static function getTaskTimeslots($context, $members = null, $user = null, $start_date = null, $end_date = null, $object_id = 0, $group_by = null, $order_by = null, $limit = 0, $offset = 0, $timeslot_type = 0, $extra_conditions = '')
 {
     $commonConditions = "";
     if ($start_date) {
         $commonConditions .= DB::prepareString(' AND `e`.`start_time` >= ? ', array($start_date));
     }
     if ($end_date) {
         $commonConditions .= DB::prepareString(' AND (`e`.`paused_on` <> 0 AND `e`.`paused_on` <= ? OR `e`.`end_time` <> 0 AND `e`.`end_time` <= ?) ', array($end_date, $end_date));
     }
     //User condition
     $commonConditions .= $user ? ' AND `e`.`contact_id` = ' . $user->getId() : '';
     //Object condition
     $commonConditions .= $object_id > 0 ? ' AND `e`.`rel_object_id` = ' . $object_id : '';
     switch ($timeslot_type) {
         case 0:
             //Task timeslots
             $conditions = " AND EXISTS (SELECT `obj`.`id` FROM `" . TABLE_PREFIX . "objects` `obj` WHERE `obj`.`id` = `e`.`rel_object_id` AND `obj`.`trashed_on` = 0 AND `obj`.`archived_on` = 0)";
             break;
         case 1:
             //Time timeslots
             $conditions = " AND `e`.`rel_object_id` = 0";
             break;
         case 2:
             //All timeslots
             $conditions = " AND (`e`.`rel_object_id` = 0 OR `e`.`rel_object_id` IN (SELECT `obj`.`id` FROM `" . TABLE_PREFIX . "objects` `obj` WHERE `obj`.`trashed_on` = 0 AND `obj`.`archived_on` = 0))";
             break;
         default:
             throw new Error("Timeslot type not recognised: " . $timeslot_type);
     }
     if (!SystemPermissions::userHasSystemPermission(logged_user(), 'can_see_assigned_to_other_tasks')) {
         $conditions .= " AND `e`.`contact_id` = " . logged_user()->getId();
     }
     $conditions .= $commonConditions . $extra_conditions;
     $order_by[] = 'start_time';
     $result = self::instance()->listing(array('order' => $order_by, 'extra_conditions' => $conditions));
     return $result->objects;
 }
 /**
  * Display all tickets assigned to this user
  *
  * @layout dashboard
  * @param void
  * @return array
  */
 function my_tickets()
 {
     $this->setLayout('dashboard');
     $this->setTemplate('my_tickets');
     $this->addHelper('textile');
     $page = (int) array_var($_GET, 'page', 1);
     $category = (int) array_var($_GET, 'category', 0);
     $priority = array_var($_GET, 'priority', FALSE);
     $type = array_var($_GET, 'type', FALSE);
     if ($page < 0) {
         $page = 1;
     }
     $closed = (bool) array_var($_GET, 'closed', false);
     $conditions = DB::prepareString('`closed_on` ' . ($closed ? '>' : '=') . ' ?', array(EMPTY_DATETIME));
     if (!logged_user()->isMemberOfOwnerCompany()) {
         $conditions .= DB::prepareString(' AND `is_private` = ?', array(0));
     }
     // if
     if ($category > 0) {
         $conditions .= DB::prepareString(' AND `category_id` = ?', array($category));
     }
     if ($priority) {
         $conditions .= DB::prepareString(' AND `priority` = ?', array($priority));
     }
     if ($type) {
         $conditions .= DB::prepareString(' AND `type` = ?', array($type));
     }
     if ($closed) {
         $order = '`project_id`, `closed_on` DESC';
     } else {
         $order = '`project_id`, `created_on` DESC';
     }
     // if
     list($tickets, $pagination) = ProjectTickets::paginate(array('conditions' => $conditions, 'order' => $order), config_option('tickets_per_page', 25), $page);
     // paginate
     tpl_assign('closed', $closed);
     tpl_assign('tickets', $tickets);
     tpl_assign('tickets_pagination', $pagination);
     tpl_assign('active_projects', logged_user()->getActiveProjects());
     $this->setSidebar(get_template_path('index_sidebar', 'tickets'));
     //      tpl_assign('active_projects', logged_user()->getActiveProjects());
     //$this->setSidebar(get_template_path('index_sidebar', 'tickets'));
 }
    /**
     * Return Day tasks this user have access on 
     *
     * @access public
     * @param DateTimeValue $date_start in user gmt
     * @param DateTimeValue $date_end	in user gmt 
     * @return array
     */
    function getRangeTasksByUser(DateTimeValue $date_start, DateTimeValue $date_end, $assignedUser, $task_filter = null, $archived = false, $raw_data = false)
    {
        $from_date = new DateTimeValue($date_start->getTimestamp());
        $from_date = $from_date->beginningOfDay();
        $to_date = new DateTimeValue($date_end->getTimestamp());
        $to_date = $to_date->endOfDay();
        //set dates to gmt 0 for sql
        $from_date->advance(-logged_user()->getTimezone() * 3600);
        $to_date->advance(-logged_user()->getTimezone() * 3600);
        $assignedFilter = '';
        if ($assignedUser instanceof Contact) {
            $assignedFilter = ' AND (`assigned_to_contact_id` = ' . $assignedUser->getId() . ' OR `assigned_to_contact_id` = \'' . $assignedUser->getCompanyId() . '\') ';
        }
        $rep_condition = " (`repeat_forever` = 1 OR `repeat_num` > 0 OR (`repeat_end` > 0 AND `repeat_end` >= '" . $from_date->toMySQL() . "')) ";
        $archived_cond = " AND `archived_on` " . ($archived ? '<>' : '=') . " 0";
        $conditions = DB::prepareString(' AND `is_template` = false AND `completed_on` ' . ($task_filter == 'complete' ? '<>' : '=') . ' ? AND 
			(IF(due_date>0,(`due_date` >= ? AND `due_date` < ?),false) OR IF(start_date>0,(`start_date` >= ? AND `start_date` < ?),false) OR ' . $rep_condition . ') ' . $archived_cond . $assignedFilter, array(EMPTY_DATETIME, $from_date, $to_date, $from_date, $to_date));
        $other_perm_conditions = SystemPermissions::userHasSystemPermission(logged_user(), 'can_see_assigned_to_other_tasks');
        if (!$other_perm_conditions) {
            $conditions = " AND (`assigned_to_contact_id` = " . logged_user()->getId() . " OR `created_by_id` = " . logged_user()->getId() . ")";
        }
        $result = self::instance()->listing(array("extra_conditions" => $conditions, "raw_data" => $raw_data));
        return $result->objects;
    }
 /**
  * Mass set is_private for a given type. If $ids is present limit update only to object with given ID-s
  *
  * @param boolean $is_private
  * @param string $type
  * @parma array $ids
  * @return boolean
  */
 static function setIsPrivateForType($is_private, $type, $ids = null)
 {
     $limit_ids = null;
     if (is_array($ids)) {
         $limit_ids = array();
         foreach ($ids as $id) {
             $limit_ids[] = DB::escape($id);
         }
         // if
         $limit_ids = count($limit_ids) > 0 ? implode(',', $limit_ids) : null;
     }
     // if
     $sql = DB::prepareString('UPDATE ' . ApplicationLogs::instance()->getTableName(true) . ' SET `is_private` = ?  WHERE `rel_object_manager` = ?', array($is_private, $type));
     if ($limit_ids !== null) {
         $sql .= " AND `rel_object_id` IN ({$limit_ids})";
     }
     // if
     return DB::execute($sql);
 }
Example #16
0
 /**
 * Return array of task that are assigned to specific user or his company
 *
 * @param User $user
 * @return array
 */
 function getUsersTickets(User $user) {
   if (!plugin_active('tickets')) return null;
   $conditions = DB::prepareString('`project_id` = ? AND ((`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR (`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR (`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR `created_by_id`= ?) AND `closed_on` = ?', array($this->getId(), $user->getId(), $user->getCompanyId(), 0, $user->getCompanyId(), 0, 0, $user->getId(), EMPTY_DATETIME));
   if(!$user->isMemberOfOwnerCompany()) {
     $conditions .= DB::prepareString(' AND `is_private` = ?', array(0));
   } // if
   return ProjectTickets::findAll(array(
     'conditions' => $conditions,
     'order' => '`created_on`'
   )); // findAll
 } // getUsersTickets
Example #17
0
 /**
  * Return array of milestones that are assigned to specific user or his company
  *
  * @param User $user
  * @return array
  */
 function getUsersMilestones(User $user)
 {
     $conditions = DB::prepareString('`project_id` = ? AND ((`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR (`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR (`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?)) AND `completed_on` = ?', array($this->getId(), $user->getId(), $user->getCompanyId(), 0, $user->getCompanyId(), 0, 0, EMPTY_DATETIME));
     if (!$user->isMemberOfOwnerCompany()) {
         $conditions .= DB::prepareString(' AND `is_private` = ?', array(0));
     }
     // if
     return ProjectMilestones::findAll(array('conditions' => $conditions, 'order' => '`due_date`'));
 }
Example #18
0
 /**
  * Return array of task that are assigned to specific user or his company
  *
  * @param User $user
  * @param array $options
  * @param boolean $include_company
  * @return array
  */
 function getUsersTickets(User $user, $options = null, $include_company = false)
 {
     if (!plugin_active('tickets')) {
         return null;
     }
     if ($include_company) {
         $conditions = DB::prepareString('`project_id` = ? AND ((`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR (`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR (`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR `created_by_id`= ?) AND `closed_on` = ?', array($this->getId(), $user->getId(), $user->getCompanyId(), 0, $user->getCompanyId(), 0, 0, $user->getId(), EMPTY_DATETIME));
     } else {
         $conditions = DB::prepareString('`project_id` = ? AND `assigned_to_user_id` = ? AND `closed_on` = ?', array($this->getId(), $user->getId(), EMPTY_DATETIME));
     }
     // if
     if (!$user->isMemberOfOwnerCompany()) {
         $conditions .= DB::prepareString(' AND `is_private` = ?', array(0));
     }
     // if
     $options['conditions'] = $conditions;
     if (!isset($options['order'])) {
         $options['order'] = '`created_on`';
     }
     return ProjectTickets::findAll($options);
     // findAll
 }