1<?php 2// pc_conflict.php -- HotCRP conflict list column 3// Copyright (c) 2006-2018 Eddie Kohler; see LICENSE. 4 5class Conflict_PaperColumn extends PaperColumn { 6 private $contact; 7 private $show_user; 8 private $not_me; 9 private $show_description; 10 private $editable = false; 11 function __construct(Conf $conf, $cj) { 12 parent::__construct($conf, $cj); 13 $this->override = PaperColumn::OVERRIDE_FOLD_IFEMPTY; 14 if (($this->show_user = isset($cj->user))) 15 $this->contact = $conf->pc_member_by_email($cj->user); 16 $this->show_description = !!get($cj, "show_description"); 17 if (get($cj, "edit")) 18 $this->mark_editable(); 19 $this->editable = !!get($cj, "edit"); 20 } 21 function mark_editable() { 22 $this->editable = true; 23 $this->override = PaperColumn::OVERRIDE_FOLD_BOTH; 24 } 25 function prepare(PaperList $pl, $visible) { 26 $this->contact = $this->contact ? : $pl->reviewer_user(); 27 $this->not_me = $this->contact->contactId !== $pl->user->contactId; 28 return true; 29 } 30 private function conflict_type(PaperList $pl, $row) { 31 if (!$this->not_me || $pl->user->can_view_conflicts($row)) { 32 $ct = $row->conflict_type($this->contact); 33 if ($this->show_description 34 && $ct > 1 35 && !$pl->user->can_view_authors($row)) 36 $ct = 1; 37 return $ct; 38 } else 39 return 0; 40 } 41 function compare(PaperInfo $a, PaperInfo $b, ListSorter $sorter) { 42 $act = $this->conflict_type($pl, $a); 43 $bct = $this->conflict_type($pl, $b); 44 if ($this->show_description) 45 return $bct - $act; 46 else 47 return ($bct ? 1 : 0) - ($act ? 1 : 0); 48 } 49 function header(PaperList $pl, $is_text) { 50 if ((!$this->show_user && !$this->not_me && !$this->editable) 51 || $pl->report_id() === "conflictassign") 52 return "Conflict"; 53 else if ($is_text) 54 return $pl->user->name_text_for($this->contact) . " conflict"; 55 else 56 return $pl->user->name_html_for($this->contact) . "<br>conflict"; 57 } 58 protected function checked(PaperList $pl, PaperInfo $row) { 59 return $pl->is_selected($row->paperId, $row->conflict_type($this->contact) > 0); 60 } 61 function content_empty(PaperList $pl, PaperInfo $row) { 62 return $this->not_me 63 && !$pl->user->can_administer($row) 64 && !$pl->user->can_view_conflicts($row); 65 } 66 function content(PaperList $pl, PaperInfo $row) { 67 if ($this->editable 68 && ($t = $this->edit_content($pl, $row))) 69 return $t; 70 $ct = $this->conflict_type($pl, $row); 71 if (!$ct) 72 return ""; 73 else if (!$this->show_description || $ct == 1) 74 return review_type_icon(-1); 75 else if ($ct >= CONFLICT_AUTHOR) 76 return "Author"; 77 else 78 return get(Conflict::$type_descriptions, $ct, "Other"); 79 } 80 function edit_content(PaperList $pl, PaperInfo $row) { 81 if (!$pl->user->allow_administer($row)) 82 return false; 83 $ct = $row->conflict_type($this->contact); 84 if ($ct >= CONFLICT_AUTHOR) 85 return "Author"; 86 return '<input type="checkbox" class="uix uikd js-range-click uich js-assign-review" ' 87 . 'data-range-type="assrevu' . ($this->show_user ? $this->contact->contactId : "") 88 . '" name="assrev' . $row->paperId . 'u' . $this->contact->contactId 89 . '" value="-1"' . ($ct ? " checked" : "") . ' />'; 90 } 91 function text(PaperList $pl, PaperInfo $row) { 92 $ct = $this->conflict_type($pl, $row); 93 if (!$ct) 94 return "N"; 95 else if (!$this->show_description || $ct == 1) 96 return "Y"; 97 else if ($ct >= CONFLICT_AUTHOR) 98 return "Author"; 99 else 100 return get(Conflict::$type_descriptions, $ct, "Other"); 101 } 102 103 static function expand($name, Conf $conf, $xfj, $m) { 104 if (!($fj = (array) $conf->basic_paper_column($m[1], $conf->xt_user))) 105 return null; 106 $rs = []; 107 $cs = new ContactSearch(ContactSearch::F_PC | ContactSearch::F_TAG | ContactSearch::F_USER, $m[2], $conf->xt_user); 108 foreach ($cs->ids as $cid) { 109 $u = $conf->pc_member_by_id($cid); 110 $fj["name"] = $m[1] . ":" . $u->email; 111 $fj["user"] = $u->email; 112 $rs[] = (object) $fj; 113 } 114 if (empty($rs)) 115 $conf->xt_factory_error("No PC member matches “" . htmlspecialchars($m[2]) . "”."); 116 return $rs; 117 } 118} 119