public static function can_edit($id) { $v = Rating::find($id); if ($v && static::is_logged_user($v->user_id)) { return true; } return false; }
public static function getUserPlusTopics($userId, $start = 0, $limit = 0) { $ratings = Rating::find(["entityType", Topic::ENTITY_TYPE, "userId", $userId, "valueType", self::VALUE_TYPE, "value", self::VALUE, "tag", self::TAG])->all(); if ($ratings == null || empty($ratings)) { return array(); } $query = Topic::find()->join("user")->join("group")->order_desc("id"); if ($ratings != null && !empty($ratings)) { $where = "[id] in ("; $args = array(); for ($count = count($ratings), $i = 0; $i < $count; $i++) { $where .= "?" . ($i < $count - 1 ? "," : ""); $args[] = $ratings[$i]->entityId; } unset($ratings); $where .= ")"; $query = $query->where($where, $args); } return $start != 0 || $limit != 0 ? $query->range($start, $limit) : $query->all(); }
function SummaryPapersAssignment(&$tpl, $db, &$TEXTS) { $registry = Zend_registry::getInstance(); $config = $registry->get("Config"); $config->putInView($tpl); $db = Zend_Db_Table::getDefaultAdapter(); $paperTbl = new Paper(); $reviewTbl = new Review(); $ratingTbl = new Rating(); $userTbl = new User(); /* Check whether there is a prefered topic for papers */ if ($config->selectedPaperTopic) { $prefPaperTopic = $config->selectedPaperTopic; } else { $prefPaperTopic = "%"; } /* Check whether there is a prefered topic for reviewers */ if ($config->selectedReviewerTopic) { $prefReviewerTopic = $config->selectedReviewerTopic; } else { $prefReviewerTopic = "%"; } // Decompose the blocks of the template $tpl->set_block("content", "MEMBER_DETAIL", "MEMBERS"); $tpl->set_block("content", "PAPER_DETAIL", "PAPERS"); $tpl->set_block("content", "NAVIGATION_TABLE", "NAVIGATION"); $tpl->set_block("PAPER_DETAIL", "ASSIGNMENT_DETAIL", "ASSIGNMENTS"); // Get the list of topics $topicList = $db->fetchPairs("SELECT id, label FROM ResearchTopic"); $topicList["0"] = "Any"; ksort($topicList); // Show the selection list $tpl->paper_topics = Zmax_View_Phplib::selectField("paperTopic", $topicList, $prefPaperTopic); $tpl->reviewer_topics = Zmax_View_Phplib::selectField("reviewerTopic", $topicList, $prefReviewerTopic); /* Store the list of reviewers in an array (+easier, +efficient). */ $members = array(); $nb_members = 0; $users = $userTbl->fetchAll("roles LIKE '%R%'", "last_name"); foreach ($users as $user) { if ($prefReviewerTopic == '%' or $user->matchTopic($prefReviewerTopic)) { $members[++$nb_members] = $user; } } // Same thing for papers $papers = array(); $nb_papers = 0; $rPapers = $db->query("SELECT * FROM Paper ORDER BY id"); while ($paper = $rPapers->fetch(Zend_Db::FETCH_OBJ)) { if ($prefPaperTopic == '%' or $paper->topic == $prefPaperTopic) { $papers[++$nb_papers] = $paper; } } // Manage the navigation table if ($nb_papers > MAX_ITEMS_IN_ASSIGNMENT or $nb_members > MAX_ITEMS_IN_ASSIGNMENT) { // Show the navigation table $tpl->set_var("nb_paper", $nb_papers); $tpl->set_var("nb_reviewers", $nb_members); $tpl->set_var("max_items_in_assignment", MAX_ITEMS_IN_ASSIGNMENT); if (isset($_REQUEST['i_paper_min'])) { // The request comes from the navigation table $i_paper_min = $_REQUEST['i_paper_min']; $i_paper_max = min($_REQUEST['i_paper_max'], $nb_papers); $i_member_min = $_REQUEST['i_member_min']; $i_member_max = min($_REQUEST['i_member_max'], $nb_members); } else { $i_paper_min = 1; $i_paper_max = min($nb_papers, MAX_ITEMS_IN_ASSIGNMENT); $i_member_min = 1; $i_member_max = min($nb_members, MAX_ITEMS_IN_ASSIGNMENT); } // Show the navigation table $tpl->set_var("NAV_TABLE", ""); $lines = ""; $script = $tpl->base_url . "/admin/chair/showassignment?1=1"; for ($i = 1; $i <= $nb_papers; $i += MAX_ITEMS_IN_ASSIGNMENT) { $line = ""; for ($j = 1; $j <= $nb_members; $j += MAX_ITEMS_IN_ASSIGNMENT) { $link = $script . "&i_paper_min={$i}" . "&i_paper_max=" . ($i + MAX_ITEMS_IN_ASSIGNMENT - 1) . "&i_member_min={$j}" . "&i_member_max=" . ($j + MAX_ITEMS_IN_ASSIGNMENT - 1); if ($i == $i_paper_min and $j == $i_member_min) { $line .= "<td bgcolor=lightblue><a href='{$link}'>" . "<font color=white>{$i}/{$j}</font></a></td>"; } else { $line .= "<td><a href='{$link}'>{$i}/{$j}</a></td>"; } } $lines .= "<tr>{$line}</tr>\n"; } $tpl->set_var("NAV_TABLE", $lines); $tpl->append("NAVIGATION", "NAVIGATION_TABLE"); } else { // Hide the navigation table $i_paper_min = $i_member_min = 1; $i_paper_max = $nb_papers; $i_member_max = $nb_members; $tpl->set_var("NAVIGATION", ""); } // Put the current values in the template $tpl->set_var("I_PAPER_MIN", $i_paper_min); $tpl->set_var("I_PAPER_MAX", $i_paper_max); $tpl->set_var("I_MEMBER_MIN", $i_member_min); $tpl->set_var("I_MEMBER_MAX", $i_member_max); // echo "I paper min=$i_paper_min I paper max = $i_paper_max<br>"; // OK, now create the table. First the columns' headers for ($j = $i_member_min; $j <= $i_member_max; $j++) { $members[$j]->putInView($tpl); $tpl->member_nb_papers = $members[$j]->countPapers(); $tpl->append("MEMBERS", "MEMBER_DETAIL"); } // then each line $tpl->PAPERS = ""; for ($i = $i_paper_min; $i <= $i_paper_max; $i++) { // Choose the CSS class if ($i % 2 == 0) { $tpl->set_var("css_class", "even"); } else { $tpl->set_var("css_class", "odd"); } $paper = $papers[$i]; $entity = "Paper" . "->id"; $tpl->setVar($entity, $papers[$i]->id); $tpl->SESSION_ID = session_id(); // Get the ratings of each PC member $nbReviewers = 0; for ($j = $i_member_min; $j <= $i_member_max; $j++) { $member = $members[$j]; $member->putInView($tpl); $rating = $ratingTbl->find($paper->id, $member->id)->current(); if ($rating) { $val = $rating->rate; } else { $val = 2; } $tpl->bg_color = "white"; $tpl->set_var("paper_rating", $val); $tpl->set_var("CHECKED_YES", ""); $tpl->set_var("CHECKED_NO", "checked='1'"); // Check if the paper is assigned $review = $reviewTbl->find($paper->id, $member->id)->current(); if ($review) { $nbReviewers = $nbReviewers + 1; $tpl->bg_color = "yellow"; $tpl->set_var("CHECKED_YES", "checked='1'"); $tpl->set_var("CHECKED_NO", ""); } // Add to the assignment line $tpl->append("ASSIGNMENTS", "ASSIGNMENT_DETAIL"); } // Add to the list of papers $tpl->setVar("paper_nb_reviewers", $nbReviewers); $tpl->append("PAPERS", "PAPER_DETAIL"); $tpl->set_var("ASSIGNMENTS", ""); } }
/** * Show the form for editing the specified rating. * * @param int $id * @return Response */ public function edit($id) { $rating = Rating::find($id); return View::make('ratings.edit', compact('rating')); }
function computeprefsAction() { // Load the template $this->view->setFile("content", "computeprefs.xml"); $this->view->setBlock("content", "MEMBER", "MEMBERS"); $paperTbl = new Paper(); $userTbl = new User(); $ratingTbl = new Rating(); // Loop on PC members $members = $userTbl->fetchAll("roles LIKE '%R%'"); $i = 0; foreach ($members as $member) { $this->view->css_class = Config::CssCLass($i++); $member->putInView($this->view); // Loop on papers if (1 == 1) { $qPapers = "SELECT * FROM Paper"; } else { // Loop on papers that match the reviewer's topics $qPapers = "SELECT p.* FROM (Paper p LEFT JOIN PaperTopic t ON id=id_paper), " . " UserTopic s " . " WHERE (p.topic=s.idTopic OR t.id_topic=s.idTopic) AND s.id_user='******' "; } $comments = ""; $rPapers = $this->zmax_context->db->query($qPapers); while ($p = $rPapers->fetch(Zend_Db::FETCH_OBJ)) { // instantiate a PaperRow object. Ok, not elegant, but easier $paper = $paperTbl->find($p->id)->current(); $conflict = false; // Get the rate, if exists $rating = $ratingTbl->find($paper->id, $member->id)->current(); if (!is_object($rating)) { // OK, the preference is unset. Check whether there is a conflict $rating = $ratingTbl->createRow(); $rating->idPaper = $paper->id; $rating->id_user = $member->id; $conflict = $paper->checkConflictWithuser($member, $comments); if ($conflict) { // Conflict! The default preference is 0 $rating->rate = 0; } else { // Check whether some topics match if ($member->matchTopic($paper->topic)) { // Match! The default preference is 3 $comments .= "Topic match with paper {$paper->id} ({$paper->title})<br/> "; $rating->rate = 3; } else { $rating->rate = 2; } } // OK, now save the rating $rating->save(); } else { $comments = $this->zmax_context->texts->admin->conflicts_prefs_already_set; } } // Loop on papers $this->view->comments = $comments; $this->view->append("MEMBERS", "MEMBER"); } // End of loop on users echo $this->view->render("layout"); }
/** * Remove the specified rating from storage. * * @param int $id * @return Response */ public function destroy($id) { $userId = Auth::user()->id; $ratingData = Rating::find($id); if ($userId === $ratingData["user_id"]) { Log::info($userId); } if ($userId === $id) { $ratingData = Rating::find($id); } if ($userId === $ratingData["user_id"]) { Rating::destroy($id); Log::info("rating id: {$id} deleted"); return Redirect::route('ratings.index'); } else { return "Access Denied: this is not your rating."; } }