updated acknowledgments
[openemr.git] / interface / product_registration / product_registration_controller.php
bloba9578bb8b69f7f6a8b4e7b53b9f1d93a1a999644
1 <?php
2 /**
3 * ProductRegistrationController
5 * LICENSE: This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
16 * @package OpenEMR
17 * @author Matthew Vita <matthewvita48@gmail.com>
18 * @link http://www.open-emr.org
21 $fake_register_globals=false;
22 $sanitize_all_escapes=true;
23 $ignoreAuth=true;
24 require_once("../globals.php");
25 require_once($GLOBALS['fileroot'] . "/interface/main/exceptions/invalid_email_exception.php");
26 require_once($GLOBALS['fileroot'] . "/interface/main/utils/http_response_helper.php");
27 require_once($GLOBALS['fileroot'] . "/interface/product_registration/product_registration_service.php");
28 require_once($GLOBALS['fileroot'] . "/interface/product_registration/exceptions/generic_product_registration_exception.php");
29 require_once($GLOBALS['fileroot'] . "/interface/product_registration/exceptions/duplicate_registration_exception.php");
31 class ProductRegistrationController {
32 private $productRegistrationService;
34 public function __construct() {
35 $this->productRegistrationService = new ProductRegistrationService();
37 // (note this is here until we use Zend Framework)
38 switch ($_SERVER['REQUEST_METHOD']) {
39 case 'POST':
40 $this->post();
41 break;
42 case 'GET':
43 $this->get();
44 break;
48 public function get() {
49 $statusPayload = $this->productRegistrationService->getProductStatus();
51 HttpResponseHelper::send(200, $statusPayload, 'JSON');
54 public function post() {
55 $registrationPayload = new stdClass();
56 $status = 500;
58 try {
59 $registrationId = $this->productRegistrationService->registerProduct($_POST['email']);
60 $registrationPayload->registration_id = $registrationId;
61 $registrationPayload->email = $_POST['email'];
62 $status = 201;
63 } catch (InvalidEmailException $emailException) {
64 $registrationPayload->error = $emailException->errorMessage();
65 } catch (DuplicateRegistrationException $duplicateRegistrationException) {
66 $registrationPayload->error = $duplicateRegistrationException->errorMessage();
67 } catch (GenericProductRegistrationException $genericProductRegistrationException) {
68 $registrationPayload->error = $genericProductRegistrationException->errorMessage();
71 HttpResponseHelper::send($status, $registrationPayload, 'JSON');
75 // Initialize self (note this is here until we use Zend Framework)
76 $productRegistrationController = new ProductRegistrationController();