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