/**
  * Try to apply the values in this form to 'obj'.
  * Since the object is auditable, make a copy of it here so that any changes
  * made during validation or the commit process do not affect the original.
  * @param AUDITABLE $obj Store the form values to this object.
  */
 public function attempt_action($obj)
 {
     if (!$this->previewing()) {
         if ($this->cloning()) {
             $obj->initialize_as_new();
         }
         $this->_history_item = $obj->new_history_item();
     }
     parent::attempt_action($obj);
 }
 /**
  * Is the passed-in object different from this history item's?
  * The object is compared to that previously set with {@link set_object()}. The objects must be the same. That
  * is, their ids must match or the function throws an exception. This function is used to track differences between
  * versions of an object, not to detect differences between objects.
  * @param AUDITABLE $obj
  * @access private
  */
 public function record_differences($obj)
 {
     $objects_are_same_or_new = $obj->exists() == $this->_object->exists() && $obj->id == $this->_object->id;
     $this->assert($objects_are_same_or_new, "Cannot compare two different objects (expected [{$this->_object->id}], got [{$obj->id}]", 'record_differences', 'HISTORY_ITEM');
     if (!$obj->exists()) {
         if (!isset($this->kind)) {
             $this->kind = $obj->history_item_kind_for_new();
         }
         $this->_is_new = true;
     } else {
         if (!isset($this->kind)) {
             $this->kind = History_item_updated;
         }
         $this->_record_differences($this->_object, $obj);
     }
 }
 /**
  * List of subscribers for this objct.
  * @param HISTORY_ITEM $history_item
  * @param AUDITABLE $obj
  * @return SUBSCRIBER[]
  */
 protected function _subscribers_for($history_item, $obj)
 {
     $query = $obj->subscriber_query($history_item);
     // Don't even bother retrieving disabled subscribers
     $query->restrict('min_hours_to_wait <> ' . Subscriptions_disabled);
     return $query->objects();
 }
 /**
  * Execute the form.
  * @param AUDITABLE $obj
  * @access private
  */
 public function commit($obj)
 {
     if ($this->object_exists() && $this->value_for('quick_save')) {
         $obj->store();
     } else {
         parent::commit($obj);
     }
 }
 /**
  * Return default handler objects for supported tasks.
  * @param string $handler_type Specific functionality required.
  * @param OBJECT_RENDERER_OPTIONS $options
  * @return object
  * @access private
  */
 protected function _default_handler_for($handler_type, $options = null)
 {
     switch ($handler_type) {
         case Handler_print_renderer:
         case Handler_html_renderer:
         case Handler_text_renderer:
         case Handler_source_renderer:
             include_once 'webcore/gui/content_object_renderer.php';
             return new CONTENT_OBJECT_RENDERER($this->app, $options);
         case Handler_mail:
             include_once 'webcore/mail/content_object_mail_renderer.php';
             return new CONTENT_OBJECT_MAIL_RENDERER($this->app);
         case Handler_history_item:
             include_once 'webcore/obj/webcore_history_items.php';
             return new CONTENT_OBJECT_HISTORY_ITEM($this->app);
         default:
             return parent::_default_handler_for($handler_type, $options);
     }
 }
 /**
  * How is the user subscribed to this object?
  * Returns a list of {@link Subscribe_constants} that match this person and the
  * given object.
  * @param AUDITABLE $obj
  * @return integer[]
  */
 public function receives_notifications_through($obj)
 {
     $Result = array();
     if (isset($this->email) && $obj->exists()) {
         $query = $obj->subscriber_query();
         $query->restrict("subscribers.email = '{$this->email}'");
         $query->set_select('subs.kind as subkind');
         $db = $query->raw_output();
         while ($db->next_record()) {
             $Result[] = $db->f('subkind');
         }
     }
     return $Result;
 }
 /**
  * Show created/updated information in plain text.
  * Uses {@link _echo_plain_text_user()} to format users.
  * @param AUDITABLE $obj
  * @access private
  */
 protected function _echo_plain_text_users($obj)
 {
     $this->_echo_plain_text_user('Created', $obj->creator(), $obj->time_created);
     if ($obj->modified()) {
         $this->_echo_plain_text_user('Updated', $obj->modifier(), $obj->time_modified);
     }
 }