function createFromDBRow($row) { $type = $row[DB::POST_TYPE]; if ($type == Post::NEWS || $type == Post::VIDEOREP) { $content = $row[DB::POST_CONTENT]; } else { $content = unserialize($row[DB::POST_CONTENT]); } $data = array("title" => $row[DB::POST_TITLE], "subtitle" => $row[DB::POST_SUBTITLE], "headline" => $row[DB::POST_HEADLINE], "author" => intval($row[DB::POST_AUTHOR]), "tags" => $row[DB::POST_TAGS], "categories" => $row[DB::POST_CATEGORIES], "content" => $content, "visible" => $row[DB::POST_VISIBLE] > 0, "type" => $type, "place" => $row[DB::POST_PLACE]); if ($type == Post::NEWS) { require_once "dataobject/News.php"; $p = new News($data); } else { if ($type == Post::VIDEOREP) { require_once "dataobject/VideoReportage.php"; $p = new VideoReportage($data); } else { if ($type == Post::ALBUM) { require_once "dataobject/Album.php"; $p = new Album($data); } else { if ($type == Post::MAGAZINE) { require_once "dataobject/Magazine.php"; $p = new Magazine($data); } else { if ($type == Post::PHOTOREP) { require_once "dataobject/PhotoReportage.php"; $p = new PhotoReportage($data); } else { if ($type == Post::PLAYLIST) { require_once "dataobject/Playlist.php"; $p = new Playlist($data); } else { if ($type == Post::COLLECTION) { require_once "dataobject/Collection.php"; $p = new Collection($data); } else { throw new Exception("Errore!!! Il tipo inserito non esiste!"); } } } } } } } $p->setCreationDate(date_timestamp_get(date_create_from_format("Y-m-d G:i:s", $row[DB::POST_CREATION_DATE]))); $p->setID(intval($row[DB::POST_ID])); if (!is_null($row[DB::POST_MODIFICATION_DATE])) { $p->setModificationDate(date_timestamp_get(date_create_from_format("Y-m-d G:i:s", $row[DB::POST_MODIFICATION_DATE]))); } else { $p->setModificationDate(date_timestamp_get(date_create_from_format("Y-m-d G:i:s", $row[DB::POST_CREATION_DATE]))); } if ($this->loadComments) { require_once 'dao/CommentDao.php'; $commentDao = new CommentDao(); $commentDao->loadAll($p); } $p->setPermalink($row[DB::POST_PERMALINK]); require_once 'dao/VoteDao.php'; $voteDao = new VoteDao(); $p->setVote($voteDao->getVote($p)); //setto lo stato $p->setEditable($row[DB::EDITABLE])->setRemovable($row[DB::REMOVABLE]); $p->setBlackContent($row[DB::BLACK_CONTENT])->setRedContent($row[DB::RED_CONTENT])->setYellowContent($row[DB::YELLOW_CONTENT])->setAutoBlackContent($row[DB::AUTO_BLACK_CONTENT]); $user = Session::getUser(); if ($this->loadReports && AuthorizationManager::canUserDo(AuthorizationManager::READ_REPORTS, $r)) { require_once 'dao/ReportDao.php'; $reportDao = new ReportDao(); $reportDao->loadAll($p); } $p->setAccessCount($this->getAccessCount($p)); return $p; }
/** * Aggiunge un voto al post selezionato e lo salva nel database. * * @param author: id dell'autore del voto * @param post: variabile di tipo Post * @param comment: il voto * @return: post aggiornato. */ static function votePost($author, $post, $vote) { require_once "dao/VoteDao.php"; $votedao = new VoteDao(); $votedao->save($post, $author, $vote); $v = $votedao->getVote($post); return $post->setVote($v); }