Exemplo n.º 1
0
 public function getFilteredDepartmentList($AppUI = null, $deptType = -1, $searchString = '', $ownerId = 0, $orderby = 'dept_name', $orderdir = 'ASC')
 {
     $orderby = in_array($orderby, array('dept_name', 'dept_type', 'countp', 'inactive')) ? $orderby : 'dept_name';
     $q = $this->_getQuery();
     $q->addTable('departments');
     $q->addQuery('departments.*, COUNT(ct.contact_department) dept_users, count(distinct p.project_id) as countp, count(distinct p2.project_id) as inactive, con.contact_first_name, con.contact_last_name');
     $q->addJoin('companies', 'c', 'c.company_id = departments.dept_company');
     $q->addJoin('project_departments', 'pd', 'pd.department_id = dept_id');
     $q->addJoin('projects', 'p', 'pd.project_id = p.project_id AND p.project_active = 1');
     $q->leftJoin('users', 'u', 'dept_owner = u.user_id');
     $q->leftJoin('contacts', 'con', 'u.user_contact = con.contact_id');
     $q->addJoin('projects', 'p2', 'pd.project_id = p2.project_id AND p2.project_active = 0');
     $q->addJoin('contacts', 'ct', 'ct.contact_department = dept_id');
     $q->addGroup('dept_id');
     $q->addOrder('dept_parent, dept_name');
     $oCpy = new CCompany();
     $oCpy->overrideDatabase($this->_query);
     $where = $oCpy->getAllowedSQL($this->_AppUI->user_id, 'c.company_id');
     $q->addWhere($where);
     if ($deptType > -1) {
         $q->addWhere('dept_type = ' . (int) $deptType);
     }
     if ($searchString != '') {
         $q->addWhere("dept_name LIKE '%{$searchString}%'");
     }
     if ($ownerId > 0) {
         $q->addWhere('dept_owner = ' . $ownerId);
     }
     $q->addGroup('dept_id');
     $q->addOrder($orderby . ' ' . $orderdir);
     return $q->loadList();
 }
Exemplo n.º 2
0
 public function getFilteredDepartmentList($notUsed = null, $deptType = -1, $searchString = '', $ownerId = 0, $orderby = 'dept_name', $orderdir = 'ASC')
 {
     $q = $this->_getQuery();
     $q->addTable('departments');
     $q->addQuery('departments.*, count(distinct p.project_id) as countp, count(distinct p2.project_id) as inactive');
     $q->addJoin('project_departments', 'pd', 'pd.department_id = dept_id');
     $q->addJoin('projects', 'p', 'pd.project_id = p.project_id AND p.project_active = 1');
     $q->addJoin('projects', 'p2', 'pd.project_id = p2.project_id AND p2.project_active = 0');
     $q->addGroup('dept_id');
     $q->addOrder('dept_name');
     $oCpy = new CCompany();
     $oCpy->overrideDatabase($this->_query);
     $where = $oCpy->getAllowedSQL($this->_AppUI->user_id, 'dept_company');
     $q->addWhere($where);
     $q = $this->setAllowedSQL($this->_AppUI->user_id, $q);
     if ($deptType > -1) {
         $q->addWhere('dept_type = ' . (int) $deptType);
     }
     if ($searchString != '') {
         $q->addWhere("dept_name LIKE '%{$searchString}%'");
     }
     if ($ownerId > 0) {
         $q->addWhere('dept_owner = ' . $ownerId);
     }
     $q->addGroup('dept_id');
     $orderby = property_exists($this, $orderby) || in_array($orderby, array('countp', 'inactive')) ? $orderby : 'dept_name';
     $q->addOrder($orderby . ' ' . $orderdir);
     return $q->loadList();
 }
