entity_share_medias_scald.abstract.inc in Entity Share 7
Class for handling scald Medias in RTE.
File
modules/entity_share_medias/modules/entity_share_medias_scald/includes/entity_share_medias_scald.abstract.incView source
<?php
/**
* @file
* Class for handling scald Medias in RTE.
*/
/**
* Abstract Class to manage scald atoms.
*/
abstract class EntityShareMediasScaldAbstract extends EntityShareMediasProviderAbstract {
const CUSTOM_UUID_PREFIX = 'entity_share-';
/**
* Types of field handled by the current class.
*
* @var array
* Type of field types managed.
*/
protected $managedFieldTypes = array(
'text',
'text_long',
'text_with_summary',
'atom_reference',
);
/**
* Get a scald Id from a UUID.
*
* @param string $uuid
* UUID of the Scald atom.
*
* @return mixed
* ScaldId or FALSE.
*/
public function getScaldIdFromUuid($uuid) {
if ($this
->isCustomUuid($uuid)) {
list(, $provider, $base_id, ) = explode('-', $uuid);
$sid = $this
->getScaldAtomFromProvider($provider, $base_id);
}
else {
$sid = $this
->getScaldIdFromBaseEntityUuid($uuid);
}
return $sid;
}
/**
* Is custom UUID.
*
* @param string $uuid
* UUID of the Scald atom.
*
* @return bool
* TRUE if custom UUID, FALSE otherwise.
*/
public function isCustomUuid($uuid) {
return substr($uuid, 0, strlen(self::CUSTOM_UUID_PREFIX)) == self::CUSTOM_UUID_PREFIX;
}
/**
* Generate manually a uuid from a scald atom.
*
* Use uuid if exists in base_entity, generate a custom "uuid" otherwise.
*
* @param object $atom
* Scald atom.
*
* @return string
* Scald UUID.
*/
public function getUniqueIdFromAtom($atom) {
$uuid = NULL;
if (empty($atom->base_entity)) {
$uuid = self::CUSTOM_UUID_PREFIX . $atom->provider . '-' . $atom->base_id . '-' . $atom->language;
}
else {
if (isset($atom->base_entity->uuid)) {
$uuid = $atom->base_entity->uuid;
}
elseif (isset($atom->base_entity['uuid'])) {
$uuid = $atom->base_entity['uuid'];
}
}
return $uuid;
}
/**
* Get the scald atom from provider and base id.
*
* @param string $provider
* The scald provider.
* @param string $base_id
* The base id of the scald atom.
*
* @return mixed
* FALSE if the atom was never imported, the scald identifier of
* the atom otherwise.
*/
protected function getScaldAtomFromProvider($provider, $base_id) {
$query = array(
'provider' => $provider,
'base_id' => $base_id,
);
return scald_search($query, FALSE, TRUE);
}
/**
* Get the scald atom id from base entity uuid.
*
* @param string $uuid
* Entity uuid.
*
* @return int
* ScaldId.
*/
public function getScaldIdFromBaseEntityUuid($uuid) {
$query = db_select('scald_atoms', 's');
$query
->join('file_usage', 'fu', "fu.type='scald_atom' AND fu.id=s.sid");
$query
->join('file_managed', 'fm', 'fm.fid=fu.fid');
$result = $query
->condition('fm.uuid', $uuid)
->fields('s', array(
'sid',
))
->execute()
->fetchAssoc();
return $result['sid'];
}
}
Classes
Name | Description |
---|---|
EntityShareMediasScaldAbstract | Abstract Class to manage scald atoms. |