Esempio n. 1
0
 /**
  * Write a new lesson to Database.
  * Sets this lesson to last_chosen.
  *
  * @param Lesson $lesson        	
  * @return Updated lesson with id if successful, FALSE otherwise.
  */
 public function saveLesson(Lesson $lesson)
 {
     $newLesson["nl"] = $lesson->getName();
     $newLesson["user_id"] = $this->user_id;
     $statement = $this->pdo->prepare("INSERT INTO lessons (name, user_id, last_chosen) VALUES (:nl, :user_id, 1)");
     if ($statement->execute($newLesson)) {
         $id = $this->pdo->lastInsertId();
         $lesson->setId($id);
         $lesson->setActive(1);
         $lesson->setLastChosen(1);
         $this->pdo->exec("UPDATE lessons SET last_chosen=0 WHERE user_id=" . $this->user_id);
         return $lesson;
     } else {
         /*
          * echo $statement->queryString;
          * echo $statement->errorInfo()[2];
          */
         return FALSE;
     }
 }