added errors to the login and adds audience id automatically
authorAnthony Talarico <talarico@gaslightmedia.com>
Fri, 13 May 2016 21:00:55 +0000 (17:00 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Fri, 13 May 2016 21:00:55 +0000 (17:00 -0400)
class-streamsendfeedaddon.php

index e68bbe1..8233033 100644 (file)
@@ -12,6 +12,7 @@ class GFStreamSendAddOn extends GFFeedAddOn
     protected $_full_path = __FILE__;
     protected $_title = 'Gravity Forms StreamSend Integration';
     protected $_short_title = 'StreamSend';
+    protected $_errorFlag = false;
 
     private static $_instance = null;
     protected $streamSendFields = array(
@@ -92,7 +93,7 @@ class GFStreamSendAddOn extends GFFeedAddOn
                         'label'             => esc_html__( 'Audience Id', 'StreamSend' ),
                         'type'              => 'text',
                         'class'             => 'small',
-                        'feedback_callback' => array( $this, 'is_valid_setting' ),
+                        'feedback_callback' => array( $this, 'is_valid_audience' ),
                     )
                 )
             )
@@ -100,6 +101,18 @@ class GFStreamSendAddOn extends GFFeedAddOn
     }
 
     public function feed_settings_fields() {
+        $settings = $this->get_plugin_settings();
+        $apiLogin = rgar($settings, 'glm_streamsend_login');
+        $apiKey = rgar($settings, 'glm_streamsend_key');
+        $ss = new StreamSend(STREAMSEND_BASE_URL, $apiLogin, $apiKey);
+//        echo '<pre>', print_r($ss->listList(),true), '</pre>';
+        $lists = $ss->listList();
+        $lists = $lists->responseData->list;
+        for($i = 0; $i < count($lists); $i++){
+           
+        }
+        
+        
         return array(
             array(
                 'title'  => 'StreamSend Form Settings',
@@ -172,6 +185,13 @@ class GFStreamSendAddOn extends GFFeedAddOn
                         'checkbox_label' => esc_html__( 'Enable Condition', 'StreamSend' ),
                         'instructions'   => esc_html__( 'Process this StreamSend feed if', 'StreamSend' ),
                     ),
+                    array(
+                        'name'           => 'Lists',
+                        'label'          => esc_html__( 'List', 'StreamSend' ),
+                        'type'           => 'select',
+                        'checkbox_label' => esc_html__( 'Enable Condition', 'StreamSend' ),
+                        'instructions'   => esc_html__( 'Process this StreamSend feed if', 'StreamSend' ),
+                    ),
                 )
             )
         );
@@ -189,13 +209,35 @@ class GFStreamSendAddOn extends GFFeedAddOn
         $apiKey = rgar($settings, 'glm_streamsend_key');
         $ss = new StreamSend(STREAMSEND_BASE_URL, $apiLogin, $apiKey);
         $ss->accountList();
-        
+        $responseData[] = $ss->audienceList();
+        $audienceId = $responseData[0]->responseData->audience->id;
         if ( $ss->responseHTTPStatus != 200){
-            echo '<div class="push-alert-red" style="border-left: 1px solid #E6DB55; border-right: 1px solid #E6DB55;">';
-                       esc_html_e( 'Invalid Login or Key', 'gravityforms' ); 
+             echo '<div> ';
+                     echo '<h4 style="color:red; margin: 2px;"> Invalid Login or API Key</h4>';
                echo '</div>';
         }
+        ?>
+        <script type="text/javascript">
+            document.addEventListener("DOMContentLoaded", function(event) { 
+   
+            var audienceId = "<?php echo $audienceId; ?>";  
+            document.getElementById("glm_streamsend_audience").value = audienceId;
+            document.getElementById("glm_streamsend_audience").readOnly = true;
+        });
+        </script>
+        <?php
     }
+    public function errorNotice(){
+        if($this->errorFlag){
+            echo '<div class="push-alert-red" style="border-left: 1px solid #E6DB55; border-right: 1px solid #E6DB55;"> ';
+                     esc_html_e( 'This add-on needs to be updated. Please contact the developer.', 'gravityforms' ); 
+               echo '</div>';
+        }
+    }
+    public function __construct() {
+        parent::__construct();
+    }
+
     public function process_feed( $feed, $entry, $form ) {
         $feedName           = $feed['meta']['feedName'];
         $field_map = $this->get_field_map_fields( $feed, 'mappedFields' );