/** * Transforms an AssetFolderModel into a source info array. * * @param AssetFolderModel $folder * @param bool $includeNestedFolders * * @return array */ private function _assembleSourceInfoForFolder(AssetFolderModel $folder, $includeNestedFolders = true) { $source = array('label' => $folder->parentId ? $folder->name : Craft::t($folder->name), 'hasThumbs' => true, 'criteria' => array('folderId' => $folder->id), 'data' => array('upload' => is_null($folder->sourceId) ? true : craft()->assets->canUserPerformAction($folder->id, 'uploadToAssetSource'))); if ($includeNestedFolders) { $source['nested'] = $this->_assembleSourceList($folder->getChildren(), true); } return $source; }
/** * Returns all of the folders that are descendants of a given folder. * * @param AssetFolderModel $parentFolder * * @return array */ public function getAllDescendantFolders(AssetFolderModel $parentFolder) { $query = craft()->db->createCommand()->select('f.*')->from('assetfolders AS f')->where(array('like', 'path', $parentFolder->path . '%'))->andWhere('sourceId = :sourceId', array(':sourceId' => $parentFolder->sourceId)); $results = $query->queryAll(); $descendantFolders = array(); foreach ($results as $result) { $folder = AssetFolderModel::populateModel($result); $this->_foldersById[$folder->id] = $folder; $descendantFolders[$folder->id] = $folder; } return $descendantFolders; }
/** * Populates a folder model. * * @param array|AssetFolderRecord $attributes * @return AssetFolderModel */ public function populateFolder($attributes) { $folder = AssetFolderModel::populateModel($attributes); return $folder; }