d81219f5dfcc124c4635ca727ffe7726fb268b8b
[core.git] / inc / 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\ObjectFactory;
7 use CoreFramework\Registry\Registerable;
8 use CoreFramework\Request\Requestable;
9
10 /**
11  * A local payment discovery class. This class looks in local database for
12  * registered payment types and like all the others it at least returns the
13  * money bank transfer type.
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 LocalPaymentDiscovery extends BaseDiscovery implements Discoverable, 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          * Create an instance of this class
47          *
48          * @param       $filterInstance         An instance of a filter
49          * @return      $discoveryInstance      An instance of this discovery class
50          */
51         public static final function createLocalPaymentDiscovery (Filterable $filterInstance) {
52                 // Get an instance of this class
53                 $discoveryInstance = new LocalPaymentDiscovery();
54
55                 // Set the action from filter
56                 $discoveryInstance->setActionName($filterInstance->getActionName());
57
58                 // Return the prepared instance
59                 return $discoveryInstance;
60         }
61
62         /**
63          * Discovers the request
64          *
65          * @param       $requestInstance        An instance of a Requestable class
66          * @return      void
67          */
68         public function discover (Requestable $requestInstance) {
69                 // Now get a search criteria and set app name and payment action as search critera
70                 $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
71                 $criteriaInstance->addCriteria('app_name', $requestInstance->getRequestElement('app'));
72                 $criteriaInstance->addCriteria('payment_action', $this->getActionName() . '_action');
73                 $criteriaInstance->setLimit(1);
74
75                 // Get a wrapper instance
76                 $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('payment_db_wrapper_class');
77
78                 // Get result back
79                 $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
80
81                 // Advanced to next entry and assert on it as it should always be there
82                 assert($resultInstance->valid());
83
84                 // Set the result instance
85                 $this->setResultInstance($resultInstance);
86         }
87
88         /**
89          * Adds the database result in a human-readable format to the helper class
90          *
91          * @param       $helperInstance         An instance of a helper class
92          * @return      void
93          * @todo        0% done
94          */
95         public function addResultsToHelper (HelpableTemplate $helperInstance) {
96                 // Undone part
97         }
98
99 }