Beispiel #1
0
 function getCount($object)
 {
     parent::load($object);
     $objectClass = get_class($object);
     $rs = $this->db->execute($s = Query::generateSelectStm(array($this->table), array(), array(new WhereConstraint($this->table->getColumn(REPORT_OBJECT_ID), Operator::EQUAL, $object->getID()), new WhereConstraint($this->table->getColumn(REPORT_OBJECT_CLASS), Operator::EQUAL, get_class($object))), array("count" => 2)));
     if ($this->db->num_rows() != 1) {
         throw new Exception("Si è verificato un errore. Riprovare.");
     }
     $row = $this->db->fetch_row();
     return intval($row[0]);
 }
Beispiel #2
0
 function loadByNickname($nickname)
 {
     parent::load($nickname);
     $this->db->execute($s = Query::generateSelectStm(array($this->table), array(), array(new WhereConstraint($this->table->getColumn(DB::USER_NICKNAME), Operator::EQUAL, $nickname)), array()));
     if ($this->db->num_rows() != 1) {
         throw new Exception("L'oggetto cercato non è stato trovato. Riprovare.");
     }
     $row = $this->db->fetch_result();
     $user = $this->createFromDBRow($row);
     return $user;
 }
Beispiel #3
0
 function loadParentName($cat)
 {
     parent::load($cat);
     if (!is_a($cat, "Category")) {
         throw new Exception("Attenzione! Il parametro di ricerca non è una categoria.");
     }
     $this->db->execute($s = Query::generateSelectStm(array($this->table_sc), array(), array(new WhereConstraint($this->table_sc->getColumn(DB::SUB_CATEGORY_CATEGORY), Operator::EQUAL, $cat->getName())), array()));
     if ($this->db->num_rows() == 1) {
         $row = $this->db->fetch_result();
         $cat->parent = $row[DB::SUB_CATEGORY_PARENT];
     }
     return $cat;
 }
Beispiel #4
0
 function loadForAuthor($author)
 {
     parent::load($author);
     if (!is_subclass_of($post, "User")) {
         throw new Exception("Attenzione! Il parametro di ricerca non è un utente.");
     }
     $this->db->execute(Query::generateSelectStm(array($this->table), array(), array(new WhereConstraint($this->table->getColumn(DB::RESOURCE_OWNER), Operator::EQUAL, intval($author->getID()))), array()));
     $resources = array();
     while ($row = $db->fetch_result()) {
         $resources[] = $this->createFromDBRow($row);
     }
     return $resources;
 }
Beispiel #5
0
 public function __construct(array $params = array())
 {
     if (!empty($params)) {
         $vars = get_object_vars($this);
         foreach ($params as $k => $v) {
             if (array_key_exists($k, $vars)) {
                 $this->{$k} = $v;
             }
         }
     }
     if (isset($this->adresse)) {
         $this->adresse = Dao::load($this->adresse, 'adresse');
         $this->linkObject = array('adresse');
     }
 }
Beispiel #6
0
 function exists($vote)
 {
     parent::load($vote);
     $post = $vote["post"];
     $author = $vote["author"];
     parent::load($post);
     if (!is_subclass_of($post, "Post")) {
         throw new Exception("Attenzione! Il parametro di ricerca non è un post.");
     }
     parent::load($author);
     if (!is_a($post, "User")) {
         throw new Exception("Attenzione! Il parametro di ricerca non è un utente.");
     }
     $this->db->execute(Query::generateSelectStm(array($this->table), array(), array(new WhereConstraint($this->table->getColumn(DB::VOTE_POST), Operator::EQUAL, intval($post->getID())), new WhereConstraint($this->table->getColumn(DB::VOTE_AUTHOR), Operator::EQUAL, intval($author->getID()))), array()));
     return $this->db->num_rows() > 0;
 }
