function FogTables($userix, $fixforix, $start_date = '1970-01-01') { $this->person = new PersonTable(); $this->project = new ProjectTable($this->person); $this->fixfor = new FixForTable($this->project); // clean up the fixforix if (!$fixforix || $fixforix == 1) { $fixforix = 0; } $f = $this->fixfor->a[$fixforix]; if (!$f) { $f = $this->fixfor->first("name", $fixforix); } if (!$f) { $f = $this->fixfor->first_prefix("name", $fixforix); } if ($f) { $fixforix = $f->ix; } if (!$fixforix || $fixforix == 1) { $fixforix = 0; } $and_fixfor = $fixforix > 0 ? "and ixFixFor={$fixforix}" : ""; // clean up the userix if (!$userix || $userix == 1) { $userix = 0; } $p = $this->person->a[$userix]; if (!$p) { $p = $this->person->first("username", $userix); } if (!$p) { $p = $this->person->first("fullname", $userix); } if ($p) { $userix = $p->ix; } if (!$userix || $userix == 1) { $userix = 0; } $this->my_userix = $userix; if ($userix > 0 || $fixforix <= 0) { $and_user = "******"; $and_useras = "and ixPersonAssignedTo={$userix}"; $and_userrb = "and ixLastPersonResolvedBy={$userix}"; } else { $and_user = $and_useras = $and_userrb = ""; } $and_dtresolved = "and (dtResolved >= '{$start_date}' " . "or ISNULL(dtResolved))"; $whichbugs = sql_simple("select ixTask from schedulator.Estimate " . " where 1 {$and_user} " . " {$and_dtresolved} " . " and fIsBug=1"); $whichbugs += sql_simple("select ixBug from Bug " . " where 1 {$and_useras} " . " {$and_fixfor}"); // this mess is referred to by the mysql people as the 'max-concat' // trick. It returns the list of bug numbers that are currently // resolved *and* the most recent person to resolve them was the // specified user. $q = "select e.ixBug, " . " substring(max(concat(lpad(ixBugEvent,12,' '),ixPerson)),13) " . " as ixLastPersonResolvedBy, " . " substring(max(concat(lpad(ixBugEvent,12,' '),dt)),13) " . " as dtResolved " . " from BugEvent e, Bug b " . " where e.ixBug=b.ixBug " . " and b.ixStatus>1 and sVerb like 'RESOLVED%' " . " and sVerb != 'Resolved (Again)' " . " {$and_fixfor} " . " group by e.ixBug " . " having 1 {$and_userrb}" . " {$and_dtresolved} "; $resolved_tasks = sql_simple($q); $stolen_bugs = array(); // Finding stolen bugs is only relevant when we have a particular // person to check against. if ($and_user != "") { // Retrieve all bugs that the user ever resolved. $stolen_query = "select e.ixBug, e.ixPerson, e.dt as dtResolved " . " from BugEvent e, Bug b " . " where e.ixBug = b.ixBug " . " and b.ixStatus > 1 and e.sVerb like 'RESOLVED%' " . " and sVerb != 'Resolved (Again)'" . " {$and_user} " . " {$and_fixfor} " . " having 1 {$and_dtresolved}" . " order by e.ixBug "; $all_resolved_tasks = sql_simple($stolen_query); // Find all bugs that the user has resolved at some point, but was // not the most recent person to resolve. $stolen_keys = array_diff(array_keys($all_resolved_tasks), array_keys($resolved_tasks)); foreach ($stolen_keys as $b) { $stolen_bugs[$b] = array($b, $all_resolved_tasks[$b][2]); } } $whichbugs += array_keys($resolved_tasks); $whichtasks = sql_simple("select ixTask from schedulator.Estimate " . " where 1 {$and_user} " . " {$and_dtresolved} " . " and fIsBug=0"); $whichtasks += sql_simple("select ixXTask from schedulator.XTask " . " where 1 {$and_useras} " . " {$and_fixfor}"); $bugwhere = count($whichbugs) ? " where ixBug in (" . join(",", $whichbugs) . ")" : " where 1=0"; $taskwhere = count($whichtasks) ? " where ixXTask in (" . join(",", $whichtasks) . ")" : " where 1=0"; $this->bug = new BugTable($bugwhere, $userix, $resolved_tasks, $stolen_bugs, $this->person, $this->project, $this->fixfor); $this->xtask = new XTaskTable($taskwhere, $userix, $this->person, $this->fixfor); $this->estimate = new EstimateTable("where 1 {$and_user} {$and_dtresolved}", $userix, $this->person, $this->bug, $this->xtask); }
function list_fixfors($wild) { $fixfors = sql_simple("select ixFixFor, sFixFor from FixFor " . "where bDeleted=0 " . "order by sFixFor"); return $this->wild_merge($fixfors, $wild); }