Example #1
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;
 }
Example #2
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;
 }
Example #3
0
 /**
  * Tests the delete of a dept
  */
 public function testDelete()
 {
     $this->obj->bind($this->post_data);
     $result = $this->obj->store();
     $this->assertTrue($result);
     $original_id = $this->obj->dept_id;
     $result = $this->obj->delete();
     $item = new CDepartment();
     $item->overrideDatabase($this->mockDB);
     $this->mockDB->stageHash(array('dept_name' => '', 'dept_owner' => ''));
     $item->load($original_id);
     $this->assertEquals('', $item->dept_name);
     $this->assertEquals('', $item->dept_owner);
 }
 /**
  * *	Overload of the w2PObject::getAllowedRecords
  * *	to ensure that the allowed projects are owned by allowed companies.
  * *
  * *	@author	handco <*****@*****.**>
  * *	@see	w2PObject::getAllowedRecords
  * */
 public function getAllowedRecords($uid, $fields = '*', $orderby = '', $index = null, $extra = null, $unused = '')
 {
     $oCpy = new CCompany();
     $oCpy->overrideDatabase($this->_query);
     $aCpies = $oCpy->getAllowedRecords($uid, 'company_id, company_name');
     if (count($aCpies)) {
         $buffer = '(contact_company IN (' . implode(',', array_keys($aCpies)) . ') OR contact_company IS NULL OR contact_company = \'\' OR contact_company = 0)';
         //Department permissions
         $oDpt = new CDepartment();
         $oDpt->overrideDatabase($this->_query);
         $aDpts = $oDpt->getAllowedRecords($uid, 'dept_id, dept_name');
         if (count($aDpts)) {
             $dpt_buffer = '(contact_department IN (' . implode(',', array_keys($aDpts)) . ') OR contact_department = 0)';
         } else {
             // There are no allowed departments, so allow projects with no department.
             $dpt_buffer = '(contact_department = 0)';
         }
         if ($extra['where'] != '') {
             $extra['where'] = $extra['where'] . ' AND ' . $buffer . ' AND ' . $dpt_buffer;
         } else {
             $extra['where'] = $buffer . ' AND ' . $dpt_buffer;
         }
     } else {
         // There are no allowed companies, so don't allow projects.
         if ($extra['where'] != '') {
             $extra['where'] = $extra['where'] . ' AND (contact_company IS NULL OR contact_company = \'\' OR contact_company = 0) ';
         } else {
             $extra['where'] = 'contact_company IS NULL OR contact_company = \'\' OR contact_company = 0';
         }
     }
     return parent::getAllowedRecords($uid, $fields, $orderby, $index, $extra);
 }
Example #5
0
 public function getDepartmentList()
 {
     if ($this->_AppUI->isActiveModule('departments') && canView('departments')) {
         $q = $this->_getQuery();
         $q->addTable('departments', 'a');
         $q->addTable('project_departments', 'b');
         $q->addQuery('a.dept_id, a.dept_name, a.dept_phone');
         $q->addWhere('a.dept_id = b.department_id and b.project_id = ' . (int) $this->project_id);
         $department = new CDepartment();
         $department->overrideDatabase($this->_query);
         $department->setAllowedSQL($this->_AppUI->user_id, $q);
         return $q->loadHashList('dept_id');
     }
 }