Continued:
[core.git] / framework / main / classes / reader / class_ConsoleNewsReader.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\CoreFramework\Reader\News\Console;
4
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;
13
14 /**
15  * A console news reader class reads news from database layer
16  *
17  * @author              Roland Haeder <webmaster@shipsimu.org>
18  * @version             0.0.0
19  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2019 Core Developer Team
20  * @license             GNU GPL 3.0 or any newer version
21  * @link                http://www.shipsimu.org
22  *
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.
27  *
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.
32  *
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/>.
35  */
36 class ConsoleNewsReader extends BaseFrameworkSystem implements ReadableNews, Registerable {
37         /**
38          * Protected constructor
39          *
40          * @return      void
41          */
42         protected function __construct () {
43                 // Call parent constructor
44                 parent::__construct(__CLASS__);
45         }
46
47         /**
48          * Creates an instance of this reader by a provided request instance
49          *
50          * @param       $requestInstance        An instance of a Requestable class
51          * @return      $readerInstance         An instance of this reader class
52          */
53         public static final function createConsoleNewsReader (Requestable $requestInstance) {
54                 // Get a new instance
55                 $readerInstance = new ConsoleNewsReader();
56
57                 // Return prepared instance
58                 return $readerInstance;
59         }
60
61         /**
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
64          *
65          * @return      void
66          */
67         public function initializeReader () {
68                 // Get 'command' for saving some calls
69                 $command = FrameworkBootstrap::getRequestInstance()->getRequestElement('command');
70
71                 // First get a wrapper instance
72                 $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('news_db_wrapper_class');
73
74                 // Next create a searchable criteria instance
75                 $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
76
77                 // Add the command as criteria to it at lease
78                 $criteriaInstance->addCriteria('command', $command);
79
80                 // Add limitation from config
81                 $criteriaInstance->setConfiguredLimit('news_' . $command . '_limit');
82
83                 // Get a resultInstance back from the database
84                 $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
85
86                 // Save that resultInstance in this class
87                 $this->setResultInstance($resultInstance);
88         }
89
90 }