public function createModel()
 {
     $model = new Review();
     $criteria = new CDbCriteria();
     $criteria->select = array(new CDbExpression('MAX(sort) as sort'));
     $max = $model->find($criteria);
     $model->sort = $max->sort + 10;
     return $model;
 }
    public function update(){
        $input=Input::get();
        unset($input['_method']);
        unset($input['_token']);
        unset($input['submit']);
        $id = $input['id'];

        $review= Review::find($input['id']);
        $review->update($input);
        return Redirect::route('review_index');
    }
 /**
  * Action that processes a review after submission
  * @author philipperigaux
  *
  */
 function processreviewAction()
 {
     if (!$this->config->isPhaseOpen(Config::REVIEWING_PHASE)) {
         $this->view->content = $this->texts->reviewer->review_phase_is_closed;
         echo $this->view->render("layout");
         return;
     }
     $this->view->setFile("content", "processreview.xml");
     $this->view->setBlock("content", "review");
     // Extract the block with marks.
     $this->view->set_block('review', "review_mark", "review_marks");
     // Extracts the block with answers
     $this->view->set_block('review', "review_answer", "review_answers");
     // Actions if the id of a paper is submitted
     if (isset($_REQUEST['idPaper'])) {
         $idPaper = $this->getRequest()->getParam("idPaper");
         $reviewTbl = new Review();
         $review = $reviewTbl->find($idPaper, $this->user->id)->current();
         // Check that the paper is REALLY assigned to the reviewer
         if (is_object($review)) {
             // Put the review in the database
             $review->updateFromArray($_POST);
             // Create the review presentation
             $this->view->review = $review->showReview($this->view, true);
             // Resolve the entities replacement
             $this->view->assign("content", "content");
             // Send a mail to confirm review submission
             $mail = new Mail(Mail::SOME_USER, $this->texts->mail->subj_ack_review, $this->view->getScriptPaths());
             $mail->setFormat(Mail::FORMAT_HTML);
             $mail->setTo($this->user->email);
             $mail->loadTemplate($this->lang, "ack_review");
             $mailViewEngine = $mail->getEngine();
             // Fixes a bug: the reviewer namespace is not present, and thus 'reviewer' texts
             // were not translated. NB: this requires a fix ubn Zmax_Translate_Db as well
             $this->texts->addTranslation($this->zmax_context->db, $this->zmax_context->locale, array("namespace" => 'reviewer', "view" => $mailViewEngine));
             $mailViewEngine->setBlock("template", "template_mark", "template_marks");
             $mailViewEngine->setBlock("template", "template_answer", "template_answers");
             $instantiatedMail = $review->showReview($mailViewEngine, true, "template");
             $mail->setTemplate($instantiatedMail);
             if ($this->config->mailOnReview == "Y") {
                 $mail->setCopyToChair(true);
             }
             $mail->send();
         } else {
             $this->view->content = $this->texts->def->access_denied;
         }
     } else {
         $this->view->content = "Invalid action<br/>";
     }
     echo $this->view->render("layout");
 }
Esempio n. 4
0
 /**
  * Assign a list of reviewers to the paper
  */
 function assignReviewers($tabIds)
 {
     $reviewTbl = new Review();
     // Loop on the reviewers ids
     foreach ($tabIds as $id_user) {
         // Check whether the review exists
         $review = $reviewTbl->find($this->id, $id_user)->current();
         // Never delete! Just insert
         if (!is_object($review)) {
             $review = $reviewTbl->createRow();
             $review->idPaper = $this->id;
             $review->id_user = $id_user;
             $review->save();
         }
     }
 }
Esempio n. 5
0
 function test_Find()
 {
     //Arrange
     $beer_id = 1;
     $user_id = 1;
     $review = "Great beer";
     $date = "2015-10-08";
     $id = 3;
     $test_review = new Review($beer_id, $user_id, $review, $date, $id);
     $test_review->save();
     $beer_id = 2;
     $user_id = 2;
     $review = "Bad beer";
     $date = "2015-10-09";
     $id = 3;
     $test_review2 = new Review($beer_id, $user_id, $review, $date, $id);
     $test_review2->save();
     //Act
     $column_id = "review";
     $search_id = "Bad beer";
     $result = Review::find($column_id, $search_id);
     //Assert
     $this->assertEquals([$test_review2], $result);
 }
