コード例 #1
0
 /**
  *  This function handle the "delete" http request
  * 
  * @param  string|null correspond to the URL after /Lan
  * 
  * @throws RestException
  */
 public function delete($padId = null)
 {
     if (isset($padId)) {
         $data = RestHandler::getData();
         $pad = NotesFactory::build(PadComponent::getClass(), array('id' => $padId));
         if (!$pad) {
             throw new RestException("Pad not found", 404);
         } else {
             if ($pad->mail_owner != Auth::user()->email) {
                 throw new RestException("Access denied", 403);
             } else {
                 // Export datas if asked
                 if (isset($data->exportContent) && $data->exportContent === true) {
                     $padContent = $this->exportPadContent($pad);
                     // Setting informations
                     $infos = array(array('pad' => array('pad_name' => $pad->pad_name)));
                     // Send by mail to pad owner
                     $attachment = new MailAttachment(str_ireplace(' ', '', $pad->pad_name) . '_' . date('YmdHis') . '.html');
                     $attachment->content = $padContent;
                     $attachment->build();
                     $this->sendPadInformationsByMail($pad, Auth::user()->email, 'delete_pad', $infos, $attachment);
                 }
                 $cdatas = array('padID' => $pad->pad_name, 'apikey' => $this->etherpadApiKey);
                 $result = RestUtilities::callAPI($this->etherpadURLApi . 'deletePad', RestMethods::GET, $cdatas);
                 //                    $result = json_encode(array('code' => 0));
                 if ($result) {
                     if (isset($result->error)) {
                         throw new RestException($result->error);
                     } else {
                         if ($result->code == 0) {
                             $pad->delete();
                             return array('status' => "success", 'content' => $pad);
                         } else {
                             throw new RestException("Pad not found", 404);
                         }
                     }
                 }
             }
         }
     } else {
         throw new RestException("Invalid pad ID", 500);
     }
 }
コード例 #2
0
 /**
  * Save in database
  */
 public function customSave()
 {
     //TODO : manage guests
     //
     // TODO: Manage date
     if ($this->id) {
         // Get new guests lists (this)
         $cPad = NotesFactory::build(PadComponent::getClass(), $this->id);
         // If guest list differs
         if ($this->guests !== $cPad->guests) {
             foreach (PadGuestComponent::getByPadID($this->id) as $padGuest) {
                 $padGuest->delete();
             }
             foreach ($this->guests as $guest) {
                 $cGuest = GuestComponent::getByEmail($guest->email);
                 // If guest not found in DB, creating it
                 if (!$cGuest) {
                     $cGuest = NotesFactory::build(GuestComponent::getClass(), $guest);
                     $cGuest->save();
                 }
                 // Create the PadGuest link
                 $padGuest = NotesFactory::build(PadGuestComponent::getClass(), array('pad_id' => $this->id, 'guest_id' => $cGuest->id));
                 $padGuest->save();
             }
         }
         $this->updateRecord($this->toDBData(), 'id');
     } else {
         // Insert record
         $this->insertRecord($this->toDBData());
         $this->id = (int) DBI::lastInsertId();
         if (count($this->guests) > 0) {
             foreach ($this->guests as $tmpGuest) {
                 if (!$tmpGuest->id) {
                     $tmpGuest->save();
                 }
                 $joint = NotesFactory::build(PadGuestComponent::getClass(), array('pad_id' => $this->id, 'guest_id' => $tmpGuest->id));
                 $joint->save();
             }
         }
     }
     self::$objectCache[get_class()][$this->id] = $this;
 }