2007-07-19 12:40:05 +02:00
< ? php
2008-02-25 03:10:37 +01:00
/**
* A special kind of complex table field for manipulating assets .
2008-06-15 15:33:53 +02:00
*
2008-02-25 03:10:37 +01:00
* @ package cms
* @ subpackage assets
*/
2007-07-19 12:40:05 +02:00
class AssetTableField extends ComplexTableField {
protected $folder ;
protected $template = " AssetTableField " ;
2007-10-02 23:34:57 +02:00
protected $permissions = array (
" edit " ,
" delete " ,
//"export",
);
2007-07-19 12:40:05 +02:00
function __construct ( $controller , $name , $sourceClass , $fieldList , $detailFormFields , $sourceFilter = " " , $sourceSort = " " , $sourceJoin = " " ) {
parent :: __construct ( $controller , $name , $sourceClass , $fieldList , $detailFormFields , $sourceFilter , $sourceSort , $sourceJoin );
2008-11-04 00:09:49 +01:00
Requirements :: javascript ( CMS_DIR . '/javascript/AssetTableField.js' );
$SNG_file = singleton ( 'File' );
// If search was request, filter the results here
$SQL_search = ( ! empty ( $_REQUEST [ 'FileSearch' ])) ? Convert :: raw2sql ( $_REQUEST [ 'FileSearch' ]) : null ;
if ( $SQL_search ) {
$searchFilters = array ();
foreach ( $SNG_file -> searchableFields () as $fieldName => $fieldSpec ) {
2008-11-23 01:31:13 +01:00
if ( strpos ( $fieldName , '.' ) === false ) $searchFilters [] = " \" $fieldName\ " LIKE '%{$SQL_search}%' " ;
2008-11-04 00:09:49 +01:00
}
$this -> sourceFilter = '(' . implode ( ' OR ' , $searchFilters ) . ')' ;
}
$this -> sourceSort = 'Title' ;
2007-07-19 12:40:05 +02:00
$this -> Markable = true ;
}
2008-11-12 05:31:53 +01:00
function FieldHolder () {
Requirements :: javascript ( 'cms/javascript/ImageEditor/Activator.js' );
return parent :: FieldHolder ();
}
2007-07-19 12:40:05 +02:00
function setFolder ( $folder ) {
$this -> folder = $folder ;
$this -> sourceFilter .= ( $this -> sourceFilter ) ? " AND " : " " ;
2008-11-24 10:30:41 +01:00
$this -> sourceFilter .= " \" ParentID \" = ' " . $folder -> ID . " ' AND \" ClassName \" <> 'Folder' " ;
2007-07-19 12:40:05 +02:00
}
function Folder () {
return $this -> folder ;
}
function sourceID () {
2007-10-02 23:34:57 +02:00
if ( $this -> folder ) return $this -> folder -> ID ;
2007-07-19 12:40:05 +02:00
}
2008-08-18 02:52:15 +02:00
/**
* Get the pop - up fields for the given record .
*/
function getCustomFieldsFor ( $childData ) {
2007-07-19 12:40:05 +02:00
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 = " <div class='field readonly'> " ;
2008-02-25 03:10:37 +01:00
$urlLink .= " <label class='left'> " . _t ( 'AssetTableField.URL' , 'URL' ) . " </label> " ;
2007-07-19 12:40:05 +02:00
$urlLink .= " <span class='readonly'><a href=' { $childData -> Link () } '> { $childData -> RelativeLink () } </a></span> " ;
$urlLink .= " </div> " ;
$detailFormFields = new FieldSet (
new TabSet ( " BottomRoot " ,
2008-02-25 03:10:37 +01:00
new Tab ( _t ( 'AssetTableField.MAIN' , 'Main' ),
2007-09-16 18:33:05 +02:00
new TextField ( " Title " , _t ( 'AssetTableField.TITLE' , 'Title' )),
new TextField ( " Name " , _t ( 'AssetTableField.FILENAME' , 'Filename' )),
2007-07-19 12:40:05 +02:00
new LiteralField ( " AbsoluteURL " , $urlLink ),
2007-09-16 18:33:05 +02:00
new ReadonlyField ( " FileType " , _t ( 'AssetTableField.TYPE' , 'Type' )),
new ReadonlyField ( " Size " , _t ( 'AssetTableField.SIZE' , 'Size' ), $childData -> getSize ()),
2008-11-11 21:45:11 +01:00
new DropdownField ( " OwnerID " , _t ( 'AssetTableField.OWNER' , 'Owner' ), Member :: mapInCMSGroups ()),
2007-09-16 18:33:05 +02:00
new DateField_Disabled ( " Created " , _t ( 'AssetTableField.CREATED' , 'First uploaded' )),
new DateField_Disabled ( " LastEdited " , _t ( 'AssetTableField.LASTEDIT' , 'Last changed' ))
2007-07-19 12:40:05 +02:00
)
)
);
2007-09-20 06:06:50 +02:00
2007-07-19 12:40:05 +02:00
if ( is_a ( $childData , 'Image' )) {
$big = $childData -> URL ;
$thumbnail = $childData -> getFormattedImage ( 'AssetLibraryPreview' ) -> URL ;
2008-02-25 03:10:37 +01:00
// Hmm this required the translated string to be appended to BottomRoot to add this to the Main tab
$detailFormFields -> addFieldToTab ( " BottomRoot. " . _t ( 'AssetTableField.MAIN' , 'Main' ),
2007-09-16 18:33:05 +02:00
new ReadonlyField ( " Dimensions " , _t ( 'AssetTableField.DIM' , 'Dimensions' )),
2007-07-19 12:40:05 +02:00
" Created "
);
$detailFormFields -> addFieldToTab ( " BottomRoot " ,
2008-02-25 03:10:37 +01:00
new Tab ( _t ( 'AssetTableField.IMAGE' , 'Image' ),
2007-07-19 12:40:05 +02:00
new LiteralField ( " ImageFull " ,
2008-02-25 03:10:37 +01:00
'<a id="ImageEditorActivator" href="javascript: void(0)">' . " <img id='thumbnailImage' src=' { $thumbnail } ?r= " . rand ( 1 , 100000 ) . " ' alt=' { $childData -> Name } ' /><p> " . _t ( 'AssetTableField.EDITIMAGE' , 'Edit this image' ) . " </p> " . '</a>' .
2007-10-03 01:26:35 +02:00
'<script type="text/javascript" src="cms/javascript/ImageEditor/Activator.js"></script><script type="text/javascript">var imageActivator = new ImageEditor.Activator.initialize();Event.observe("ImageEditorActivator","click",imageActivator.onOpen);</script>'
2007-07-19 12:40:05 +02:00
)
),
'Main'
);
2007-09-20 06:06:50 +02:00
2007-10-02 07:17:35 +02:00
if ( class_exists ( 'GalleryFile' )) {
$detailFormFields -> addFieldToTab ( " BottomRoot " ,
2008-02-25 03:10:37 +01:00
new Tab ( _t ( 'AssetTableField.GALLERYOPTIONS' , 'Gallery Options' ),
new TextField ( " Content " , _t ( 'AssetTableField.CAPTION' , 'Caption' ) )
2007-10-02 07:17:35 +02:00
)
);
}
2007-07-19 12:40:05 +02:00
}
2007-10-02 07:17:35 +02:00
else if ( class_exists ( 'GalleryFile' )) {
2007-09-20 06:06:50 +02:00
if ( $childData -> Extension == 'swf' ) {
$detailFormFields -> addFieldToTab ( " BottomRoot " ,
2008-02-25 03:10:37 +01:00
new Tab ( _t ( 'AssetTableField.GALLERYOPTIONS' , 'Gallery Options' ),
new TextField ( " Content " , _t ( 'AssetTableField.CAPTION' , 'Caption' ) ),
new TextField ( 'PopupWidth' , _t ( 'AssetTableField.POPUPWIDTH' , 'Popup Width' ) ),
new TextField ( 'PopupHeight' , _t ( 'AssetTableField.POPUPHEIGHT' , 'Popup Height' ) ),
2008-10-16 15:27:12 +02:00
new HeaderField ( 'SWFFileOptionsHeader' , _t ( 'AssetTableField.SWFFILEOPTIONS' , 'SWF File Options' ) ),
2008-02-25 03:10:37 +01:00
new CheckboxField ( 'Embed' , _t ( 'AssetTableField.ISFLASH' , 'Is A Flash Document' ) ),
new CheckboxField ( 'LimitDimensions' , _t ( 'AssetTableField.DIMLIMT' , 'Limit The Dimensions In The Popup Window' ) )
2007-09-20 06:06:50 +02:00
)
);
}
else {
$detailFormFields -> addFieldToTab ( " BottomRoot " ,
2008-02-25 03:10:37 +01:00
new Tab ( _t ( 'AssetTableField.GALLERYOPTIONS' , 'Gallery Options' ),
new TextField ( " Content " , _t ( 'AssetTableField.CAPTION' , 'Caption' ) ),
new TextField ( 'PopupWidth' , _t ( 'AssetTableField.POPUPWIDTH' , 'Popup Width' ) ),
new TextField ( 'PopupHeight' , _t ( 'AssetTableField.POPUPHEIGHT' , 'Popup Height' ) )
2007-09-20 06:06:50 +02:00
)
);
}
}
2007-07-19 12:40:05 +02:00
if ( $childData && $childData -> hasMethod ( 'BackLinkTracking' )) {
$links = $childData -> BackLinkTracking ();
if ( $links -> exists ()) {
foreach ( $links as $link ) {
$backlinks [] = " <li><a href= \" admin/show/ $link->ID\ " > " . $link->Breadcrumbs (null,true). " </ a ></ li > " ;
}
2007-09-16 18:33:05 +02:00
$backlinks = " <div style= \" clear:left \" > " . _t ( 'AssetTableField.PAGESLINKING' , 'The following pages link to this file:' ) . " <ul> " . implode ( " " , $backlinks ) . " </ul> " ;
2007-07-19 12:40:05 +02:00
}
2007-09-16 18:33:05 +02:00
if ( ! isset ( $backlinks )) $backlinks = " <p> " . _t ( 'AssetTableField.NOLINKS' , " This file hasn't been linked to from any pages. " ) . " </p> " ;
2007-07-19 12:40:05 +02:00
$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' );
2008-11-10 05:07:03 +01:00
if ( $childData ) $childData -> extend ( 'updateCMSFields' , $detailFormFields );
2008-08-18 02:52:15 +02:00
return $detailFormFields ;
2007-07-19 12:40:05 +02:00
}
2008-11-04 00:09:49 +01:00
/**
* 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 () {
$searchFields = new FieldGroup (
new TextField ( 'FileSearch' , _t ( 'MemberTableField.SEARCH' , 'Search' )),
new HiddenField ( " ctf[ID] " , '' , $this -> ID ),
new HiddenField ( 'FileFieldName' , '' , $this -> name )
);
$actionFields = new LiteralField (
'FileFilterButton' ,
'<input type="submit" class="action" name="FileFilterButton" value="' . _t ( 'MemberTableField.FILTER' , 'Filter' ) . '" id="FileFilterButton"/>'
);
$fieldContainer = new FieldGroup (
$searchFields ,
$actionFields
);
return $fieldContainer -> FieldHolder ();
}
2007-07-19 12:40:05 +02:00
}
2008-12-04 23:38:58 +01:00
?>