+ Reply to Thread
Results 1 to 5 of 5

Thread: Salesforce, PHP, and the Google Vizualization API

  1. #1
    Wesleysakamoto is offline Junior Member
    Join Date
    Sep 2009
    Posts
    3

    Salesforce, PHP, and the Google Vizualization API

    All, I piggy-backed off of Mike's original SF to Oracle scripts to create a query call to Salesforce and feed the query result into a Google table Visualization. For this exercise, I'm querying the Opportunity object for all opportunity ID's with a stage name of "LOI/Going to Contract".

    FYI: I'm running PHP toolkit version 13.1 and PHP version 5.3. It only works in Firefox, Chrome, and IE7. There are known compatibility issues between IE8 and the google visualization API. I had to tweak the metatags to assure some level of IE compatibility.


    Here is the code below:
    Code:
    <html xmlns="http://www.w3.org/1999/xhtml">
        <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
        <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    
        <head>
            <title>Google Visualization Demo</title>
            <script type="text/javascript" src="http://www.google.com/jsapi">
                //call google
            </script>
            <script type="text/javascript">
            google.load('visualization', '1', {'packages':['table']}); //load the viz
            
            google.setOnLoadCallback(drawTable);
            function drawTable() 
            {
            var data = new google.visualization.DataTable();
            data.addColumn('string', 'Opportunity ID');
            data.addColumn('string', 'Stage');
            <?php
                ini_set("soap.wsdl.cache_enabled", "0");
                require_once ("./soapclient/SforcePartnerClient.php");
                require_once ("./soapclient/SforceHeaderOptions.php");
                
    
                $username = "insert your username here";
                $password = "insert your pw here";
                $token = "insert your token here";
                $wdsl = "./soapclient/partner.wsdl.xml";
                    
                function get_data($username,$password,$token,$wdsl)
                {
                            
                            $client = new SforcePartnerClient();
                            $client->createConnection($wdsl);
                            $mylogin = $client->login($username, $password.$token);
                            
                            $sql = "Select a.Id, a.StageName from Opportunity a where a.StageName like '%LOI%'";
                            $response = $client->query($sql);
                            
                            $size = $response->size;
                                                    
                            if ($size > 0)
                            {
                                $result = $response->records; //dump array results into var
                                while (!$response->done) 
                                {
                                    $response = $client->queryMore($response->queryLocator);
                                    $result = array_merge($result, $response->records); //merge all batches into one master array
                                }
                            }
                            return $result;
                }
                $data = get_data($username,$password,$token,$wdsl); //passed user info and other parameters from above into function to estab connection and execute query.
                $i = sizeof($data);
                $int_y_pos = -1;
                $int_y_step_small = 1;
                $outputVal = "";
                foreach ($data as $r)
                {
                $int_y_pos += $int_y_step_small;
                $outputVal .= "data.setValue(" . $int_y_pos . ", 0,'" . $r->Id . "');"; //string
                $outputVal .= "data.setValue(" . $int_y_pos . ", 1,'" . $r->fields->StageName . "');"; //string
                }
                echo "data.addRows($i);";
                echo $outputVal;
    
            ?>
            var table = new google.visualization.Table(document.getElementById('table'));
           
            
            
            table.draw(data, {width: 'automatic', allowHtml: true, showRowNumber: true, page: 'enable', pageSize: 50});
            }
            
            </script>
        </head>
    <body style="font-family: Arial;border: 0 none;">
        <div id="table"></div>
    </body>
    
    
    </html>
    Cheers!

  2. #2
    Wesleysakamoto is offline Junior Member
    Join Date
    Sep 2009
    Posts
    3
    *Visualization

  3. #3
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15
    I am going to check this out today, will let you know if I can get this working

    ~Mike

  4. #4
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15
    Dude with your help over IM, I was able to get this working because I had a STUPID print_r in there

    Thanks for the help and this looks like it could be useful for dashboards

  5. #5
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15
    There is actually a open source class that I found that deals with this when I did a search for PHP and Google Visualization.


    From what this class states it writes all the JavaScript for you and all you throw it is an array of data. I am sure there is more to it than that, but I will report back and let you know what the deal is

    ~Mike
    Attached Files

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO 3.5.1