Hello! I am attempting to bring the 1.3.4 news mod to 1.3.6 but have hit a snag.
So far there's no adminCP support, but I successfully have it showing on the news page with pagination:
But for some reason I can't get the view page working. And I have no idea why lol. I get an error saying it doesn't exist on the server.
The URL is news/view/(newsID)
Here are my files, any help would be appreciated lol:
model/domainmodel/news.php:
model/domainmodel/newscomments.php:
newscontroller.php:
newsview.php:
As you can see I'm trying to use view($nid) to call the ID in the URL but even news/view doesn't work. So I'm a little lost. I think it has to do with the __construct but I don't know what's wrong with it. Thank you!
So far there's no adminCP support, but I successfully have it showing on the news page with pagination:

But for some reason I can't get the view page working. And I have no idea why lol. I get an error saying it doesn't exist on the server.
The URL is news/view/(newsID)

Here are my files, any help would be appreciated lol:
model/domainmodel/news.php:
PHP:
<?php
namespace Model\DomainModel;
use ArrayObject;
use Resource\Core\Model;
use Resource\Core\Registry;
use Resource\Exception\InvalidIDException;
use Resource\Native\MysString;
use Resource\Utility\Date;
class News extends Model{
protected $nid;
protected $user;
protected $title;
protected $content;
protected $date;
protected $posted;
protected $allowcomments;
public function __construct($nid, $dto = NULL){
$mysidia = Registry::get("mysidia");
if(!$dto){
$whereClause = "nid = '{$nid}'";
$dto = $mysidia->db->select("news",array(),$whereClause)->fetchObject();
if(!is_object($dto)) throw new InvalidIDException("News {$nid} does not exist...");
}
parent::__construct($dto);
}
protected function createFromDTO($dto){
parent::createFromDTO($dto);
$this->date = new Date($dto->date);
}
public function getID(){
return $this->nid;
}
public function getProfile(){
return new UserProfile($this->user);
}
public function getUserID($fetchMode = ""){
if($fetchMode == Model::MODEL) return new Member($this->user);
else return $this->user;
}
public function getUsername(){
if(!$this->user) return NULL;
return $this->getUserID(Model::MODEL)->getUsername();
}
public function getTitle(){
return $this->title;
}
public function getContent(){
return $this->content;
}
public function getDate($format = NULL){
return $format ? $this->date->format($format) : $this->date;
}
public function getPosted(){
return $this->posted;
}
public function getAllowComment(){
return $this->allowcomments;
}
public function changeAllowComment(){
$mysidia = Registry::get("mysidia");
if($this->allowcomments != $allow){
$this->allowcomments = $allow;
$this->save("allowcomments", $this->allowcomments);
}
}
public function addComment($content, $date, $user){
$mysidia = Registry::get("mysidia");
if($this->nid != 0) return FALSE;
else{
$date = new Date;
$mysidia->db->insert("newscomments", ["cid" => NULL, "nid" => $this->nid, "uid" => $user->getID(), "comment" => $this->format($content), "date" => $date->format("Y-m-d H:i:s")]);
}
return TRUE;
}
public function format($text){
return preg_replace('`<((script)|(style))[^>]*>[^<]*</\1>`si', '', stripslashes(html_entity_decode($text)));
}
public function saveDraft(){
$mysidia = Registry::get("mysidia");
$todayDate = $this->todayDate();
if($this->date != $todayDate) $this->newDate($todayDate);
$this->posted = "no";
$this->save("posted", $this->posted);
}
public function post(){
$mysidia = Registry::get("mysidia");
$todayDate = $this->todayDate();
if($this->date != $todayDate) $this->newDate($todayDate);
$this->posted = "yes";
$this->save("posted", $this->posted);
}
public function editContent($content){
$mysidia = Registry::get("mysidia");
$this->content = $content;
$this->save("content", $this->content);
}
public function editTitle($title){
$mysidia = Registry::get("mysidia");
$this->title = $title;
$this->save("title", $this->title);
}
public function todayDate(){
$dateTime = new DateTime;
$date = $dateTime->format('Y-m-d H:i:s');
return $date;
}
public function newDate($date){
$mysidia = Registry::get("mysidia");
$this->date = $date;
$this->save("date", $this->date);
}
public function getCommentNumber(){
$mysidia = Registry::get("mysidia");
$stmt = $mysidia->db->select("newscomments", ["cid"], "nid = '{$this->nid}'");
return $stmt->rowCount();
}
public function getComments(){
$mysidia = Registry::get("mysidia");
$stmt = $mysidia->db->join("news", "news.nid = newscomments.nid")
->select("newscomments", [], "nid = '{$this->nid}'");
$comments = new ArrayObject;
while($dto = $stmt->fetchObject()){
$comments[] = new NewsComments($dto->nid, $dto);
}
return $comments;
}
protected function save($field, $value){
$mysidia = Registry::get("mysidia");
$mysidia->db->update("news", [$field => $value], "nid='{$this->nid}'");
}
}
model/domainmodel/newscomments.php:
PHP:
<?php
namespace Model\DomainModel;
use Resource\Core\Model;
use Resource\Core\Registry;
use Resource\Exception\InvalidIDException;
use Resource\Utility\Date;
class NewsComments extends Model{
protected $cid;
protected $nid;
protected $uid;
protected $comment;
protected $date;
public function __construct($cid, $dto = NULL){
$mysidia = Registry::get("mysidia");
if(!$dto){
$prefix = constant("PREFIX");
$dto = $mysidia->db->join("news", "news.nid = newscomments.nid")
->select("newscomments", [], "{$prefix}newscomments.cid = :cid", ["cid" => $cid])->fetchObject();
if(!is_object($dto)) throw new InvalidIDException("The comment ID {$cid} does not exist...");
}
$this->createFromDTO($dto);
}
protected function createFromDTO($dto){
parent::createFromDTO($dto);
$this->date = new Date($dto->date);
}
public function getID(){
return $this->cid;
}
public function getNewsID(){
return $this->nid;
}
public function getUserID($fetchMode = ""){
if($fetchMode == Model::MODEL) return new Member($this->user);
else return $this->user;
}
public function getUsername(){
if(!$this->user) return NULL;
return $this->getUserID(Model::MODEL)->getUsername();
}
public function getComments(){
return $this->comment;
}
public function getDate($format = NULL){
return $format ? $this->date->format($format) : $this->date;
}
public function setComments($comment){
$mysidia = Registry::get("mysidia");
$this->comment = $comment;
$this->save("comment", $this->comment);
}
public function todayDate(){
$dateTime = new DateTime;
$date = $dateTime->format('Y-m-d H:i:s');
return $date;
}
public function newDate($date){
$mysidia = Registry::get("mysidia");
$this->date = $date;
$mysidia->db->update("newscomments",["date" => $this->date],"cid = {$this->cid}");
}
protected function save($field, $value){
$mysidia = Registry::get("mysidia");
$mysidia->db->update("newscomments", [$field => $value], "cid='{$this->cid}'");
}
}
newscontroller.php:
PHP:
<?php
namespace Controller\Main;
use Model\DomainModel\News;
use Model\DomainModel\NewsComments;
use Resource\Core\AppController;
use Resource\Core\Registry;
use Resource\Core\Pagination;
use Resource\Collection\ArrayList;
use Resource\Exception\InvalidIDException;
use Resource\Exception\NoPermissionException;
class NewsController extends AppController{
public function __construct(){
parent::__construct("member");
}
public function index(){
$mysidia = Registry::get("mysidia");
$total = $mysidia->db->select("news", ["nid"], "posted='yes'")->rowCount();
if($total == 0) throw new NoPermissionException("There is currently no news to display!");
$pagination = new Pagination($total, $mysidia->settings->pagination,
"news", $mysidia->input->get("page"));
$stmt = $mysidia->db->select("news", [], "posted='yes' ORDER BY nid ASC LIMIT {$pagination->getLimit()},{$pagination->getRowsperPage()}");
$news = new ArrayList;
while($dto = $stmt->fetchObject()){
$news->add(new News($dto->nid, $dto));
}
$this->setField("pagination", $pagination);
$this->setField("news", $news);
}
public function view($nid){
$mysidia = Registry::get("mysidia");
$this->news = new News($nid);
}
}
?>
newsview.php:
PHP:
<?php
namespace View\Main;
use Smarty;
use Resource\Core\Registry;
use Resource\Core\View;
use Resource\Core\Model;
use Resource\Model\DomainModel;
use Model\DomainModel\News;
use Model\DomainModel\NewsComments;
use Model\DomainModel\UserProfile;
use Resource\GUI\Document\Comment;
use Resource\GUI\Container\FieldSet;
use Resource\Native\MysString;
class NewsView extends View{
public function index(){
$mysidia = Registry::get("mysidia");
$home = SCRIPTPATH."/";
$pagination = $this->getField("pagination");
$news = $this->getField("news");
$document = $this->document;
$document->setTitle("News");
$iterator = $news->iterator();
while($iterator->hasNext()){
$news = $iterator->next();
$comments = $news->getCommentNumber();
$document->add(new Comment("<div id='news' class='news'>"));
$document->add(new Comment("<span class='date'>Date: {$news->getDate()}</span><br>",FALSE));
$document->add(new Comment("<span class='title'><a href='/news/view/{$news->getID()}'>{$news->getTitle()}</a></span>",FALSE));
$document->add(new Comment("<span class='author'>by <a href='/profile/view/{$news->getUserID()}' target='_blank'>{$news->getUsername()}</a></span>",FALSE));
$document->add(new Comment("<span class='comment'><a href='/news/view/{$news->getID()}'>Comments({$comments})</a></span><br>",FALSE));
$document->add(new Comment("<span class='content'><img class='authorimg' src='{$home}{$news->getProfile()->getAvatar()}'>{$news->getContent()}</span></div>"));
$document->add(new Comment('</br></br>'));
}
$document->addLangvar($pagination->showPage());
}
public function view(){
$mysidia = Registry::get("mysidia");
$news = $this->getField("news");
$document = $this->document;
$document->setTitle("News");
$document->add(new Comment('Test'));
}
}
As you can see I'm trying to use view($nid) to call the ID in the URL but even news/view doesn't work. So I'm a little lost. I think it has to do with the __construct but I don't know what's wrong with it. Thank you!