3 namespace Org\Mxchange\CoreFramework\Reader\News\Console;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
7 use Org\Mxchange\CoreFramework\Factory\Database\Wrapper\DatabaseWrapperFactory;
8 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
9 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
10 use Org\Mxchange\CoreFramework\Reader\News\ReadableNews;
11 use Org\Mxchange\CoreFramework\Registry\Registerable;
12 use Org\Mxchange\CoreFramework\Request\Requestable;
15 * A console news reader class reads news from database layer
17 * @author Roland Haeder <webmaster@shipsimu.org>
19 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
20 * @license GNU GPL 3.0 or any newer version
21 * @link http://www.shipsimu.org
23 * This program is free software: you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by
25 * the Free Software Foundation, either version 3 of the License, or
26 * (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
33 * You should have received a copy of the GNU General Public License
34 * along with this program. If not, see <http://www.gnu.org/licenses/>.
36 class ConsoleNewsReader extends BaseFrameworkSystem implements ReadableNews, Registerable {
38 * Protected constructor
42 protected function __construct () {
43 // Call parent constructor
44 parent::__construct(__CLASS__);
48 * Creates an instance of this reader by a provided request instance
50 * @param $requestInstance An instance of a Requestable class
51 * @return $readerInstance An instance of this reader class
53 public static final function createConsoleNewsReader (Requestable $requestInstance) {
55 $readerInstance = new ConsoleNewsReader();
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 = FrameworkBootstrap::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);