Exemple #1
0
 /**
  *  Write a review in the DB
  */
 function save()
 {
     $db = Zend_Db_Table::getDefaultAdapter();
     // First save the paper
     parent::save();
     // Save marks. First clean the current content
     $db->query("DELETE FROM ReviewMark WHERE id_user='******' and idPaper='{$this->idPaper}'");
     foreach ($this->_marks as $mark) {
         // echo "Save $mark->idPaper -- $mark->id_user for criteria $mark->idCriteria<br/>";
         $mark->save();
     }
     // Save answers. First clean the current content
     $db->query("DELETE FROM ReviewAnswer WHERE id_user='******' and id_paper='{$this->idPaper}'");
     foreach ($this->_answers as $answer) {
         $answer->save();
     }
 }
Exemple #2
0
 /**
  * Override the 'save' function to encrypt the password
  */
 function save()
 {
     $db = Zend_Db_Table::getDefaultAdapter();
     // Always put the email in lowercase
     $this->email = strToLower($this->email);
     // We do no accept empty password. If the password is
     // empty, assign the default one
     if (empty($this->password)) {
         $registry = Zend_registry::getInstance();
         $config = $registry->get("Config");
         $this->password = md5($this->defaultPassword($config->passwordGenerator));
     }
     // Trim some values
     $this->address = trim($this->address);
     // No role? This is an author
     if (empty($this->roles)) {
         $this->roles = User::AUTHOR_ROLE;
     }
     parent::save();
     // Do we have research topics? Save them.
     if ($this->isReviewer()) {
         // Clean the UserTopic table for this paper.
         $db->query("DELETE FROM UserTopic WHERE id_user='******'");
         $UserTopicTbl = new UserTopic();
         foreach ($this->_topics as $topic) {
             $userTopicRow = $UserTopicTbl->createRow();
             $userTopicRow->setFromArray(array("id_user" => $this->id, "id_topic" => $topic->id_topic));
             $userTopicRow->save();
         }
     }
     // Clean the RegAnswer table for this user.
     $db->query("DELETE FROM RegAnswer WHERE id_user='******'");
     // And, finally, save the answers to questions
     $regAnswerTbl = new RegAnswer();
     foreach ($this->_answers as $idQuestion => $answer) {
         $regAnswerRow = $regAnswerTbl->createRow();
         $regAnswerRow->setFromArray(array("id_question" => $idQuestion, "id_answer" => $answer->id_answer, "id_user" => $this->id));
         $regAnswerRow->save();
     }
 }