You are here

class WorkflowScheduledTransition in Workflow 7.2

Same name and namespace in other branches
  1. 7 includes/Entity/WorkflowScheduledTransition.php \WorkflowScheduledTransition

Implements a scheduled transition, as shown on Workflow form.

Hierarchy

Expanded class hierarchy of WorkflowScheduledTransition

3 string references to 'WorkflowScheduledTransition'
WorkflowScheduledTransition::load in includes/Entity/WorkflowScheduledTransition.php
Given a node, get all scheduled transitions for it.
WorkflowScheduledTransition::loadBetween in includes/Entity/WorkflowScheduledTransition.php
Given a timeframe, get all scheduled transitions.
workflow_entity_info in ./workflow.entity.inc
Implements hook_entity_info().

File

includes/Entity/WorkflowScheduledTransition.php, line 11
Contains workflow\includes\Entity\WorkflowScheduledTransition.

View source
class WorkflowScheduledTransition extends WorkflowTransition {

  // Scheduled timestamp of state change.
  public $scheduled;

  /**
   * Constructor.
   */
  public function __construct(array $values = array(), $entityType = 'WorkflowScheduledTransition') {

    // Please be aware that $entity_type and $entityType are different things!
    parent::__construct($values, $entityType);
    $this->is_scheduled = TRUE;
    $this->is_executed = FALSE;
  }
  public function setValues($entity_type, $entity, $field_name, $old_sid, $new_sid, $uid = NULL, $scheduled = REQUEST_TIME, $comment = '') {

    // A scheduled transition does not have a timestamp, yet.
    $stamp = 0;
    parent::setValues($entity_type, $entity, $field_name, $old_sid, $new_sid, $uid, $stamp, $comment);

    // Set the scheduled timestamp of state change.
    $this->scheduled = $scheduled;
  }

  /**
   * Given a node, get all scheduled transitions for it.
   *
   * @param string $entity_type
   * @param int $entity_id
   * @param string $field_name
   *   Optional.
   *
   * @return array
   *   An array of WorkflowScheduledTransitions.
   *
   * deprecated: workflow_get_workflow_scheduled_transition_by_nid() --> WorkflowScheduledTransition::load()
   */
  public static function load($entity_type, $entity_id, $field_name = '', $limit = NULL) {
    if (!$entity_id) {
      return array();
    }
    $query = db_select('workflow_scheduled_transition', 'wst');
    $query
      ->fields('wst');
    $query
      ->condition('entity_type', $entity_type, '=');
    $query
      ->condition('nid', $entity_id, '=');
    if ($field_name !== NULL) {
      $query
        ->condition('field_name', $field_name, '=');
    }
    $query
      ->orderBy('scheduled', 'ASC');
    $query
      ->addTag('workflow_scheduled_transition');
    if ($limit) {
      $query
        ->range(0, $limit);
    }
    $result = $query
      ->execute()
      ->fetchAll(PDO::FETCH_CLASS, 'WorkflowScheduledTransition');
    return $result;
  }

  /**
   * Given a timeframe, get all scheduled transitions.
   *
   * deprecated: workflow_get_workflow_scheduled_transition_by_between() --> WorkflowScheduledTransition::loadBetween()
   */
  public static function loadBetween($start = 0, $end = 0) {
    $query = db_select('workflow_scheduled_transition', 'wst');
    $query
      ->fields('wst');
    $query
      ->orderBy('scheduled', 'ASC');
    $query
      ->addTag('workflow_scheduled_transition');
    if ($start) {
      $query
        ->condition('scheduled', $start, '>');
    }
    if ($end) {
      $query
        ->condition('scheduled', $end, '<');
    }
    $result = $query
      ->execute()
      ->fetchAll(PDO::FETCH_CLASS, 'WorkflowScheduledTransition');
    return $result;
  }

  /**
   * Save a scheduled transition. If the transition is executed, save in history.
   */
  public function save() {

    // If executed, save in history.
    if ($this->is_executed) {

      // Be careful, we are not a WorkflowScheduleTransition anymore!
      $this->entityType = 'WorkflowTransition';
      $this
        ->setUp();
      return parent::save();

      // <--- exit !!
    }

    // Since we do not have an entity_id here, we cannot use entity_delete.
    // @todo: Add an 'entity id' to WorkflowScheduledTransition entity class.
    // $result = parent::save();
    // Avoid duplicate entries.
    $clone = clone $this;
    $clone
      ->delete();

    // Save (insert or update) a record to the database based upon the schema.
    drupal_write_record('workflow_scheduled_transition', $this);

    // Create user message.
    if ($state = $this
      ->getNewState()) {
      $entity_type = $this->entity_type;
      $entity = $this
        ->getEntity();
      $message = '%entity_title scheduled for state change to %state_name on %scheduled_date';
      $args = array(
        '@entity_type' => $entity_type,
        '%entity_title' => entity_label($entity_type, $entity),
        '%state_name' => entity_label('WorkflowState', $state),
        '%scheduled_date' => format_date($this->scheduled),
      );
      $uri = entity_uri($entity_type, $entity);
      watchdog('workflow', $message, $args, WATCHDOG_NOTICE, l('view', $uri['path'] . '/workflow'));
      drupal_set_message(t($message, $args));
    }
  }

  /**
   * Given a node, delete transitions for it.
   *
   * deprecated: workflow_delete_workflow_scheduled_transition_by_nid() --> WorkflowScheduledTransition::delete()
   */
  public function delete() {

    // Support translated Workflow Field workflows by including the language.
    db_delete($this->entityInfo['base table'])
      ->condition('entity_type', $this->entity_type)
      ->condition('nid', $this->entity_id)
      ->condition('field_name', $this->field_name)
      ->condition('language', $this->language)
      ->execute();
  }

