You are here

protected function Textimage::getCached in Textimage 7.3

Get a cached Textimage.

Cache and store are checked for existing image files.

Return value

bool TRUE if an existing image file can be used, FALSE if no hit

1 call to Textimage::getCached()
Textimage::process in classes/Textimage.inc
Process the Textimage, with the required raw text.

File

classes/Textimage.inc, line 702
Textimage - Textimage class.

Class

Textimage
@file Textimage - Textimage class.

Code

protected function getCached() {

  // At first, check cache.
  if ($cached = cache_get('tiid:' . $this->id, 'cache_textimage')) {
    if (is_file($cached->data['uri'])) {
      $this->uri = $cached->data['uri'];
      return TRUE;
    }
  }

  // No cache. Check if we have the hash in store.
  $stored_image = db_select('textimage_store', 'ic')
    ->fields('ic')
    ->condition('tiid', $this->id, '=')
    ->execute()
    ->fetchAssoc();

  // Not in stock, return to make.
  if (!$stored_image) {
    return FALSE;
  }

  // In stock, check file is there.
  $uri = $stored_image['uri'];
  if (is_file($uri)) {
    $this->uri = $uri;
    $this
      ->setCached();
    return TRUE;
  }
  else {
    return FALSE;
  }
}