本文整理汇总了PHP中GridField::Value方法的典型用法代码示例。如果您正苦于以下问题:PHP GridField::Value方法的具体用法?PHP GridField::Value怎么用?PHP GridField::Value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GridField
的用法示例。
在下文中一共展示了GridField::Value方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveAllRecords
protected function saveAllRecords(\GridField $grid, $arguments, $data)
{
if (isset($data[$grid->Name])) {
$currValue = $grid->Value();
$grid->setValue($data[$grid->Name]);
$model = singleton($grid->List->dataClass());
foreach ($grid->getConfig()->getComponents() as $component) {
if ($component instanceof \GridField_SaveHandler) {
$component->handleSave($grid, $model);
}
}
if ($this->publish) {
// Only use the viewable list items, since bulk publishing can take a toll on the system
$list = ($paginator = $grid->getConfig()->getComponentByType('GridFieldPaginator')) ? $paginator->getManipulatedData($grid, $grid->List) : $grid->List;
$list->each(function ($item) {
if ($item->hasExtension('Versioned')) {
$item->writeToStage('Stage');
$item->publish('Stage', 'Live');
}
});
}
if ($model->exists()) {
$model->delete();
$model->destroy();
}
$grid->setValue($currValue);
if (\Controller::curr() && ($response = \Controller::curr()->Response)) {
if (!$this->completeMessage) {
$this->completeMessage = _t('GridField.DONE', 'Done.');
}
$response->addHeader('X-Status', rawurlencode($this->completeMessage));
}
}
}
示例2: handleSave
public function handleSave(GridField $grid, DataObjectInterface $record)
{
$list = $grid->getList();
$value = $grid->Value();
if (!isset($value[__CLASS__]) || !is_array($value[__CLASS__])) {
// throw error ?
return;
}
$updatedList = ArrayList::create();
foreach ($value[__CLASS__] as $id => $v) {
if (!is_numeric($id)) {
continue;
}
$updatedList->push($id);
}
$list->exclude(['ID' => $updatedList->toArray()])->removeAll();
foreach ($updatedList->toArray() as $i => $id) {
// if list already contains item, leave it there
if ($list->byID($id)) {
continue;
}
$gridfieldItem = DataObject::get_by_id($list->dataClass, $id);
if (!$gridfieldItem || !$gridfieldItem->canEdit()) {
continue;
}
$list->add($gridfieldItem);
}
}
开发者ID:helpfulrobot,项目名称:danbroooks-gridfield-selectexisting,代码行数:28,代码来源:GridFieldSelectExisting.php
示例3: handleSave
public function handleSave(GridField $grid, DataObjectInterface $record)
{
$list = $grid->getList();
$value = $grid->Value();
if (!isset($value[__CLASS__]) || !is_array($value[__CLASS__])) {
return;
}
/** @var GridFieldOrderableRows $sortable */
$sortable = $grid->getConfig()->getComponentByType('GridFieldOrderableRows');
$form = $this->getForm($grid, $record);
foreach ($value[__CLASS__] as $id => $fields) {
if (!is_numeric($id) || !is_array($fields)) {
continue;
}
$item = $list->byID($id);
if (!$item || !$item->canEdit()) {
continue;
}
$extra = array();
$form->loadDataFrom($fields, Form::MERGE_CLEAR_MISSING);
$form->saveInto($item);
// Check if we are also sorting these records
if ($sortable) {
$sortField = $sortable->getSortField();
$item->setField($sortField, $fields[$sortField]);
}
if ($list instanceof ManyManyList) {
$extra = array_intersect_key($form->getData(), (array) $list->getExtraFields());
}
$item->write();
$list->add($item, $extra);
}
}
示例4: handleSave
public function handleSave(GridField $grid, DataObjectInterface $record)
{
$list = $grid->getList();
$value = $grid->Value();
if (!isset($value[__CLASS__]) || !is_array($value[__CLASS__])) {
return;
}
$form = $this->getForm($grid, $record);
foreach ($value[__CLASS__] as $id => $fields) {
if (!is_numeric($id) || !is_array($fields)) {
continue;
}
$item = $list->byID($id);
if (!$item || !$item->canEdit()) {
continue;
}
$extra = array();
$form->loadDataFrom($fields, Form::MERGE_CLEAR_MISSING);
$form->saveInto($item);
if ($list instanceof ManyManyList) {
$extra = array_intersect_key($form->getData(), (array) $list->getExtraFields());
}
$item->write();
$list->add($item, $extra);
}
}
示例5: handleSave
/**
* If the record exists, will use the valFieldAfterSave callback, otherwise
* it will try to find an object by ID, and if it can't it will save to valFieldAfterSave
*
* @param GridField $grid
* @param DataObjectInterface $record
*
* @throws ValidationException
*/
public function handleSave(GridField $grid, DataObjectInterface $record)
{
$list = $grid->getList();
$value = $grid->Value();
$editable = $grid->getConfig()->getComponentByType('GridFieldEditableColumns');
if ($editable) {
$this->addFallbackValueToDisplayFields($grid, $editable);
}
if (!isset($value['GridFieldAddNewInlineButton']) || !is_array($value['GridFieldAddNewInlineButton'])) {
return;
}
$class = $grid->getModelClass();
if (!singleton($class)->canCreate()) {
return;
}
$form = $editable->getForm($grid, $record);
foreach ($value['GridFieldAddNewInlineButton'] as $fields) {
$item = null;
if (isset($fields['_AddOrExistingID']) && !$list->byID($fields['_AddOrExistingID'])) {
if ($item = DataList::create($class)->byID($fields['_AddOrExistingID'])) {
unset($fields['_AddOrExistingID']);
} elseif (!isset($fields[$this->valFieldAfterSave])) {
$fields[$this->valFieldAfterSave] = $fields['_AddOrExistingID'];
}
}
$fields = array_merge($this->additionalData, $fields);
if (!$item) {
$item = $class::create();
}
$extra = [];
if ($item->exists()) {
$form->loadDataFrom($item)->loadDataFrom($fields);
} else {
$form->loadDataFrom($fields, Form::MERGE_CLEAR_MISSING);
}
$form->saveInto($item);
if ($list instanceof ManyManyList) {
$extra = array_intersect_key(array_merge($this->additionalData, $form->getData()), (array) $list->getExtraFields());
}
$item->write();
$list->add($item, $extra);
}
}
开发者ID:helpfulrobot,项目名称:milkyway-multimedia-ss-mwm-autocomplete,代码行数:52,代码来源:GridFieldAddNewOrExistingInlineButton.php
示例6: handleSave
public function handleSave(GridField $grid, DataObjectInterface $record)
{
$data = $grid->Value();
$base = ClassInfo::baseDataClass($record);
if (isset($data['GridFieldEditableColumns'])) {
// go through every warehouse and make sure the have either 0 stock
// or take the value from this
$warehouses = ProductWarehouse::get();
foreach ($warehouses as $warehouse) {
$stock = $record->getStockForWarehouse($warehouse);
$quantity = null;
if (isset($data['GridFieldEditableColumns'][$stock->ID])) {
if (isset($data['GridFieldEditableColumns'][$stock->ID]['Quantity'])) {
$quantity = (int) $data['GridFieldEditableColumns'][$stock->ID]['Quantity'];
}
}
$stock->Quantity = $quantity;
$stock->write();
}
}
}
示例7: handleSave
public function handleSave(\GridField $grid, \DataObjectInterface $record)
{
$list = $grid->getList();
$value = $grid->Value();
$className = $this->getComponentName();
if (!isset($value[$className]) || !is_array($value[$className])) {
return;
}
foreach ($value[$className] as $id => $fields) {
if (!is_numeric($id) || !is_array($fields)) {
continue;
}
$item = $list->byID($id);
if (!$item || !$item->canEdit()) {
continue;
}
$form = $this->getForm($grid, $item, false);
$form->loadDataFrom($fields);
$form->saveInto($item);
$extra = method_exists($list, 'getExtraFields') ? array_intersect_key($form->Data, (array) $list->getExtraFields()) : [];
// FIX: nonsaving boolean/checkboxfields (unchecked will not be posted)
foreach ($form->Fields()->saveableFields() as $formfield) {
// if boolean field is included in form and unset in values, unset on object
if ($formfield instanceof CheckboxField && !array_key_exists($formfield->name, $fields)) {
$item->{$formfield->name} = 0;
}
}
$item->write();
$list->add($item, $extra);
}
}
示例8: handleSave
public function handleSave(\GridField $grid, \DataObjectInterface $record)
{
$list = $grid->getList();
$value = $grid->Value();
$componentName = $this->getComponentName();
if (!isset($value[$componentName]) || !is_array($value[$componentName])) {
return;
}
$class = $grid->getModelClass();
if (!singleton($class)->canCreate()) {
return;
}
$form = $this->getForm($grid, '', false);
$id = $grid->ID();
$orderable = $grid->Config->getComponentByType('GridFieldOrderableRows');
$sortField = $orderable ? $orderable->getSortField() : '';
$max = $sortField && !$this->prepend ? $orderable->getManipulatedData($grid, $list)->max($sortField) + 1 : false;
$count = 1;
$itemIds = [];
foreach ($value[$componentName] as $fields) {
$item = isset($fields['_modelClass']) ? \Object::create($fields['_modelClass']) : \Object::create($class);
$form->loadDataFrom($fields);
$form->saveInto($item);
$extra = method_exists($list, 'getExtraFields') ? array_intersect_key($form->Data, (array) $list->getExtraFields()) : [];
if ($sortField && $max !== false) {
$item->{$sortField} = $max;
$extra[$sortField] = $max;
$max++;
} else {
if ($sortField) {
$item->{$sortField} = $count;
$extra[$sortField] = $count;
$count++;
}
}
$item->write();
$list->add($item, $extra);
$itemIds[] = $item->ID;
Session::set('EditableRowToggles.' . $id . '.' . get_class($item) . '_' . $item->ID, true);
}
// Fix other sorts for prepends in one query
if ($sortField && $max === false) {
\DB::query(sprintf('UPDATE "%s" SET "%s" = %s + %d WHERE %s', $orderable->getSortTable($list), $sortField, $sortField, $count, '"ID" NOT IN (' . implode(',', $itemIds) . ')'));
}
}
示例9: handleSave
public function handleSave(\GridField $grid, \DataObjectInterface $record)
{
$list = $grid->getList();
$value = $grid->Value();
$className = str_replace('\\', '_', __CLASS__);
if (!isset($value[$className]) || !is_array($value[$className])) {
return;
}
foreach ($value[$className] as $id => $fields) {
if (!is_numeric($id) || !is_array($fields)) {
continue;
}
$item = $list->byID($id);
if (!$item || !$item->canEdit()) {
continue;
}
$form = $this->getForm($grid, $item, false);
$form->loadDataFrom($fields);
$form->saveInto($item);
$extra = method_exists($list, 'getExtraFields') ? array_intersect_key($form->Data, (array) $list->getExtraFields()) : [];
$item->write();
$list->add($item, $extra);
}
}
示例10: handleSave
/**
* Handle saving when 'immediateUpdate' is disabled, otherwise this isn't
* necessary for the default sort mode.
*/
public function handleSave(GridField $grid, DataObjectInterface $record)
{
if (!$this->immediateUpdate) {
$value = $grid->Value();
$sortedIDs = $this->getSortedIDs($value);
if ($sortedIDs) {
$this->executeReorder($grid, $sortedIDs);
}
}
}
示例11: handleSave
public function handleSave(GridField $grid, DataObjectInterface $record)
{
$list = $grid->getList();
$value = $grid->Value();
if (!isset($value[__CLASS__]) || !is_array($value[__CLASS__])) {
return;
}
$class = $grid->getModelClass();
$editable = $grid->getConfig()->getComponentByType('GridFieldEditableColumns');
$form = $editable->getForm($grid, $record);
if (!singleton($class)->canCreate()) {
return;
}
foreach ($value[__CLASS__] as $fields) {
$item = $class::create();
$extra = array();
$form->loadDataFrom($fields, Form::MERGE_CLEAR_MISSING);
$form->saveInto($item);
if ($list instanceof ManyManyList) {
$extra = array_intersect_key($form->getData(), (array) $list->getExtraFields());
}
$item->write();
$list->add($item, $extra);
}
}
开发者ID:helpfulrobot,项目名称:ajshort-silverstripe-gridfieldextensions,代码行数:25,代码来源:GridFieldAddNewInlineButton.php