Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/zend/Zend/Gdata/Health.php
Go to the documentation of this file.
00001 <?php
00002 
00027 require_once 'Zend/Gdata.php';
00028 
00032 require_once 'Zend/Gdata/Health/ProfileFeed.php';
00033 
00037 require_once 'Zend/Gdata/Health/ProfileListFeed.php';
00038 
00042 require_once 'Zend/Gdata/Health/ProfileListEntry.php';
00043 
00047 require_once 'Zend/Gdata/Health/ProfileEntry.php';
00048 
00060 class Zend_Gdata_Health extends Zend_Gdata
00061 {
00065     const AUTHSUB_PROFILE_FEED_URI =
00066         'https://www.google.com/health/feeds/profile/default';
00067     const AUTHSUB_REGISTER_FEED_URI =
00068         'https://www.google.com/health/feeds/register/default';
00069 
00073     const CLIENTLOGIN_PROFILELIST_FEED_URI =
00074         'https://www.google.com/health/feeds/profile/list';
00075     const CLIENTLOGIN_PROFILE_FEED_URI =
00076         'https://www.google.com/health/feeds/profile/ui';
00077     const CLIENTLOGIN_REGISTER_FEED_URI =
00078         'https://www.google.com/health/feeds/register/ui';
00079 
00083     const HEALTH_SERVICE_NAME = 'health';
00084     const H9_SANDBOX_SERVICE_NAME = 'weaver';
00085 
00092     private $_profileID = null;
00093 
00100     private $_useH9Sandbox = false;
00101 
00102     public static $namespaces =
00103         array('ccr' => 'urn:astm-org:CCR',
00104               'batch' => 'http://schemas.google.com/gdata/batch',
00105               'h9m' => 'http://schemas.google.com/health/metadata',
00106               'gAcl' => 'http://schemas.google.com/acl/2007',
00107               'gd' => 'http://schemas.google.com/g/2005');
00108 
00119     public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0', $useH9Sandbox = false)
00120     {
00121         $this->registerPackage('Zend_Gdata_Health');
00122         $this->registerPackage('Zend_Gdata_Health_Extension_Ccr');
00123         parent::__construct($client, $applicationId);
00124         $this->_useH9Sandbox = $useH9Sandbox;
00125     }
00126 
00132     public function getProfileID()
00133     {
00134         return $this->_profileID;
00135     }
00136 
00143     public function setProfileID($id) {
00144         $this->_profileID = $id;
00145         return $this;
00146     }
00147 
00155     public function getHealthProfileListFeed($query = null)
00156     {
00157         if ($this->_httpClient->getClientLoginToken() === null) {
00158             require_once 'Zend/Gdata/App/AuthException.php';
00159             throw new Zend_Gdata_App_AuthException(
00160                 'Profiles list feed is only available when using ClientLogin');
00161         }
00162 
00163         if($query === null)  {
00164             $uri = self::CLIENTLOGIN_PROFILELIST_FEED_URI;
00165         } else if ($query instanceof Zend_Gdata_Query) {
00166             $uri = $query->getQueryUrl();
00167         } else {
00168             $uri = $query;
00169         }
00170 
00171         // use correct feed for /h9 or /health
00172         if ($this->_useH9Sandbox) {
00173             $uri = preg_replace('/\/health\//', '/h9/', $uri);
00174         }
00175 
00176         return parent::getFeed($uri, 'Zend_Gdata_Health_ProfileListFeed');
00177     }
00178 
00187     public function getHealthProfileFeed($query = null)
00188     {
00189         if ($this->_httpClient->getClientLoginToken() !== null &&
00190             $this->getProfileID() == null) {
00191             require_once 'Zend/Gdata/App/AuthException.php';
00192             throw new Zend_Gdata_App_AuthException(
00193                 'Profile ID must not be null. Did you call setProfileID()?');
00194         }
00195 
00196         if ($query instanceof Zend_Gdata_Query) {
00197             $uri = $query->getQueryUrl();
00198         } else if ($this->_httpClient->getClientLoginToken() !== null &&
00199                    $query == null) {
00200             $uri = self::CLIENTLOGIN_PROFILE_FEED_URI . '/' . $this->getProfileID();
00201         } else if ($query === null) {
00202             $uri = self::AUTHSUB_PROFILE_FEED_URI;
00203         } else {
00204             $uri = $query;
00205         }
00206 
00207         // use correct feed for /h9 or /health
00208         if ($this->_useH9Sandbox) {
00209             $uri = preg_replace('/\/health\//', '/h9/', $uri);
00210         }
00211 
00212         return parent::getFeed($uri, 'Zend_Gdata_Health_ProfileFeed');
00213     }
00214 
00221     public function getHealthProfileEntry($query = null)
00222     {
00223         if ($query === null) {
00224             require_once 'Zend/Gdata/App/InvalidArgumentException.php';
00225             throw new Zend_Gdata_App_InvalidArgumentException(
00226                 'Query must not be null');
00227         } else if ($query instanceof Zend_Gdata_Query) {
00228             $uri = $query->getQueryUrl();
00229         } else {
00230             $uri = $query;
00231         }
00232         return parent::getEntry($uri, 'Zend_Gdata_Health_ProfileEntry');
00233     }
00234 
00246     public function sendHealthNotice($subject, $body, $bodyType = null, $ccrXML = null)
00247     {
00248         if ($this->_httpClient->getClientLoginToken()) {
00249             $profileID = $this->getProfileID();
00250             if ($profileID !== null) {
00251                 $uri = self::CLIENTLOGIN_REGISTER_FEED_URI . '/' . $profileID;
00252             } else {
00253                 require_once 'Zend/Gdata/App/AuthException.php';
00254                 throw new Zend_Gdata_App_AuthException(
00255                     'Profile ID must not be null. Did you call setProfileID()?');
00256             }
00257         } else {
00258             $uri = self::AUTHSUB_REGISTER_FEED_URI;
00259         }
00260 
00261         $entry = new Zend_Gdata_Health_ProfileEntry();
00262         $entry->title = $this->newTitle($subject);
00263         $entry->content = $this->newContent($body);
00264         $entry->content->type = $bodyType ? $bodyType : 'text';
00265         $entry->setCcr($ccrXML);
00266 
00267         // use correct feed for /h9 or /health
00268         if ($this->_useH9Sandbox) {
00269             $uri = preg_replace('/\/health\//', '/h9/', $uri);
00270         }
00271 
00272         return $this->insertEntry($entry, $uri, 'Zend_Gdata_Health_ProfileEntry');
00273     }
00274 }
 All Data Structures Namespaces Files Functions Variables Enumerations