Rename PTAWebservice to SharingAPI; a few other fixes regarding Fruneau's review.
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Fri, 5 Aug 2011 23:57:15 +0000 (01:57 +0200)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Tue, 9 Aug 2011 22:45:52 +0000 (00:45 +0200)
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
classes/profile.php
classes/userfilter.php
classes/xorg.php
configs/platal.ini
modules/sharingapi.php [moved from modules/ptawebservice.php with 92% similarity]
modules/sharingapi/request.inc.php [moved from modules/ptawebservice/request.inc.php with 94% similarity]

index eb9839d..6574d0a 100644 (file)
@@ -925,10 +925,10 @@ class Profile implements PlExportable
 
     public function getPartnerSettings($partner_id)
     {
 
     public function getPartnerSettings($partner_id)
     {
-        if ($this->partners_settings == null && !$this->fetched(self::FETCH_PARTNER)) {
+        if ($this->partners_settings === null && !$this->fetched(self::FETCH_PARTNER)) {
             $this->setPartnersSettings($this->getProfileField(self::FETCH_PARTNER));
         }
             $this->setPartnersSettings($this->getProfileField(self::FETCH_PARTNER));
         }
-        if ($this->partners_settings == null) {
+        if ($this->partners_settings === null) {
             return PartnerSettings::getEmpty($partner_id);
         }
         return $this->partners_settings->get($partner_id);
             return PartnerSettings::getEmpty($partner_id);
         }
         return $this->partners_settings->get($partner_id);
index 236721d..983b2ee 100644 (file)
@@ -1392,7 +1392,7 @@ class UserFilter extends PlFilter
     public function addPartnerSharingFilter($partner_id)
     {
         $this->requireProfiles();
     public function addPartnerSharingFilter($partner_id)
     {
         $this->requireProfiles();
-        $sub = "ppss_$partner_id";
+        $sub = "ppss_" . $partner_id;
         $this->ppss[$sub] = $partner_id;
         return $sub;
     }
         $this->ppss[$sub] = $partner_id;
         return $sub;
     }
@@ -1411,6 +1411,7 @@ class UserFilter extends PlFilter
         $sub = $this->addPartnerSharingFilter($partner_id);
         $this->visibility_field = $sub . '.sharing_level';
     }
         $sub = $this->addPartnerSharingFilter($partner_id);
         $this->visibility_field = $sub . '.sharing_level';
     }
+
     /** VISIBILITY
      */
     private $vlevels = array();
     /** VISIBILITY
      */
     private $vlevels = array();
@@ -1429,6 +1430,12 @@ class UserFilter extends PlFilter
         return $sub;
     }
 
         return $sub;
     }
 
+    /** Since this method might perform inner joins on tables which have been
+     * joined previously (e.g when using addVisibilityFieldFilter), it has to
+     * come after the Joins() methods for those tables.
+     * This is due to the implementation logic for discovering joins and the
+     * ordering used by PHP introspection.
+     */
     protected function visibilityJoins()
     {
         $joins = array();
     protected function visibilityJoins()
     {
         $joins = array();
index cec21a6..387309c 100644 (file)
@@ -29,7 +29,7 @@ class Xorg extends Platal
                             'newsletter', 'axletter', 'epletter', 'bandeau', 'survey',
                             'fusionax', 'gadgets', 'googleapps', 'poison',
                             'openid', 'reminder', 'api', 'urlshortener', 'deltaten',
                             'newsletter', 'axletter', 'epletter', 'bandeau', 'survey',
                             'fusionax', 'gadgets', 'googleapps', 'poison',
                             'openid', 'reminder', 'api', 'urlshortener', 'deltaten',
-                            'geoloc', 'ptawebservice');
+                            'geoloc', 'sharingapi');
     }
 
     public function find_hook()
     }
 
     public function find_hook()
index 95ba757..a7abb91 100644 (file)
@@ -402,6 +402,14 @@ private_max = 800
 per_page    =  20
 
 
 per_page    =  20
 
 
