From 76cd47dc75006d6be4cc00c31741d3f6fafd064f Mon Sep 17 00:00:00 2001 From: Eddie Kohler Date: Sat, 16 May 2020 17:14:03 -0400 Subject: [PATCH] Conflicts: Don't refer to PINNED. And type declarations. --- manualassign.php | 2 +- src/assigners/a_conflict.php | 2 +- src/conflict.php | 32 +++++++++++++++++++++++++++++++- src/papertable.php | 3 ++- test/test01.php | 4 ++-- 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/manualassign.php b/manualassign.php index 92fa196af1..bd7ea3f6c3 100644 --- a/manualassign.php +++ b/manualassign.php @@ -75,7 +75,7 @@ function saveAssignments($qreq, $reviewer) { } if ($assrev < 0) { - $newct = Conflict::is_conflicted($ct) ? $ct : Conflict::PINNED; + $newct = Conflict::is_conflicted($ct) ? $ct : Conflict::set_pinned(Conflict::GENERAL, true); } else { $newct = Conflict::is_conflicted($ct) ? 0 : $ct; } diff --git a/src/assigners/a_conflict.php b/src/assigners/a_conflict.php index cde86177e6..617c17f1bb 100644 --- a/src/assigners/a_conflict.php +++ b/src/assigners/a_conflict.php @@ -114,7 +114,7 @@ function apply(PaperInfo $prow, Contact $contact, $req, AssignmentState $state) if (Conflict::is_conflicted($old_ct & $mask)) { $ct = $old_ct & $mask; } else { - $ct = $admin ? Conflict::PINNED : Conflict::GENERAL; + $ct = Conflict::set_pinned(Conflict::GENERAL, $admin); } } $new_ct = ($old_ct & ~$mask) | $ct; diff --git a/src/conflict.php b/src/conflict.php index d937e6e191..f309a4cf21 100644 --- a/src/conflict.php +++ b/src/conflict.php @@ -5,7 +5,9 @@ class Conflict { /** @var Conf */ private $conf; + /** @var bool */ private $_desc; + /** @var ?array */ private $_tmap; const GENERAL = 2; @@ -29,15 +31,24 @@ class Conflict { CONFLICT_AUTHOR => "author", CONFLICT_CONTACTAUTHOR => "author"]; + /** @param int $ct + * @return bool */ static function is_conflicted($ct) { return $ct > 0; } + /** @param int $ct + * @return bool */ static function is_author($ct) { return $ct >= CONFLICT_AUTHOR; } + /** @param int $ct + * @return bool */ static function is_pinned($ct) { return $ct >= self::PINNED; } + /** @param int $ct + * @param bool $pinned + * @return int */ static function set_pinned($ct, $pinned) { if (self::is_author($ct) || (self::is_pinned($ct) === !!$pinned)) { return $ct; @@ -51,11 +62,14 @@ static function strip($ct) { function __construct(Conf $conf) { $this->conf = $conf; - $this->_desc = $conf->setting("sub_pcconfdesc"); + $this->_desc = !!$conf->setting("sub_pcconfdesc"); } + + /** @return list */ function basic_conflict_types() { return array_keys(self::$desc_map); } + /** @param string $text * @param int $default_yes * @return int|false */ @@ -87,6 +101,7 @@ function parse_assignment($text, $default_yes) { return false; } } + /** @return int|false */ function parse_json($j) { if (is_bool($j)) { @@ -116,13 +131,22 @@ private function tmap() { } return $this->_tmap; } + + /** @param int $ct + * @return string */ function unparse_text($ct) { $tm = $this->tmap(); return $tm[self::strip($ct)] ?? $tm[1]; } + + /** @param int $ct + * @return string */ function unparse_html($ct) { return htmlspecialchars($this->unparse_text($ct)); } + + /** @param int $ct + * @return string */ function unparse_csv($ct) { if ($ct <= 0 || $ct === self::PINNED || !$this->_desc) { return $ct <= 0 ? "N" : "Y"; @@ -130,9 +154,15 @@ function unparse_csv($ct) { return $this->unparse_text($ct); } } + + /** @param int $ct + * return bool|string */ function unparse_json($ct) { return self::$json_map[self::strip($ct)]; } + + /** @param int $ct + * @return string */ function unparse_assignment($ct) { $j = self::$json_map[self::strip($ct)] ?? null; if (is_bool($j)) { diff --git a/src/papertable.php b/src/papertable.php index bf026b83db..b71af10812 100644 --- a/src/papertable.php +++ b/src/papertable.php @@ -1576,7 +1576,8 @@ function echo_editable_pc_conflicts($option) { $extra = ["class" => "pcconf-selector"]; if ($this->admin) { $ctypes["xsep"] = null; - $ctypes[Conflict::PINNED] = $confset->unparse_text(Conflict::PINNED); + $ct = Conflict::set_pinned(Conflict::GENERAL, true); + $ctypes[$ct] = $confset->unparse_text($ct); } $author_ctype = $confset->unparse_html(CONFLICT_AUTHOR); } else { diff --git a/test/test01.php b/test/test01.php index 3384c6ca9f..ca1ff841fb 100644 --- a/test/test01.php +++ b/test/test01.php @@ -835,10 +835,10 @@ function sorted_conflicts(PaperInfo $prow, $contacts) { xassert_eqq($paper3->conflict_type($user_rguerin), Conflict::GENERAL); xassert_assign($user_chair, "paper,action,user,conflict\n3,conflict,rguerin@ibm.com,pinned\n"); $paper3->load_conflicts(false); -xassert_eqq($paper3->conflict_type($user_rguerin), Conflict::PINNED); +xassert_eqq($paper3->conflict_type($user_rguerin), Conflict::set_pinned(Conflict::GENERAL, true)); xassert_assign($user_sclin, "paper,action,user,conflict type\n3,conflict,rguerin@ibm.com,pinned\n"); $paper3->load_conflicts(false); -xassert_eqq($paper3->conflict_type($user_rguerin), Conflict::PINNED); +xassert_eqq($paper3->conflict_type($user_rguerin), Conflict::set_pinned(Conflict::GENERAL, true)); xassert_assign($user_chair, "paper,action,user,conflicttype\n3,conflict,rguerin@ibm.com,none\n"); xassert_assign($user_sclin, "paper,action,user,conflicttype\n3,conflict,rguerin@ibm.com,conflict\n"); $paper3->load_conflicts(false);