Ejemplo n.º 1
0
 /**
  * Checks the user and transaction items' course and ensures they exist
  * @return bool 
  */
 protected function verify_transaction()
 {
     global $DB;
     // Ensure that the user associated to the transaction actually exists
     if (!($user = $DB->get_record('user', array('id' => $this->_transaction->get_user_id())))) {
         // Check that user exists
         $this->send_error_to_admin("User " . $this->_transaction->get_user_id() . " doesn't exist");
         $transaction->fail();
         return false;
     }
     // Check that each course associated with the items in the transaction ACTUALLY exist
     // (it should be VERY unlikely for this to happen, but we check nonetheless!)
     foreach ($this->_transaction->get_items() as $item) {
         $product = local_moodec_get_product($item->get_product_id());
         if (!($course = $DB->get_record('course', array('id' => $product->get_course_id())))) {
             // Check that course exists
             $this->send_error_to_admin("Course " . $product->get_course_id() . " doesn't exist");
             $this->_transaction->fail();
             return false;
         }
     }
     return true;
 }