Exemplo n.º 3
0
 public function getStructuredProjects($active_only = false)
 {
     //global $st_projects_arr;
     $st_projects = array(0 => '');
     $q = $this->getQuery();
     $q->addTable('projects');
     $q->addJoin('companies', '', 'projects.project_company = company_id', 'inner');
     $q->addQuery('DISTINCT(projects.project_id), project_name, project_parent, project_company');
     if ($this->project_original_parent) {
         $q->addWhere('project_original_parent = ' . (int) $this->project_original_parent);
     }
     if ($this->project_status >= 0) {
         $q->addWhere('project_status = ' . (int) $this->project_status);
     }
     if ($active_only) {
         $q->addWhere('project_active = 1');
     }
     $q->addOrder('project_start_date, project_end_date');
     $obj = new CCompany();
     $obj->overrideDatabase($this->_query);
     $q = $obj->setAllowedSQL($this->_AppUI->user_id, $q);
     $dpt = new CDepartment();
     $dpt->overrideDatabase($this->_query);
     $q = $dpt->setAllowedSQL($this->_AppUI->user_id, $q);
     $q->leftJoin('project_departments', 'pd', 'pd.project_id = projects.project_id');
     $q->leftJoin('departments', 'd', 'd.dept_id = pd.department_id');
     $st_projects = $q->loadList();
     $tnums = count($st_projects);
     for ($i = 0; $i < $tnums; $i++) {
         $st_project = $st_projects[$i];
         if ($st_project['project_parent'] == $st_project['project_id']) {
             $this->show_st_project($st_project);
             $this->find_proj_child($st_projects, $st_project['project_id']);
         }
     }
     return $this->st_projects_arr;
 }
Exemplo n.º 4
0
 /**
  * 	Calculate the extent of utilization of user assignments
  * 	@param string hash	 a hash for the returned hashList
  * 	@param array users	 an array of user_ids calculating their assignment capacity
  * 	@return array		 returns hashList of extent of utilization for assignment of the users
  */
 public function getAllocation($hash = null, $users = null, $get_user_list = false)
 {
     /*
      * TODO: The core of this function has been simplified to always return 100%
      * free capacity available.  The allocation checking (aka resource
      * management) is a complex subject which is currently not even close to be
      * handled properly.
      */
     if (!w2PgetConfig('check_overallocation', false)) {
         if ($get_user_list) {
             $users_list = w2PgetUsersHashList();
             foreach ($users_list as $key => $user) {
                 $users_list[$key]['userFC'] = $user['contact_name'];
             }
             $hash = $users_list;
         } else {
             $hash = array();
         }
     } else {
         $q = $this->_getQuery();
         // retrieve the systemwide default preference for the assignment maximum
         $q->addTable('user_preferences');
         $q->addQuery('pref_value');
         $q->addWhere('pref_user = 0 AND pref_name = \'' . TASKASSIGNMAX . '\'');
         $sysChargeMax = $q->loadHash();
         $q->clear();
         if (!$sysChargeMax) {
             $scm = 0;
         } else {
             $scm = $sysChargeMax['pref_value'];
         }
         /*
          * provide actual assignment charge, individual chargeMax
          * and freeCapacity of users' assignments to tasks
          */
         $q->addTable('users', 'u');
         $q->addJoin('contacts', 'c', 'c.contact_id = u.user_contact', 'inner');
         $q->leftJoin('user_tasks', 'ut', 'ut.user_id = u.user_id');
         $q->leftJoin('user_preferences', 'up', 'up.pref_user = u.user_id');
         $q->addWhere("up.pref_name = 'TASKASSIGNMAX'");
         $q->addQuery('u.user_id, CONCAT(CONCAT_WS(\' [\', contact_display_name, IF(IFNULL((IFNULL(up.pref_value, ' . $scm . ') - SUM(ut.perc_assignment)), up.pref_value) > 0, IFNULL((IFNULL(up.pref_value, ' . $scm . ') - SUM(ut.perc_assignment)), up.pref_value), 0)), \'%]\') AS userFC, IFNULL(SUM(ut.perc_assignment), 0) AS charge');
         $q->addQuery('u.user_username, IFNULL(up.pref_value,' . $scm . ') AS chargeMax');
         $q->addQuery('IFNULL(up.pref_value, ' . $scm . ') AS freeCapacity');
         if (!empty($users)) {
             // use userlist if available otherwise pull data for all users
             $q->addWhere('u.user_id IN (' . implode(',', $users) . ')');
         }
         $q->addGroup('u.user_id');
         $q->addOrder('contact_first_name, contact_last_name');
         // get CCompany() to filter by company
         $obj = new CCompany();
         $obj->overrideDatabase($this->_query);
         $companies = $obj->getAllowedSQL($this->_AppUI->user_id, 'company_id');
         $q->addJoin('companies', 'com', 'company_id = contact_company');
         if ($companies) {
             $q->addWhere('(' . implode(' OR ', $companies) . ' OR contact_company=\'\' OR contact_company IS NULL OR contact_company = 0)');
         }
         $dpt = new CDepartment();
         $dpt->overrideDatabase($this->_query);
         $depts = $dpt->getAllowedSQL($this->_AppUI->user_id, 'dept_id');
         $q->addJoin('departments', 'dep', 'dept_id = contact_department');
         if ($depts) {
             $q->addWhere('(' . implode(' OR ', $depts) . ' OR contact_department=0)');
         }
         $hash = $q->loadHashList($hash);
         $q->clear();
     }
     return $hash;
 }