  /**
   * Property functions.
   */

  /**
   * If a scheduled transition has no comment, a default comment is added before executing it.
   */
  public function addDefaultComment() {
    $this->comment = t('Scheduled by user @uid.', array(
      '@uid' => $this->uid,
    ));
  }

  /**
   * {@inheritdoc}
   */
  public function getTimestamp() {
    return $this->scheduled;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Entity::$defaultLabel protected property 1
Entity::$entityInfo protected property
Entity::$entityType protected property
Entity::$idKey protected property
Entity::$wrapper protected property
Entity::buildContent public function Builds a structured array representing the entity's content. Overrides EntityInterface::buildContent 1
Entity::bundle public function Returns the bundle of the entity. Overrides EntityInterface::bundle
Entity::defaultUri protected function Override this in order to implement a custom default URI and specify 'entity_class_uri' as 'uri callback' hook_entity_info().
Entity::entityInfo public function Returns the info of the type of the entity. Overrides EntityInterface::entityInfo
Entity::entityType public function Returns the type of the entity. Overrides EntityInterface::entityType
Entity::export public function Exports the entity. Overrides EntityInterface::export
Entity::getTranslation public function Gets the raw, translated value of a property or field. Overrides EntityInterface::getTranslation
Entity::hasStatus public function Checks if the entity has a certain exportable status. Overrides EntityInterface::hasStatus
Entity::identifier public function Returns the entity identifier, i.e. the entities name or numeric id. Overrides EntityInterface::identifier
Entity::internalIdentifier public function Returns the internal, numeric identifier. Overrides EntityInterface::internalIdentifier
Entity::isDefaultRevision public function Checks whether the entity is the default revision. Overrides EntityInterface::isDefaultRevision
Entity::label public function Returns the label of the entity. Overrides EntityInterface::label
Entity::setUp protected function Set up the object instance on construction or unserializiation.
Entity::uri public function Returns the uri of the entity just as entity_uri(). Overrides EntityInterface::uri
Entity::view public function Generate an array for rendering the entity. Overrides EntityInterface::view
Entity::wrapper public function Returns the EntityMetadataWrapper of the entity. Overrides EntityInterface::wrapper
Entity::__sleep public function Magic method to only serialize what's necessary.
Entity::__wakeup public function Magic method to invoke setUp() on unserialization.
WorkflowScheduledTransition::$scheduled public property
WorkflowScheduledTransition::addDefaultComment public function If a scheduled transition has no comment, a default comment is added before executing it.
WorkflowScheduledTransition::delete public function Given a node, delete transitions for it. Overrides Entity::delete
WorkflowScheduledTransition::getTimestamp public function Returns the time on which the transitions was or will be executed. Overrides WorkflowTransition::getTimestamp
WorkflowScheduledTransition::load public static function Given a node, get all scheduled transitions for it.
WorkflowScheduledTransition::loadBetween public static function Given a timeframe, get all scheduled transitions.
WorkflowScheduledTransition::save public function Save a scheduled transition. If the transition is executed, save in history. Overrides Entity::save
WorkflowScheduledTransition::setValues public function Helper function for __construct. Used for all children of WorkflowTransition (aka WorkflowScheduledTransition) Overrides WorkflowTransition::setValues
WorkflowScheduledTransition::__construct public function Constructor. Overrides WorkflowTransition::__construct
WorkflowTransition::$comment public property
WorkflowTransition::$delta public property
WorkflowTransition::$entity protected property
WorkflowTransition::$entity_id public property
WorkflowTransition::$entity_type public property
WorkflowTransition::$field_name public property
WorkflowTransition::$force protected property
WorkflowTransition::$is_executed protected property
WorkflowTransition::$is_scheduled protected property
WorkflowTransition::$language public property
WorkflowTransition::$new_sid public property
WorkflowTransition::$nid public property
WorkflowTransition::$old_sid public property
WorkflowTransition::$revision_id public property
WorkflowTransition::$sid public property
WorkflowTransition::$stamp public property
WorkflowTransition::$uid public property
WorkflowTransition::$user protected property
WorkflowTransition::$wid public property
WorkflowTransition::defaultLabel protected function Defines the entity label if the 'entity_class_label' callback is used. Overrides Entity::defaultLabel
WorkflowTransition::dpm public function Helper debugging function to easily show the contents fo a transition.
WorkflowTransition::execute public function Execute a transition (change state of a node).
WorkflowTransition::force public function
WorkflowTransition::getComment public function
WorkflowTransition::getEntity public function Get the Transitions $entity.
WorkflowTransition::getFieldName public function
WorkflowTransition::getNewState public function
WorkflowTransition::getOldState public function Functions, common to the WorkflowTransitions.
WorkflowTransition::getTimestampFormatted public function
WorkflowTransition::getUser public function
WorkflowTransition::getWorkflow public function Get the Transitions $workflow.
WorkflowTransition::isAllowed protected function Verifies if the given transition is allowed.
WorkflowTransition::isExecuted public function
WorkflowTransition::isForced public function A transition may be forced skipping checks.
WorkflowTransition::isScheduled public function Returns if this is a Scheduled Transition.
WorkflowTransition::loadMultiple public static function Given a node, get all transitions for it.
WorkflowTransition::post_execute public function Invokes 'transition post'.
WorkflowTransition::schedule public function
WorkflowTransition::setEntity public function Set the Transitions $entity.
WorkflowTransition::setTimestamp public function