Ejemplo n.º 1
0
 /**
  * Method launched for the HTTP GET requests
  * 
  * @param mixed $param Correspond to the URL after /Lan
  * 
  * @return array List of visio referents
  */
 public function get($param = null)
 {
     // Sensure user authentified
     if (!Auth::user()) {
         throw new AuthNotConnectedException();
     }
     if (is_null($param)) {
         $pads = array();
         foreach (PadComponent::getByMailOwner($this->user) as $pad) {
             $pads[$pad->id] = $pad;
         }
         return array('data' => array('size' => count($pads), 'content' => $pads));
     } else {
         $resultCode = 404;
         $cdatas = array('padID' => $param, 'apikey' => $this->etherpadApiKey);
         $result = RestUtilities::callAPI($this->etherpadURLApi . 'getRevisionsCount', RestMethods::GET, $cdatas);
         if ($result) {
             if (isset($result->error)) {
                 throw new RestException($result->error);
             } else {
                 if ($result->code == 0) {
                     // Found via Etherpad API
                     $resultCode = 200;
                 } else {
                     throw new PadNotFoundException();
                 }
             }
         }
         if ($resultCode === 200) {
             // Try to get it from BDD
             $pad = PadComponent::getByPadName($param);
             if ($pad && $pad->mail_owner === Auth::user()->email) {
                 // Pad found and owned
                 $resultCode = 200;
             } else {
                 throw new PadNotOwnedException();
             }
         }
         return array('data' => array('size' => $pad !== false ? 1 : 0, 'content' => $pad));
     }
 }