Ejemplo n.º 1
0
 public static function log(Model_List $list, $description)
 {
     $list->touch();
     $t = new Model_Listtransaction();
     $t->list_id = $list->id;
     $t->description = $description;
     $t->save();
 }
Ejemplo n.º 2
0
 public function save(Validation $validation = NULL)
 {
     $action = $this->loaded() ? 'Updated' : 'Added';
     if ($this->loaded()) {
         // get this gift from the DB again
         // so we can check for an unreserve action
         $original = ORM::factory('gift', $this->id);
     }
     parent::save($validation);
     if ($this->reserver_id == Auth::instance()->get_user()->id) {
         // the reserver is currently logged in
         // and has made a change to the gift
         // don't send any emails
         return;
     }
     if ($this->reserver_id) {
         // the gift owner has made a change
         // inform the reserver immediately that the gift
         // has been edited
         $config = Kohana::$config->load('giftcircle');
         $reserver = $this->reserver;
         $gift_owner = $this->list->owner;
         if (!$reserver->email || !$gift_owner->email) {
             // account deleted or something crazy
             return;
         }
         $subject = Message::t('email', 'edited_gift.subject', array('owner_name' => $gift_owner->firstname . ' ' . $gift_owner->surname));
         $message = Message::t('email', 'edited_gift.plain', array('url' => URL::base('http') . 'gift/shopping', 'reserver_email' => $reserver->email, 'reserver_firstname' => $reserver->firstname, 'reserver_surname' => $reserver->surname, 'owner_name' => $gift_owner->firstname . ' ' . $gift_owner->surname, 'gift_name' => $this->name), false);
         $to = array($reserver->email, $reserver->firstname . ' ' . $reserver->surname);
         $from = array($config->get('email-from'), $config->get('email-from-name'));
         if (is_object(Kohana::$log)) {
             Kohana::$log->add(Log::INFO, 'Sending email To "' . implode(' ', $to) . '", ' . 'From "' . implode(' ', $from) . '", ' . 'Subject "' . $subject . '".');
             Kohana::$log->write();
         }
         Email::send($to, $from, $subject, $message);
     } else {
         // not reserved yet
         if (isset($original) && !empty($original->reserver_id)) {
             // there was a reserver_id but now there isn't
             // the "update" is just someone unreserving the gift
             return;
         }
         $link = '<a href="' . URL::base('http') . 'gift/details/' . $this->id . '">' . htmlspecialchars($this->name) . '</a>';
         Model_Listtransaction::log($this->list, $action . ' a gift: ' . $link);
     }
 }