You are here

class ResourceFactory in D7 Media 6

Hierarchy

Expanded class hierarchy of ResourceFactory

File

resource/resource.module, line 478
Resource API for Drupal, a replacement for files.

View source
class ResourceFactory {
  static $resources;
  function __construct() {
  }

  /**
   * Return the first matching file in the files table. This is a simple single
   * object loader it in combination with the static $files variable allows all
   * drupal file objects to also act as factories and share the same static cache.
   *
   * @param string key (required) database column to use in where condition.
   * @param int|string value (required) the value of the column to use in the where condition.
   * @return object|bool A Drupal file object or FALSE if a file was not found.
   * @see drupal_file::load(), drupal_file::load_path()
   */
  public function _load($column, $value) {

    // set a cache id based on key and value so we can statically cache
    // all simple loads.
    $cid = $column . '::' . $value;
    if (empty(self::$files[$cid])) {
      $resource = db_fetch_object(db_query('SELECT f.* FROM {resource} r WHERE r.%s = %d', $column, $value));
      $resource = new Resource($r);
    }
    module_invoke_all('resource_load', $r);
    self::$resources[$cid] = $r;

    // Files are not cloned, because there is in fact only one.
    return self::$resources[$cid];
  }

  /**
   * Load a file object from the database by id.
   *
   * @param int   $id     A file id. (required)
   * @return object|bool A Drupal file object or FALSE if a file was not found.
   * @see: drupal_file::load()
   */
  public function loadId($id) {
    return $this
      ->_load('rid', $id);
  }

  /**
   * Load a file object from the database by path.
   *
   * @param string  $path   A path to a file. (required)
   * @return object|bool A Drupal file object or FALSE if a file was not found.
   * @see: drupal_file::load()
   */
  public function loadUrl($url) {
    return $this
      ->_load('url', $url);
  }
  public function loadUpload($key) {
  }

  /**
   * Reset the shared static cache.
   */
  public function resetCache($cid = FALSE) {

    // no cache id, reset the entire cache.
    if (!$cid) {
      self::$resources = array();
    }
    elseif (isset(self::$resources[$cid])) {
      unset(self::$resources[$cid]);
    }
  }

  // table relationship
  // relationship_id
  // left, (resource_id)
  // relationship ( parent_of, member_of, friend_of, ... )
  // right, (resource_id)
  // table resource_formatter
  // relationship_id
  // display_context(node_full, node_teaser, comment, block, profile, default)
  // media(screen, print),
  // formatter
  // formatter_arguments
  function loadChildren($rid, $context = NULL, $media = NULL) {

    // select * from {resource_relationships} where parent = $resource->id;
    // foreach child { $children[] = $this->loadId($child->rid)->context($context); }
    // return $children;
  }
  function loadParents($rid, $context = NULL, $media = NULL) {

    // select * from {resource_relationships} where child = $resource->id;
    // foreach parent { $parent[] = $this->loadId($child->rid)->context($context); }
    // return $parents;
  }
  function loadPeers($rid, $context, $media) {
  }

  /**
  * @param key    primary key for where clause
  * @param value  to limit key to.
   think about this context thing later..
  */
  function loadRelationship($key, $id, $context = NULL, $media = NULL) {

    // select * from relationships where $key = $candidate AND context = $context
    // foreach row { $relatives[] = $this->loadId($relative->rid)->context($row) }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ResourceFactory::$resources static property
ResourceFactory::loadChildren function
ResourceFactory::loadId public function Load a file object from the database by id.
ResourceFactory::loadParents function
ResourceFactory::loadPeers function
ResourceFactory::loadRelationship function
ResourceFactory::loadUpload public function
ResourceFactory::loadUrl public function Load a file object from the database by path.
ResourceFactory::resetCache public function Reset the shared static cache.
ResourceFactory::_load public function Return the first matching file in the files table. This is a simple single object loader it in combination with the static $files variable allows all drupal file objects to also act as factories and share the same static cache.
ResourceFactory::__construct function