class UcCouponController in Ubercart Discount Coupons 7.3
Controller class for uc_coupon entity.
Hierarchy
- class \DrupalDefaultEntityController implements DrupalEntityControllerInterface- class \EntityAPIController implements EntityAPIControllerRevisionableInterface- class \UcCouponController
 
 
- class \EntityAPIController implements EntityAPIControllerRevisionableInterface
Expanded class hierarchy of UcCouponController
1 string reference to 'UcCouponController'
- uc_coupon_entity_info in ./uc_coupon.module 
- Implements hook_entity_info();
File
- ./uc_coupon.entity.inc, line 10 
- Entity Controller and Metadata Controller classes for uc_coupon.
View source
class UcCouponController extends EntityAPIController {
  /**
   * @see EntityAPIController::delete()
   */
  public function delete($ids, DatabaseTransaction $transaction = NULL) {
    parent::delete($ids, $transaction);
    db_delete('uc_coupons_orders')
      ->condition('cid', $ids, 'IN')
      ->execute();
  }
  /**
   * @see EntityAPIController::save()
   */
  public function save($coupon, DatabaseTransaction $transaction = NULL) {
    if (empty($coupon->cid)) {
      $coupon->created = REQUEST_TIME;
      $coupon->bulk_seed = md5(uniqid());
    }
    parent::save($coupon, $transaction);
  }
  /**
   * @see EntityAPIController::buildContent()
   */
  public function buildContent($coupon, $view_mode = 'full', $langcode = NULL, $content = array()) {
    $rows = array();
    $rows[] = array(
      t('Name'),
      check_plain($coupon->name),
    );
    if (!$coupon->status) {
      $status = t('Inactive');
    }
    elseif (!$coupon->valid_until) {
      $status = t('Active');
    }
    elseif (REQUEST_TIME < $coupon->valid_from) {
      $status = t('Not valid until @date', array(
        '@date' => _uc_coupon_format_date($coupon->valid_from, variable_get('date_format_uc_store', 'm/d/Y H:iT')),
      ));
    }
    elseif (REQUEST_TIME > $coupon->valid_until) {
      $status = t('Expired on @date', array(
        '@date' => _uc_coupon_format_date($coupon->valid_until, variable_get('date_format_uc_store', 'm/d/Y H:iT')),
      ));
    }
    else {
      $status = t('Active until @date', array(
        '@date' => _uc_coupon_format_date($coupon->valid_until, variable_get('date_format_uc_store', 'm/d/Y H:iT')),
      ));
    }
    $rows[] = array(
      t('Status'),
      $status,
    );
    if (!$coupon->bulk) {
      $rows[] = array(
        t('Code'),
        check_plain($coupon->code) . ' (' . l(t('Print'), 'admin/store/coupons/' . $coupon->cid . '/print') . ')',
      );
      if ($coupon->max_uses) {
        $rows[] = array(
          t('Maximum uses'),
          $coupon->max_uses,
        );
      }
    }
    else {
      $codes = '<strong>' . check_plain($coupon->code) . ' × ' . check_plain($coupon->data['bulk_number']) . '</strong>';
      $codes .= ' (' . l(t('Download codes'), 'admin/store/coupons/' . $coupon->cid . '/codes') . ')';
      $codes .= ' (' . l(t('Print all'), 'admin/store/coupons/' . $coupon->cid . '/print') . ')';
      for ($id = 0; $id < $coupon->data['bulk_number']; $id++) {
        $code = uc_coupon_get_bulk_code($coupon, $id);
        $codes .= '<br />' . check_plain($code) . ' (' . l(t('Print'), 'admin/store/coupons/' . $coupon->cid . '/print/' . $code) . ')';
      }
      $rows[] = array(
        t('Codes'),
        $codes,
      );
      //$rows[] = array(t('Bulk seed'), check_plain($coupon->bulk_seed));
      if ($coupon->max_uses) {
        $rows[] = array(
          t('Maximum uses per code'),
          $coupon->max_uses,
        );
      }
    }
    $rows[] = array(
      t('Discount value'),
      theme('uc_coupon_discount', array(
        'coupon' => $coupon,
      )),
    );
    switch ($coupon->data['apply_to']) {
      case 'subtotal':
        $applies = t('Order subtotal');
        break;
      case 'products_total':
        $applies = t('Total of matching products');
        break;
      case 'products':
        $applies = t('Matching products');
        break;
      case 'cheapest':
        $applies = format_plural($coupon->data['apply_count'], 'Cheapest product', '@count cheapest products');
        break;
      case 'expensive':
        $applies = format_plural($coupon->data['apply_count'], 'Most expensive product', '@count most expensive products');
        break;
    }
    $rows[] = array(
      t('Applied to'),
      $applies,
    );
    if ($coupon->data['apply_to'] != 'subtotal') {
      $restrict = array();
      if (isset($coupon->data['product_types'])) {
        $key = format_plural(count($coupon->data['product_types']), 'All products in class', 'All products in classes');
        $restrict[$key] = $coupon->data['product_types'];
      }
      if (isset($coupon->data['products'])) {
        $products = array();
        foreach ($coupon->data['products'] as $nid) {
          $products[] = check_plain(db_query("SELECT title FROM {node} WHERE nid = :nid", array(
            ':nid' => $nid,
          ))
            ->fetchField());
        }
        if (isset($coupon->data['negate_products'])) {
          $restrict[t('All products except')] = $products;
        }
        else {
          $restrict[format_plural(count($products), 'Product', 'Products')] = $products;
        }
      }
      if (isset($coupon->data['skus'])) {
        $restrict[format_plural(count($coupon->data['skus']), 'SKU', 'SKUs')] = $coupon->data['skus'];
      }
      if (isset($coupon->data['terms'])) {
        $terms = array();
        foreach ($coupon->data['terms'] as $tid) {
          $terms[] = check_plain(db_query("SELECT name FROM {taxonomy_term_data} WHERE tid = :tid", array(
            ':tid' => $tid,
          ))
            ->fetchField());
        }
        if (isset($coupon->data['negate_terms'])) {
          $restrict[t('All taxonomy terms except')] = $terms;
        }
        else {
          $restrict[format_plural(count($terms), 'Taxonomy term', 'Taxonomy terms')] = $terms;
        }
      }
      if ($restrict) {
        $or = FALSE;
        foreach ($restrict as $title => &$restriction) {
          if ($or) {
            $title = t('or') . ' ' . $title;
          }
          $restriction = $title . ': <em>' . implode('</em>, <em>', $restriction) . '</em>';
          $or = TRUE;
        }
        $rows[] = array(
          t('Product restrictions'),
          implode('<br />', $restrict),
        );
      }
    }
    $restrict = array();
    if (isset($coupon->data['users'])) {
      $users = array();
      foreach ($coupon->data['users'] as $uid) {
        $users[] = check_plain(db_query("SELECT name FROM {users} WHERE uid = :uid", array(
          ':uid' => $uid,
        ))
          ->fetchField());
      }
      if (isset($coupon->data['negate_users'])) {
        $restrict[t('All users except')] = $users;
      }
      else {
        $restrict[format_plural(count($users), 'User', 'Users')] = $users;
      }
    }
    if (isset($coupon->data['max_uses_per_user'])) {
      $restrict['Maximum uses per user'] = array(
        $coupon->data['max_uses_per_user'],
      );
    }
    if (isset($coupon->data['roles'])) {
      if (isset($coupon->data['negate_roles'])) {
        $restrict[t('All roles except')] = $coupon->data['roles'];
      }
      else {
        $restrict[format_plural(count($coupon->data['roles']), 'Role', 'Roles')] = $coupon->data['roles'];
      }
    }
    if ($restrict) {
      foreach ($restrict as $title => &$restriction) {
        $restriction = $title . ': <em>' . implode('</em>, <em>', $restriction) . '</em>';
      }
      $rows[] = array(
        t('User restrictions'),
        implode('<br />', $restrict),
      );
    }
    if ($coupon->minimum_order > 0) {
      $rows[] = array(
        t('Order restrictions'),
        t('Minimum subtotal') . ': <em>' . uc_currency_format($coupon->minimum_order) . '</em>',
      );
    }
    $combo_list = array();
    if (!empty($coupon->data['combinations'])) {
      $combos = db_query('SELECT cid, name FROM {uc_coupons} where cid IN (:cids)', array(
        ':cids' => $coupon->data['combinations'],
      ));
      foreach ($combos as $combo) {
        $combo_list[] = check_plain("{$combo->name} [cid:{$combo->cid}]");
      }
    }
    if (isset($coupon->data['negate_combinations'])) {
      $ctext = empty($combo_list) ? t('Any.') : t('Any but:') . ' ' . implode(', ', $combo_list);
    }
    else {
      $ctext = empty($combo_list) ? t('None.') : t('Only:') . ' ' . implode(', ', $combo_list);
    }
    $rows[] = array(
      t('Allowed Combinations'),
      $ctext,
    );
    foreach ($rows as &$row) {
      $row[0] = array(
        'header' => TRUE,
        'data' => $row[0],
      );
    }
    $content['admin_summary'] = array(
      '#title' => t('Administrative Summary'),
      '#theme' => 'table',
      '#rows' => $rows,
    );
    return parent::buildContent($coupon, $view_mode, $langcode, $content);
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| DrupalDefaultEntityController:: | protected | property | Whether this entity type should use the static cache. | |
| DrupalDefaultEntityController:: | protected | property | Static cache of entities, keyed by entity ID. | |
| DrupalDefaultEntityController:: | protected | property | Array of information about the entity. | |
| DrupalDefaultEntityController:: | protected | property | Entity type for this controller instance. | |
| DrupalDefaultEntityController:: | protected | property | Additional arguments to pass to hook_TYPE_load(). | |
| DrupalDefaultEntityController:: | protected | property | Name of the entity's ID field in the entity database table. | |
| DrupalDefaultEntityController:: | protected | property | Name of entity's revision database table field, if it supports revisions. | |
| DrupalDefaultEntityController:: | protected | property | The table that stores revisions, if the entity supports revisions. | |
| DrupalDefaultEntityController:: | protected | function | Attaches data to entities upon loading. | 4 | 
| DrupalDefaultEntityController:: | protected | function | Gets entities from the static cache. | 1 | 
| DrupalDefaultEntityController:: | protected | function | Stores entities in the static entity cache. | |
| DrupalDefaultEntityController:: | protected | function | Ensures integer entity IDs are valid. | |
| DrupalDefaultEntityController:: | protected | function | Callback for array_filter that removes non-integer IDs. | |
| EntityAPIController:: | protected | property | ||
| EntityAPIController:: | protected | property | ||
| EntityAPIController:: | protected | property | ||
| EntityAPIController:: | protected | function | Overrides DrupalDefaultEntityController::buildQuery(). Overrides DrupalDefaultEntityController:: | 1 | 
| EntityAPIController:: | public | function | Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: | |
| EntityAPIController:: | public | function | Implements EntityAPIControllerRevisionableInterface::deleteRevision(). Overrides EntityAPIControllerRevisionableInterface:: | |
| EntityAPIController:: | public | function | Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: | 1 | 
| EntityAPIController:: | public | function | Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: | |
| EntityAPIController:: | public | function | Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: | 1 | 
| EntityAPIController:: | public | function | Overridden. Overrides DrupalDefaultEntityController:: | 1 | 
| EntityAPIController:: | public | function | Builds and executes the query for loading. | |
| EntityAPIController:: | protected | function | Renders a single entity property. | |
| EntityAPIController:: | public | function | Overrides DrupalDefaultEntityController::resetCache(). Overrides DrupalDefaultEntityController:: | 1 | 
| EntityAPIController:: | protected | function | Saves an entity revision. | |
| EntityAPIController:: | public | function | Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface:: | 1 | 
| EntityAPIController:: | public | function | Overridden. Overrides DrupalDefaultEntityController:: | 1 | 
| UcCouponController:: | public | function | Overrides EntityAPIController:: | |
| UcCouponController:: | public | function | Overrides EntityAPIController:: | |
| UcCouponController:: | public | function | Overrides EntityAPIController:: | 