+; The SharingAPI section contains parameters about the 'sharing' webservice
+[SharingAPI]
+
+; $globals->sharingapi->max_result_per_query
+; Maximum number of results returned in an API response.
+max_result_per_query = 10;
+
+
 ; The register section contains parameters for the registration process
 [Register]
 
 ; The register section contains parameters for the registration process
 [Register]
 
@@ -467,14 +475,6 @@ payed_list = ""
 event_lists = ""
 
 
 event_lists = ""
 
 
-; The PTA section contains parameters about the 'RSPTA' webservice
-[PTA]
-
-; $globals->pta->max_result_per_query
-; Maximum number of results returned in an API response.
-max_result_per_query = 10;
-
-
 ; The merge section contains parameters about the merge's state.
 [Merge]
 
 ; The merge section contains parameters about the merge's state.
 [Merge]
 
similarity index 92%
rename from modules/ptawebservice.php
rename to modules/sharingapi.php
index badc0dd..e914ca6 100644 (file)
  ***************************************************************************/
 
 
  ***************************************************************************/
 
 
-class PTAWebServiceModule extends PlModule
+class SharingAPIModule extends PlModule
 {
     function handlers()
     {
         return array(
 {
     function handlers()
     {
         return array(
-            'pta/ws/directory/1/search'     => $this->make_api_hook('search',   AUTH_COOKIE, 'api_user_readonly'),
-            'pta/ws/bulkmail/1/get_context' => $this->make_api_hook('bulkmail', AUTH_COOKIE, 'api_user_readonly'),
-            'pta/picture'                   => $this->make_hook('picture_token', AUTH_PUBLIC),
+            'api/1/sharing/search'    => $this->make_api_hook('search',    AUTH_COOKIE, 'api_user_readonly'),
+            'api/1/sharing/bulkmail'  => $this->make_api_hook('bulkmail',  AUTH_COOKIE, 'api_user_readonly'),
+            'api/1/sharing/picture'   => $this->make_hook('picture_token', AUTH_PUBLIC),
         );
     }
 
         );
     }
 
similarity index 94%
rename from modules/ptawebservice/request.inc.php
rename to modules/sharingapi/request.inc.php
index 44ef174..0dd7910 100644 (file)
@@ -35,7 +35,7 @@ class WSDirectoryRequest
     const ORDER_NAME = 'name';
     const ORDER_PROMOTION = 'promotion';
 
     const ORDER_NAME = 'name';
     const ORDER_PROMOTION = 'promotion';
 
-    public static $ORDER_CHOICES = array(
+    public static $order_choices = array(
         self::ORDER_RAND,
         self::ORDER_NAME,
         self::ORDER_PROMOTION,
         self::ORDER_RAND,
         self::ORDER_NAME,
         self::ORDER_PROMOTION,
@@ -46,30 +46,30 @@ class WSDirectoryRequest
         $this->partner = $partner;
         global $globals;
 
         $this->partner = $partner;
         global $globals;
 
-        $this->fields = array_intersect($payload->v('fields'), WSRequestFields::$CHOICES);
-        $this->order = array_intersect($payload->v('order', array()), self::$ORDER_CHOICES);
+        $this->fields = array_intersect($payload->v('fields'), WSRequestFields::$choices);
+        $this->order = array_intersect($payload->v('order', array()), self::$order_choices);
 
         $this->criteria = array();
         $criteria = new PlDict($payload->v('criteria'));
 
         $this->criteria = array();
         $criteria = new PlDict($payload->v('criteria'));
-        foreach (WSRequestCriteria::$CHOICES_SIMPLE as $criterion) {
+        foreach (WSRequestCriteria::$choices_simple as $criterion) {
             if ($criteria->has($criterion)) {
                 $this->criteria[$criterion] = $criteria->s($criterion);
             }
         }
             if ($criteria->has($criterion)) {
                 $this->criteria[$criterion] = $criteria->s($criterion);
             }
         }
-        foreach (WSRequestCriteria::$CHOICES_ENUM as $criterion) {
+        foreach (WSRequestCriteria::$choices_enum as $criterion) {
             if ($criteria->has($criterion)) {
                 $this->criteria[$criterion] = $criteria->s($criterion);
             }
         }
             if ($criteria->has($criterion)) {
                 $this->criteria[$criterion] = $criteria->s($criterion);
             }
         }
-        foreach (WSRequestCriteria::$CHOICES_LIST as $criterion) {
+        foreach (WSRequestCriteria::$choices_list as $criterion) {
             if ($criteria->has($criterion)) {
                 $this->criteria[$criterion] = $criteria->v($criterion);
             }
         }
 
             if ($criteria->has($criterion)) {
                 $this->criteria[$criterion] = $criteria->v($criterion);
             }
         }
 
-        // Amount may not exceed $globals->pta->max_result_per_query.
+        // Amount may not exceed $globals->sharingapi->max_result_per_query.
         $amount = $payload->i('amount', self::DEFAULT_AMOUNT);
         $amount = $payload->i('amount', self::DEFAULT_AMOUNT);
-        $this->amount = min($amount, $globals->pta->max_result_per_query);
+        $this->amount = min($amount, $globals->sharingapi->max_result_per_query);
     }
 
     public function get()
     }
 
     public function get()
@@ -141,14 +141,14 @@ class WSDirectoryRequest
             // ENUM fields
             case WSRequestCriteria::SCHOOL:
                 // Useless criterion: we don't need to check on origin school
             // ENUM fields
             case WSRequestCriteria::SCHOOL:
                 // Useless criterion: we don't need to check on origin school
-                if (WSRequestCriteria::$CHOICES_ENUM[$criterion][$value]) {
+                if (WSRequestCriteria::$choices_enum[$criterion][$value]) {
                     $cond->addChild(new PFC_True());
                 } else {
                     $cond->addChild(new PFC_False());
                 };
                 break;
             case WSRequestCriteria::DIPLOMA:
                     $cond->addChild(new PFC_True());
                 } else {
                     $cond->addChild(new PFC_False());
                 };
                 break;
             case WSRequestCriteria::DIPLOMA:
-                $diploma = WSRequestCriteria::$CHOICES_ENUM[$criterion][$value];
+                $diploma = WSRequestCriteria::$choices_enum[$criterion][$value];
                 $id_X = XDB::fetchOneCell('SELECT  id
                                              FROM  profile_education_enum
                                             WHERE  abbreviation = {?}', 'X');
                 $id_X = XDB::fetchOneCell('SELECT  id
                                              FROM  profile_education_enum
                                             WHERE  abbreviation = {?}', 'X');
@@ -436,7 +436,7 @@ class WSRequestEntry
                     WSRequestFields::PIC_LARGE => 'large',
                 );
                 $size = $size_mappings[$field];
                     WSRequestFields::PIC_LARGE => 'large',
                 );
                 $size = $size_mappings[$field];
-                return pl_url("pta/picture/$size/$token");
+                return pl_url("api/1/sharing/picture/$size/$token");
             } else {
                 return null;
             }
             } else {
                 return null;
             }
