Source for file activities.php

Documentation is available at activities.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Google
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Google+ data class for the Joomla Platform.
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  Google
  17.  * @since       1234
  18.  */
  19. {
  20.     /**
  21.      * Constructor.
  22.      *
  23.      * @param   JRegistry    $options  Google options object
  24.      * @param   JGoogleAuth  $auth     Google data http client object
  25.      *
  26.      * @since   1234
  27.      */
  28.     public function __construct(JRegistry $options nullJGoogleAuth $auth null)
  29.     {
  30.     parent::__construct($options$auth);
  31.  
  32.         if (isset($this->auth&& !$this->auth->getOption('scope'))
  33.         {
  34.             $this->auth->setOption('scope''https://www.googleapis.com/auth/plus.me');
  35.         }
  36.     }
  37.  
  38.     /**
  39.      * List all of the activities in the specified collection for a particular user.
  40.      *
  41.      * @param   string   $userId      The ID of the user to get activities for. The special value "me" can be used to indicate the authenticated user.
  42.      * @param   string   $collection  The collection of activities to list. Acceptable values are: "public".
  43.      * @param   string   $fields      Used to specify the fields you want returned.
  44.      * @param   integer  $max         The maximum number of people to include in the response, used for paging.
  45.      * @param   string   $token       The continuation token, used to page through large result sets. To get the next page of results, set this
  46.      *                                   parameter to the value of "nextPageToken" from the previous response. This token may be of any length.
  47.      * @param   string   $alt         Specifies an alternative representation type. Acceptable values are: "json" - Use JSON format (default)
  48.      *
  49.      * @return  mixed  Data from Google
  50.      *
  51.      * @since   1234
  52.      */
  53.     public function listActivities($userId$collection$fields null$max 10$token null$alt null)
  54.     {
  55.         if ($this->isAuthenticated())
  56.         {
  57.             $url $this->getOption('api.url''people/' $userId '/activities/' $collection;
  58.  
  59.             // Check if fields is specified.
  60.             if ($fields)
  61.             {
  62.                 $url .= '?fields=' $fields;
  63.             }
  64.  
  65.             // Check if max is specified.
  66.             if ($max != 10)
  67.             {
  68.                 $url .= (strpos($url'?'=== false'?maxResults=' '&maxResults=';
  69.                 $url .= $max;
  70.             }
  71.  
  72.             // Check if token is specified.
  73.             if ($token)
  74.             {
  75.                 $url .= (strpos($url'?'=== false'?pageToken=' '&pageToken=';
  76.                 $url .= $token;
  77.             }
  78.  
  79.             // Check if alt is specified.
  80.             if ($alt)
  81.             {
  82.                 $url .= (strpos($url'?'=== false'?alt=' '&alt=';
  83.                 $url .= $alt;
  84.             }
  85.  
  86.             $jdata $this->auth->query($url);
  87.  
  88.             return json_decode($jdata->bodytrue);
  89.         }
  90.         else
  91.         {
  92.             return false;
  93.         }
  94.     }
  95.  
  96.     /**
  97.      * Get an activity.
  98.      *
  99.      * @param   string  $id      The ID of the activity to get.
  100.      * @param   string  $fields  Used to specify the fields you want returned.
  101.      * @param   string  $alt     Specifies an alternative representation type. Acceptable values are: "json" - Use JSON format (default)
  102.      *
  103.      * @return  mixed  Data from Google
  104.      *
  105.      * @since   1234
  106.      */
  107.     public function getActivity($id$fields null$alt null)
  108.     {
  109.         if ($this->isAuthenticated())
  110.         {
  111.             $url $this->getOption('api.url''activities/' $id;
  112.  
  113.             // Check if fields is specified.
  114.             if ($fields)
  115.             {
  116.                 $url .= '?fields=' $fields;
  117.             }
  118.  
  119.             // Check if alt is specified.
  120.             if ($alt)
  121.             {
  122.                 $url .= (strpos($url'?'=== false'?alt=' '&alt=';
  123.                 $url .= $alt;
  124.             }
  125.  
  126.             $jdata $this->auth->query($url);
  127.  
  128.             return json_decode($jdata->bodytrue);
  129.         }
  130.         else
  131.         {
  132.             return false;
  133.         }
  134.     }
  135.  
  136.     /**
  137.      * Search all public activities.
  138.      *
  139.      * @param   string   $query     Full-text search query string.
  140.      * @param   string   $fields    Used to specify the fields you want returned.
  141.      * @param   string   $language  Specify the preferred language to search with. https://developers.google.com/+/api/search#available-languages
  142.      * @param   integer  $max       The maximum number of people to include in the response, used for paging.
  143.      * @param   string   $order     Specifies how to order search results. Acceptable values are "best" and "recent".
  144.      * @param   string   $token     The continuation token, used to page through large result sets. To get the next page of results, set this
  145.      *                                  parameter to the value of "nextPageToken" from the previous response. This token may be of any length.
  146.      *
  147.      * @return  mixed  Data from Google
  148.      *
  149.      * @since   1234
  150.      */
  151.     public function search($query$fields null$language null$max 10$order null$token null)
  152.     {
  153.         if ($this->isAuthenticated())
  154.         {
  155.             $url $this->getOption('api.url''activities?query=' urlencode($query);
  156.  
  157.             // Check if fields is specified.
  158.             if ($fields)
  159.             {
  160.                 $url .= '&fields=' $fields;
  161.             }
  162.  
  163.             // Check if language is specified.
  164.             if ($language)
  165.             {
  166.                 $url .= '&language=' $language;
  167.             }
  168.  
  169.             // Check if max is specified.
  170.             if ($max != 10)
  171.             {
  172.                 $url .= '&maxResults=' $max;
  173.             }
  174.  
  175.             // Check if order is specified.
  176.             if ($order)
  177.             {
  178.                 $url .= '&orderBy=' $order;
  179.             }
  180.  
  181.             // Check of token is specified.
  182.             if ($token)
  183.             {
  184.                 $url .= '&pageToken=' $token;
  185.             }
  186.  
  187.             $jdata $this->auth->query($url);
  188.  
  189.             return json_decode($jdata->bodytrue);
  190.         }
  191.         else
  192.         {
  193.             return false;
  194.         }
  195.     }
  196. }

Documentation generated on Tue, 19 Nov 2013 14:53:22 +0100 by phpDocumentor 1.4.3