예제 #1
0
 /**
  * This function allows to get a pad by ID
  * 
  * @param integer $padId
  * @return PadComponent The pad associated with the ID
  */
 public static function getByPadID($padID)
 {
     $padGuests = PadGuestComponent::getByPadID($padID);
     $guests = array();
     if (count($padGuests) > 0) {
         foreach ($padGuests as $padGuestid => $padGuest) {
             $guests[] = new self(self::getByID($padGuest->guest_id));
         }
     }
     return $guests;
 }
예제 #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;
 }