3 namespace CoreFramework\Reader\News;
5 // Import framework stuff
6 use CoreFramework\Factory\ObjectFactory;
7 use CoreFramework\Object\BaseFrameworkSystem;
8 use CoreFramework\Registry\Registerable;
9 use CoreFramework\Request\Requestable;
12 * A console news reader class reads news from database layer
14 * @author Roland Haeder <webmaster@shipsimu.org>
16 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
17 * @license GNU GPL 3.0 or any newer version
18 * @link http://www.shipsimu.org
20 * This program is free software: you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation, either version 3 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program. If not, see <http://www.gnu.org/licenses/>.
33 class ConsoleNewsReader extends BaseFrameworkSystem implements ReadableNews, Registerable {
35 * Protected constructor
39 protected function __construct () {
40 // Call parent constructor
41 parent::__construct(__CLASS__);
45 * Creates an instance of this reader by a provided request instance
47 * @param $requestInstance An instance of a Requestable class
48 * @return $readerInstance An instance of this reader class
50 public static final function createConsoleNewsReader (Requestable $requestInstance) {
52 $readerInstance = new ConsoleNewsReader();
54 // Set request instance
55 $readerInstance->setRequestInstance($requestInstance);
57 // Return prepared instance
58 return $readerInstance;
62 * Initializes this reader class by pre-fetching news depending on 'command'
63 * (outside or login area), which amount of news and how much to skip
67 public function initializeReader () {
68 // Get 'command' for saving some calls
69 $command = $this->getRequestInstance()->getRequestElement('command');
71 // First get a wrapper instance
72 $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('news_db_wrapper_class');
74 // Next create a searchable criteria instance
75 $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
77 // Add the command as criteria to it at lease
78 $criteriaInstance->addCriteria('command', $command);
80 // Add limitation from config
81 $criteriaInstance->setConfiguredLimit('news_' . $command . '_limit');
83 // Get a resultInstance back from the database
84 $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
86 // Save that resultInstance in this class
87 $this->setResultInstance($resultInstance);