本文整理汇总了PHP中ArrayList::sort方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayList::sort方法的具体用法?PHP ArrayList::sort怎么用?PHP ArrayList::sort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayList
的用法示例。
在下文中一共展示了ArrayList::sort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: downloads
/**
* This may need to be optimised. We'll just have to see how it performs.
*
* @param SS_HTTPRequest $req
* @return array
*/
public function downloads(SS_HTTPRequest $req)
{
$downloads = new ArrayList();
$member = Member::currentUser();
if (!$member || !$member->exists()) {
$this->httpError(401);
}
// create a dropdown for sorting
$sortOptions = Config::inst()->get('DownloadableAccountPageController', 'sort_options');
if ($sortOptions) {
$sort = $req->requestVar('sort');
if (empty($sort)) {
reset($sortOptions);
$sort = key($sortOptions);
}
$sortControl = new DropdownField('download-sort', 'Sort By:', $sortOptions, $sort);
} else {
$sort = 'PurchaseDate';
$sortControl = '';
}
// create a list of downloads
$orders = $member->getPastOrders();
if (!empty($orders)) {
foreach ($orders as $order) {
if ($order->DownloadsAvailable()) {
$downloads->merge($order->getDownloads());
}
}
}
Requirements::javascript(SHOP_DOWNLOADABLE_FOLDER . '/javascript/AccountPage_downloads.js');
return array('Title' => 'Digital Purchases', 'Content' => '', 'SortControl' => $sortControl, 'HasDownloads' => $downloads->count() > 0, 'Downloads' => $downloads->sort($sort));
}
开发者ID:helpfulrobot,项目名称:markguinn-silverstripe-shop-downloadable,代码行数:38,代码来源:DownloadableAccountPageController.php
示例2: getCurrentFilms
public function getCurrentFilms()
{
$r = new ArrayList();
//$RestfulService = new RestfulService("http://www.odeon.co.uk/api/uk/v2/cinemas/cinema/{$this->ID}/filmswithdetails.json");
$RestfulService = new RestfulService("http://www.odeon.co.uk/api/uk/v2/cinemas/cinema/{$this->ID}/", 259200);
$Response = $RestfulService->request("filmswithdetails.json");
if (!$Response->isError()) {
$films = Convert::json2array($Response->getBody());
foreach ($films as $film) {
$OdeonFilm = OdeonFilm::get_by_id('OdeonFilm', (int) $film['masterId']);
if (!$OdeonFilm) {
$OdeonFilm = new OdeonFilm();
$OdeonFilm->ID = (int) $film['masterId'];
$OdeonFilm->Title = Convert::raw2sql($film['title']);
if (isset($film['media']['imageUrl400'])) {
$OdeonFilm->imageUrlSmall = Convert::raw2sql($film['media']['imageUrl400']);
}
if (isset($film['casts'])) {
$OdeonFilm->Content = Convert::raw2sql($film['casts']);
}
$OdeonFilm->write();
}
$r->push($OdeonFilm);
}
}
return $r->sort("Title DESC");
}
示例3: BlogTags
public function BlogTags()
{
if ($newsIndex = $this->NewsIndex()) {
$alRet = new ArrayList();
$arrTags = array();
$strTable = Versioned::current_stage() == 'Stage' ? 'NewsPost' : 'NewsPost_Live';
$results = DB::query('SELECT `Tags` AS Tags, COUNT(1) AS Items
FROM ' . $strTable . '
WHERE `Tags` IS NOT NULL
GROUP BY Tags');
while ($row = $results->nextRecord()) {
$arrCurrentItems = explode(',', $row['Tags']);
foreach ($arrCurrentItems as $strItem) {
$strItem = trim($strItem);
$strLower = strtolower($strItem);
if (!array_key_exists($strLower, $arrTags)) {
$arrTags[$strLower] = new ArrayData(array('Tag' => $strItem, 'Count' => $row['Items'], 'Link' => $newsIndex->Link('tag/' . urlencode($strItem))));
} else {
$arrayData = $arrTags[$strLower];
$arrayData->Count += $row['Items'];
}
}
}
foreach ($arrTags as $arrTag) {
$alRet->push($arrTag);
}
return $alRet->sort('Count')->limit(SiteConfig::current_site_config()->NumberOfTags ?: PHP_INT_MAX);
}
}
示例4: unsignedAgreements
/**
* returns sorted User Agreements to be signed
* @return ArrayList UserAgreement's required
**/
public function unsignedAgreements()
{
// are there any required agreements for this users groups?
$groupIDs = $this->owner->Groups()->getIdList();
$agreementsRemaining = new ArrayList();
$requiredAgreements = $groupIDs ? UserAgreement::get()->filter('Archived', false)->filterAny('GroupID', $groupIDs) : null;
$this->owner->extend('updateRequiredAgreements', $requiredAgreements);
// collect agreements to be signed - checking agreement type (one off vs session)
if ($requiredAgreements) {
//Flush the component cache - which causes the First Agreement for each Member to be shown twice on the first occurrence
$this->owner->flushCache();
$signedAgreements = $this->owner->SignedAgreements();
foreach ($requiredAgreements as $required) {
if (!$signedAgreements->find('UserAgreementID', $required->ID)) {
$agreementsRemaining->push($required);
} else {
if ($required->Type == 'Every Login') {
$signings = $this->owner->SignedAgreements("UserAgreementID='" . $required->ID . "'");
if (!$signings->find('SessionID', session_id())) {
$agreementsRemaining->push($required);
}
}
}
}
$agreementsRemaining->sort('Sort', 'ASC');
}
return $agreementsRemaining;
}
示例5: BillingHistory
public function BillingHistory()
{
$billingHistory = new ArrayList();
$orders = Order::get()->filter(array('MemberID' => Member::currentUserID(), 'OrderStatus' => 'c'))->sort('Created');
foreach ($orders as $order) {
$productId = $order->ProductID;
if (($productId == 1 || $productId == 2 || $productId == 3) && $order->IsTrial == 1) {
$productDesc = 'First Month Trial';
} else {
$product = Product::get()->byID($productId);
$productDesc = $product->Name;
}
$creditCard = $order->CreditCard();
$ccNumber = 'XXXX-XXXX-XXXX-' . substr($creditCard->CreditCardNumber, -4);
$orderDetails = array('Date' => $order->Created, 'Description' => $productDesc, 'CCType' => strtoupper($creditCard->CreditCardType), 'CCNumber' => $ccNumber, 'Amount' => $order->Amount);
$billingHistory->push(new ArrayData($orderDetails));
}
$memBillHistory = MemberBillingHistory::get()->filter('MemberID', Member::currentUserID())->sort('Created');
foreach ($memBillHistory as $history) {
$creditCard = $history->CreditCard();
$ccNumber = 'XXXX-XXXX-XXXX-' . substr($creditCard->CreditCardNumber, -4);
$details = array('Date' => $history->Created, 'Description' => $history->Product()->Name, 'CCType' => strtoupper($creditCard->CreditCardType), 'CCNumber' => $ccNumber, 'Amount' => $history->Product()->RecurringPrice);
$billingHistory->push(new ArrayData($details));
}
$sortedBillingHistory = $billingHistory->sort('Date');
return $sortedBillingHistory;
}
示例6: 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);
}
示例7: testSortObjectsComparator
function testSortObjectsComparator()
{
$oList = new ArrayList("SampleSortableObject");
$oList->add(new SampleSortableObject(new String("b")));
$oList->add(new SampleSortableObject(new String("a")));
$oList->add(new SampleSortableObject(new String("c")));
$oList->sort(new SampleSortableObjectComparator());
$this->assertEqual(new String("c"), $oList->get(0)->getField());
$this->assertEqual(new String("b"), $oList->get(1)->getField());
$this->assertEqual(new String("a"), $oList->get(2)->getField());
}
示例8: sortedOptions
public function sortedOptions()
{
$options = $this->Options();
$newList = new ArrayList();
// Add to new list
foreach ($options as $option) {
//$option->Position = $option->getPos();
$newList->add($option);
$newList->byID($option->ID)->Position = $option->getPos();
}
return $newList->sort('Position DESC');
}
示例9: getTagsCollection
public function getTagsCollection()
{
$allTags = new ArrayList();
$max = 0;
$member = Member::currentUser();
// Find if we need to filter tags by current discussion page
$controller = Controller::curr();
if (method_exists($controller, "data")) {
$page = $controller->data();
} else {
$page = null;
}
if ($page != null && $page instanceof DiscussionPage) {
$discussions = $page->Discussions();
} else {
$discussions = Discussion::get();
}
if ($discussions) {
foreach ($discussions as $discussion) {
if ($discussion->canView($member)) {
$theseTags = preg_split(" *, *", trim($discussion->Tags));
foreach ($theseTags as $tag) {
if ($tag) {
if ($allTags->find("Tag", $tag)) {
$allTags->find("Tag", $tag)->Count++;
} else {
$allTags->push(new ArrayData(array("Tag" => $tag, "Count" => 1, "Link" => Controller::join_links($discussion->Parent()->Link("tag"), Convert::raw2url($tag)))));
}
$tag_count = $allTags->find("Tag", $tag)->Count;
$max = $tag_count > $max ? $tag_count : $max;
}
}
}
}
if ($allTags->exists()) {
// First sort our tags
$allTags->sort($this->SortParam, $this->SortOrder);
// Now if a limit has been set, limit the list
if ($this->Limit) {
$allTags = $allTags->limit($this->Limit);
}
}
return $allTags;
}
return;
}
示例10: getDockedBlocks
public function getDockedBlocks()
{
$blocks = Block::get()->filter(array('showBlockbyClass' => true));
$blocks_map = $blocks->map('ID', 'shownInClass');
foreach ($blocks_map as $blockID => $Classes) {
$Classes = explode(',', $Classes);
if (!in_array($this->owner->ClassName, $Classes)) {
$blocks = $blocks->exclude('ID', $blockID);
}
}
$published_blocks = new ArrayList();
foreach ($blocks as $block) {
if ($block->isPublished()) {
$published_blocks->push($block);
}
}
return $published_blocks->sort('SortOrder', 'ASC');
}
示例11: FutureEvents
function FutureEvents($num, $filter = '')
{
if ($this->event_manager == null) {
$this->buildEventManager();
}
$filterLowerCase = strtolower($filter);
$events_array = new ArrayList();
if ($filterLowerCase != 'other') {
$filter_array = array('EventEndDate:GreaterThanOrEqual' => date('Y-m-d'));
if (strtolower($filter) != 'all' && $filter != '') {
$filter_array['EventCategory'] = $filter;
}
$pulled_events = EventPage::get()->filter($filter_array)->sort('EventStartDate', 'ASC')->limit($num)->toArray();
} else {
$pulled_events = EventPage::get()->where("EventCategory is null and EventEndDate >= CURDATE()")->sort('EventStartDate', 'ASC')->limit($num)->toArray();
}
$events_array->merge($pulled_events);
return $events_array->sort('EventStartDate', 'ASC')->limit($num, 0)->toArray();
}
示例12: getEstimates
function getEstimates()
{
if ($this->calculated) {
return $this->estimates;
}
$output = new ArrayList();
if ($options = $this->getShippingMethods()) {
foreach ($options as $option) {
$rate = $option->getCalculator($this->order)->calculate($this->address);
if ($rate !== null) {
$option->CalculatedRate = $rate;
$output->push($option);
}
}
}
$output->sort("CalculatedRate", "ASC");
//sort by rate, lowest to highest
// cache estimates
$this->estimates = $output;
$this->calculated = true;
return $output;
}
示例13: sourceRecords
function sourceRecords($params, $sort, $limit) {
$join = '';
$sortBrokenReason = false;
if($sort) {
$parts = explode(' ', $sort);
$field = $parts[0];
$direction = $parts[1];
if($field == 'AbsoluteLink') {
$sort = 'URLSegment ' . $direction;
} elseif($field == 'Subsite.Title') {
$join = 'LEFT JOIN "Subsite" ON "Subsite"."ID" = "SiteTree"."SubsiteID"';
} elseif($field == 'BrokenReason') {
$sortBrokenReason = true;
$sort = '';
}
}
$q = DB::USE_ANSI_SQL ? '"' : '`';
if (!isset($_REQUEST['CheckSite']) || $params['CheckSite'] == 'Published') $ret = Versioned::get_by_stage('SiteTree', 'Live', "({$q}SiteTree{$q}.{$q}HasBrokenLink{$q} = 1 OR {$q}SiteTree{$q}.{$q}HasBrokenFile{$q} = 1)", $sort, $join, $limit);
else $ret = DataObject::get('SiteTree', "({$q}SiteTree{$q}.{$q}HasBrokenFile{$q} = 1 OR {$q}HasBrokenLink{$q} = 1)", $sort, $join, $limit);
$returnSet = new ArrayList();
if ($ret) foreach($ret as $record) {
$reason = false;
$isRedirectorPage = in_array($record->ClassName, ClassInfo::subclassesFor('RedirectorPage'));
$isVirtualPage = in_array($record->ClassName, ClassInfo::subclassesFor('VirtualPage'));
if ($isVirtualPage) {
if ($record->HasBrokenLink) {
$reason = _t('BrokenLinksReport.VirtualPageNonExistent', "virtual page pointing to non-existent page");
$reasonCodes = array("VPBROKENLINK");
}
} else if ($isRedirectorPage) {
if ($record->HasBrokenLink) {
$reason = _t('BrokenLinksReport.RedirectorNonExistent', "redirector page pointing to non-existent page");
$reasonCodes = array("RPBROKENLINK");
}
} else {
if ($record->HasBrokenLink && $record->HasBrokenFile) {
$reason = _t('BrokenLinksReport.HasBrokenLinkAndFile', "has broken link and file");
$reasonCodes = array("BROKENFILE", "BROKENLINK");
} else if ($record->HasBrokenLink && !$record->HasBrokenFile) {
$reason = _t('BrokenLinksReport.HasBrokenLink', "has broken link");
$reasonCodes = array("BROKENLINK");
} else if (!$record->HasBrokenLink && $record->HasBrokenFile) {
$reason = _t('BrokenLinksReport.HasBrokenFile', "has broken file");
$reasonCodes = array("BROKENFILE");
}
}
if ($reason) {
if (isset($params['Reason']) && $params['Reason'] && !in_array($params['Reason'], $reasonCodes)) continue;
$record->BrokenReason = $reason;
$returnSet->push($record);
}
}
if($sortBrokenReason) $returnSet->sort('BrokenReason', $direction);
return $returnSet;
}
示例14: ExportFullSchedule
public function ExportFullSchedule()
{
$sort = $this->getRequest()->getVar('sort') ? $this->getRequest()->getVar('sort') : 'day';
$show_desc = $this->getRequest()->getVar('show_desc') ? $this->getRequest()->getVar('show_desc') : false;
$base = Director::protocolAndHost();
if (is_null($this->Summit())) {
return $this->httpError(404, 'Sorry, summit not found');
}
$schedule = $this->Summit()->getSchedule();
$events = new ArrayList();
$sort_list = false;
foreach ($schedule as $event) {
switch ($sort) {
case 'day':
$group_label = $event->getDayLabel();
break;
case 'track':
if (!$event->isPresentation() || !$event->Category() || !$event->Category()->Title) {
continue 2;
}
$group_label = $event->Category()->Title;
$sort_list = true;
break;
case 'event_type':
$group_label = $event->Type->Type;
$sort_list = true;
break;
}
if ($group_array = $events->find('Group', $group_label)) {
$group_array->Events->push($event);
} else {
$group_array = new ArrayData(array('Group' => $group_label, 'Events' => new ArrayList()));
$group_array->Events->push($event);
$events->push($group_array);
}
}
if ($sort_list) {
$events->sort('Group');
}
$html_inner = $this->renderWith(array('SummitAppMySchedulePage_pdf'), array('Schedule' => $events, 'Summit' => $this->Summit(), 'ShowDescription' => $show_desc, 'Heading' => 'Full Schedule by ' . $sort));
$css = @file_get_contents($base . "/summit/css/summitapp-myschedule-pdf.css");
//create pdf
$file = FileUtils::convertToFileName('full-schedule') . '.pdf';
$html_outer = sprintf("<html><head><style>%s</style></head><body><div class='container'>%s</div></body></html>", $css, $html_inner);
try {
$html2pdf = new HTML2PDF('P', 'A4', 'en', true, 'UTF-8', array(15, 5, 15, 5));
$html2pdf->setTestIsImage(false);
$html2pdf->WriteHTML($html_outer);
//clean output buffer
ob_end_clean();
$html2pdf->Output($file, "D");
} catch (HTML2PDF_exception $e) {
$message = array('errno' => '', 'errstr' => $e->__toString(), 'errfile' => 'SummitAppSchedPage.php', 'errline' => '', 'errcontext' => '');
SS_Log::log($message, SS_Log::ERR);
$this->httpError(404, 'There was an error on PDF generation!');
}
}
示例15: AllPages
/**
* Generate a list of all the pages in the documentation grouped by the first letter of the page.
* @return {GroupedList}
*/
public function AllPages()
{
$pages = $this->getManifest()->getPages();
$output = new ArrayList();
$baseLink = Config::inst()->get('DocumentationViewer', 'link_base');
foreach ($pages as $url => $page) {
$first = strtoupper(trim(substr($page['title'], 0, 1)));
if ($first) {
$output->push(new ArrayData(array('Link' => Controller::join_links($baseLink, $url), 'Title' => $page['title'], 'FirstLetter' => $first)));
}
}
return GroupedList::create($output->sort('Title', 'ASC'));
}