/**
  * Returns an array of all embedded assets thumbnails, indexed by the asset file models ID.
  * This method is used to inject the asset thumbnails into the CP front-end. Since embedded asset files are stored
  * as JSON files, there's no supported way of setting the thumbnail on the front-end for these files. The
  * alternative is to pass a list of these thumbnails to the front-end, and use JS to patch them on-top of the
  * elements system.
  *
  * @return array
  */
 private function _getThumbnails()
 {
     // TODO Redo this using the elements API so it's not depending on the DB schema
     // Escape for using in LIKE clause
     // See: http://www.yiiframework.com/doc/guide/1.1/en/database.query-builder
     $prefix = strtr(self::getFileNamePrefix(), array('%' => '\\%', '_' => '\\_'));
     $results = craft()->db->createCommand()->select('assetfiles.*')->from('assetfiles assetfiles')->where(array('like', 'assetfiles.filename', $prefix . '%.json'))->queryAll();
     $assets = AssetFileModel::populateModels($results, 'id');
     $thumbnails = array();
     foreach ($assets as $id => $asset) {
         $embed = craft()->embeddedAssets->getEmbeddedAsset($asset);
         if ($embed) {
             $thumbnails[$id] = $embed->thumbnailUrl;
         }
     }
     return $thumbnails;
 }
Esempio n. 2
0
 /**
  * Returns all top-level files in a source.
  *
  * @param int         $sourceId
  * @param string|null $indexBy
  *
  * @return array
  */
 public function getFilesBySourceId($sourceId, $indexBy = null)
 {
     $files = craft()->db->createCommand()->select('fi.*')->from('assetfiles fi')->join('assetfolders fo', 'fo.id = fi.folderId')->where('fo.sourceId = :sourceId', array(':sourceId' => $sourceId))->order('fi.filename')->queryAll();
     return AssetFileModel::populateModels($files, $indexBy);
 }