/** * 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. */ global $AppUI; 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 = new w2p_Database_Query(); // 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(\' [\', CONCAT_WS(\' \', contact_first_name, contact_last_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(); $companies = $obj->getAllowedSQL($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(); $depts = $dpt->getAllowedSQL($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; }
public function getAllowedSQL($uid, $index = null) { $oCpy = new CCompany(); $where = $oCpy->getAllowedSQL($uid, 'project_company'); $oDpt = new CDepartment(); $where += $oDpt->getAllowedSQL($uid, 'dept_id'); $project_where = parent::getAllowedSQL($uid, $index); return array_merge($where, $project_where); }
$q->addQuery('company_name'); $q->addQuery('dept_name'); if ($where) { // Don't assume where is set. Change needed to fix Mantis Bug 0002056 $q->addWhere($where); } if ($where_dept) { // Don't assume where is set. Change needed to fix Mantis Bug 0002056 $q->addWhere($where_dept); } $oCpy = new CCompany(); $aCpies = $oCpy->getAllowedRecords($AppUI->user_id, 'company_id, company_name', 'company_name'); $where = $oCpy->getAllowedSQL($AppUI->user_id, 'contact_company'); $q->addWhere($where); $oDpt = new CDepartment(); $where = $oDpt->getAllowedSQL($AppUI->user_id, 'contact_department'); $q->addWhere($where); $q->addWhere('(contact_owner = ' . (int) $AppUI->user_id . ' OR contact_private = 0)'); $q->addOrder('company_name, contact_company, dept_name, contact_department, contact_last_name'); // May need to review this. $contacts = $q->loadHashList('contact_id'); ?> <form action="index.php?m=public&a=contact_selector&dialog=1&<?php if (!is_null($call_back)) { echo 'call_back=' . $call_back . '&'; } ?> company_id=<?php echo $company_id; ?>
function w2PgetUsersHashList($stub = null, $where = null, $orderby = 'contact_first_name, contact_last_name') { global $AppUI; $q = new DBQuery(); $q->addTable('users'); $q->addQuery('DISTINCT(user_id), user_username, contact_last_name, contact_first_name, contact_email, company_name, contact_company, dept_id, dept_name, CONCAT(contact_first_name,\' \',contact_last_name) contact_name, user_type'); $q->addJoin('contacts', 'con', 'contact_id = user_contact', 'inner'); if ($stub) { $q->addWhere('(UPPER(user_username) LIKE \'' . $stub . '%\' or UPPER(contact_first_name) LIKE \'' . $stub . '%\' OR UPPER(contact_last_name) LIKE \'' . $stub . '%\')'); } elseif ($where) { $where = $q->quote('%' . $where . '%'); $q->addWhere('(UPPER(user_username) LIKE ' . $where . ' OR UPPER(contact_first_name) LIKE ' . $where . ' OR UPPER(contact_last_name) LIKE ' . $where . ')'); } $q->addGroup('user_id'); $q->addOrder($orderby); // get CCompany() to filter by company $obj = new CCompany(); $companies = $obj->getAllowedSQL($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(); $depts = $dpt->getAllowedSQL($AppUI->user_id, 'dept_id'); $q->addJoin('departments', 'dep', 'dept_id = contact_department'); if ($depts) { $q->addWhere('(' . implode(' OR ', $depts) . ' OR contact_department=0)'); } return $q->loadHashList('user_id'); }