예제 #1
0
 function getProjectIdsByUser(User $user, $additional_conditions = null, $order_by = null)
 {
     $projects_table = Projects::instance()->getTableName(true);
     $project_users_table = ProjectUsers::instance()->getTableName(true);
     $group_users_table = GroupUsers::instance()->getTableName(true);
     $projects = array();
     $usercond = "({$project_users_table}.`user_id` = " . DB::escape($user->getId()) . ")";
     $groupcond = "({$project_users_table}.`user_id` IN (SELECT `group_id` FROM {$group_users_table} WHERE {$group_users_table}.`user_id` = " . DB::escape($user->getId()) . "))";
     $commoncond = "{$projects_table}.`id` = {$project_users_table}.`project_id`";
     $sql = "SELECT {$projects_table}.`id` as `id` FROM {$projects_table}, {$project_users_table} WHERE {$commoncond} AND ({$usercond} OR {$groupcond}) ";
     if (trim($additional_conditions) != '') {
         $sql .= " AND ({$additional_conditions})";
     }
     // if
     if ($order_by) {
         $sql .= " ORDER BY '" . $order_by;
     } else {
         $sql .= " ORDER BY {$projects_table}.`name`";
     }
     $rows = DB::executeAll($sql);
     $ids = array();
     foreach ($rows as $row) {
         $ids[] = $row['id'];
     }
     return $ids;
 }
예제 #2
0
 /**
  * Return the user's workspaces query that returns user's workspaces ids.
  * @param bool $active If null, all projects; if true, only active, if false, only archived
  * @return string
  */
 function getWorkspacesQuery($active = null, $additional_conditions = null)
 {
     //return $this->getActiveProjectIdsCSV();
     $project_users_table = ProjectUsers::instance()->getTableName(true);
     $group_users_table = GroupUsers::instance()->getTableName(true);
     $usercond = "({$project_users_table}.`user_id` = " . DB::escape($this->getId()) . ")";
     $groupcond = "({$project_users_table}.`user_id` IN (SELECT `group_id` FROM {$group_users_table} WHERE {$group_users_table}.`user_id` = " . DB::escape($this->getId()) . "))";
     $addcond = $additional_conditions == null ? "" : "AND " . $additional_conditions;
     if ($active === null) {
         return "SELECT {$project_users_table}.`project_id` FROM {$project_users_table} WHERE ({$usercond} OR {$groupcond}) {$addcond}";
     } else {
         $projects_table = Projects::instance()->getTableName(true);
         $empty_date = DB::escape(EMPTY_DATETIME);
         $active_cond = $active ? "{$projects_table}.`completed_on` = {$empty_date}" : "{$projects_table}.`completed_on` <> {$empty_date}";
         $projectcond = "({$project_users_table}.`project_id` = {$projects_table}.`id` AND  {$active_cond})";
         return "SELECT {$project_users_table}.`project_id` FROM {$project_users_table}, {$projects_table} WHERE ({$usercond} OR {$groupcond}) AND {$projectcond} {$addcond}";
     }
 }
 /**
  * Return manager instance
  *
  * @access protected
  * @param void
  * @return GroupUser 
  */
 function manager()
 {
     if (!$this->manager instanceof GroupUsers) {
         $this->manager = GroupUsers::instance();
     }
     return $this->manager;
 }
 /**
  * This function will return paginated result. Result is an array where first element is 
  * array of returned object and second populated pagination object that can be used for 
  * obtaining and rendering pagination data using various helpers.
  * 
  * Items and pagination array vars are indexed with 0 for items and 1 for pagination
  * because you can't use associative indexing with list() construct
  *
  * @access public
  * @param array $arguments Query argumens (@see find()) Limit and offset are ignored!
  * @param integer $items_per_page Number of items per page
  * @param integer $current_page Current page number
  * @return array
  */
 function paginate($arguments = null, $items_per_page = 10, $current_page = 1)
 {
     if (isset($this) && instance_of($this, 'GroupUsers')) {
         return parent::paginate($arguments, $items_per_page, $current_page);
     } else {
         return GroupUsers::instance()->paginate($arguments, $items_per_page, $current_page);
         //$instance =&  GroupUsers::instance();
         //return $instance->paginate($arguments, $items_per_page, $current_page);
     }
     // if
 }