function run(Contact $user, $qreq, $ssel) { if (substr($qreq->getfn, 0, 4) === "opt-" && ($opts = PaperOption::search(substr($qreq->getfn, 4))) && count($opts) == 1 && ($o = current($opts)) && $user->can_view_some_paper_option($o)) { $ga = new GetDocument_SearchAction($o->id); return $ga->run($user, $qreq, $ssel); } else { return self::ENOENT; } }
public static function parse_dtype($dname) { if (preg_match('/\\A-?\\d+\\z/', $dname)) { return (int) $dname; } $dname = strtolower($dname); if ($dname === "paper" || $dname === "submission") { return DTYPE_SUBMISSION; } if ($dname === "final") { return DTYPE_FINAL; } $omatches = PaperOption::search($dname); if (count($omatches) == 1) { return current($omatches)->id; } return null; }
public function make_column($name, $errors) { $p = strpos($name, ":") ?: -1; $opts = PaperOption::search(substr($name, $p + 1)); if (count($opts) == 1) { reset($opts); $opt = current($opts); if ($opt->display() >= 0) { return self::_make_column($opt); } self::make_column_error($errors, "Option “" . htmlspecialchars(substr($name, $p + 1)) . "” can’t be displayed."); } else { if ($p > 0) { self::make_column_error($errors, "No such option “" . htmlspecialchars(substr($name, $p + 1)) . "”.", 1); } } return null; }
private function normalize_options($pj) { $options = $pj->options; $pj->options = (object) array(); $pj->parsed_options = array(); // - canonicalize option values to use IDs, not abbreviations // - parse options into SQL foreach ($options as $id => $oj) { $omatches = PaperOption::search($id); if (count($omatches) != 1) { $pj->bad_options[$id] = true; continue; } $o = current($omatches); // XXX setting decision in JSON? if ($o->final && (!$this->prow || $this->prow->outcome <= 0)) { continue; } $result = null; if ($oj !== null) { $result = $o->parse_json($oj, $this); } if ($result === null) { $result = []; } if (!is_array($result)) { $result = [[$result]]; } else { if (count($result) == 2 && is_string($result[1])) { $result = [$result]; } } $pj->parsed_options[$o->id] = $result; } ksort($pj->parsed_options); }
public static function analyze_option_search($word) { if (preg_match('/\\A(.*?)([:#](?:[=!<>]=?|≠|≤|≥|)|[=!<>]=?|≠|≤|≥)(.*)\\z/', $word, $m)) { $oname = $m[1]; if ($m[2][0] === ":" || $m[2][0] === "#") { $m[2] = substr($m[2], 1); } $ocompar = CountMatcher::canonical_comparator($m[2]); $oval = strtolower(simplify_whitespace($m[3])); } else { $oname = $word; $ocompar = "="; $oval = ""; } $oname = strtolower(simplify_whitespace($oname)); // match all options $qo = $warn = array(); $option_failure = false; if ($oname === "none" || $oname === "any") { $omatches = PaperOption::option_list(); } else { $omatches = PaperOption::search($oname); } // Conf::msg_info(Ht::pre_text(var_export($omatches, true))); if (count($omatches)) { foreach ($omatches as $oid => $o) { // selectors handle “yes”, “”, and “no” specially if ($o->has_selector()) { $xval = array(); if ($oval === "") { foreach ($o->selector as $k => $v) { if (strcasecmp($v, "yes") == 0) { $xval[$k] = $v; } } if (count($xval) == 0) { $xval = $o->selector; } } else { $xval = Text::simple_search($oval, $o->selector); } if (count($xval) == 0) { $warn[] = "“" . htmlspecialchars($oval) . "” doesn’t match any " . htmlspecialchars($oname) . " values."; } else { if (count($xval) == 1) { reset($xval); $qo[] = new OptionMatcher($o, $ocompar, key($xval), $oval); } else { if ($ocompar !== "=" && $ocompar !== "!=") { $warn[] = "Submission option “" . htmlspecialchars("{$oname}:{$oval}") . "” matches multiple values, can’t use " . htmlspecialchars($ocompar) . "."; } else { $qo[] = new OptionMatcher($o, $ocompar, array_keys($xval), $oval); } } } continue; } if ($oval === "" || $oval === "yes" || $oval === "'yes'") { $qo[] = new OptionMatcher($o, "!=", 0, $oval); } else { if ($oval === "no" || $oval === "'no'") { $qo[] = new OptionMatcher($o, "=", 0, $oval); } else { if ($o->type == "text") { if (!empty($oval)) { $qo[] = new OptionMatcher($o, ' like ', str_replace("+", " ", $oval), $oval); } } else { if ($o->type === "numeric") { if (preg_match('/\\A\\s*([-+]?\\d+)\\s*\\z/', $oval, $m)) { $qo[] = new OptionMatcher($o, $ocompar, $m[1], $oval); } else { $warn[] = "Submission option “" . htmlspecialchars($o->name) . "” takes integer values."; } } else { if ($o->type === "attachments") { if ($oval === "any") { $qo[] = new OptionMatcher($o, "!=", 0, $oval); } else { if (preg_match('/\\A\\s*([-+]?\\d+)\\s*\\z/', $oval, $m)) { if (CountMatcher::compare(0, $ocompar, $m[1])) { $qo[] = new OptionMatcher($o, "=", 0, $oval); } $qo[] = new OptionMatcher($o, $ocompar, $m[1], $oval, "attachment-count"); } else { $qo[] = new OptionMatcher($o, "~=", $oval, $oval, "attachment-name", $oval); } } } else { continue; } } } } } } } else { if (($ocompar === "=" || $ocompar === "!=") && $oval === "") { foreach (PaperOption::option_list() as $oid => $o) { if ($o->has_selector()) { foreach (Text::simple_search($oname, $o->selector) as $xval => $text) { $qo[] = new OptionMatcher($o, $ocompar, $xval, "~val~"); } } } } } return (object) array("os" => $qo, "warn" => $warn, "negate" => $oname === "none"); }