Beispiel #7
0
 function loadAll($post)
 {
     parent::load($post);
     if (!is_subclass_of($post, "Post")) {
         throw new Exception("Attenzione! Il parametro di ricerca non è un post.");
     }
     $rs = $this->db->execute($s = Query::generateSelectStm(array($this->table), array(), array(new WhereConstraint($this->table->getColumn(DB::COMMENT_POST), Operator::EQUAL, intval($post->getID()))), array()), $this->table->getName(), $this);
     $comm = array();
     if ($this->db->num_rows() > 0) {
         while ($row = $this->db->fetch_result()) {
             $c = new Comment($row[DB::COMMENT_COMMENT], intval($row[DB::COMMENT_POST]), intval($row[DB::COMMENT_AUTHOR]));
             $com->setID($row[DB::COMMENT_ID])->setCreationDate(date_timestamp_get(date_create_from_format("Y-m-d G:i:s", $row[DB::COMMENT_CREATION_DATE])));
             $comm[] = $com;
         }
     }
     return $post->setComments($comm);
 }
Beispiel #8
0
 function loadAll($user)
 {
     parent::load($user);
     if (is_numeric($user)) {
         $id = $user;
     } else {
         if (!is_a($user, "User")) {
             throw new Exception("Attenzione! Il parametro di ricerca non è un utente.");
         }
         $id = $user->getID();
     }
     $this->db->execute(Query::generateSelectStm(array($this->table, $this->table_ct), array(new JoinConstraint($this->table->getColumn(DB::CONTACT_NAME), $this->table_ct->getColumn(DB::CONTACT_TYPE_NAME))), array(new WhereConstraint($this->table->getColumn(DB::CONTACT_USER), Operator::EQUAL, intval($id))), array()));
     $conts = array();
     while ($row = $this->db->fetch_result()) {
         $conts[] = $this->createFromDBRow($row);
     }
     return $conts;
 }
Beispiel #9
0
 function load($rl_name)
 {
     parent::load($rl_name);
     $result = array();
     $query = "SELECT * FROM " . DB::TABLE_ROLE . " WHERE " . DB::ROLE_NAME . " = '" . $rl_name . "'";
     // query usando le const
     $this->db->execute($query);
     //eseguo la query con l'oggetto DBManager che hanno tutti i DAO
     if ($this->db->num_rows() != 1) {
         //controllo la quantit� di risultati
         throw new Exception("L'oggetto cercato non � stato trovato. Riprovare.");
     }
     $res = $this->db->fetch_result();
     //recupero il primo (e unico) risultato.
     //TRUCCO!!! il risultato � gi� in un array associativo dove l'indice � il nome della colonna...
     //posso ritornarlo direttamente cos�...
     //ma se voglio fare qualche cosa in pi�, posso fare cos�:
     foreach ($res as $index => $value) {
         $result[$index] = $value > 0;
     }
     //metto nell'array dei valori booleani
     return $result;
 }
Beispiel #10
0
 function permalinkExists($permalink)
 {
     parent::load($permalink);
     $rs = $this->db->execute($s = Query::generateSelectStm(array($this->table), array(), array(new WhereConstraint($this->table->getColumn(DB::POST_PERMALINK), Operator::EQUAL, $permalink)), array("count" => 2)));
     if ($this->db->num_rows() != 1) {
         throw new Exception("Si è verificato un errore. Riprovare.");
     }
     $row = $this->db->fetch_row();
     return $row[0] > 0;
 }
Beispiel #11
0
 private function loadWinners()
 {
     parent::load($contest);
     if (!is_subclass_of($contest, self::OBJECT_CLASS)) {
         throw new Exception("Attenzione! Il parametro di ricerca non è un contest.");
     }
     $s = "SELECT * FROM " . $this->table_cs->getName() . " WHERE " . DB::CONTEST_SUBSCRIBER_PLACEMENT . " IS NOT NULL ORDER BY " . DB::CONTEST_SUBSCRIBER_PLACEMENT . " ASC";
     $rs = $this->db->execute($s, $this->table_cs->getName(), $contest);
     $subscribers = array();
     while ($row = $this->db->fetch_result()) {
         require_once 'dao/PostDao.php';
         $postdao = new PostDao();
         $subscribers[] = $postdao->quickLoad(intval($row[CONTEST_SUBSCRIBER_POST]));
     }
     return $contest->setSubscribers($subscribers);
 }