Esempio n. 6
0
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", "");
    }
}
Esempio n. 7
0
    $user = User::find("id", $user_id);
    $store = Store::find("id", $store_id);
    return $app['twig']->render('store.html.twig', array('store' => $store[0], 'user' => $user[0], 'beers' => $store[0]->getBeers(), 'all_beers' => Beer::getAll()));
});
//from store
//add beer to store
//show store
$app->post("/{user_id}/store/{store_id}", function ($user_id, $store_id) use($app) {
    $store = Store::find("id", $store_id);
    $beer = Beer::find("id", $_POST['beer_id']);
    $store[0]->addBeer($beer[0]->getId());
    $user = User::find("id", $user_id);
    return $app['twig']->render('store.html.twig', array('store' => $store[0], 'user' => $user[0], 'beers' => $store[0]->getBeers(), 'all_beers' => Beer::getAll()));
});
//--------------------------------------------- Begin Review Functionality ----------------------------------------
$app->get("/{user_id}/review/{beer_id}", function ($user_id, $beer_id) use($app) {
    $user = User::find("id", $user_id);
    $beer = Beer::find("id", $beer_id);
    return $app['twig']->render('review.html.twig', array('user' => $user[0], 'beer' => $beer[0]));
});
$app->post("/{user_id}/review/{beer_id}", function ($user_id, $beer_id) use($app) {
    $user = User::find("id", $user_id);
    $review = Review::findReview($beer_id, $user_id);
    $review[0]->update($_POST['beer_review'], $_POST['review_date']);
    $reviews = Review::find("user_id", $user[0]->getId());
    $new_beers = User::findBeerStyle($user[0]->getId(), $user[0]->getPreferredStyle());
    $local_stores = Store::find("region", $user[0]->getRegion());
    return $app['twig']->render('profile.html.twig', array('user' => $user[0], 'reviews' => $reviews, 'new_beers' => $new_beers, 'local_stores' => $local_stores));
});
return $app;
//End of app, do not code below here
Esempio n. 8
0
 function test_find()
 {
     //Arrange
     $rating = 1;
     $comment = "This place sucks!";
     $id = null;
     $test_review = new Review($rating, $comment, $id);
     $test_review->save();
     $rating2 = 2;
     $comment2 = "This place smells!";
     $id2 = null;
     $test_review2 = new Review($rating2, $comment2, $id2);
     $test_review2->save();
     //Act
     $result = Review::find($test_review2->getId());
     //Assert
     $this->assertEquals($test_review2, $result);
 }
