News - last edited working; added future and past week relative dates
This commit is contained in:
@@ -12,7 +12,7 @@ class NewsController extends Controller
|
|||||||
// TODO: Include podcast
|
// TODO: Include podcast
|
||||||
private static $BASE_SQL = <<<QUERY
|
private static $BASE_SQL = <<<QUERY
|
||||||
SELECT `news`.`id`, `content`.`title`, `content`.`content`, `news`.`podcast`, `news`.`video`, `news`.`keywords`, `news`.`titlewithdate`,
|
SELECT `news`.`id`, `content`.`title`, `content`.`content`, `news`.`podcast`, `news`.`video`, `news`.`keywords`, `news`.`titlewithdate`,
|
||||||
`content`.`publishingdt` AS `published`, `content`.`creator`, `content`.`editingdt` AS `edited`, `content`.`editor`,
|
`news`.`creationdt` AS `published`, `content`.`creator`, `content`.`editingdt` AS `edited`, `content`.`editor`,
|
||||||
`content`.`showsource`, `sources`.`title` AS `source`, `sources`.`url` AS `source_url`,
|
`content`.`showsource`, `sources`.`title` AS `source`, `sources`.`url` AS `source_url`,
|
||||||
`themes`.`title` AS `theme`, `themes`.`thumbnail` AS `theme_thumbnail`, `regions`.`title` AS `region`
|
`themes`.`title` AS `theme`, `themes`.`thumbnail` AS `theme_thumbnail`, `regions`.`title` AS `region`
|
||||||
FROM `news`
|
FROM `news`
|
||||||
@@ -53,6 +53,8 @@ QUERY;
|
|||||||
|
|
||||||
$result = array();
|
$result = array();
|
||||||
foreach($newsItems as $newsItem) {
|
foreach($newsItems as $newsItem) {
|
||||||
|
// Note: content is stored in the database with an additional addslashes() - don't ask why, just remove it :)
|
||||||
|
$newsItem->content = stripslashes($newsItem->content);
|
||||||
$pictures = app('db')->select(self::$LOAD_IMAGES, ['newsId' => $newsItem->id]);
|
$pictures = app('db')->select(self::$LOAD_IMAGES, ['newsId' => $newsItem->id]);
|
||||||
$result[] = new \Model\NewsItem($newsItem, $pictures);
|
$result[] = new \Model\NewsItem($newsItem, $pictures);
|
||||||
}
|
}
|
||||||
@@ -71,6 +73,8 @@ QUERY;
|
|||||||
if(count($newsItem) != 1) {
|
if(count($newsItem) != 1) {
|
||||||
return abort(404);
|
return abort(404);
|
||||||
} else {
|
} else {
|
||||||
|
// Note: content is stored in the database with an additional addslashes() - don't ask why, just remove it :)
|
||||||
|
$newsItem[0]->content = stripslashes($newsItem[0]->content);
|
||||||
$images = app('db')->select(self::$LOAD_IMAGES, ['newsId' => $id]);
|
$images = app('db')->select(self::$LOAD_IMAGES, ['newsId' => $id]);
|
||||||
return response()->json(new \Model\NewsItem($newsItem[0], $images));
|
return response()->json(new \Model\NewsItem($newsItem[0], $images));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,11 @@ class NewsItem extends Model {
|
|||||||
parent::__construct($data);
|
parent::__construct($data);
|
||||||
parent::ConvertToDateTime($this->published);
|
parent::ConvertToDateTime($this->published);
|
||||||
parent::ConvertToDateTime($this->edited);
|
parent::ConvertToDateTime($this->edited);
|
||||||
|
|
||||||
|
if($this->edited && ($this->edited->getTimestamp() - $this->published->getTimestamp() < 1800 /* == 30 minutes */)) {
|
||||||
|
// If last edit was within grace period, consider it unedited (note: currently RES always saves edited == published on creation)
|
||||||
|
$this->edited = null;
|
||||||
|
}
|
||||||
|
|
||||||
$this->source = null;
|
$this->source = null;
|
||||||
if($data->source)
|
if($data->source)
|
||||||
|
|||||||
Reference in New Issue
Block a user