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