Esempio n. 9
0
 /**
  * Show the list of papers wit their status
  */
 function paperstatusAction()
 {
     $paperTbl = new Paper();
     $paperStatusTbl = new PaperStatus();
     $exportLatex = $exportExcel = false;
     if (isset($_REQUEST['export_latex'])) {
         $exportLatex = true;
         $this->view->message = "The LaTeX file <i>paperstatus.tex</i> has been generated in files/selection";
     }
     if (isset($_REQUEST['export_excel'])) {
         $exportExcel = true;
         $this->view->message = "The LaTeX file <i>paperstatus.tex</i> has been generated in files/selection";
     } else {
         $this->view->MESSAGE = "";
     }
     if (!$exportExcel) {
         $this->view->set_file("content", "paperstatus.xml");
         $this->view->set_block("content", "SELECTION_FORM");
         $this->view->set_block("content", "MESSAGE");
         $this->view->set_block("content", "SHOW_SELECTION_FORM");
         $this->view->set_file("ranked_papers_list", "ranked_papers.xml");
     } else {
         $this->view->set_file("ranked_papers_list", "paperstatus_excel.xml");
     }
     // Check whether the current selection must be changed
     if (isset($_POST['spStatus'])) {
         $this->config->changeCurrentSelection();
     }
     if (isset($_REQUEST['remove'])) {
         $reviewTbl = new Review();
         $review = $reviewTbl->find($_REQUEST['idPaper'], $_REQUEST['remove'])->current();
         if (is_object($review)) {
             $review->delete();
         }
     } else {
         if (isset($_REQUEST['idPaper'])) {
             // If the status is submitted: update in the DB
             $idPaper = $_REQUEST['idPaper'];
             $status = $_REQUEST['status'];
             foreach ($idPaper as $key => $val) {
                 if (isset($status[$val])) {
                     // echo "ID = $val<br/>";
                     $paper = $paperTbl->find($val)->current();
                     if (is_object($paper)) {
                         $paper->status = $status[$val];
                         $paper->save();
                     } else {
                         throw new Zmax_Exception("Unknown paper id sent to the change status function?");
                     }
                 }
             }
         }
     }
     // If required, hide the selection form
     if (isset($_REQUEST['hide_selection_form'])) {
         $this->config->show_selection_form = 'N';
         $this->config->save();
     } else {
         if (isset($_REQUEST['show_selection_form'])) {
             $this->config->show_selection_form = 'Y';
             $this->config->save();
         }
     }
     // Show the form for filtering papers, if required
     if ($this->config->show_selection_form == 'Y') {
         $this->view->set_var("FORM_SELECT_PAPERS", $this->formSelectPapers($this->view->base_url . "/admin/chair/paperstatus", $this->view, $this->db_v1));
         $this->view->set_var("SHOW_SELECTION_FORM", "");
     } else {
         $this->view->set_var("SELECTION_FORM", "");
     }
     // Create the list of lists to toggle all the selected papers
     $comma = $listLinks = "";
     $statusList = $paperStatusTbl->fetchAll("final_status='Y'");
     foreach ($statusList as $status) {
         $listLinks .= $comma . " <a href='#' onClick=\"TogglePaperStatus('{$status->id}')\">" . $status->label . "</a>";
         $comma = ",";
     }
     $this->view->set_var("TOGGLE_LIST", $listLinks);
     // Always list the papers
     if ($exportExcel) {
         $this->papersReviews($this->view, "ranked_papers_list", false);
     } else {
         $this->papersReviews($this->view, "ranked_papers_list");
     }
     // In addition, produce the Latex file
     if ($exportLatex) {
         $anonymized = false;
         if (isset($_REQUEST['anonymized'])) {
             $anonymized = true;
         }
         // Instantiate the data export object
         $dataExport = new DataExport($this->view->getScriptPaths());
         // Load the latex templates
         $dataExport->getView()->setFile("latex_papers_list", "paperstatus.tex");
         $this->papersReviews($dataExport->getView(), "latex_papers_list", false, $anonymized);
         // The directory where Latex files are produced
         $tex_dir = "selection/";
         $dataExport->getView()->assign("result", "latex_papers_list");
         $result = $dataExport->replaceBadChars($dataExport->getView()->result);
         $dataExport->writeFile($tex_dir, "paperstatus.tex", $result);
         $dataExport->downloadFile($tex_dir, "paperstatus.tex");
     }
     if ($exportExcel) {
         $this->view->assign("export", "ranked_papers_list");
         $this->exportFile("submissions.xls", "text/xls", $this->view->export);
         return;
     }
     echo $this->view->render("layout");
 }
Esempio n. 10
0
 public static function GetByProductId($productId)
 {
     return Review::find('all', array('product_id' => $productId));
 }
$review_id = 0;
$review = new Review();
try {
    $review_id = $review->create($fields);
    $success = true;
    $message = 'New review creation is complete.<br>';
    echo $message;
} catch (Exception $e) {
    $success = false;
    $message = $e->getMessage();
    echo "Creating a new review Error: " . $message . "<br>";
}
echo ($success == true ? "SUCCESS" : "FAILURE") . "<br>";
try {
    echo "<br>Testing find review:<br>";
    print_r("If found review:" . $review->find($review_id) . "<br>");
    print_r($review->get_review_info());
    echo "<br>";
    echo $review->get_review_info_json();
    echo "<br>";
} catch (Exception $e) {
    $success = false;
    $message = $e->getMessage();
    echo "Find review Error: " . $message . "<br>";
}
echo ($success == true ? "SUCCESS" : "FAILURE") . "<br>";
try {
    echo "<br>Testing for canceling a review : <br> review_id: {$review_id}<br>";
    echo "Result: " . $review->cancel($review_id) . "<br>";
} catch (Exception $e) {
    $success = false;
Esempio n. 12
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function reviewEdit($id)
 {
     $review = Review::find($id);
     if (Auth::user()->usr_level == 2) {
         return view('reviews.edit', compact('review'));
     } else {
         return Redirect::to(Config::get('url.home'));
     }
 }