本文整理汇总了PHP中ArrayList::First方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayList::First方法的具体用法?PHP ArrayList::First怎么用?PHP ArrayList::First使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayList
的用法示例。
在下文中一共展示了ArrayList::First方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: canBeDiscounted
/**
* normally returns TRUE, but returns FALSE when it, or its parent is in the list.
* todo: add products in other product categories
* @param SiteTree $page
* @return Boolean
*/
function canBeDiscounted(SiteTree $page)
{
if ($this->owner->PageIDs) {
$allowedPageIDs = explode(',', $this->owner->PageIDs);
$checkPages = new ArrayList(array($page));
$alreadyCheckedPageIDs = array();
while ($checkPages->Count()) {
$page = $checkPages->First();
if (array_search($page->ID, $allowedPageIDs) !== false) {
return true;
}
$alreadyCheckedPageIDs[] = $page->ID;
$checkPages->remove($page);
// Parents list update
if ($page->hasMethod('AllParentGroups')) {
$parents = new ArrayList($page->AllParentGroups()->toArray());
} else {
$parents = new ArrayList();
}
$parent = $page->Parent();
if ($parent && $parent->exists()) {
$parents->unshift($parent);
}
foreach ($parents as $parent) {
if (array_search($parent->ID, $alreadyCheckedPageIDs) === false) {
$checkPages->push($parent);
}
}
$checkPages->removeDuplicates();
}
return false;
}
return true;
}
开发者ID:helpfulrobot,项目名称:sunnysideup-ecommerce-discount-coupon,代码行数:40,代码来源:DiscountCouponSiteTreeDOD.php
示例2: onAfterInit
public function onAfterInit()
{
if (!Director::isDev()) {
// Only on live site
$errorcode = $this->owner->failover->ErrorCode ? $this->owner->failover->ErrorCode : 404;
$extract = preg_match('/^([a-z0-9\\.\\_\\-\\/]+)/i', $_SERVER['REQUEST_URI'], $rawString);
if ($errorcode == 404 && $extract) {
$uri = preg_replace('/\\.(aspx?|html?|php[34]?)$/i', '', $rawString[0]);
$parts = preg_split('/\\//', $uri, -1, PREG_SPLIT_NO_EMPTY);
$page_key = array_pop($parts);
$sounds_like = soundex($page_key);
// extend ignored classes with child classes
$ignoreClassNames = array();
if ($configClasses = Config::inst()->get('Intelligent404', 'intelligent_404_ignored_classes')) {
foreach ($configClasses as $class) {
$ignoreClassNames = array_merge($ignoreClassNames, array_values(ClassInfo::subclassesFor($class)));
}
}
// get all pages
$SiteTree = SiteTree::get()->exclude('ClassName', $ignoreClassNames);
// Translatable support
if (class_exists('Translatable')) {
$SiteTree = $SiteTree->filter('Locale', Translatable::get_current_locale());
}
// Multisites support
if (class_exists('Multisites')) {
$SiteTree = $SiteTree->filter('SiteID', Multisites::inst()->getCurrentSiteId());
}
$ExactMatches = new ArrayList();
$PossibleMatches = new ArrayList();
foreach ($SiteTree as $page) {
if ($page->URLSegment == $page_key) {
$ExactMatches->push($page);
} elseif ($sounds_like == soundex($page->URLSegment)) {
$PossibleMatches->push($page);
}
}
$ExactCount = $ExactMatches->Count();
$PossibleCount = $PossibleMatches->Count();
$redirectOnSingleMatch = Config::inst()->get('Intelligent404', 'redirect_on_single_match');
if ($ExactCount == 1 && $redirectOnSingleMatch) {
return $this->RedirectToPage($ExactMatches->First()->Link());
} elseif ($ExactCount == 0 && $PossibleCount == 1 && $redirectOnSingleMatch) {
return $this->RedirectToPage($PossibleMatches->First()->Link());
} elseif ($ExactCount > 1 || $PossibleCount > 1 || !$redirectOnSingleMatch) {
$ExactMatches->merge($PossibleMatches);
$content = $this->owner->customise(array('Pages' => $ExactMatches))->renderWith(array('Intelligent404Options'));
$this->owner->Content .= $content;
}
}
}
}