You are here

class WebformRulesSubmissionWrapper in Webform Rules 7

Provide entity-like access to webform submission data.

Hierarchy

Expanded class hierarchy of WebformRulesSubmissionWrapper

See also

webform_rules_condition_data_nid_assertions()

2 string references to 'WebformRulesSubmissionWrapper'
WebformRulesSubmissionWrapper::__construct in ./webform_rules.rules.inc
Construct a new wrapper object.
webform_rules_rules_data_info in ./webform_rules.rules.inc
Implements hook_rules_data_info().

File

./webform_rules.rules.inc, line 460
Functions for rules integration.

View source
class WebformRulesSubmissionWrapper extends RulesIdentifiableDataWrapper {

  // @TODO: implement RulesDataWrapperSavableInterface
  public function __construct($type, $data = NULL, $info = array()) {
    if (!is_null($data)) {

      // If we have a webform submission, add the form values as properties.
      // (If we do not have a submission, properties are added by assertion.
      // @see webform_rules_condition_data_nid_assertions()).
      $info['property info alter'] = array(
        'WebformRulesSubmissionWrapper',
        'webformSubmissionValues',
      );
    }
    parent::__construct($type, $data, $info);
    $this
      ->setData($data);
  }
  public static function webformSubmissionValues($wrapper, $property_info) {
    $submission = $wrapper
      ->value();
    $properties = $property_info['properties'];
    if (!empty($submission->nid)) {
      $properties += _webform_rules_component_property_info($submission->nid);
    }
    return array(
      'properties' => $properties,
    );
  }
  protected function setData($data) {
    parent::setData($data);
    if (!is_array($data)) {
      return;
    }
    $submission = current($data);
    if (!isset($submission->sid)) {
      return;
    }
    $s = webform_get_submissions(array(
      'sid' => $submission->sid,
    ));
    if (empty($s) || !is_array($s)) {
      return;
    }
    $s = current($s);
    $this->id = $s->sid;
    $this->data = $s;
    $webform = node_load($this->data->nid);
    $components = $webform->webform['components'];
    foreach ($s->data as $cid => $val) {
      $c_key = $components[$cid]['form_key'];
      $id = "{$c_key}";
      $this->data->{$id} = array_values($val);
    }
  }
  protected function extractIdentifier($data) {
    return $data->sid;
  }
  public function getIdentifier() {
    return $this
      ->dataAvailable() && $this
      ->value() ? $this->id : NULL;
  }
  protected function load($data) {
    if (is_array($data)) {
      $sid = $data['sid'];
    }
    else {
      $sid = $data;
    }
    module_load_include('inc', 'webform', 'includes/webform.submissions');
    return webform_get_submissions(array(
      'sid' => $sid,
    ));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityMetadataWrapper::$cache protected property
EntityMetadataWrapper::$data protected property
EntityMetadataWrapper::$info protected property
EntityMetadataWrapper::$type protected property 1
EntityMetadataWrapper::access public function Determines whether the given user has access to view or edit this property. Apart from relying on access metadata of properties, this takes into account information about entity level access, if available: 1
EntityMetadataWrapper::dataAvailable protected function Returns whether data is available to work with.
EntityMetadataWrapper::debugIdentifierLocation public function Returns a string to use to identify this wrapper in error messages. 1
EntityMetadataWrapper::info public function Gets info about the wrapped data.
EntityMetadataWrapper::label public function Returns the label for the currently set property value if there is one available, i.e. if an options list has been specified. 2
EntityMetadataWrapper::optionsList public function Returns the options list specifying possible values for the property, if defined.
EntityMetadataWrapper::raw public function Returns the raw, unprocessed data. Most times this is the same as returned by value(), however for already processed and sanitized textual data, this will return the unprocessed data in contrast to value().
EntityMetadataWrapper::type public function Gets the (entity)type of the wrapped data. 1
EntityMetadataWrapper::updateParent protected function Updates the parent data structure of a data property with the latest data value.
EntityMetadataWrapper::validate public function Returns whether $value is a valid value to set. 1
EntityMetadataWrapper::__toString public function
EntityStructureWrapper::$langcode protected property
EntityStructureWrapper::$propertyInfo protected property
EntityStructureWrapper::$propertyInfoDefaults protected property
EntityStructureWrapper::get public function Get the wrapper for a property.
EntityStructureWrapper::getIterator public function
EntityStructureWrapper::getPropertyInfo public function Gets the info about the given property.
EntityStructureWrapper::getPropertyLanguage public function Gets the language used for retrieving properties.
EntityStructureWrapper::getPropertyRaw protected function Gets the raw value of a property.
EntityStructureWrapper::getPropertyValue protected function Gets the value of a property.
EntityStructureWrapper::language public function Sets a new language to use for retrieving properties.
EntityStructureWrapper::propertyAccess protected function
EntityStructureWrapper::refPropertyInfo public function Returns a reference on the property info.
EntityStructureWrapper::setProperty protected function Sets a property.
EntityStructureWrapper::spotInfo protected function May be used to lazy-load additional info about the data, depending on the concrete passed data. 1
EntityStructureWrapper::__get public function Magic method: Get a wrapper for a property.
EntityStructureWrapper::__isset public function Magic method: Can be used to check if a property is known.
EntityStructureWrapper::__set public function Magic method: Set a property.
RulesIdentifiableDataWrapper::$id protected property Contains the id.
RulesIdentifiableDataWrapper::clear public function Overridden. Overrides EntityStructureWrapper::clear
RulesIdentifiableDataWrapper::set public function Overridden to support setting the data by either the object or the id. Overrides EntityMetadataWrapper::set
RulesIdentifiableDataWrapper::value public function Overridden. Overrides EntityMetadataWrapper::value
RulesIdentifiableDataWrapper::__sleep public function Prepare for serialization. Overrides EntityStructureWrapper::__sleep
RulesIdentifiableDataWrapper::__wakeup public function Prepare for unserialization.
WebformRulesSubmissionWrapper::extractIdentifier protected function Extract the identifier of the given data object. Overrides RulesIdentifiableDataWrapper::extractIdentifier
WebformRulesSubmissionWrapper::getIdentifier public function Returns the identifier of the wrapped data. Overrides RulesIdentifiableDataWrapper::getIdentifier
WebformRulesSubmissionWrapper::load protected function Load a data object given an identifier. Overrides RulesIdentifiableDataWrapper::load
WebformRulesSubmissionWrapper::setData protected function Sets the data internally accepting both the data id and object. Overrides RulesIdentifiableDataWrapper::setData
WebformRulesSubmissionWrapper::webformSubmissionValues public static function
WebformRulesSubmissionWrapper::__construct public function Construct a new wrapper object. Overrides RulesIdentifiableDataWrapper::__construct