Exemplo n.º 5
0
 /**
  * @deprecated
  */
 public function getCompanyName()
 {
     trigger_error("getCompanyName has been deprecated and will be removed in v4.0. Please use getCompanyDetails() instead.", E_USER_NOTICE);
     $company = new CCompany();
     $company->overrideDatabase($this->_query);
     $company->load((int) $this->contact_company);
     return $company->company_name;
 }
Exemplo n.º 6
0
 /**
  * Tests the delete of a company
  */
 public function testDelete()
 {
     $this->obj->bind($this->post_data);
     $result = $this->obj->store();
     $this->assertTrue($result);
     $original_id = $this->obj->company_id;
     $result = $this->obj->delete();
     $item = new CCompany();
     $item->overrideDatabase($this->mockDB);
     $this->mockDB->stageHash(array('company_name' => '', 'company_owner' => ''));
     $item->load($original_id);
     $this->assertEquals('', $item->company_name);
     $this->assertEquals('', $item->company_owner);
 }
Exemplo n.º 7
0
 /**
  * 	Overload of the w2PObject::getDeniedRecords
  * 	to ensure that the projects owned by denied companies are denied.
  *
  * 	@author	handco <*****@*****.**>
  * 	@see	w2PObject::getAllowedRecords
  */
 public function getDeniedRecords($uid)
 {
     $aBuf1 = parent::getDeniedRecords($uid);
     $oCpy = new CCompany();
     $oCpy->overrideDatabase($this->_query);
     // Retrieve which projects are allowed due to the company rules
     $aCpiesAllowed = $oCpy->getAllowedRecords($uid, 'company_id,company_name');
     //Department permissions
     $oDpt = new CDepartment();
     $oDpt->overrideDatabase($this->_query);
     $aDptsAllowed = $oDpt->getAllowedRecords($uid, 'dept_id,dept_name');
     $q = $this->_getQuery();
     $q->addTable('projects');
     $q->addQuery('projects.project_id');
     $q->addJoin('project_departments', 'pd', 'pd.project_id = projects.project_id');
     if (count($aCpiesAllowed)) {
         if (array_search('0', $aCpiesAllowed) === false) {
             //If 0 (All Items of a module) are not permited then just add the allowed items only
             $q->addWhere('NOT (project_company IN (' . implode(',', array_keys($aCpiesAllowed)) . '))');
         } else {
             //If 0 (All Items of a module) are permited then don't add a where clause so the user is permitted to see all
         }
     } else {
         //if the user is not allowed any company then lets shut him off
         $q->addWhere('0=1');
     }
     if (count($aDptsAllowed)) {
         if (array_search('0', $aDptsAllowed) === false) {
             //If 0 (All Items of a module) are not permited then just add the allowed items only
             $q->addWhere('NOT (department_id IN (' . implode(',', array_keys($aDptsAllowed)) . '))');
         } else {
             //If 0 (All Items of a module) are permited then don't add a where clause so the user is permitted to see all
             $q->addWhere('NOT (department_id IS NULL)');
         }
     } else {
         //If 0 (All Items of a module) are permited then don't add a where clause so the user is permitted to see all
         $q->addWhere('NOT (department_id IS NULL)');
     }
     $aBuf2 = $q->loadColumn();
     $q->clear();
     return array_merge($aBuf1, $aBuf2);
 }