public static function filterQueries($queries, $user) { $result = array(); foreach ($queries as $qid => $title) { $qdao = new QueryDAO(); $segments = $qdao->getSegmentsByQueryId($qid); $tristate = User::createPropertyMap(0); foreach (array_values($segments) as $segment) { $prop = $segment[0]; $value = $segment[1]; if ($tristate[$prop] != 1) { $tristate[$prop] = User::indexOfUserValue($prop, $user) == $value ? 1 : -1; } } $applies = true; foreach (array_values($tristate) as $value) { if ($value == -1) { $applies = false; break; } } if ($applies) { $result[$qid] = $title; } } return $result; }
private function classify($aid, $var) { if ($this->sdao->getVarType($var) == "uVar") { $uid = $this->adao->getUserByAnswersId($aid); $user = $this->udao->selectUserById($uid); $varValue = $this->sdao->getVarValue($var); return User::indexOfUserValue($varValue, $user); } else { $qid = $this->sdao->getVarValue($var); $qmap = $this->adao->getOptionsMap($qid); $ansOpt = $this->adao->getAswersOptionsMap($aid); foreach ($qmap as $oid => $number) { foreach ($ansOpt as $ansOid) { if ($oid == $ansOid) { return $number - 1; } } } } }