本文整理汇总了PHP中SS_List类的典型用法代码示例。如果您正苦于以下问题:PHP SS_List类的具体用法?PHP SS_List怎么用?PHP SS_List使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SS_List类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setLists
/**
* The list of TodoLists
*
* @param SS_List $lists
* @return $this
*/
public function setLists($lists)
{
$this->lists = $lists->filterByCallback(function ($item) {
return $item->canView();
});
return $this;
}
示例2: getPhpExcelObject
/**
* Generate a {@link PHPExcel} for the provided DataObject List
* @param SS_List $set List of DataObjects
* @return PHPExcel
*/
public function getPhpExcelObject(SS_List $set)
{
// Get the first object. We'll need it to know what type of objects we
// are dealing with
$first = $set->first();
// Get the Excel object
$excel = $this->setupExcel($first);
$sheet = $excel->setActiveSheetIndex(0);
// Make sure we have at lease on item. If we don't, we'll be returning
// an empty spreadsheet.
if ($first) {
// Set up the header row
$fields = $this->getFieldsForObj($first);
$this->headerRow($sheet, $fields);
// Add a new row for each DataObject
foreach ($set as $item) {
$this->addRow($sheet, $item, $fields);
}
// Freezing the first column and the header row
$sheet->freezePane("B2");
// Auto sizing all the columns
$col = sizeof($fields);
for ($i = 0; $i < $col; $i++) {
$sheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setAutoSize(true);
}
}
return $excel;
}
示例3: batchaction
/**
* Helper method for processing batch actions.
* Returns a set of status-updating JavaScript to return to the CMS.
*
* @param $objs The SS_List of objects to perform this batch action
* on.
* @param $helperMethod The method to call on each of those objects.
* @return JSON encoded map in the following format:
* {
* 'modified': {
* 3: {'TreeTitle': 'Page3'},
* 5: {'TreeTitle': 'Page5'}
* },
* 'deleted': {
* // all deleted pages
* }
* }
*/
public function batchaction(SS_List $objs, $helperMethod, $successMessage, $arguments = array()) {
$status = array('modified' => array(), 'error' => array());
foreach($objs as $obj) {
// Perform the action
if (!call_user_func_array(array($obj, $helperMethod), $arguments)) {
$status['error'][$obj->ID] = '';
}
// Now make sure the tree title is appropriately updated
$publishedRecord = DataObject::get_by_id($this->managedClass, $obj->ID);
if ($publishedRecord) {
$status['modified'][$publishedRecord->ID] = array(
'TreeTitle' => $publishedRecord->TreeTitle,
);
}
$obj->destroy();
unset($obj);
}
$response = Controller::curr()->getResponse();
if($response) {
$response->setStatusCode(
200,
sprintf($successMessage, $objs->Count(), count($status['error']))
);
}
return Convert::raw2json($status);
}
示例4: to_autocomplete_array
/**
* @param SS_List $scope the scope to iterate over - handy if you don't want
* to add this extension for a one-off use
* @return array
*/
public static function to_autocomplete_array($scope)
{
$items = $scope->toArray();
foreach ($items as &$item) {
if ($item->hasMethod('toAutocompleteMap')) {
$item = $item->toAutocompleteMap();
} else {
$item = $item->toMap();
}
}
return $items;
}
示例5: __construct
/**
* Usage [e.g. in getCMSFields]
* $field = new PickerField('Authors', 'Selected Authors', $this->Authors(), 'Select Author(s)');
*
* @param string $name - Name of field (typically the relationship method)
* @param string $title - GridField Title
* @param SS_List $dataList - Result of the relationship component method (E.g. $this->Authors())
* @param string $linkExistingTitle - AddExisting Button Title
* @param string $sortField - Field to sort on. Be sure it exists in the $many_many_extraFields static
*/
public function __construct($name, $title = null, SS_List $dataList = null, $linkExistingTitle = null, $sortField = null)
{
$config = GridfieldConfig::create()->addComponents(new GridFieldButtonRow('before'), new GridFieldToolbarHeader(), new GridFieldDataColumns(), new GridFieldTitleHeader(), new GridFieldPaginator(), new PickerFieldAddExistingSearchButton(), new PickerFieldDeleteAction());
if ($sortField) {
$config->addComponent(new GridFieldOrderableRows($sortField));
}
if (!$linkExistingTitle) {
$linkExistingTitle = $this->isHaveOne() ? 'Select a ' . $dataList->dataClass() : 'Select ' . $dataList->dataClass() . '(s)';
// plural [has_many, many_many]
}
$config->getComponentByType('PickerFieldAddExistingSearchButton')->setTitle($linkExistingTitle);
return parent::__construct($name, $title, $dataList, $config);
}
示例6: 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;
}
示例7: __construct
/**
* @param string $name
* @param string $title
* @param DataObjectInterface $object
* @param string $sort
* @param SS_List $source
* @param string $titleField
*/
public function __construct($name, $title, DataObjectInterface $object, $sort = false, SS_List $source = null, $titleField = 'Title')
{
$this->setSort($sort);
if ($object->many_many($name)) {
$dataSource = $object->{$name}();
// Check if we're dealing with an UnsavedRelationList
$unsaved = $dataSource instanceof UnsavedRelationList;
// Store the relation's class name
$class = $dataSource->dataClass();
$this->dataClass = $class;
// Sort the items
if ($this->getSort()) {
$dataSource = $dataSource->sort($this->getSort());
}
// If we're dealing with an UnsavedRelationList, it'll be empty, so we
// can skip this and just use an array of all available items
if ($unsaved) {
$dataSource = $class::get()->map()->toArray();
} else {
// If we've been given a list source, filter on those IDs only.
if ($source) {
$dataSource = $dataSource->filter('ID', $source->column('ID'));
}
// Start building the data source from scratch. Currently selected items first,
// in the correct sort order
$dataSource = $dataSource->map('ID', $titleField)->toArray();
// Get the other items
$theRest = $class::get();
// Exclude items that we've already found
if (!empty($dataSource)) {
$theRest = $theRest->exclude('ID', array_keys($dataSource));
}
// If we've been given a list source, filter on those IDs only
if ($source) {
$theRest = $theRest->filter('ID', $source->column('ID'));
}
$theRest = $theRest->map('ID', $titleField)->toArray();
// ... we then add the remaining items in whatever order they come
$dataSource = $dataSource + $theRest;
}
} elseif ($source instanceof SS_List) {
$dataSource = $source->map('ID', $titleField)->toArray();
} elseif (is_array($source) && ArrayLib::is_associative($source)) {
$dataSource = $source;
} else {
user_error('MultiSelectField::__construct(): MultiSelectField only supports many-to-many relations');
}
parent::__construct($name, $title, $dataSource, '', null, true);
}
开发者ID:helpfulrobot,项目名称:fullscreeninteractive-silverstripe-multiselectfield,代码行数:57,代码来源:MultiSelectField.php
示例8: getManipulatedData
public function getManipulatedData(GridField $gridField, SS_List $dataList)
{
if (!$gridField->State->GridFieldAddRelation) {
return $dataList;
}
$objectID = Convert::raw2sql($gridField->State->GridFieldAddRelation);
if ($objectID) {
$object = DataObject::get_by_id($dataList->dataclass(), $objectID);
if ($object) {
$dataList->add($object);
}
}
$gridField->State->GridFieldAddRelation = null;
return $dataList;
}
示例9: getExtraSavedData
/**
* Get the list of extra data from the $record as saved into it by
* {@see Form::saveInto()}
*
* Handles detection of falsey values explicitly saved into the
* DataObject by formfields
*
* @param DataObject $record
* @param SS_List $list
* @return array List of data to write to the relation
*/
protected function getExtraSavedData($record, $list)
{
// Skip extra data if not ManyManyList
if (!$list instanceof ManyManyList) {
return null;
}
$data = array();
foreach ($list->getExtraFields() as $field => $dbSpec) {
$savedField = "ManyMany[{$field}]";
if ($record->hasField($savedField)) {
$data[$field] = $record->getField($savedField);
}
}
return $data;
}
示例10: run
public function run(SS_List $pages)
{
// Sort pages by depth
$pageArray = $pages->toArray();
// because of https://bugs.php.net/bug.php?id=50688
foreach ($pageArray as $page) {
$page->getPageLevel();
}
usort($pageArray, function ($a, $b) {
return $a->getPageLevel() - $b->getPageLevel();
});
$pages = new ArrayList($pageArray);
// Restore
return $this->batchaction($pages, 'doRestoreToStage', _t('CMSBatchActions.RESTORED_PAGES', 'Restored %d pages'));
}
示例11: getItems
/**
* @return SS_List
*/
public function getItems()
{
$name = $this->getName();
if (!$this->items || !$this->items->exists()) {
$record = $this->getRecord();
$this->items = array();
// Try to auto-detect relationship
if ($record && $record->exists()) {
if ($record->has_many($name) || $record->many_many($name)) {
// Ensure relationship is cast to an array, as we can't alter the items of a DataList/RelationList (see below)
$this->items = $record->{$name}()->toArray();
} elseif ($record->has_one($name)) {
$item = $record->{$name}();
if ($item && $item->exists()) {
$this->items = array($record->{$name}());
}
}
}
$this->items = new ArrayList($this->items);
// hack to provide $UploadFieldThumbnailURL, $hasRelation and $UploadFieldEditLink in template for each file
if ($this->items->exists()) {
foreach ($this->items as $i => $file) {
$this->items[$i] = $this->customiseFile($file);
if (!$file->canView()) {
unset($this->items[$i]);
}
// Respect model permissions
}
}
}
return $this->items;
}
示例12: getManipulatedData
/**
* If an object ID is set, add the object to the list
*
* @param GridField $gridField
* @param SS_List $dataList
* @return SS_List
*/
public function getManipulatedData(GridField $gridField, SS_List $dataList)
{
if (!$gridField->State->GridFieldAddRelation) {
return $dataList;
}
$objectID = Convert::raw2sql($gridField->State->GridFieldAddRelation);
if ($objectID) {
$object = DataObject::get_by_id($dataList->dataclass(), $objectID);
if ($object) {
$virtual = new ElementVirtualLinked();
$virtual->LinkedElementID = $object->ID;
$virtual->write();
$dataList->add($virtual);
}
}
$gridField->State->GridFieldAddRelation = null;
return $dataList;
}
开发者ID:nyeholt,项目名称:silverstripe-elemental,代码行数:25,代码来源:ElementalGridFieldAddExistingAutocompleter.php
示例13: merge_owners
/**
* Takes a list of groups and members and return a list of unique member.
*
* @param SS_List $groups
* @param SS_List $members
*
* @return ArrayList
*/
public static function merge_owners(SS_List $groups, SS_List $members)
{
$contentReviewOwners = new ArrayList();
if ($groups->count()) {
$groupIDs = array();
foreach ($groups as $group) {
$familyIDs = $group->collateFamilyIDs();
if (is_array($familyIDs)) {
$groupIDs = array_merge($groupIDs, array_values($familyIDs));
}
}
array_unique($groupIDs);
if (count($groupIDs)) {
$groupMembers = DataObject::get("Member")->where("\"Group\".\"ID\" IN (" . implode(",", $groupIDs) . ")")->leftJoin("Group_Members", "\"Member\".\"ID\" = \"Group_Members\".\"MemberID\"")->leftJoin("Group", "\"Group_Members\".\"GroupID\" = \"Group\".\"ID\"");
$contentReviewOwners->merge($groupMembers);
}
}
$contentReviewOwners->merge($members);
$contentReviewOwners->removeDuplicates();
return $contentReviewOwners;
}
示例14: getManipulatedData
/**
* If an object ID is set, add the object to the list
*
* @param GridField $gridField
* @param SS_List $dataList
* @return SS_List
*/
public function getManipulatedData(GridField $gridField, SS_List $dataList)
{
if (!$gridField->State->GridFieldAddRelation) {
return $dataList;
}
$objectID = Convert::raw2sql($gridField->State->GridFieldAddRelation);
if ($objectID) {
$object = DataObject::get_by_id($dataList->dataclass(), $objectID);
if ($object) {
if ($this->_item_limit > 0 && $dataList->count() + 1 > $this->_item_limit) {
$gridField->getForm()->getController()->getResponse()->addHeader('X-Status', _t('LimitedRelationsGridField.ITEM_LIMIT_REACHED', '_You cannot add any more items, you can only add {count} items. Please remove one then try again.', array('count' => $this->_item_limit)));
} else {
$dataList->add($object);
}
}
}
$gridField->State->GridFieldAddRelation = null;
return $dataList;
}
开发者ID:helpfulrobot,项目名称:webbuilders-group-silverstripe-limitedrelationsgridfield,代码行数:26,代码来源:LRGridFieldAddExistingAutocompleter.php
示例15: getManipulatedData
/**
* If an object ID is set, add the object to the list
*
* @param GridField $gridField
* @param SS_List $dataList
* @return SS_List
*/
public function getManipulatedData(GridField $gridField, SS_List $dataList)
{
if (!$gridField->State->GridFieldAddRelation) {
return $dataList;
}
$objectID = Convert::raw2sql($gridField->State->GridFieldAddRelation);
if ($objectID) {
$object = DataObject::get_by_id($dataList->dataclass(), $objectID);
if ($object) {
// if the object is currently not linked to either a page or another list then we want to link to
// the original, otherwise link to a clone
if (!$object->ParentID && !$object->ListID) {
$dataList->add($object);
} else {
$virtual = new ElementVirtualLinked();
$virtual->LinkedElementID = $object->ID;
$virtual->write();
$dataList->add($virtual);
}
}
}
$gridField->State->GridFieldAddRelation = null;
return $dataList;
}
开发者ID:dnadesign,项目名称:silverstripe-elemental,代码行数:31,代码来源:ElementalGridFieldAddExistingAutocompleter.php