本文整理汇总了PHP中GridField::getModelClass方法的典型用法代码示例。如果您正苦于以下问题:PHP GridField::getModelClass方法的具体用法?PHP GridField::getModelClass怎么用?PHP GridField::getModelClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GridField
的用法示例。
在下文中一共展示了GridField::getModelClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getManipulatedData
/**
*
* @param \GridField $gridField
* @param \SS_List $dataList
* @return \SS_List
*/
public function getManipulatedData(\GridField $gridField, \SS_List $dataList)
{
$state = $gridField->State->Milkyway_SS_GridFieldUtils_RangeSlider;
if (!isset($state->min) && !isset($state->value)) {
$settings = $this->scaffoldSliderSettingsForField(singleton($gridField->getModelClass())->obj($this->filterField), $dataList);
$this->working = [$gridField, $dataList];
if (isset($settings['start'])) {
if (is_array($settings['start'])) {
$state->min = $settings['start'][0];
$state->max = $settings['start'][1];
} else {
$state->value = $settings['start'];
}
} else {
return $dataList;
}
}
$dataListClone = clone $dataList;
$dbField = singleton($gridField->getModelClass())->obj($this->filterField);
if (isset($state->value)) {
$comparisonFilter = $this->comparisonFilter ? '' : ':' . $this->comparisonFilter;
$dataListClone = $dataListClone->filter($this->filterField . $comparisonFilter, $this->getValueForDB($dbField, $state->value));
} elseif (isset($state->min) && isset($state->max)) {
$dataListClone = $dataListClone->filter([$this->filterField . ':GreaterThan' => $this->getValueForDB($dbField, $state->min), $this->filterField . ':LessThan' => $this->getValueForDB($dbField, $state->max)]);
}
return $dataListClone;
}
示例2: getClasses
/**
* Gets the classes that can be created using this button, defaulting to the model class and
* its subclasses.
*
* @param GridField $grid
* @return array a map of class name to title
*/
public function getClasses(GridField $grid)
{
$result = array();
if (is_null($this->classes)) {
$classes = array_values(ClassInfo::subclassesFor($grid->getModelClass()));
sort($classes);
} else {
$classes = $this->classes;
}
$kill_ancestors = array();
foreach ($classes as $class => $title) {
if (!is_string($class)) {
$class = $title;
$is_abstract = ($reflection = new ReflectionClass($class)) && $reflection->isAbstract();
if (!$is_abstract) {
$title = singleton($class)->i18n_singular_name();
}
} else {
$is_abstract = ($reflection = new ReflectionClass($class)) && $reflection->isAbstract();
}
if ($ancestor_to_hide = Config::inst()->get($class, 'hide_ancestor', Config::FIRST_SET)) {
$kill_ancestors[$ancestor_to_hide] = true;
}
if ($is_abstract || !singleton($class)->canCreate()) {
continue;
}
$result[$class] = $title;
}
if ($kill_ancestors) {
foreach ($kill_ancestors as $class => $bool) {
unset($result[$class]);
}
}
return $result;
}
示例3: setupGridField
protected function setupGridField(GridField $gridfield, Config_ForClass $classConfig)
{
if (!$gridfield) {
return;
}
$config = $gridfield->getConfig();
$class = $gridfield->getModelClass();
// More item per page
$paginator = $config->getComponentByType('GridFieldPaginator');
$paginator->setItemsPerPage(50);
// Bulk manage
if ($classConfig->bulk_manage && class_exists('GridFieldBulkManager')) {
$already = $config->getComponentByType('GridFieldBulkManager');
if (!$already) {
$config->addComponent($bulkManager = new GridFieldBulkManager());
$bulkManager->removeBulkAction('unLink');
}
}
// Better export
if ($classConfig->export_csv) {
/* @var $export GridFieldExportButton */
$export = $config->getComponentByType('GridFieldExportButton');
$export->setExportColumns(ExcelImportExport::exportFieldsForClass($class));
} else {
$config->removeComponentsByType('GridFieldExportButton');
}
if ($classConfig->export_excel) {
if ($class == 'Group') {
$config->addComponent(new GridFieldButtonRow('after'));
}
$config->addComponent(new ExcelGridFieldExportButton('buttons-after-left'));
}
}
示例4: handleAction
public function handleAction(\GridField $gridField, $actionName, $arguments, $data)
{
if ($actionName != $this->urlSegment) {
return;
}
$record = $gridField->Form && $gridField->Form->Record ? $gridField->Form->Record : null;
if (!$record || !$record->SiteTreeID) {
throw new \ValidationException(_t('Link.NO_CURRENT_PAGE', 'No current page to draw from'), 0);
}
$root = \SiteTree::get()->filter('ParentID', $record->SiteTreeID);
if (!$root->exists()) {
throw new \ValidationException(_t('Link.NO_PAGES', 'No pages available'), 0);
}
$item = singleton($gridField->getModelClass());
if (!$item->canCreate()) {
throw new \ValidationException(_t('Link.CANNOT_CREATE', 'You cannot create a Link'), 0);
}
foreach ($root as $page) {
$link = $item->create();
$link->Type = 'SiteTree';
$link->SiteTreeID = $page->ID;
$link->write();
$gridField->getList()->add($link);
}
}
示例5: updateCMSFields
public function updateCMSFields(FieldList $fields)
{
if ($this->owner->ID) {
// Relation handler for Blocks
$SConfig = GridFieldConfig_RelationEditor::create(25);
$SConfig->addComponent(new GridFieldOrderableRows('SortOrder'));
$SConfig->addComponent(new GridFieldDeleteAction());
// If the copy button module is installed, add copy as option
if (class_exists('GridFieldCopyButton')) {
$SConfig->addComponent(new GridFieldCopyButton(), 'GridFieldDeleteAction');
}
$gridField = new GridField("Blocks", "Content blocks", $this->owner->Blocks(), $SConfig);
$classes = array_values(ClassInfo::subclassesFor($gridField->getModelClass()));
if (count($classes) > 1 && class_exists('GridFieldAddNewMultiClass')) {
$SConfig->removeComponentsByType('GridFieldAddNewButton');
$SConfig->addComponent(new GridFieldAddNewMultiClass());
}
if (self::$create_block_tab) {
$fields->addFieldToTab("Root.Blocks", $gridField);
} else {
// Downsize the content field
$fields->removeByName('Content');
$fields->addFieldToTab('Root.Main', HTMLEditorField::create('Content')->setRows(self::$contentarea_rows), 'Metadata');
$fields->addFieldToTab("Root.Main", $gridField, 'Metadata');
}
}
return $fields;
}
示例6: handleAction
/**
* Handles the add action for the given DataObject.
*
* @param $gridField GridField
* @param $actionName string
* @param $arguments mixed
* @param $data array
*
* @return null|SS_HTTPResponse
*
* @throws UnexpectedValueException
*/
public function handleAction(GridField $gridField, $actionName, $arguments, $data)
{
if ($actionName == 'add') {
$dbField = $this->getDataObjectField();
$objClass = $gridField->getModelClass();
/**
* @var DataObject $obj
*/
$obj = new $objClass();
if ($obj->hasField($dbField)) {
$obj->setCastedField($dbField, $data['gridfieldaddbydbfield'][$obj->ClassName][$dbField]);
if ($obj->canCreate()) {
$id = $gridField->getList()->add($obj);
if (!$id) {
$gridField->setError(_t('GridFieldAddByDBField.AddFail', 'Unable to save {class} to the database.', 'Unable to add the DataObject.', array('class' => get_class($obj))), 'error');
}
} else {
return Security::permissionFailure(Controller::curr(), _t('GridFieldAddByDBField.PermissionFail', 'You don\'t have permission to create a {class}.', 'Unable to add the DataObject.', array('class' => get_class($obj))));
}
} else {
throw new UnexpectedValueException(sprintf('Invalid field (%s) on %s.', $dbField, $obj->ClassName));
}
}
return null;
}
示例7: getClasses
/**
* Gets the classes that can be created using this button, defaulting to the model class and
* its subclasses.
*
* @param GridField $grid
* @return array a map of class name to title
*/
public function getClasses(GridField $grid)
{
$result = array();
if (is_null($this->classes)) {
$classes = array_values(ClassInfo::subclassesFor($grid->getModelClass()));
sort($classes);
} else {
$classes = $this->classes;
}
foreach ($classes as $class => $title) {
if (!is_string($class)) {
$class = $title;
if (($reflection = new ReflectionClass($class)) && $reflection->isAbstract()) {
continue;
}
$title = singleton($class)->i18n_singular_name();
} else {
if (($reflection = new ReflectionClass($class)) && $reflection->isAbstract()) {
continue;
}
}
if (!singleton($class)->canCreate()) {
continue;
}
$result[$class] = $title;
}
return $result;
}
开发者ID:DrMartinGonzo,项目名称:silverstripe-gridfieldextensions,代码行数:35,代码来源:GridFieldAddNewMultiClass.php
示例8: getAllowedClasses
/**
* Gets the classes that can be created using this button, defaulting to the model class and
* its subclasses.
*
* @param \GridField $grid
* @return array a map of class name to title
*/
public function getAllowedClasses(\GridField $grid)
{
$result = array();
if ($this->useAllowedClasses) {
$classes = $this->useAllowedClasses;
$this->useAllowedClasses = null;
return $classes;
} else {
if (is_null($this->allowedClasses)) {
$classes = array_values(\ClassInfo::subclassesFor($grid->getModelClass()));
sort($classes);
} else {
$classes = $this->allowedClasses;
}
}
foreach ($classes as $class => $title) {
if (!is_string($class)) {
$class = $title;
$title = singleton($class)->i18n_singular_name();
}
if (!singleton($class)->canCreate()) {
continue;
}
$result[$class] = $title;
}
return $result;
}
开发者ID:helpfulrobot,项目名称:milkyway-multimedia-ss-gridfield-utils,代码行数:34,代码来源:AddNewInlineExtended_MultiClass.php
示例9: generateExportFileData
/**
* Generate export fields for EXCEL.
*
* @param GridField $gridField
* @return array
*/
public function generateExportFileData($gridField)
{
$excelColumns = $this->exportColumns ? $this->exportColumns : singleton($gridField->getModelClass())->summaryFields();
$objPHPExcel = new \PHPExcel\Spreadsheet();
$worksheet = $objPHPExcel->getActiveSheet()->setTitle($gridField->getModelClass());
$col = 'A';
foreach ($excelColumns as $columnSource => $columnHeader) {
$heading = !is_string($columnHeader) && is_callable($columnHeader) ? $columnSource : $columnHeader;
$worksheet->setCellValue($col . '1', $heading);
$col++;
}
$worksheet->freezePane('A2');
$items = $gridField->getManipulatedList();
// @todo should GridFieldComponents change behaviour based on whether others are available in the config?
foreach ($gridField->getConfig()->getComponents() as $component) {
if ($component instanceof GridFieldFilterHeader || $component instanceof GridFieldSortableHeader) {
$items = $component->getManipulatedData($gridField, $items);
}
}
$row = 2;
foreach ($items->limit(null) as $item) {
$columnData = array();
$col = 'A';
foreach ($excelColumns as $columnSource => $columnHeader) {
if (!is_string($columnHeader) && is_callable($columnHeader)) {
if ($item->hasMethod($columnSource)) {
$relObj = $item->{$columnSource}();
} else {
$relObj = $item->relObject($columnSource);
}
$value = $columnHeader($relObj);
} else {
$value = $gridField->getDataFieldValue($item, $columnSource);
}
$worksheet->getCell($col . $row)->setValueExplicit($value, PHPExcel\Cell\DataType::TYPE_STRING);
$col++;
}
$row++;
$item->destroy();
}
$writer = PHPExcel\IOFactory::createWriter($objPHPExcel, 'Excel2007');
ob_start();
$writer->save('php://output');
$data = ob_get_clean();
return $data;
}
示例10: isHtmlAllowedFor
/**
* Check whether HTML output is allowed for the given field.
*
* @param string $fieldName Field name to check
* @param GridField $gridField GridField to check
*
* @return void
*
* @author Sebastian Diel <sdiel@pixeltricks.de>
* @since 26.03.2013
*/
public function isHtmlAllowedFor($fieldName, $gridField)
{
$htmlIsAllowed = false;
$object = singleton($gridField->getModelClass());
if ($object instanceof DataObject && $object->hasMethod('allowHtmlDataFor') && is_array($object->allowHtmlDataFor()) && in_array($fieldName, $object->allowHtmlDataFor())) {
$htmlIsAllowed = true;
}
return $htmlIsAllowed;
}
示例11: scaffoldLoader
/**
* Scaffold a bulk loader, if none is provided
*
* @param GridField $gridField
* @return mixed
*/
public function scaffoldLoader(GridField $gridField)
{
$gridlist = $gridField->getList();
$class = $gridlist instanceof HasManyList ? "ListBulkLoader" : "BetterBulkLoader";
//set the correct constructor argument
$arg = $class === "ListBulkLoader" || is_subclass_of($class, "ListBulkLoader") ? $gridlist : $gridField->getModelClass();
$loader = new $class($arg);
$loader->setSource(new CsvBulkLoaderSource());
return $loader;
}
示例12: generateExportFileData
/**
* Generate export fields for CSV.
*
* @param GridField $gridField
* @return array
*/
public function generateExportFileData($gridField)
{
$separator = $this->csvSeparator;
$singl = singleton($gridField->getModelClass());
if ($singl->hasMethod('exportedFields')) {
$fallbackColumns = $singl->exportedFields();
} else {
$fallbackColumns = $singl->summaryFields();
}
$csvColumns = $this->exportColumns ? $this->exportColumns : $fallbackColumns;
$fileData = '';
$columnData = array();
$fieldItems = new ArrayList();
if ($this->csvHasHeader) {
$headers = array();
// determine the CSV headers. If a field is callable (e.g. anonymous function) then use the
// source name as the header instead
foreach ($csvColumns as $columnSource => $columnHeader) {
$headers[] = !is_string($columnHeader) && is_callable($columnHeader) ? utf8_decode($columnSource) : utf8_decode($columnHeader);
}
$fileData .= "\"" . implode("\"{$separator}\"", array_values($headers)) . "\"";
$fileData .= "\n";
}
$items = $gridField->getList();
foreach ($items as $item) {
if (!$item->hasMethod('canView') || $item->canView()) {
$columnData = array();
foreach ($csvColumns as $columnSource => $columnHeader) {
if (!is_string($columnHeader) && is_callable($columnHeader)) {
if ($item->hasMethod($columnSource)) {
$relObj = $item->{$columnSource}();
} else {
$relObj = $item->relObject($columnSource);
}
$value = $columnHeader($relObj);
} else {
$value = $gridField->getDataFieldValue($item, $columnSource);
if (!$value) {
$value = $gridField->getDataFieldValue($item, $columnHeader);
}
}
$value = str_replace(array("\r", "\n"), "\n", $value);
$columnData[] = '"' . str_replace('"', '""', utf8_decode($value)) . '"';
}
$fileData .= implode($separator, $columnData);
$fileData .= "\n";
}
if ($item->hasMethod('destroy')) {
$item->destroy();
}
}
return $fileData;
}
示例13: handleAdd
/**
* Handles adding a new instance of the grid's model class.
*
* @param GridField $grid
* @param SS_HTTPRequest $request
* @throws Exception
* @return \GridFieldAddNewMultiClassHandler
*/
public function handleAdd($grid, $request)
{
$component = $grid->getConfig()->getComponentByType('GridFieldDetailForm');
if (!$component) {
throw new Exception('The ReplicantAddNewButton component requires a detail form component in the grid.');
}
$controller = $grid->getForm()->getController();
$className = $grid->getModelClass();
$obj = $className::create();
$handler = new ReplicantAddNewButtonHandler($grid, $component, $obj, $controller);
$handler->setTemplate($component->getTemplate());
return $handler;
}
示例14: getManipulatedData
/**
* Adds the records to the database and returns a new {@link DataList}
*
* @param GridField
* @param SS_List
* @return SS_List
*/
public function getManipulatedData(GridField $gridField, SS_List $dataList)
{
$state = $gridField->State->MockDataGenerator;
$count = (string) $state->Count;
if (!$count) {
return $dataList;
}
$generator = new MockDataBuilder($gridField->getModelClass());
$ids = $generator->setCount($count)->setIncludeRelations($state->IncludeRelations)->setDownloadImages($state->DownloadImages === true)->generate();
foreach ($ids as $id) {
$dataList->add($id);
}
return $dataList;
}
示例15: generateExportFileData
/**
* Generate export fields for CSV.
*
* Replaces the definition in GridFieldExportButton, this is the same as original except
* it sources the {@link List} from $gridField->getList() instead of $gridField->getManipulatedList()
*
* @param GridField $gridField
* @return array
*/
public function generateExportFileData($gridField)
{
$separator = $this->csvSeparator;
$csvColumns = $this->exportColumns ? $this->exportColumns : singleton($gridField->getModelClass())->summaryFields();
$fileData = '';
$columnData = array();
if ($this->csvHasHeader) {
$headers = array();
// determine the CSV headers. If a field is callable (e.g. anonymous function) then use the
// source name as the header instead
foreach ($csvColumns as $columnSource => $columnHeader) {
$headers[] = !is_string($columnHeader) && is_callable($columnHeader) ? $columnSource : $columnHeader;
}
$fileData .= "\"" . implode("\"{$separator}\"", array_values($headers)) . "\"";
$fileData .= "\n";
}
// The is the only variation from the parent, using getList() instead of getManipulatedList()
$items = $gridField->getList();
// @todo should GridFieldComponents change behaviour based on whether others are available in the config?
foreach ($gridField->getConfig()->getComponents() as $component) {
if ($component instanceof GridFieldFilterHeader || $component instanceof GridFieldSortableHeader) {
$items = $component->getManipulatedData($gridField, $items);
}
}
foreach ($items->limit(null) as $item) {
$columnData = array();
foreach ($csvColumns as $columnSource => $columnHeader) {
if (!is_string($columnHeader) && is_callable($columnHeader)) {
if ($item->hasMethod($columnSource)) {
$relObj = $item->{$columnSource}();
} else {
$relObj = $item->relObject($columnSource);
}
$value = $columnHeader($relObj);
} else {
$value = $gridField->getDataFieldValue($item, $columnSource);
}
$value = str_replace(array("\r", "\n"), "\n", $value);
$columnData[] = '"' . str_replace('"', '\\"', $value) . '"';
}
$fileData .= implode($separator, $columnData);
$fileData .= "\n";
$item->destroy();
}
return $fileData;
}