You are here

class ServicesClientControl in Services Client 7.2

Class for handling control data.

Hierarchy

Expanded class hierarchy of ServicesClientControl

File

include/plugin.inc, line 413
Base plugin definitions. All other plugins should be extended from this set of plugins.

View source
class ServicesClientControl {
  protected $entity;
  protected $data;
  protected $client_id;
  protected $remote_id;

  /**
   * Constructor.
   *
   * @param stdClass $entity
   *   Drupal entity that is being processed.
   *
   * @param string $client_id
   *   Name of local services client
   *
   * @param string $remote_id
   *   Remote client id.
   */
  public function __construct($entity, $client_id, $remote_id) {
    $this->entity = $entity;
    $this->data = isset($entity->_services_client) ? $entity->_services_client : array();
    $this->client_id = $client_id;
    $this->remote_id = $remote_id;
  }

  /**
   * Determine if bypass queue flag is set.
   *
   * @return bool
   *   TRUE if bypassing queue is requested.
   */
  public function bypassQueue() {
    return !empty($this->data['bypass_queue']) || !empty($this->data['v2']['bypass_queue']);
  }

  /**
   * Determine weather data should be queued.
   *
   * @return bool
   *   TRUE if event should be queued.
   */
  public function shouldQueue() {
    if (!$this
      ->bypassQueue() && (!empty($this->data['origin']) || !empty($this->data['v2']['id']))) {
      return TRUE;
    }
    return FALSE;
  }

  /**
   * Determine weather entity received by event is looping.
   *
   * @return boolean
   *   TRUE if entity already visited.
   */
  public function isLooping() {
    if (isset($this->data['visted']) && in_array($this->remote_id, $this->data['visted'])) {
      return TRUE;
    }
    if (isset($this->data['v2']['nodes']) && in_array($this->remote_id, $this->data['v2']['nodes'])) {
      return TRUE;
    }
    return FALSE;
  }

  /**
   * Retrieve new controlling data which contains info about current node.
   *
   * @return array
   */
  public function getData() {
    $data = $this->data;

    // V1 data
    $data['origin'] = services_client_get_id();
    $data['visted'] = isset($data['visted']) ? $data['visted'] : array();
    if (empty($data['visted']) && !empty($this->data['v2']['nodes'])) {
      $data['visted'] = $this->data['v2']['nodes'];
    }
    if (!in_array($this->client_id, $data['visted'])) {
      $data['visted'][] = $this->client_id;
    }

    // V2 data
    $data['v2']['id'] = services_client_get_id();
    $data['v2']['source'] = drupal_is_cli() ? 'cli' : $_SERVER['HTTP_REFERER'];
    $data['v2']['nodes'] = isset($data['v2']['nodes']) ? $data['v2']['nodes'] : array();
    if (empty($data['v2']['nodes']) && !empty($this->data['visted'])) {
      $data['v2']['nodes'] = $this->data['visted'];
    }
    if (!in_array($this->client_id, $data['v2']['nodes'])) {
      $data['v2']['nodes'][] = $this->client_id;
    }
    return $data;
  }

  /**
   * Set control dat to new object that is sent to remote site.
   *
   * @param stdClass $object
   *   Mapped object.
   */
  public function setData($object) {
    $object->_services_client = $this
      ->getData();
    return $this;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ServicesClientControl::$client_id protected property
ServicesClientControl::$data protected property
ServicesClientControl::$entity protected property
ServicesClientControl::$remote_id protected property
ServicesClientControl::bypassQueue public function Determine if bypass queue flag is set.
ServicesClientControl::getData public function Retrieve new controlling data which contains info about current node.
ServicesClientControl::isLooping public function Determine weather entity received by event is looping.
ServicesClientControl::setData public function Set control dat to new object that is sent to remote site.
ServicesClientControl::shouldQueue public function Determine weather data should be queued.
ServicesClientControl::__construct public function Constructor.