Skip to content

Commit

Permalink
Conflicts: Don't refer to PINNED.
Browse files Browse the repository at this point in the history
And type declarations.
  • Loading branch information
kohler committed May 16, 2020
1 parent da38fbb commit 76cd47d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion manualassign.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/assigners/a_conflict.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 31 additions & 1 deletion src/conflict.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
class Conflict {
/** @var Conf */
private $conf;
/** @var bool */
private $_desc;
/** @var ?array<int,string> */
private $_tmap;

const GENERAL = 2;
Expand All @@ -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;
Expand All @@ -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<int> */
function basic_conflict_types() {
return array_keys(self::$desc_map);
}

/** @param string $text
* @param int $default_yes
* @return int|false */
Expand Down Expand Up @@ -87,6 +101,7 @@ function parse_assignment($text, $default_yes) {
return false;
}
}

/** @return int|false */
function parse_json($j) {
if (is_bool($j)) {
Expand Down Expand Up @@ -116,23 +131,38 @@ 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";
} else {
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)) {
Expand Down
3 changes: 2 additions & 1 deletion src/papertable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions test/test01.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,[email protected],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,[email protected],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,[email protected],none\n");
xassert_assign($user_sclin, "paper,action,user,conflicttype\n3,conflict,[email protected],conflict\n");
$paper3->load_conflicts(false);
Expand Down

0 comments on commit 76cd47d

Please sign in to comment.