mirror of
https://github.com/Karaka-Management/oms-News.git
synced 2026-02-16 08:28:42 +00:00
Cleanup and function pull out
This commit is contained in:
parent
a9a95d3dd2
commit
5b293282fa
|
|
@ -48,21 +48,20 @@ class Installer extends InstallerAbstract
|
||||||
`news_title` varchar(250) NOT NULL,
|
`news_title` varchar(250) NOT NULL,
|
||||||
`news_featured` tinyint(1) DEFAULT NULL,
|
`news_featured` tinyint(1) DEFAULT NULL,
|
||||||
`news_content` text NOT NULL,
|
`news_content` text NOT NULL,
|
||||||
`news_plain` text NOT NULL,
|
|
||||||
`news_type` tinyint(2) NOT NULL,
|
`news_type` tinyint(2) NOT NULL,
|
||||||
`news_status` tinyint(1) NOT NULL,
|
`news_status` tinyint(1) NOT NULL,
|
||||||
`news_lang` varchar(2) NOT NULL,
|
`news_lang` varchar(2) NOT NULL,
|
||||||
`news_publish` datetime NOT NULL,
|
`news_publish` datetime NOT NULL,
|
||||||
`news_created` datetime NOT NULL,
|
`news_created_at` datetime NOT NULL,
|
||||||
`news_author` int(11) NOT NULL,
|
`news_created_by` int(11) NOT NULL,
|
||||||
PRIMARY KEY (`news_id`),
|
PRIMARY KEY (`news_id`),
|
||||||
KEY `news_author` (`news_author`)
|
KEY `news_created_by` (`news_created_by`)
|
||||||
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'
|
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'
|
||||||
)->execute();
|
)->execute();
|
||||||
|
|
||||||
$dbPool->get('core')->con->prepare(
|
$dbPool->get('core')->con->prepare(
|
||||||
'ALTER TABLE `' . $dbPool->get('core')->prefix . 'news`
|
'ALTER TABLE `' . $dbPool->get('core')->prefix . 'news`
|
||||||
ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'news_ibfk_1` FOREIGN KEY (`news_author`) REFERENCES `' . $dbPool->get('core')->prefix . 'account` (`account_id`);'
|
ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'news_ibfk_1` FOREIGN KEY (`news_created_by`) REFERENCES `' . $dbPool->get('core')->prefix . 'account` (`account_id`);'
|
||||||
)->execute();
|
)->execute();
|
||||||
|
|
||||||
$dbPool->get('core')->con->prepare(
|
$dbPool->get('core')->con->prepare(
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ class Controller extends ModuleAbstract implements WebInterface
|
||||||
{
|
{
|
||||||
$view = new View($this->app, $request, $response);
|
$view = new View($this->app, $request, $response);
|
||||||
$view->setTemplate('/Modules/News/Theme/Backend/news-dashboard');
|
$view->setTemplate('/Modules/News/Theme/Backend/news-dashboard');
|
||||||
$view->addData('nav', $this->createNavigation(1000701001, $request, $response));
|
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000701001, $request, $response));
|
||||||
|
|
||||||
$news = $this->getNewsListR(20, 0, 'news.news_publish', 'DESC', $this->app->accountManager->get($request->getAccount()));
|
$news = $this->getNewsListR(20, 0, 'news.news_publish', 'DESC', $this->app->accountManager->get($request->getAccount()));
|
||||||
$headline = $this->getHeadlineListR(20, 0, 'news.news_publish', 'ASC', $this->app->accountManager->get($request->getAccount()));
|
$headline = $this->getHeadlineListR(20, 0, 'news.news_publish', 'ASC', $this->app->accountManager->get($request->getAccount()));
|
||||||
|
|
@ -145,7 +145,7 @@ class Controller extends ModuleAbstract implements WebInterface
|
||||||
{
|
{
|
||||||
$view = new View($this->app, $request, $response);
|
$view = new View($this->app, $request, $response);
|
||||||
$view->setTemplate('/Modules/News/Theme/Backend/news-single');
|
$view->setTemplate('/Modules/News/Theme/Backend/news-single');
|
||||||
$view->addData('nav', $this->createNavigation(1000701001, $request, $response));
|
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000701001, $request, $response));
|
||||||
|
|
||||||
$newsArticleMapper = new NewsArticleMapper($this->app->dbPool->get());
|
$newsArticleMapper = new NewsArticleMapper($this->app->dbPool->get());
|
||||||
$article = $newsArticleMapper->get((int) $request->getData('id'));
|
$article = $newsArticleMapper->get((int) $request->getData('id'));
|
||||||
|
|
@ -168,7 +168,7 @@ class Controller extends ModuleAbstract implements WebInterface
|
||||||
{
|
{
|
||||||
$view = new View($this->app, $request, $response);
|
$view = new View($this->app, $request, $response);
|
||||||
$view->setTemplate('/Modules/News/Theme/Backend/news-archive');
|
$view->setTemplate('/Modules/News/Theme/Backend/news-archive');
|
||||||
$view->addData('nav', $this->createNavigation(1000701001, $request, $response));
|
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000701001, $request, $response));
|
||||||
|
|
||||||
return $view;
|
return $view;
|
||||||
}
|
}
|
||||||
|
|
@ -187,7 +187,7 @@ class Controller extends ModuleAbstract implements WebInterface
|
||||||
{
|
{
|
||||||
$view = new View($this->app, $request, $response);
|
$view = new View($this->app, $request, $response);
|
||||||
$view->setTemplate('/Modules/News/Theme/Backend/news-create');
|
$view->setTemplate('/Modules/News/Theme/Backend/news-create');
|
||||||
$view->addData('nav', $this->createNavigation(1000701001, $request, $response));
|
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1000701001, $request, $response));
|
||||||
|
|
||||||
return $view;
|
return $view;
|
||||||
}
|
}
|
||||||
|
|
@ -283,25 +283,4 @@ class Controller extends ModuleAbstract implements WebInterface
|
||||||
return $newsArticleMapper->getAllByQuery($query);
|
return $newsArticleMapper->getAllByQuery($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $pageId Page/parent Id for navigation
|
|
||||||
* @param RequestAbstract $request Request
|
|
||||||
* @param ResponseAbstract $response Response
|
|
||||||
*
|
|
||||||
* @return RenderableInterface
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
||||||
*/
|
|
||||||
private function createNavigation(int $pageId, RequestAbstract $request, ResponseAbstract $response)
|
|
||||||
{
|
|
||||||
$nav = Navigation::getInstance($request, $this->app->dbPool);
|
|
||||||
$navView = new NavigationView($this->app, $request, $response);
|
|
||||||
$navView->setTemplate('/Modules/Navigation/Theme/Backend/mid');
|
|
||||||
$navView->setNav($nav->getNav());
|
|
||||||
$navView->setLanguage($request->getL11n()->getLanguage());
|
|
||||||
$navView->setParent($pageId);
|
|
||||||
|
|
||||||
return $navView;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@
|
||||||
*/
|
*/
|
||||||
namespace Modules\News\Models;
|
namespace Modules\News\Models;
|
||||||
|
|
||||||
|
use phpOMS\Datatypes\Exception\InvalidEnumValue;
|
||||||
use phpOMS\Localization\ISO639Enum;
|
use phpOMS\Localization\ISO639x1Enum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* News article class.
|
* News article class.
|
||||||
|
|
@ -40,14 +40,6 @@ class NewsArticle
|
||||||
*/
|
*/
|
||||||
private $id = 0;
|
private $id = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* Author ID.
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
private $author = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Title.
|
* Title.
|
||||||
*
|
*
|
||||||
|
|
@ -64,14 +56,6 @@ class NewsArticle
|
||||||
*/
|
*/
|
||||||
private $content = '';
|
private $content = '';
|
||||||
|
|
||||||
/**
|
|
||||||
* Plain.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
private $plain = '';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* News type.
|
* News type.
|
||||||
*
|
*
|
||||||
|
|
@ -86,7 +70,7 @@ class NewsArticle
|
||||||
* @var int
|
* @var int
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private $status = NewsStatus::VISIBLE;
|
private $status = NewsStatus::DRAFT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Language.
|
* Language.
|
||||||
|
|
@ -94,7 +78,7 @@ class NewsArticle
|
||||||
* @var string
|
* @var string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private $lang = ISO639Enum::_EN;
|
private $language = ISO639x1Enum::_EN;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created.
|
* Created.
|
||||||
|
|
@ -102,7 +86,15 @@ class NewsArticle
|
||||||
* @var \DateTime
|
* @var \DateTime
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private $created = null;
|
private $createdAt = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creator.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private $createdBy = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Publish.
|
* Publish.
|
||||||
|
|
@ -128,21 +120,10 @@ class NewsArticle
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->created = new \DateTime('NOW');
|
$this->createdAt = new \DateTime('NOW');
|
||||||
$this->publish = new \DateTime('NOW');
|
$this->publish = new \DateTime('NOW');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
||||||
*/
|
|
||||||
public function getAuthor() : int
|
|
||||||
{
|
|
||||||
return $this->author;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
|
|
@ -173,9 +154,9 @@ class NewsArticle
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
*/
|
*/
|
||||||
public function getCreated() : \DateTime
|
public function getCreatedAt() : \DateTime
|
||||||
{
|
{
|
||||||
return $this->created;
|
return $this->createdAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -189,19 +170,6 @@ class NewsArticle
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $id Id
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
||||||
*/
|
|
||||||
public function setId(int $id)
|
|
||||||
{
|
|
||||||
$this->id = $id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
|
|
@ -210,31 +178,7 @@ class NewsArticle
|
||||||
*/
|
*/
|
||||||
public function getLanguage() : string
|
public function getLanguage() : string
|
||||||
{
|
{
|
||||||
return $this->lang;
|
return $this->language;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
||||||
*/
|
|
||||||
public function getPlain() : string
|
|
||||||
{
|
|
||||||
return $this->plain;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $plain
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
||||||
*/
|
|
||||||
public function setPlain(string $plain)
|
|
||||||
{
|
|
||||||
$this->plain = $plain;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -249,16 +193,20 @@ class NewsArticle
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $lang
|
* @param string $language
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
*/
|
*/
|
||||||
public function setLang(string $lang)
|
public function setLanguage(string $language)
|
||||||
{
|
{
|
||||||
$this->lang = $lang;
|
if(!ISO639x1Enum::isValidValue($language)) {
|
||||||
|
throw new InvalidEnumValue($language);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->language = $language;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -275,29 +223,38 @@ class NewsArticle
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \DateTime $created
|
* @return int
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
*/
|
*/
|
||||||
public function setCreated(\DateTime $created)
|
public function getCreatedBy() : int
|
||||||
{
|
{
|
||||||
$this->created = $created;
|
return $this->createdBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $author
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public function setCreatedBy(int $id)
|
||||||
|
{
|
||||||
|
$this->createdBy = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \DateTime $createdAt
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
*/
|
*/
|
||||||
public function setAuthor(int $author)
|
public function setCreatedAt(\DateTime $createdAt)
|
||||||
{
|
{
|
||||||
$this->author = $author;
|
$this->createdAt = $createdAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -345,6 +302,10 @@ class NewsArticle
|
||||||
*/
|
*/
|
||||||
public function setType(int $type)
|
public function setType(int $type)
|
||||||
{
|
{
|
||||||
|
if(!NewsType::isValidValue($type)) {
|
||||||
|
throw new InvalidEnumValue($type);
|
||||||
|
}
|
||||||
|
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -364,11 +325,17 @@ class NewsArticle
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
|
* @throws
|
||||||
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
*/
|
*/
|
||||||
public function setStatus(int $status)
|
public function setStatus(int $status)
|
||||||
{
|
{
|
||||||
|
if(!NewsStatus::isValidValue($status)) {
|
||||||
|
throw new InvalidEnumValue($status);
|
||||||
|
}
|
||||||
|
|
||||||
$this->status = $status;
|
$this->status = $status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,16 +29,16 @@ class NewsArticleMapper extends DataMapperAbstract
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
static protected $columns = [
|
static protected $columns = [
|
||||||
'news_id' => ['name' => 'news_id', 'type' => 'int', 'internal' => 'id'],
|
'news_id' => ['name' => 'news_id', 'type' => 'int', 'internal' => 'id'],
|
||||||
'news_author' => ['name' => 'news_author', 'type' => 'string', 'internal' => 'author'],
|
'news_created_by' => ['name' => 'news_created_by', 'type' => 'string', 'internal' => 'createdBy'],
|
||||||
'news_publish' => ['name' => 'news_publish', 'type' => 'DateTime', 'internal' => 'publish'],
|
'news_publish' => ['name' => 'news_publish', 'type' => 'DateTime', 'internal' => 'publish'],
|
||||||
'news_title' => ['name' => 'news_title', 'type' => 'string', 'internal' => 'title'],
|
'news_title' => ['name' => 'news_title', 'type' => 'string', 'internal' => 'title'],
|
||||||
'news_plain' => ['name' => 'news_plain', 'type' => 'string', 'internal' => 'plain'],
|
'news_content' => ['name' => 'news_content', 'type' => 'string', 'internal' => 'content'],
|
||||||
'news_content' => ['name' => 'news_content', 'type' => 'string', 'internal' => 'content'],
|
'news_lang' => ['name' => 'news_lang', 'type' => 'string', 'internal' => 'language'],
|
||||||
'news_status' => ['name' => 'news_status', 'type' => 'int', 'internal' => 'status'],
|
'news_status' => ['name' => 'news_status', 'type' => 'int', 'internal' => 'status'],
|
||||||
'news_type' => ['name' => 'news_type', 'type' => 'int', 'internal' => 'type'],
|
'news_type' => ['name' => 'news_type', 'type' => 'int', 'internal' => 'type'],
|
||||||
'news_featured' => ['name' => 'news_featured', 'type' => 'bool', 'internal' => 'featured'],
|
'news_featured' => ['name' => 'news_featured', 'type' => 'bool', 'internal' => 'featured'],
|
||||||
'news_created' => ['name' => 'news_created', 'type' => 'DateTime', 'internal' => 'created'],
|
'news_created_at' => ['name' => 'news_created_at', 'type' => 'DateTime', 'internal' => 'createdAt'],
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -55,7 +55,7 @@ class NewsArticleMapper extends DataMapperAbstract
|
||||||
* @var string
|
* @var string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static $primaryField = 'id';
|
protected static $primaryField = 'news_id';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create article.
|
* Create article.
|
||||||
|
|
@ -73,20 +73,20 @@ class NewsArticleMapper extends DataMapperAbstract
|
||||||
$objId = parent::create($obj);
|
$objId = parent::create($obj);
|
||||||
$query = new Builder($this->db);
|
$query = new Builder($this->db);
|
||||||
$query->prefix($this->db->getPrefix())
|
$query->prefix($this->db->getPrefix())
|
||||||
->insert(
|
->insert(
|
||||||
'account_permission_account',
|
'account_permission_account',
|
||||||
'account_permission_from',
|
'account_permission_from',
|
||||||
'account_permission_for',
|
'account_permission_for',
|
||||||
'account_permission_id1',
|
'account_permission_id1',
|
||||||
'account_permission_id2',
|
'account_permission_id2',
|
||||||
'account_permission_r',
|
'account_permission_r',
|
||||||
'account_permission_w',
|
'account_permission_w',
|
||||||
'account_permission_m',
|
'account_permission_m',
|
||||||
'account_permission_d',
|
'account_permission_d',
|
||||||
'account_permission_p'
|
'account_permission_p'
|
||||||
)
|
)
|
||||||
->into('account_permission')
|
->into('account_permission')
|
||||||
->values($obj->getAuthor(), 'news', 'news', 1, $objId, 1, 1, 1, 1, 1);
|
->values($obj->getCreatedBy(), 'news', 'news', 1, $objId, 1, 1, 1, 1, 1);
|
||||||
|
|
||||||
$this->db->con->prepare($query->toSql())->execute();
|
$this->db->con->prepare($query->toSql())->execute();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|
@ -109,9 +109,9 @@ class NewsArticleMapper extends DataMapperAbstract
|
||||||
public function find(...$columns) : Builder
|
public function find(...$columns) : Builder
|
||||||
{
|
{
|
||||||
return parent::find(...$columns)->from('account_permission')
|
return parent::find(...$columns)->from('account_permission')
|
||||||
->where('account_permission.account_permission_for', '=', 'news')
|
->where('account_permission.account_permission_for', '=', 'news')
|
||||||
->where('account_permission.account_permission_id1', '=', 1)
|
->where('account_permission.account_permission_id1', '=', 1)
|
||||||
->where('news.news_id', '=', new Column('account_permission.account_permission_id2'))
|
->where('news.news_id', '=', new Column('account_permission.account_permission_id2'))
|
||||||
->where('account_permission.account_permission_r', '=', 1);
|
->where('account_permission.account_permission_r', '=', 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,106 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Orange Management
|
|
||||||
*
|
|
||||||
* PHP Version 7.0
|
|
||||||
*
|
|
||||||
* @category TBD
|
|
||||||
* @package TBD
|
|
||||||
* @author OMS Development Team <dev@oms.com>
|
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
||||||
* @copyright 2013 Dennis Eichhorn
|
|
||||||
* @license OMS License 1.0
|
|
||||||
* @version 1.0.0
|
|
||||||
* @link http://orange-management.com
|
|
||||||
*/
|
|
||||||
namespace Modules\News\Models;
|
|
||||||
|
|
||||||
use phpOMS\DataStorage\Database\DatabaseType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* News list class.
|
|
||||||
*
|
|
||||||
* @category Modules
|
|
||||||
* @package Modules\News
|
|
||||||
* @author OMS Development Team <dev@oms.com>
|
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
||||||
* @license OMS License 1.0
|
|
||||||
* @link http://orange-management.com
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
class NewsList
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Database instance.
|
|
||||||
*
|
|
||||||
* @var \phpOMS\DataStorage\Database\Database
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
private $dbPool = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* @param \phpOMS\DataStorage\Database\Pool $dbPool Database pool instance
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
||||||
*/
|
|
||||||
public function __construct($dbPool)
|
|
||||||
{
|
|
||||||
$this->dbPool = $dbPool;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all news.
|
|
||||||
*
|
|
||||||
* This function gets all accounts in a range
|
|
||||||
*
|
|
||||||
* @param array $filter Filter for search results
|
|
||||||
* @param int $offset Offset for first account
|
|
||||||
* @param int $limit Limit for results
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
||||||
*/
|
|
||||||
public function getList($filter = null, $offset = 0, $limit = 100)
|
|
||||||
{
|
|
||||||
$result = null;
|
|
||||||
|
|
||||||
switch ($this->dbPool->get('core')->getType()) {
|
|
||||||
case DatabaseType::MYSQL:
|
|
||||||
$search = $this->dbPool->get('core')->generate_sql_filter($filter, true);
|
|
||||||
|
|
||||||
// SQL_CALC_FOUND_ROWS
|
|
||||||
$sth = $this->dbPool->get('core')->con->prepare(
|
|
||||||
'SELECT DISTINCT
|
|
||||||
`' . $this->dbPool->get('core')->prefix . 'news`.*,
|
|
||||||
`' . $this->dbPool->get('core')->prefix . 'account_data`.`name1`,
|
|
||||||
`' . $this->dbPool->get('core')->prefix . 'account_data`.`name2`,
|
|
||||||
`' . $this->dbPool->get('core')->prefix . 'account_data`.`name3`
|
|
||||||
FROM
|
|
||||||
`' . $this->dbPool->get('core')->prefix . 'news`
|
|
||||||
LEFT JOIN `' . $this->dbPool->get('core')->prefix . 'account_data`
|
|
||||||
ON `' . $this->dbPool->get('core')->prefix . 'news`.`news_author` = `' . $this->dbPool->get('core')->prefix . 'account_data`.`account`
|
|
||||||
GROUP BY `' . $this->dbPool->get('core')->prefix . 'news`.`news_id` '
|
|
||||||
. $search . 'LIMIT ' . $offset . ',' . $limit
|
|
||||||
);
|
|
||||||
$sth->execute();
|
|
||||||
|
|
||||||
$result['list'] = $sth->fetchAll();
|
|
||||||
|
|
||||||
$sth = $this->dbPool->get('core')->con->prepare(
|
|
||||||
'SELECT FOUND_ROWS();'
|
|
||||||
);
|
|
||||||
$sth->execute();
|
|
||||||
|
|
||||||
$result['count'] = $sth->fetchAll()[0][0];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user