@@ -532,12 +532,13 @@ class WSRequestEntry
 
     protected function jobToResponse($job)
     {
 
     protected function jobToResponse($job)
     {
-        $data = array();
-        $data['company'] = $job->company->name;
-        $data['title'] = $job->description;
-        $data['sector'] = array_pop($job->terms);
-        $data['entry'] = null;
-        $data['left'] = null;
+        $data = array(
+            'company' => $job->company->name,
+            'title' => $job->description,
+            'sector' => array_pop($job->terms),
+            'entry' => null,
+            'left' => null,
+        );
         foreach($job->phones() as $phone) {
             if ($this->isVisible($phone->pub)) {
                 $data['phone'] = $phone->display;
         foreach($job->phones() as $phone) {
             if ($this->isVisible($phone->pub)) {
                 $data['phone'] = $phone->display;
@@ -552,13 +553,14 @@ class WSRequestEntry
 
     protected function addressToResponse($address)
     {
 
     protected function addressToResponse($address)
     {
-        $data = array();
-        $data['street'] = $address->postalText;
-        $data['zipcode'] = $address->postalCode;
-        $data['city'] = $address->locality;
-        $data['country'] = $address->country;
-        $data['latitude'] = $address->latitude;
-        $data['longitude'] = $address->longitude;
+        $data = array(
+            'street' => $address->postalText,
+            'zipcode' => $address->postalCode,
+            'city' => $address->locality,
+            'country' => $address->country,
+            'latitude' => $address->latitude,
+            'longitude' => $address->longitude,
+        );
         return $data;
     }
 }
         return $data;
     }
 }
@@ -592,7 +594,7 @@ class WSRequestCriteria
     const ALT_DIPLOMA = 'alt_diploma';
     const NOT_UID = 'not_uid';
 
     const ALT_DIPLOMA = 'alt_diploma';
     const NOT_UID = 'not_uid';
 
-    public static $CHOICES_SIMPLE = array(
+    public static $choices_simple = array(
         self::FIRSTNAME,
         self::LASTNAME,
         self::PROMOTION,
         self::FIRSTNAME,
         self::LASTNAME,
         self::PROMOTION,
@@ -629,7 +631,7 @@ class WSRequestCriteria
     const DIPLOMA_MASTER = 'MASTER';
     const DIPLOMA_PHD = 'PHD';
 
     const DIPLOMA_MASTER = 'MASTER';
     const DIPLOMA_PHD = 'PHD';
 
-    public static $CHOICES_ENUM = array(
+    public static $choices_enum = array(
         self::SCHOOL => array(
             self::SCHOOL_AGRO => false,
             self::SCHOOL_ENSAE => false,
         self::SCHOOL => array(
             self::SCHOOL_AGRO => false,
             self::SCHOOL_ENSAE => false,
@@ -652,7 +654,7 @@ class WSRequestCriteria
         ),
     );
 
         ),
     );
 
-    public static $CHOICES_LIST = array(
+    public static $choices_list = array(
         self::HOBBIES,
         self::JOB_COMPETENCIES,
         self::JOB_RESUME,
         self::HOBBIES,
         self::JOB_COMPETENCIES,
         self::JOB_RESUME,
@@ -706,7 +708,7 @@ class WSRequestFields
     const DIPLOMA_MASTER = 'master';
     const DIPLOMA_PHD = 'phd';
 
     const DIPLOMA_MASTER = 'master';
     const DIPLOMA_PHD = 'phd';
 
-    public static $CHOICES = array(
+    public static $choices = array(
         self::UID,
         self::FIRSTNAME,
         self::LASTNAME,
         self::UID,
         self::FIRSTNAME,
         self::LASTNAME,
@@ -743,14 +745,14 @@ class WSRequestFields
     public static function profileDegreeToWSDiploma($degree)
     {
         switch ($degree) {
     public static function profileDegreeToWSDiploma($degree)
     {
         switch ($degree) {
-        case Profile::DEGREE_X:
-            return self::DIPLOMA_ING;
-        case Profile::DEGREE_M:
-            return self::DIPLOMA_MASTER;
-        case Profile::DEGREE_D:
-            return self::DIPLOMA_PHD;
-        default:
-            return null;
+            case Profile::DEGREE_X:
+                return self::DIPLOMA_ING;
+            case Profile::DEGREE_M:
+                return self::DIPLOMA_MASTER;
+            case Profile::DEGREE_D:
+                return self::DIPLOMA_PHD;
+            default:
+                return null;
         }
     }
 
         }
     }