Imported HelpableTemplate
[core.git] / framework / main / classes / discovery / payment / class_LocalPaymentDiscovery.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Discovery\Payment;
4
5 // Import framework stuff
6 use CoreFramework\Factory\Database\Wrapper\DatabaseWrapperFactory;
7 use CoreFramework\Factory\ObjectFactory;
8 use CoreFramework\Filter\Filterable;
9 use CoreFramework\Helper\Template\HelpableTemplate;
10 use CoreFramework\Registry\Registerable;
11 use CoreFramework\Request\Requestable;
12
13 /**
14  * A local payment discovery class. This class looks in local database for
15  * registered payment types and like all the others it at least returns the
16  * money bank transfer type.
17  *
18  * @author              Roland Haeder <webmaster@shipsimu.org>
19  * @version             0.0.0
20  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
21  * @license             GNU GPL 3.0 or any newer version
22  * @link                http://www.shipsimu.org
23  *
24  * This program is free software: you can redistribute it and/or modify
25  * it under the terms of the GNU General Public License as published by
26  * the Free Software Foundation, either version 3 of the License, or
27  * (at your option) any later version.
28  *
29  * This program is distributed in the hope that it will be useful,
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32  * GNU General Public License for more details.
33  *
34  * You should have received a copy of the GNU General Public License
35  * along with this program. If not, see <http://www.gnu.org/licenses/>.
36  */
37 class LocalPaymentDiscovery extends BaseDiscovery implements Discoverable, Registerable {
38         /**
39          * Protected constructor
40          *
41          * @return      void
42          */
43         protected function __construct () {
44                 // Call parent constructor
45                 parent::__construct(__CLASS__);
46         }
47
48         /**
49          * Create an instance of this class
50          *
51          * @param       $filterInstance         An instance of a filter
52          * @return      $discoveryInstance      An instance of this discovery class
53          */
54         public static final function createLocalPaymentDiscovery (Filterable $filterInstance) {
55                 // Get an instance of this class
56                 $discoveryInstance = new LocalPaymentDiscovery();
57
58                 // Set the action from filter
59                 $discoveryInstance->setActionName($filterInstance->getActionName());
60
61                 // Return the prepared instance
62                 return $discoveryInstance;
63         }
64
65         /**
66          * Discovers the request
67          *
68          * @param       $requestInstance        An instance of a Requestable class
69          * @return      void
70          */
71         public function discover (Requestable $requestInstance) {
72                 // Now get a search criteria and set app name and payment action as search critera
73                 $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
74                 $criteriaInstance->addCriteria('app_name', $requestInstance->getRequestElement('app'));
75                 $criteriaInstance->addCriteria('payment_action', $this->getActionName() . '_action');
76                 $criteriaInstance->setLimit(1);
77
78                 // Get a wrapper instance
79                 $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('payment_db_wrapper_class');
80
81                 // Get result back
82                 $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
83
84                 // Advanced to next entry and assert on it as it should always be there
85                 assert($resultInstance->valid());
86
87                 // Set the result instance
88                 $this->setResultInstance($resultInstance);
89         }
90
91         /**
92          * Adds the database result in a human-readable format to the helper class
93          *
94          * @param       $helperInstance         An instance of a helper class
95          * @return      void
96          * @todo        0% done
97          */
98         public function addResultsToHelper (HelpableTemplate $helperInstance) {
99                 // Undone part
100         }
101
102 }