2012-07-20 20:04:38 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Generic helper class for the various bulk editing component
|
|
|
|
* contains common functions
|
|
|
|
*
|
|
|
|
* @author colymba
|
2012-07-28 13:16:05 +02:00
|
|
|
* @package GridFieldBulkEditingTools
|
2012-07-20 20:04:38 +02:00
|
|
|
*/
|
|
|
|
class GridFieldBulkEditingTools {
|
|
|
|
//put your code here
|
|
|
|
|
2012-07-28 13:16:05 +02:00
|
|
|
public static function getModelCMSDataFields ( $config, $modelClass )
|
2012-07-20 20:04:38 +02:00
|
|
|
{
|
|
|
|
$cmsFields = singleton($modelClass)->getCMSFields();
|
2012-07-28 13:16:05 +02:00
|
|
|
$cmsDataFields = $cmsFields->dataFields();
|
|
|
|
$cmsDataFields = GridFieldBulkEditingTools::filterNonEditableRecordsFields($config, $cmsDataFields);
|
|
|
|
|
|
|
|
return $cmsDataFields;
|
2012-07-20 20:04:38 +02:00
|
|
|
}
|
|
|
|
|
2012-07-28 13:16:05 +02:00
|
|
|
|
|
|
|
public static function filterNonEditableRecordsFields ( $config, $dataFields )
|
|
|
|
{
|
|
|
|
if ( isset($config['editableFields']) )
|
|
|
|
{
|
|
|
|
if ( $config['editableFields'] != null )
|
|
|
|
{
|
|
|
|
foreach ($dataFields as $name => $field)
|
|
|
|
{
|
|
|
|
if ( !in_array($name, $config['editableFields']) )
|
|
|
|
{
|
|
|
|
unset( $dataFields[$name] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $dataFields;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filters out all unwanted fields from the config settings
|
|
|
|
*
|
|
|
|
* @param array $config
|
|
|
|
* @param array $dataFields
|
|
|
|
* @return array
|
|
|
|
*/
|
2012-07-20 20:04:38 +02:00
|
|
|
public static function getModelFilteredDataFields ( $config, $dataFields )
|
|
|
|
{
|
2012-07-28 13:16:05 +02:00
|
|
|
//remove the image field - for bulk image upload
|
|
|
|
if ( isset($config['imageFieldName']) )
|
|
|
|
{
|
|
|
|
if ( $config['imageFieldName'] != null )
|
|
|
|
{
|
|
|
|
//@TODO: this wont work if the fieldname has ID in it: i.e. TheIDImageID -> remove last 2 char only
|
|
|
|
unset( $dataFields[str_ireplace('ID', '', $config['imageFieldName']) ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//if class blacklist filter
|
|
|
|
if ( count($config['fieldsClassBlacklist']) > 0 )
|
|
|
|
{
|
|
|
|
foreach ($dataFields as $fieldName => $field)
|
|
|
|
{
|
|
|
|
//@TODO find PHP function that return the classname
|
|
|
|
if ( in_array($field->ClassName, $config['fieldsClassBlacklist']) )
|
|
|
|
{
|
|
|
|
array_push($config['fieldsNameBlacklist'], $fieldName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//if name blacklist filter
|
|
|
|
if ( count($config['fieldsNameBlacklist']) > 0 )
|
|
|
|
{
|
|
|
|
foreach ( $config['fieldsNameBlacklist'] as $badFieldName )
|
|
|
|
{
|
|
|
|
unset( $dataFields[ $badFieldName ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $dataFields;
|
2012-07-20 20:04:38 +02:00
|
|
|
}
|
|
|
|
|
2012-07-20 20:26:34 +02:00
|
|
|
public static function filterDatafieldsByClass ( $config, $dataFields )
|
|
|
|
{
|
|
|
|
//@todo
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function filterDataFieldsByName ( $config, $dataFields )
|
|
|
|
{
|
|
|
|
//@todo
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function dataFieldsToHTML ( $dataFields )
|
|
|
|
{
|
2012-07-28 13:16:05 +02:00
|
|
|
$fieldsHTML = array();
|
|
|
|
|
|
|
|
foreach ( $dataFields as $key => $field )
|
|
|
|
{
|
|
|
|
//@TODO: FieldHolder() does not seem to exist on UploadField
|
|
|
|
$fieldsHTML[$key] = $field->FieldHolder();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $fieldsHTML;
|
2012-07-20 20:26:34 +02:00
|
|
|
}
|
2012-07-20 20:04:38 +02:00
|
|
|
|
2012-07-28 13:16:05 +02:00
|
|
|
public static function escapeFormFieldsHTML ( $formFieldsHTML, $unique )
|
2012-07-20 20:26:34 +02:00
|
|
|
{
|
2012-07-28 13:16:05 +02:00
|
|
|
$prefix = 'record_'.$unique.'_';
|
|
|
|
|
|
|
|
foreach ( $formFieldsHTML as $name => $html )
|
|
|
|
{
|
|
|
|
$formFieldsHTML[$name] = str_ireplace ( array('id="', 'for="', 'name="'),
|
|
|
|
array('id="'.$prefix, 'for="'.$prefix, 'name="'.$prefix),
|
|
|
|
$html);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $formFieldsHTML;
|
2012-07-20 20:26:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function unescapeFormFieldsPOSTData ( $requestVars )
|
|
|
|
{
|
|
|
|
//@todo
|
|
|
|
}
|
2012-07-20 20:04:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|