Parcourir la source

Refactor api_model to use instance variables for API URL and API key

szisz1982 il y a 1 semaine
Parent
commit
e80a679314
1 fichiers modifiés avec 47 ajouts et 38 suppressions
  1. 47 38
      application/models/api_model.php

+ 47 - 38
application/models/api_model.php

@@ -2,14 +2,14 @@
 
 class api_model extends Model {
 
-  const API = $config['api_url'];
-  const API_KEY = $config['api_key'];
+  private $API = 'https://szollosil.bbus.smbinfo.hu/api/index.php';
+  private $API_KEY = '92JxvN5Zeti4E1FDwKg0QPEl3md4vY63';
 
   public function getGroupsList() {
     $curl = curl_init();
 
     curl_setopt_array($curl, array(
-      CURLOPT_URL => self::API.'/affiliateapi/groups',
+      CURLOPT_URL => $this->API.'/affiliateapi/groups',
       CURLOPT_RETURNTRANSFER => true,
       CURLOPT_ENCODING => '',
       CURLOPT_MAXREDIRS => 10,
@@ -18,7 +18,7 @@ class api_model extends Model {
       CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
       CURLOPT_CUSTOMREQUEST => 'GET',
       CURLOPT_HTTPHEADER => array(
-        'DOLAPIKEY: '.self::API_KEY
+        'DOLAPIKEY: '.$this->API_KEY
       ),
     ));
     $response = curl_exec($curl);
@@ -39,7 +39,7 @@ class api_model extends Model {
     $curl = curl_init();
 
     curl_setopt_array($curl, array(
-      CURLOPT_URL => self::API.'/affiliateapi/products?group_id='.$groupID,
+      CURLOPT_URL => $this->API.'/affiliateapi/products?group_id='.$groupID,
       CURLOPT_RETURNTRANSFER => true,
       CURLOPT_ENCODING => '',
       CURLOPT_MAXREDIRS => 10,
@@ -48,7 +48,7 @@ class api_model extends Model {
       CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
       CURLOPT_CUSTOMREQUEST => 'GET',
       CURLOPT_HTTPHEADER => array(
-        'DOLAPIKEY: '.self::API_KEY
+        'DOLAPIKEY: '.$this->API_KEY
       ),
     ));
     $response = curl_exec($curl);
@@ -76,7 +76,7 @@ class api_model extends Model {
     $curl = curl_init();
 
     curl_setopt_array($curl, array(
-      CURLOPT_URL => self::API.'/affiliateapi/events?group_id='.$groupID.'&groupByDate=1',
+      CURLOPT_URL => $this->API.'/affiliateapi/events?group_id='.$groupID.'&groupByDate=1',
       CURLOPT_RETURNTRANSFER => true,
       CURLOPT_ENCODING => '',
       CURLOPT_MAXREDIRS => 10,
@@ -85,7 +85,7 @@ class api_model extends Model {
       CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
       CURLOPT_CUSTOMREQUEST => 'GET',
       CURLOPT_HTTPHEADER => array(
-        'DOLAPIKEY: '.self::API_KEY
+        'DOLAPIKEY: '.$this->API_KEY
       ),
     ));
     $response = curl_exec($curl);
@@ -123,7 +123,7 @@ class api_model extends Model {
     $curl = curl_init();
 
     curl_setopt_array($curl, array(
-      CURLOPT_URL => self::API.'/affiliateapi/menus?eventDetailId='.$eventID,
+      CURLOPT_URL => $this->API.'/affiliateapi/menus?eventDetailId='.$eventID,
       CURLOPT_RETURNTRANSFER => true,
       CURLOPT_ENCODING => '',
       CURLOPT_MAXREDIRS => 10,
@@ -132,7 +132,7 @@ class api_model extends Model {
       CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
       CURLOPT_CUSTOMREQUEST => 'GET',
       CURLOPT_HTTPHEADER => array(
-        'DOLAPIKEY: '.self::API_KEY
+        'DOLAPIKEY: '.$this->API_KEY
       ),
     ));
     $response = curl_exec($curl);
@@ -155,7 +155,7 @@ class api_model extends Model {
         $curl = curl_init();
     
         curl_setopt_array($curl, array(
-          CURLOPT_URL => self::API.'/affiliateapi/events?id='.$packageid.'&participants='.$participants,
+          CURLOPT_URL => $this->API.'/affiliateapi/events?id='.$packageid.'&participants='.$participants,
           CURLOPT_RETURNTRANSFER => true,
           CURLOPT_ENCODING => '',
           CURLOPT_MAXREDIRS => 10,
@@ -164,7 +164,7 @@ class api_model extends Model {
           CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
           CURLOPT_CUSTOMREQUEST => 'GET',
           CURLOPT_HTTPHEADER => array(
-            'DOLAPIKEY: '.self::API_KEY
+            'DOLAPIKEY: '.$this->API_KEY
           ),
         ));
         $response = curl_exec($curl);
@@ -221,7 +221,7 @@ class api_model extends Model {
     $curl = curl_init();
 
     curl_setopt_array($curl, array(
-      CURLOPT_URL => self::API.'/affiliateapi/init',
+      CURLOPT_URL => $this->API.'/affiliateapi/init',
       CURLOPT_RETURNTRANSFER => true,
       CURLOPT_ENCODING => '',
       CURLOPT_MAXREDIRS => 10,
@@ -230,7 +230,7 @@ class api_model extends Model {
       CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
       CURLOPT_CUSTOMREQUEST => 'GET',
       CURLOPT_HTTPHEADER => array(
-        'DOLAPIKEY: '.self::API_KEY
+        'DOLAPIKEY: '.$this->API_KEY
       ),
     ));
 
@@ -250,7 +250,7 @@ class api_model extends Model {
     );
 
     curl_setopt_array($curl, array(
-      CURLOPT_URL => self::API.'/affiliateapi/reserve',
+      CURLOPT_URL => $this->API.'/affiliateapi/reserve',
       CURLOPT_RETURNTRANSFER => true,
       CURLOPT_ENCODING => '',
       CURLOPT_MAXREDIRS => 10,
@@ -260,7 +260,7 @@ class api_model extends Model {
       CURLOPT_CUSTOMREQUEST => 'POST',
       CURLOPT_POSTFIELDS => http_build_query($post_data), 
       CURLOPT_HTTPHEADER => array(
-        'DOLAPIKEY: '.self::API_KEY
+        'DOLAPIKEY: '.$this->API_KEY
       ),
     ));
 
@@ -277,7 +277,7 @@ class api_model extends Model {
     $post_data->uuid = str_replace('"','',$post_data->uuid);
 
     curl_setopt_array($curl, array(
-      CURLOPT_URL => self::API.'/affiliateapi/order',
+      CURLOPT_URL => $this->API.'/affiliateapi/order',
       CURLOPT_RETURNTRANSFER => true,
       CURLOPT_ENCODING => '',
       CURLOPT_MAXREDIRS => 10,
@@ -288,7 +288,7 @@ class api_model extends Model {
       CURLOPT_POSTFIELDS => json_encode($post_data), 
       CURLOPT_HTTPHEADER => array(
         'Content-Type: application/json',
-        'DOLAPIKEY: '.self::API_KEY
+        'DOLAPIKEY: '.$this->API_KEY
       ),
     ));
     
@@ -304,7 +304,7 @@ class api_model extends Model {
     $curl = curl_init();
 
     curl_setopt_array($curl, array(
-      CURLOPT_URL => self::API.'/affiliateapi/paymentstatus?uuid='.$_REQUEST['uuid'],
+      CURLOPT_URL => $this->API.'/affiliateapi/paymentstatus?uuid='.$_REQUEST['uuid'],
       CURLOPT_RETURNTRANSFER => true,
       CURLOPT_ENCODING => '',
       CURLOPT_MAXREDIRS => 10,
@@ -313,7 +313,7 @@ class api_model extends Model {
       CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
       CURLOPT_CUSTOMREQUEST => 'GET',
       CURLOPT_HTTPHEADER => array(
-        'DOLAPIKEY: '.self::API_KEY
+        'DOLAPIKEY: '.$this->API_KEY
       ),
     ));
 
@@ -326,7 +326,7 @@ class api_model extends Model {
     $curl = curl_init();
 
     curl_setopt_array($curl, array(
-      CURLOPT_URL => self::API.'/affiliateapi/getCustomerData',
+      CURLOPT_URL => $this->API.'/affiliateapi/getCustomerData',
       CURLOPT_RETURNTRANSFER => true,
       CURLOPT_ENCODING => '',
       CURLOPT_MAXREDIRS => 10,
@@ -335,7 +335,7 @@ class api_model extends Model {
       CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
       CURLOPT_CUSTOMREQUEST => 'GET',
       CURLOPT_HTTPHEADER => array(
-        'DOLAPIKEY: '.self::API_KEY
+        'DOLAPIKEY: '.$this->API_KEY
       ),
     ));
 
@@ -377,12 +377,21 @@ class api_model extends Model {
     return $row[0]->parent_service;
   }
 
+  public function getLowestEventprice($eventID) {
+    $events = $this->getMenusList($eventID);
+    foreach ($events as $event) {
+      if (!isset($lowest) || $event['price'] < $lowest) {
+        $lowest = $event['price'];
+      }
+    }
+    return formatize::currency(round($lowest));
+  }
+
   public function getEventsData($groupID, $lang = 'hu') {
     $parentID = $this->getGroupID($groupID);
     $rows = $this->query("SELECT * FROM `azonics_events` WHERE box_status=1 AND parent_service=".$parentID.";");
-    //print_r($rows);
-    //die();
     foreach ($rows as $row) {
+      $row->parent_price = $this->getLowestEventprice($row->parent_event);
       $images = $this->query("SELECT * FROM `azonics_events_blocks` WHERE block_status=1 AND box_id=".$row->box_id.";");
       $row->images = $images;
       $row->dates = $this->getEventsList($groupID);
@@ -456,7 +465,7 @@ class api_model extends Model {
     $curl = curl_init();
 
     curl_setopt_array($curl, array(
-      CURLOPT_URL => self::API.'/affiliateapi/init',
+      CURLOPT_URL => $this->API.'/affiliateapi/init',
       CURLOPT_RETURNTRANSFER => true,
       CURLOPT_ENCODING => '',
       CURLOPT_MAXREDIRS => 10,
@@ -465,7 +474,7 @@ class api_model extends Model {
       CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
       CURLOPT_CUSTOMREQUEST => 'GET',
       CURLOPT_HTTPHEADER => array(
-        'DOLAPIKEY: '.self::API_KEY
+        'DOLAPIKEY: '.$this->API_KEY
       ),
     ));
     $response = curl_exec($curl);
@@ -479,7 +488,7 @@ class api_model extends Model {
     $post_data = array('uuid' => $uuid, 'event_id' => $eventID, 'qty' => $qty);
 
     curl_setopt_array($curl, array(
-      CURLOPT_URL => self::API.'/affiliateapi/reserve',
+      CURLOPT_URL => $this->API.'/affiliateapi/reserve',
       CURLOPT_RETURNTRANSFER => true,
       CURLOPT_ENCODING => '',
       CURLOPT_MAXREDIRS => 10,
@@ -490,7 +499,7 @@ class api_model extends Model {
       CURLOPT_POSTFIELDS => json_encode($post_data), 
       CURLOPT_HTTPHEADER => array(
         'Content-Type:application/json',
-        'DOLAPIKEY: '.self::API_KEY
+        'DOLAPIKEY: '.$this->API_KEY
       ),
     ));
 
@@ -502,7 +511,7 @@ class api_model extends Model {
   public function getHotels($onlyHotels = false) {
     $curl = curl_init();
 
-    $url = self::API.'/affiliateapi/getAllHotels?givePartnerData=1';
+    $url = $this->API.'/affiliateapi/getAllHotels?givePartnerData=1';
     if ($onlyHotels) {
       //$url .= '?givePartnerData=1';
     }
@@ -517,7 +526,7 @@ class api_model extends Model {
       CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
       CURLOPT_CUSTOMREQUEST => 'GET',
       CURLOPT_HTTPHEADER => array(
-        'DOLAPIKEY: '.self::API_KEY
+        'DOLAPIKEY: '.$this->API_KEY
       ),
     ));
     $response = curl_exec($curl);
@@ -536,7 +545,7 @@ class api_model extends Model {
     $curl = curl_init();
 
     curl_setopt_array($curl, array(
-      CURLOPT_URL => self::API.'/affiliateapi/order',
+      CURLOPT_URL => $this->API.'/affiliateapi/order',
       CURLOPT_RETURNTRANSFER => true,
       CURLOPT_ENCODING => '',
       CURLOPT_MAXREDIRS => 10,
@@ -547,7 +556,7 @@ class api_model extends Model {
       CURLOPT_POSTFIELDS => json_encode($data), 
       CURLOPT_HTTPHEADER => array(
         'Content-Type:application/json',
-        'DOLAPIKEY: '.self::API_KEY
+        'DOLAPIKEY: '.$this->API_KEY
       ),
     ));
 
@@ -560,7 +569,7 @@ class api_model extends Model {
     $curl = curl_init();
 
     curl_setopt_array($curl, array(
-      CURLOPT_URL => self::API.'/setup/dictionary/countries?sortfield=code&sortorder=ASC&limit=3000',
+      CURLOPT_URL => $this->API.'/setup/dictionary/countries?sortfield=code&sortorder=ASC&limit=3000',
       CURLOPT_RETURNTRANSFER => true,
       CURLOPT_ENCODING => '',
       CURLOPT_MAXREDIRS => 10,
@@ -569,7 +578,7 @@ class api_model extends Model {
       CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
       CURLOPT_CUSTOMREQUEST => 'GET',
       CURLOPT_HTTPHEADER => array(
-        'DOLAPIKEY: '.self::API_KEY
+        'DOLAPIKEY: '.$this->API_KEY
       ),
     ));
     $response = curl_exec($curl);
@@ -586,7 +595,7 @@ class api_model extends Model {
     $curl = curl_init();
 
     curl_setopt_array($curl, array(
-      CURLOPT_URL => self::API.'/affiliateapi/paymentstatus?uuid='.$uuid,
+      CURLOPT_URL => $this->API.'/affiliateapi/paymentstatus?uuid='.$uuid,
       CURLOPT_RETURNTRANSFER => true,
       CURLOPT_ENCODING => '',
       CURLOPT_MAXREDIRS => 10,
@@ -595,7 +604,7 @@ class api_model extends Model {
       CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
       CURLOPT_CUSTOMREQUEST => 'GET',
       CURLOPT_HTTPHEADER => array(
-        'DOLAPIKEY: '.self::API_KEY
+        'DOLAPIKEY: '.$this->API_KEY
       ),
     ));
     $response = curl_exec($curl);
@@ -627,7 +636,7 @@ class api_model extends Model {
     }
 
     curl_setopt_array($curl, array(
-      CURLOPT_URL => self::API.'/affiliateapi/getAmount?hotel_id='.$hotelID.$postfix,
+      CURLOPT_URL => $this->API.'/affiliateapi/getAmount?hotel_id='.$hotelID.$postfix,
       CURLOPT_RETURNTRANSFER => true,
       CURLOPT_ENCODING => '',
       CURLOPT_MAXREDIRS => 10,
@@ -636,7 +645,7 @@ class api_model extends Model {
       CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
       CURLOPT_CUSTOMREQUEST => 'GET',
       CURLOPT_HTTPHEADER => array(
-        'DOLAPIKEY: '.self::API_KEY
+        'DOLAPIKEY: '.$this->API_KEY
       ),
     ));
     $response = curl_exec($curl);