本文整理汇总了PHP中DataList类的典型用法代码示例。如果您正苦于以下问题:PHP DataList类的具体用法?PHP DataList怎么用?PHP DataList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DataList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getManipulatedData
public function getManipulatedData(GridField $gridField, SS_List $list)
{
if (!$list instanceof RelationList) {
user_error('GridFieldManyRelationHandler requires the GridField to have a RelationList. Got a ' . get_class($list) . ' instead.', E_USER_WARNING);
}
$state = $this->getState($gridField);
// We don't use setupState() as we need the list
if ($state->FirstTime) {
$state->RelationVal = array_values($list->getIdList()) ?: array();
}
if (!$state->ShowingRelation && $this->useToggle) {
return $list;
}
$query = clone $list->dataQuery();
try {
$query->removeFilterOn($this->cheatList->getForeignIDFilter($list));
} catch (InvalidArgumentException $e) {
/* NOP */
}
$orgList = $list;
$list = new DataList($list->dataClass());
$list = $list->setDataQuery($query);
if ($orgList instanceof ManyManyList) {
$joinTable = $this->cheatManyList->getJoinTable($orgList);
$baseClass = ClassInfo::baseDataClass($list->dataClass());
$localKey = $this->cheatManyList->getLocalKey($orgList);
$query->leftJoin($joinTable, "\"{$joinTable}\".\"{$localKey}\" = \"{$baseClass}\".\"ID\"");
$list = $list->setDataQuery($query);
}
return $list;
}
开发者ID:helpfulrobot,项目名称:arillo-gridfieldrelationhandler,代码行数:31,代码来源:GridFieldManyRelationHandler.php
示例2: getCMSFields
public function getCMSFields()
{
$fields = parent::getCMSFields();
// Remove MCListSegment GridField Tab And Manually Manage
$fields->removeByName("MCListSegments");
// Manually Manage Creation of MCListSegments Based on Selected MCLists
if (empty($this->owner->ID)) {
$lists = new DataList("MCList");
if ($lists->count() > 1) {
$fields->addFieldToTab('Root.Main', new LiteralField('_AffectedMCListsTitle', '<h2>Affected MailChimp Lists</h2>'));
$map = $lists->map("ID", "Name");
$listIDs = new CheckboxSetField('_AffectedMCListIDs', 'Which MailChimp List(s) Does This Event Relate To', $map);
$listIDs->setDefaultItems(array_keys($map->toArray()));
} else {
if ($lists->count() == 1) {
$listIDs = new HiddenField('_AffectedMCListIDs', 'Which MailChimp List(s) Does This Event Relate To', $lists->first()->ID);
} else {
$listIDs = new HiddenField('_AffectedMCListIDs', 'Which MailChimp List(s) Does This Event Relate To', 0);
}
}
$fields->addFieldToTab('Root.Main', $listIDs);
}
// Configure Attendees Gridfield
$gf = $fields->fieldByName('Root.Attendees.Attendees');
if (is_object($gf) && $gf->exists()) {
$gf->setList($this->getMyManyManyComponents('Attendees'));
$config = $gf->getConfig();
$config->removeComponentsByType('GridfieldAddNewButton');
}
return $fields;
}
示例3: constrainGridListFilters
/**
* If HideUnmatchedFilters is on then remove all filters which are not found in the items by their 'AssociatedFilters' relationship.
*
* @param \DataList $filters list of GridListFilter models
* @param array $parameters
* @return \ArrayList
*/
public function constrainGridListFilters(&$filters, &$parameters = [])
{
$out = new \ArrayList();
if ($this()->{self::SingleFieldName}) {
$ids = $filters->column('ID');
if (count($ids)) {
$items = $this()->GridListItems();
// this is where we keep track of GridListFilters which have been found on items where ID is the key
$foundFilters = array_combine($ids, array_fill(0, count($ids), false));
foreach ($foundFilters as $filterID => &$found) {
/** @var \Page|Model $item */
foreach ($items as $item) {
if ($item->hasExtension(HasGridListFilters::class_name())) {
if ($itemFilters = $item->{HasGridListFilters::relationship_name()}()->column('ID')) {
if (in_array($filterID, $itemFilters)) {
$found = true;
break;
}
}
}
}
}
foreach ($filters as $filter) {
if (isset($foundFilters[$filter->ID])) {
$out->push($filter);
}
}
$filters = $out;
}
}
}
示例4: testNoSpecificColumnNamesSubclassDataObjectQuery
public function testNoSpecificColumnNamesSubclassDataObjectQuery()
{
// This queries all columns from base table and subtable
$playerList = new DataList('DataObjectTest_SubTeam');
// Should be a left join.
$this->assertEquals(1, preg_match($this->normaliseSQL('/SELECT DISTINCT .* LEFT JOIN .* /'), $this->normaliseSQL($playerList->sql($parameters))));
}
示例5: run
public function run($request) {
$pages = 0;
$links = 0;
$linkedPages = new DataList('SiteTree');
$linkedPages->innerJoin('SiteTree_LinkTracking', '"SiteTree_LinkTracking"."SiteTreeID" = "SiteTree"."ID"');
if($linkedPages) foreach($linkedPages as $page) {
$tracking = DB::query(sprintf('SELECT "ChildID", "FieldName" FROM "SiteTree_LinkTracking" WHERE "SiteTreeID" = %d', $page->ID))->map();
foreach($tracking as $childID => $fieldName) {
$linked = DataObject::get_by_id('SiteTree', $childID);
// TOOD: Replace in all HTMLText fields
$page->Content = preg_replace (
"/href *= *([\"']?){$linked->URLSegment}\/?/i",
"href=$1[sitetree_link id={$linked->ID}]",
$page->Content,
-1,
$replaced
);
if($replaced) {
$links += $replaced;
}
}
$page->write();
$pages++;
}
echo "Rewrote $links link(s) on $pages page(s) to use shortcodes.\n";
}
示例6: LastUpdated
public function LastUpdated()
{
$elements = new DataList($this->dataClass);
$lastUpdated = new SS_Datetime('LastUpdated');
$lastUpdated->setValue($elements->max('LastEdited'));
return $lastUpdated;
}
示例7: filter
public function filter(DataList $list)
{
$groupids = array(0);
if ($member = $this->getMember()) {
$groupids = $groupids + $member->Groups()->map('ID', 'ID')->toArray();
}
return $list->filter("GroupID", $groupids);
}
示例8: removeByID
/**
* Overloading ManyManyList removeByID Rather Then remove() as That Just Calls removeByID()
* Remove the given item from this list.
* Note that for a ManyManyList, the item is never actually deleted, only the join table is affected
* @param $itemID The item it
*/
public function removeByID($itemID)
{
parent::removeByID($itemID);
// Get Item Object Itself Based on $itemID
$dl = new DataList($this->dataClass);
// Must Include Table Prefix To Prevent "Column 'ID' in where clause is ambiguous" Error
$item = $dl->where("\"" . $this->dataClass . "\".\"ID\" = '" . $itemID . "'")->first();
$this->onUnlink($item);
}
示例9: filter
public static function filter(DataList $list, $member = null)
{
$now = date('Y-m-d H:i:s');
$nowminusone = date('Y-m-d H:i:s', strtotime("-1 day"));
$groupids = array(0);
if ($member) {
$groupids = array_merge($member->Groups()->map('ID', 'ID')->toArray(), $groupids);
}
return $list->where("(\"SpecificPrice\".\"StartDate\" IS NULL) OR (\"SpecificPrice\".\"StartDate\" < '{$now}')")->where("(\"SpecificPrice\".\"EndDate\" IS NULL) OR (\"SpecificPrice\".\"EndDate\" > '{$nowminusone}')")->filter("GroupID", $groupids);
}
示例10: sortByRating
/**
* takes a DataList of Rateable DataObjects and sorts them by their average score
* @param DataList $list
* @return ArrayList
**/
public function sortByRating(DataList $list, $dir = 'DESC')
{
$items = new ArrayList($list->toArray());
foreach ($items as $item) {
$score = $item->getAverageScore();
$item->Score = $score ? $score : 0;
$item->Title = $item->Title;
}
return $items->sort('Score', $dir);
}
示例11: onBeforeWrite
public function onBeforeWrite()
{
// If there is no URLSegment set, generate one from Title
if ((!$this->URLSegment || $this->URLSegment == 'new-product') && $this->Title != 'New Product') {
$siteTree = DataList::create('SiteTree')->first();
$this->URLSegment = $siteTree->generateURLSegment($this->Title);
} else {
if ($this->isChanged('URLSegment')) {
// Make sure the URLSegment is valid for use in a URL
$segment = preg_replace('/[^A-Za-z0-9]+/', '-', $this->URLSegment);
$segment = preg_replace('/-+/', '-', $segment);
// If after sanitising there is no URLSegment, give it a reasonable default
if (!$segment) {
$segment = "product-{$this->ID}";
}
$this->URLSegment = $segment;
}
}
// Ensure that this object has a non-conflicting URLSegment value.
$count = 2;
while ($this->LookForExistingURLSegment($this->URLSegment)) {
$this->URLSegment = preg_replace('/-[0-9]+$/', null, $this->URLSegment) . '-' . $count;
$count++;
}
parent::onBeforeWrite();
}
示例12: scaffoldFormField
public function scaffoldFormField($title = null, $params = null)
{
if (empty($this->object)) {
return null;
}
$relationName = substr($this->name, 0, -2);
$hasOneClass = $this->object->hasOneComponent($relationName);
if (empty($hasOneClass)) {
return null;
}
$hasOneSingleton = singleton($hasOneClass);
if ($hasOneSingleton instanceof File) {
$field = new UploadField($relationName, $title);
if ($hasOneSingleton instanceof Image) {
$field->setAllowedFileCategories('image/supported');
}
return $field;
}
// Build selector / numeric field
$titleField = $hasOneSingleton->hasField('Title') ? "Title" : "Name";
$list = DataList::create($hasOneClass);
// Don't scaffold a dropdown for large tables, as making the list concrete
// might exceed the available PHP memory in creating too many DataObject instances
if ($list->count() < 100) {
$field = new DropdownField($this->name, $title, $list->map('ID', $titleField));
$field->setEmptyString(' ');
} else {
$field = new NumericField($this->name, $title);
}
return $field;
}
示例13: getCMSFields
public function getCMSFields()
{
$fields = new FieldList();
$fields->push(new TabSet('Root', new Tab('Main', _t('SiteTree.TABMAIN', 'Main'), new TextField('Title', _t('UniadsObject.db_Title', 'Title')))));
if ($this->ID) {
$previewLink = Director::absoluteBaseURL() . 'admin/' . UniadsAdmin::config()->url_segment . '/UniadsObject/preview/' . $this->ID;
$fields->addFieldToTab('Root.Main', new ReadonlyField('Impressions', _t('UniadsObject.db_Impressions', 'Impressions')), 'Title');
$fields->addFieldToTab('Root.Main', new ReadonlyField('Clicks', _t('UniadsObject.db_Clicks', 'Clicks')), 'Title');
$fields->addFieldsToTab('Root.Main', array(DropdownField::create('CampaignID', _t('UniadsObject.has_one_Campaign', 'Campaign'), DataList::create('UniadsCampaign')->map())->setEmptyString(_t('UniadsObject.Campaign_none', 'none')), DropdownField::create('ZoneID', _t('UniadsObject.has_one_Zone', 'Zone'), DataList::create('UniadsZone')->map())->setEmptyString(_t('UniadsObject.Zone_select', 'select one')), new NumericField('Weight', _t('UniadsObject.db_Weight', 'Weight (controls how often it will be shown relative to others)')), new TextField('TargetURL', _t('UniadsObject.db_TargetURL', 'Target URL')), new Treedropdownfield('InternalPageID', _t('UniadsObject.has_one_InternalPage', 'Internal Page Link'), 'Page'), new CheckboxField('NewWindow', _t('UniadsObject.db_NewWindow', 'Open in a new Window')), $file = new UploadField('File', _t('UniadsObject.has_one_File', 'Advertisement File')), $AdContent = new TextareaField('AdContent', _t('UniadsObject.db_AdContent', 'Advertisement Content')), $Starts = new DateField('Starts', _t('UniadsObject.db_Starts', 'Starts')), $Expires = new DateField('Expires', _t('UniadsObject.db_Expires', 'Expires')), new NumericField('ImpressionLimit', _t('UniadsObject.db_ImpressionLimit', 'Impression Limit')), new CheckboxField('Active', _t('UniadsObject.db_Active', 'Active')), new LiteralField('Preview', '<a href="' . $previewLink . '" target="_blank">' . _t('UniadsObject.Preview', 'Preview this advertisement') . "</a>")));
$app_categories = File::config()->app_categories;
$file->setFolderName($this->config()->files_dir);
$file->getValidator()->setAllowedMaxFileSize(array('*' => $this->config()->max_file_size));
$file->getValidator()->setAllowedExtensions(array_merge($app_categories['image'], $app_categories['flash']));
$AdContent->setRows(10);
$AdContent->setColumns(20);
$Starts->setConfig('showcalendar', true);
$Starts->setConfig('dateformat', i18n::get_date_format());
$Starts->setConfig('datavalueformat', 'yyyy-MM-dd');
$Expires->setConfig('showcalendar', true);
$Expires->setConfig('dateformat', i18n::get_date_format());
$Expires->setConfig('datavalueformat', 'yyyy-MM-dd');
$Expires->setConfig('min', date('Y-m-d', strtotime($this->Starts ? $this->Starts : '+1 days')));
}
$this->extend('updateCMSFields', $fields);
return $fields;
}
示例14: search
public function search($request)
{
$list = DataList::create($this->getConfig('classToSearch'));
$params = array();
$searchFields = $this->getConfig('searchFields');
foreach ($searchFields as $searchField) {
$name = strpos($searchField, ':') !== false ? $searchField : "{$searchField}:partialMatch";
$params[$name] = $request->getVar('term');
}
$start = (int) $request->getVar('id') ? (int) $request->getVar('id') * $this->getConfig('resultsLimit') : 0;
$list = $list->filterAny($params)->exclude($this->getConfig('excludes'));
$filter = $this->getConfig('filter');
if (count($filter) > 0) {
$list = $list->filter($filter);
}
$total = $list->count();
$results = $list->sort(strtok($searchFields[0], ':'), 'ASC')->limit($this->getConfig('resultsLimit'), $start);
$return = array('list' => array(), 'total' => $total);
$originalSourceFileComments = Config::inst()->get('SSViewer', 'source_file_comments');
Config::inst()->update('SSViewer', 'source_file_comments', false);
foreach ($results as $object) {
$return['list'][] = array('id' => $object->ID, 'resultsContent' => html_entity_decode(SSViewer::fromString($this->getConfig('resultsFormat'))->process($object)), 'selectionContent' => SSViewer::fromString($this->getConfig('selectionFormat'))->process($object));
}
Config::inst()->update('SSViewer', 'source_file_comments', $originalSourceFileComments);
return Convert::array2json($return);
}
示例15: doSearch
public function doSearch($gridField, $request)
{
$dataClass = $gridField->getList()->dataClass();
$allList = $this->searchList ? $this->searchList : DataList::create($dataClass);
$searchFields = $this->getSearchFields() ? $this->getSearchFields() : $this->scaffoldSearchFields($dataClass);
if (!$searchFields) {
throw new LogicException(sprintf('GridFieldAddExistingAutocompleter: No searchable fields could be found for class "%s"', $dataClass));
}
$params = array();
foreach ($searchFields as $searchField) {
$name = strpos($searchField, ':') !== FALSE ? $searchField : "{$searchField}:StartsWith";
$params[$name] = $request->getVar('gridfield_relationsearch');
}
if (!$gridField->getList() instanceof UnsavedRelationList) {
$allList = $allList->subtract($gridField->getList());
}
$results = $allList->filterAny($params)->sort(strtok($searchFields[0], ':'), 'ASC')->limit($this->getResultsLimit());
$json = array();
$originalSourceFileComments = Config::inst()->get('SSViewer', 'source_file_comments');
Config::inst()->update('SSViewer', 'source_file_comments', false);
foreach ($results as $result) {
$json[$result->ID] = html_entity_decode(SSViewer::fromString($this->resultsFormat)->process($result));
}
Config::inst()->update('SSViewer', 'source_file_comments', $originalSourceFileComments);
return Convert::array2json($json);
}