searchableFields() as $fieldName => $fieldSpec) { if(strpos($fieldName, '.') === false) $searchFilters[] = "\"$fieldName\" LIKE '%{$SQL_search}%'"; } $this->sourceFilter = '(' . implode(' OR ', $searchFilters) . ')'; $this->searchingFor = $_REQUEST['FileSearch']; // @todo Integrate search form more closely and don't rely on deprecated // $extraLinkParams. $this->extraLinkParams = array( 'FileSearch' => $SQL_search ); } $this->sourceSort = 'Title'; $this->Markable = true; } /** * Creates the link to this form, including the search pattern * * @return string */ function CurrentLink() { $link = parent::CurrentLink(); if(isset($_REQUEST['FileSearch']) ) { if ( strpos($link, '?')!==false ) $link .= "&"; else $link .= "/?"; $link .= "FileSearch=".urlencode($_REQUEST['FileSearch']); } return $link; } function FieldHolder() { $ret = parent::FieldHolder(); Requirements::javascript(CMS_DIR . '/javascript/AssetTableField.js'); return $ret; } function FirstLink() { $link = parent::FirstLink(); if($link && isset($_REQUEST['FileSearch'])) { return $link . '&FileSearch=' . $_REQUEST['FileSearch']; } return $link; } function PrevLink() { $link = parent::PrevLink(); if($link && isset($_REQUEST['FileSearch'])) { return $link . '&FileSearch=' . $_REQUEST['FileSearch']; } return $link; } function NextLink() { $link = parent::NextLink(); if($link && isset($_REQUEST['FileSearch'])) { return $link . '&FileSearch=' . $_REQUEST['FileSearch']; } return $link; } function LastLink() { $link = parent::LastLink(); if($link && isset($_REQUEST['FileSearch'])) { return $link . '&FileSearch=' . $_REQUEST['FileSearch']; } return $link; } function setFolder($folder) { $this->folder = $folder; $this->sourceFilter .= ($this->sourceFilter) ? " AND " : ""; // If you are searching for files then show all those from subfolders if($this->searchingFor) { $folderIDs = $nextIDSet = array($folder->ID); $folderClasses = "'" . implode("','", ClassInfo::subclassesFor("Folder")) . "'"; while($nextIDSet) { // TO DO: In 2.4 this should be refactored to use the new data mapper. $nextIDSet = DB::query("SELECT \"ID\" FROM \"File\" WHERE \"ParentID\" IN (" . implode(", " , $nextIDSet) . ") AND \"ClassName\" IN ($folderClasses)")->column(); if($nextIDSet) $folderIDs = array_merge($folderIDs, $nextIDSet); } $this->sourceFilter .= " \"ParentID\" IN (" . implode(", ", $folderIDs) . ") AND \"ClassName\" <> 'Folder'"; // Otherwise just show the direct contents } else { $this->sourceFilter .= " \"ParentID\" = '" . $folder->ID . "' AND \"ClassName\" <> 'Folder'"; } } function Folder() { return $this->folder; } function sourceID() { if($this->folder) return $this->folder->ID; } /** * Get the pop-up fields for the given record. */ function getCustomFieldsFor($childData) { if(!$childData) { user_error("AssetTableField::DetailForm No record found"); return null; } if($childData->ParentID) { $folder = DataObject::get_by_id('File', $childData->ParentID ); } else { $folder = singleton('Folder'); } $urlLink = "
". _t('AssetTableField.NOLINKS',"This file hasn't been linked to from any pages.") ."
"; $detailFormFields->addFieldToTab("BottomRoot.Links", new LiteralField("Backlinks", $backlinks)); } // the ID field confuses the Controller-logic in finding the right view for ReferencedField $detailFormFields->removeByName('ID'); if($childData) $childData->extend('updateCMSFields', $detailFormFields); return $detailFormFields; } /** * Provide some HTML for a search form, to be * added above the AssetTable field, allowing * a user to filter the current table's files * by their filename. * * @return string HTML for search form */ function SearchForm() { $fieldContainer = new FieldGroup( new FieldGroup( new TextField( 'FileSearch', _t('MemberTableField.SEARCH', 'Search'), $this->searchingFor ) ), new FieldGroup( $btnFilter = new InlineFormAction( 'FileFilterButton', _t('MemberTableField.FILTER', 'Filter') ), $btnClear = new InlineFormAction( 'FileFilterClearButton', _t('AssetTableField.CLEAR', 'Clear') ) ) ); $btnFilter->includeDefaultJS(false); $btnClear->includeDefaultJS(false); return $fieldContainer->FieldHolder(); } /** * @return FormField|null */ function DeleteMarkedButton() { if(!$this->isReadonly() ) { $deleteButton = new InlineFormAction( 'deletemarked', _t('Folder.DELSELECTED','Delete selected files'), 'delete' ); $deleteButton->includeDefaultJS(false); return $deleteButton; } } /** * @return string HTML */ public function deletemarked($request) { $fileIDs = $request->requestVar($this->Name()); $numFiles = 0; $brokenPageList = ''; if($fileIDs && count($fileIDs)) { $files = DataObject::get( "File", sprintf("\"File\".\"ID\" IN (%s)", Convert::raw2sql(implode(',', $fileIDs))) ); if($files) { $brokenPages = array(); foreach($files as $file) { $brokenPages = array_merge($brokenPages, $file->BackLinkTracking()->toArray()); $file->delete(); $numFiles++; } if($brokenPages) { $brokenPageList = " ". _t('AssetAdmin.NOWBROKEN', 'These pages now have broken links:') . '