]> git.mxchange.org Git - core.git/blob - inc/main/classes/reader/class_DefaultNewsReader.php
Continued:
[core.git] / inc / main / classes / reader / class_DefaultNewsReader.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Reader\News;
4
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;
11
12 /**
13  * A default news reader class reads news from database layer
14  *
15  * @author              Roland Haeder <webmaster@shipsimu.org>
16  * @version             0.0.0
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
20  *
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.
25  *
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.
30  *
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/>.
33  */
34 class DefaultNewsReader extends BaseFrameworkSystem implements ReadableNews, Registerable {
35         /**
36          * Protected constructor
37          *
38          * @return      void
39          */
40         protected function __construct () {
41                 // Call parent constructor
42                 parent::__construct(__CLASS__);
43         }
44
45         /**
46          * Creates an instance of this reader by a provided request instance
47          *
48          * @param       $requestInstance        An instance of a Requestable class
49          * @return      $readerInstance         An instance of this reader class
50          */
51         public static final function createDefaultNewsReader (Requestable $requestInstance) {
52                 // Get a new instance
53                 $readerInstance = new DefaultNewsReader();
54
55                 // Set request instance
56                 $readerInstance->setRequestInstance($requestInstance);
57
58                 // Return prepared instance
59                 return $readerInstance;
60         }
61
62         /**
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
65          *
66          * @return      void
67          */
68         public function initializeReader () {
69                 // Get 'command' for saving some calls
70                 $command = $this->getRequestInstance()->getRequestElement('command');
71
72                 // First get a wrapper instance
73                 $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('news_db_wrapper_class');
74
75                 // Next create a searchable criteria instance
76                 $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
77
78                 // Add the page as criteria to it at lease
79                 $criteriaInstance->addCriteria('command', $command);
80
81                 // Add limitation from config
82                 $criteriaInstance->setConfiguredLimit('news_' . $command . '_limit');
83
84                 // Get a resultInstance back from the database
85                 $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
86
87                 // Save that resultInstance in this class
88                 $this->setResultInstance($resultInstance);
89         }
90
91 }