本文整理汇总了PHP中File::getByID方法的典型用法代码示例。如果您正苦于以下问题:PHP File::getByID方法的具体用法?PHP File::getByID怎么用?PHP File::getByID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类File
的用法示例。
在下文中一共展示了File::getByID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: on_start
public function on_start()
{
Events::extend('on_file_add', function ($f, $fv) {
$setless_fs = FileSet::getByName('Setless');
$setless_fs->addFileToSet($f);
});
Events::extend('on_file_added_to_set', function ($fID, $fv) {
$setless_fs = FileSet::getByName('Setless');
$file = File::getByID($fID);
$file_sets = $file->getFileSets();
$file_set_ids = array();
foreach ($file_sets as $file_set) {
$file_set_ids[] = $file_set->fsID;
}
// If file is in multiple sets and setless is one of them, remove from setless
if (count($file_set_ids) >= 2 && in_array($setless_fs->fsID, $file_set_ids)) {
$setless_fs->removeFileFromSet($file);
}
});
Events::extend('on_file_removed_from_set', function ($fID, $fv) {
$setless_fs = FileSet::getByName('Setless');
$file = File::getByID($fID);
$file_sets = $file->getFileSets();
// If file is no longer in any sets, add to setless
if (count($file_sets) == 0) {
$setless_fs->addFileToSet($file);
}
});
}
示例2: getFile
function getFile($fID) {
Loader::model('file');
$mf = new File();
$file_obj = $mf->getByID($fID);
$fileversion_obj = $file_obj->getVersion();
$bf = new LibraryFileBlockController;
$ftype = FileTypeList::getType($fileversion_obj->getExtension());
$this->generictype = strtolower($ftype->getGenericTypeText($ftype->getGenericType()));
$this->filename = $fileversion_obj->getFileName();
$this->type = $fileversion_obj->getType();
$this->url = $fileversion_obj->getURL();
$this->filepath = $fileversion_obj->getPath();
$this->relpath = $fileversion_obj->getRelativePath();
$this->origfilename = $fileversion_obj->getRelativePath();
$this->filesize = $fileversion_obj->getFullSize();
$len = strlen(REL_DIR_FILES_UPLOADED);
$fh = Loader::helper('concrete/file');
$bf->bID = $fileversion_obj->getFileID();
$bf->generictype = $this->generictype;
$bf->type = $this->type;
$bf->url = $this->url;
$bf->filepath = $this->filepath;
$bf->relpath = $this->relpath;
$bf->filename = substr($this->relpath, $len); // for backwards compatibility this must include the prefixes
$bf->filesize = $this->filesize;
return $bf;
}
示例3: testFilterBySet
public function testFilterBySet()
{
$fs = \FileSet::add('test');
$f = \File::getByID(1);
$f2 = \File::getByID(4);
$fs->addFileToSet($f);
$fs->addFileToSet($f2);
$fs2 = \FileSet::add('test2');
$fs2->addFiletoSet($f);
$this->list->filterBySet($fs);
$pagination = $this->list->getPagination();
$this->assertEquals(2, $pagination->getTotalResults());
$results = $this->list->getResults();
$this->assertEquals(2, count($results));
$this->assertEquals(4, $results[1]->getFileID());
$this->list->filterBySet($fs2);
$results = $this->list->getResults();
$this->assertEquals(1, count($results));
$this->assertEquals(1, $results[0]->getFileID());
$nl = new \Concrete\Core\File\FileList();
$nl->ignorePermissions();
$nl->filterByNoSet();
$results = $nl->getResults();
$this->assertEquals(9, count($results));
}
示例4: addFilesForProduct
public static function addFilesForProduct(array $files, StoreProduct $product)
{
self::removeFilesForProduct($product);
//add new ones.
if (!empty($files['dffID'])) {
foreach ($files['dffID'] as $fileID) {
if (!empty($fileID) && $fileID > 0) {
self::add($product->getProductID(), $fileID);
$fileObj = \File::getByID($fileID);
$fs = \FileSet::getByName("Digital Downloads");
$fs->addFileToSet($fileObj);
$fileObj->resetPermissions(1);
$pk = \Concrete\Core\Permission\Key\FileKey::getByHandle('view_file');
$pk->setPermissionObject($fileObj);
$pao = $pk->getPermissionAssignmentObject();
$groupEntity = \Concrete\Core\Permission\Access\Entity\GroupEntity::getOrCreate(\Group::getByID(GUEST_GROUP_ID));
$pa = $pk->getPermissionAccessObject();
if ($pa) {
$pa->removeListItem($groupEntity);
$pao->assignPermissionAccess($pa);
}
}
}
}
}
示例5: file
/**
* Sets up a file field for use with a block.
* @param string $id The ID of your form field
* @param string $postname The name of your database column into which you'd like to save the file ID
* @param string $chooseText
* @param LibraryFileBlock $bf
* return string $html
*/
public function file($id, $postname, $chooseText, $bf = null, $filterArgs = array())
{
$selectedDisplay = 'none';
$resetDisplay = 'block';
$fileID = 0;
if (isset($_POST[$postname])) {
$bf = File::getByID($_POST[$postname]);
}
if (is_object($bf) && !$bf->isError() && $bf->getFileID() > 0) {
$fileID = $bf->getFileID();
$selectedDisplay = 'block';
$resetDisplay = 'none';
}
$html = '<div id="' . $id . '-fm-selected" onclick="ccm_chooseAsset=false" class="ccm-file-selected-wrapper" style="display: ' . $selectedDisplay . '"><img src="' . ASSETS_URL_IMAGES . '/throbber_white_16.gif" /></div>';
$html .= '<div class="ccm-file-manager-select" id="' . $id . '-fm-display" ccm-file-manager-field="' . $id . '" style="display: ' . $resetDisplay . '">';
$html .= '<a href="javascript:void(0)" onclick="ccm_chooseAsset=false; ccm_alLaunchSelectorFileManager(\'' . $id . '\')">' . $chooseText . '</a>';
if ($filterArgs != false) {
foreach ($filterArgs as $key => $value) {
$html .= '<input type="hidden" class="ccm-file-manager-filter" name="' . $key . '" value="' . $value . '" />';
}
}
$html .= '</div><input id="' . $id . '-fm-value" type="hidden" name="' . $postname . '" value="' . $fileID . '" />';
if (is_object($bf) && !$bf->isError() && $bf->getFileID() > 0) {
$html .= '<script type="text/javascript">$(function() { ccm_triggerSelectFile(' . $fileID . ', \'' . $id . '\'); });</script>';
}
return $html;
}
示例6: saveForm
public function saveForm($data) {
if ($data['value'] > 0) {
$f = File::getByID($data['value']);
$this->saveValue($f);
} else {
$db = Loader::db();
$db->Replace('atFile', array('avID' => $this->getAttributeValueID(), 'fID' => 0), 'avID', true);
}
}
示例7: getImageObjectsForProduct
public static function getImageObjectsForProduct(StoreProduct $product)
{
$images = self::getImagesForProduct($product);
$imageObjects = array();
foreach ($images as $img) {
$imageObjects[] = File::getByID($img->getFileID());
}
return $imageObjects;
}
示例8: submit_password
public function submit_password($fID = 0)
{
$f = File::getByID($fID);
if ($f->getPassword() == $_POST['password']) {
return $this->download($f);
}
$this->set('error', t("Password incorrect. Please try again."));
$this->view($fID);
}
示例9: delete
function delete($useWhere = false)
{
try {
$f = File::getByID($this->file_id);
$f->blowCache();
} catch (NoResultException $e) {
// ...alright, that's weird, but no File to delete anyway.
}
return parent::delete($useWhere);
}
示例10: convert
public function convert($val)
{
if ($val) {
$file = File::getByID($val);
if (!$file->error) {
$im = Loader::helper('image');
return t('<a href="%s" target="_blank"><img src="%s" /></a>', $file->getRelativePath(), $im->getThumbNail($file, $this->w, $this->h, $this->crop)->src);
}
}
}
示例11: import_wordpress_xml
public function import_wordpress_xml()
{
if ($this->post('import-images') == 'on') {
$this->importImages = true;
$filesetname;
$this->post('file-set-name') ? $this->filesetname = $this->post('file-set-name') : ($this->filesetname = t("Imported Wordpress Files"));
$this->createFileSet = true;
}
$pages = array();
if (intval($this->post('wp-file')) > 0) {
Loader::model('file');
$co = new Config();
$pkg = Package::getByHandle('wordpress_site_importer');
$co->setPackageObject($pkg);
$co->save("WORDPRESS_IMPORT_FID", $this->post('wp-file'));
$importFile = File::getByID($this->post('wp-file'));
$nv = $importFile->getVersion();
$fileUrl = $nv->getDownloadURL();
$xml = @simplexml_load_file($fileUrl, "SimpleXMLElement", LIBXML_NOCDATA);
$items = array();
foreach ($xml->channel->item as $item) {
$items[] = $item->asxml();
}
$db = Loader::db();
$sql = $db->Prepare('insert into WordpressItems (wpItem) values(?)');
foreach ($items as $item) {
$db->Execute($sql, $item);
}
$categories = array();
$namespaces = $xml->getDocNamespaces();
foreach ($xml->xpath('/rss/channel/wp:category') as $term_arr) {
$t = $term_arr->children($namespaces['wp']);
$categories[] = array('term_id' => (int) $t->term_id, 'category_nicename' => (string) $t->category_nicename, 'category_parent' => (string) $t->category_parent, 'cat_name' => (string) $t->cat_name, 'category_description' => (string) $t->category_description);
}
Loader::model('attribute/categories/collection');
$akt = CollectionAttributeKey::getByHandle("wordpress_category");
for ($i = 0; $i < count($categories); $i++) {
$opt = new SelectAttributeTypeOption(0, $categories[$i]['cat_name'], $i);
$opt = $opt->saveOrCreate($akt);
}
foreach ($xml->xpath('/rss/channel/wp:tag') as $term_arr) {
$t = $term_arr->children($namespaces['wp']);
$tags[] = array('term_id' => (int) $t->term_id, 'tag_slug' => (string) $t->tag_slug, 'tag_name' => (string) $t->tag_name, 'tag_description' => (string) $t->tag_description);
}
$akt = CollectionAttributeKey::getByHandle("tags");
for ($i = 0; $i < count($tags); $i++) {
$opt = new SelectAttributeTypeOption(0, $tags[$i]['tag_name'], $i);
$opt = $opt->saveOrCreate($akt);
}
} else {
echo t("No file");
exit;
}
$this->view();
}
示例12: submit_password
public function submit_password($fID = 0)
{
if ($fID > 0 && Loader::helper('validation/numbers')->integer($fID)) {
$f = File::getByID($fID);
if ($f->getPassword() == $_POST['password']) {
return $this->download($f);
}
$this->set('error', t("Password incorrect. Please try again."));
$this->view($fID);
}
}
示例13: view
public function view()
{
$image = false;
if ($this->fID) {
$f = \File::getByID($this->fID);
if (is_object($f)) {
$image = Core::make('html/image', array($f, false))->getTag();
$image->alt($this->name);
$this->set('image', $image);
}
}
}
示例14: update
public function update()
{
Loader::model('file');
Loader::model('attribute/categories/file');
$fIDs = $this->post("fID");
foreach ($fIDs as $key => $id) {
$f = File::getByID($id);
$fv = $f->getRecentVersion();
$fv->setAttribute(MOOTOOLS_PLUGIN_DISPLAY_ORDER, $key);
}
$this->view();
}
示例15: getPermittedFiles
public function getPermittedFiles($imagesOnly = false)
{
$fileIDs = $this->getSortedFileIDs($imagesOnly);
$files = array();
foreach ($fileIDs as $fID) {
$f = File::getByID($fID);
$fp = new Permissions($f);
if ($fp->canRead()) {
$files[] = $f;
}
}
return $files;
}