本文整理汇总了PHP中AssetFileModel::populateModels方法的典型用法代码示例。如果您正苦于以下问题:PHP AssetFileModel::populateModels方法的具体用法?PHP AssetFileModel::populateModels怎么用?PHP AssetFileModel::populateModels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AssetFileModel
的用法示例。
在下文中一共展示了AssetFileModel::populateModels方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _getThumbnails
/**
* 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;
}
示例2: getFilesBySourceId
/**
* 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);
}