/**
  * adds a test-type node to database
  *
  * @access public
  *
  * @param $data - an associative array containing all the node's data
  *
  * @return an error if something goes wrong or true
  *
  */
 public function test_addNode($data)
 {
     $db =& $this->getConnection();
     if (self::isError($db)) {
         return $db;
     }
     //validazione campi
     $d = array('id_corso', 'id_posizione', 'id_utente', 'id_istanza', 'nome', 'titolo', 'consegna', 'testo', 'tipo', 'data_creazione', 'ordine', 'id_nodo_parent', 'id_nodo_radice', 'id_nodo_riferimento', 'livello', 'versione', 'n_contatti', 'icona', 'colore_didascalia', 'colore_sfondo', 'correttezza', 'copyright', 'didascalia', 'durata', 'titolo_dragdrop');
     foreach ($data as $k => $v) {
         if (!in_array($k, $d)) {
             unset($data[$k]);
         }
     }
     $data['data_creazione'] = time();
     //fine validazione campi
     $keys = array_keys($data);
     $array_values = array_values($data);
     $placeholders = array_fill(0, count($data), '?');
     $sql = "INSERT INTO `" . self::$PREFIX . "nodes` (" . implode(',', $keys) . ") VALUES (" . implode(",", $placeholders) . ")";
     ADALogger::log_db("trying inserting the test node: " . $sql);
     $res = $this->queryPrepared($sql, $array_values);
     // if an error is detected, an error is created and reported
     if (self::isError($res)) {
         return new AMA_Error($this->errorMessage(AMA_ERR_ADD) . " while in test_addNode." . AMA_SEP . ": " . $res->getMessage());
     }
     return $db->lastInsertID();
 }
Beispiel #2
0
 /**
  * Remove a tutor from the DB
  *
  * @access public
  *
  * @param $id the unique id of the tutor
  *
  * @return an AMA_Error object if something goes wrong, true on success
  *
  */
 public function remove_tutor($id)
 {
     $db =& $this->getConnection();
     if (AMA_DB::isError($db)) {
         return $db;
     }
     $sql = "delete from tutor where id_utente_tutor={$id}";
     ADALogger::log_db($sql);
     $res = $this->executeCritical($sql);
     if (AMA_DB::isError($res)) {
         // $res is ana AMA_Error object
         return $res;
     }
     $sql = "delete from utente where id_utente={$id}";
     $res = $this->executeCritical($sql);
     if (AMA_DB::isError($res)) {
         // $res is ana AMA_Error object
         return $res;
     }
     return true;
 }
 /**
  * Method for handling thrown exceptions all in the same way.
  * For time being, simply logs the exception and returns it.
  *
  * @author giorgio 31/mag/2013
  *
  * @param  PDOException $e the PDOException to be handled
  * @return PDOException the passed PDOException
  *
  * @access private
  */
 private static function handleException(PDOException $e)
 {
     /**
      * Probably log the error somewhere and return it in the connection_object itself
      */
     ADALogger::log_db("[PDOException] : " . $e->getFile() . ":" . $e->getLine() . " - " . $e->getMessage());
     return $e;
 }