cac2836006c5c558a44ad3d29ebe3c4629dbfd6b
[core.git] / inc / main / classes / reader / class_ConsoleNewsReader.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Reader\News;
4
5 // Import framework stuff
6 use CoreFramework\Factory\ObjectFactory;
7 use CoreFramework\Object\BaseFrameworkSystem;
8 use CoreFramework\Registry\Registerable;
9 use CoreFramework\Request\Requestable;
10
11 /**
12  * A console news reader class reads news from database layer
13  *
14  * @author              Roland Haeder <webmaster@shipsimu.org>
15  * @version             0.0.0
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
19  *
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.
24  *
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.
29  *
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/>.
32  */
33 class ConsoleNewsReader extends BaseFrameworkSystem implements ReadableNews, Registerable {
34         /**
35          * Protected constructor
36          *
37          * @return      void
38          */
39         protected function __construct () {
40                 // Call parent constructor
41                 parent::__construct(__CLASS__);
42         }
43
44         /**
45          * Creates an instance of this reader by a provided request instance
46          *
47          * @param       $requestInstance        An instance of a Requestable class
48          * @return      $readerInstance         An instance of this reader class
49          */
50         public static final function createConsoleNewsReader (Requestable $requestInstance) {
51                 // Get a new instance
52                 $readerInstance = new ConsoleNewsReader();
53
54                 // Set request instance
55                 $readerInstance->setRequestInstance($requestInstance);
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 = $this->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 }