本文整理汇总了PHP中ArrayList::Count方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayList::Count方法的具体用法?PHP ArrayList::Count怎么用?PHP ArrayList::Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayList
的用法示例。
在下文中一共展示了ArrayList::Count方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: SplitSetIntoGridRows
public function SplitSetIntoGridRows($itemsInGridMethod, $numberOfCols)
{
error_log("GRID ROWS");
$itemsInGrid = $this->owner->{$itemsInGridMethod}();
$position = 1;
$columns = new ArrayList();
$result = new ArrayList();
foreach ($itemsInGrid as $key => $item) {
$columns->push($item);
error_log("Comparing position {$position} > number of cols {$numberOfCols}");
if ($position >= $numberOfCols) {
error_log("NEW ROW");
$position = 1;
$row = new ArrayList();
$row->Columns = $columns;
$result->push($row);
$columns = new ArrayList();
} else {
$position = $position + 1;
}
}
if ($columns->Count() > 0) {
$row = new ArrayList();
$row->Columns = $columns;
$result->push($row);
}
// FIXME add padding?
return $result;
//$result = new DataObjectSet();
}
示例3: testAppendToTopAutoSort
public function testAppendToTopAutoSort()
{
if (Member::currentUser()) {
Member::currentUser()->logOut();
}
$this->gridField->getConfig()->getComponentByType('GridFieldSortableRows')->setAppendToTop(true);
$this->assertEquals(0, $this->list->last()->SortOrder, 'Auto sort should not have run');
$stateID = 'testGridStateActionField';
Session::set($stateID, array('grid' => '', 'actionName' => 'sortableRowsToggle', 'args' => array('GridFieldSortableRows' => array('sortableToggle' => true))));
$request = new SS_HTTPRequest('POST', 'url', array(), array('action_gridFieldAlterAction?StateID=' . $stateID => true));
$this->gridField->gridFieldAlterAction(array('StateID' => $stateID), $this->form, $request);
//Insure sort ran
$this->assertEquals(3, $this->list->last()->SortOrder, 'Auto sort should have run');
//Check for duplicates (there shouldn't be any)
$count = $this->list->Count();
$indexes = count(array_unique($this->list->column('SortOrder')));
$this->assertEquals(0, $count - $indexes, 'Duplicate indexes detected');
}
示例4: testEach
public function testEach()
{
$list = new ArrayList(array(1, 2, 3));
$count = 0;
$test = $this;
$list->each(function ($item) use(&$count, $test) {
$count++;
$test->assertTrue(is_int($item));
});
$this->assertEquals($list->Count(), $count);
}
示例5: 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;
}
}
}
}
示例6: setupEntities
/**
* Sets up the top level entities.
*
* Either manually registered through the YAML syntax or automatically
* loaded through investigating the file system for `docs` folder.
*/
public function setupEntities()
{
if ($this->registeredEntities->Count() > 0) {
return;
}
if (Config::inst()->get('DocumentationManifest', 'automatic_registration')) {
$this->populateEntitiesFromInstall();
}
$registered = Config::inst()->get('DocumentationManifest', 'register_entities');
foreach ($registered as $details) {
// validate the details provided through the YAML configuration
$required = array('Path', 'Title');
foreach ($required as $require) {
if (!isset($details[$require])) {
throw new Exception("{$require} is a required key in DocumentationManifest.register_entities");
}
}
// if path is not an absolute value then assume it is relative from
// the BASE_PATH.
$path = $this->getRealPath($details['Path']);
$key = isset($details['Key']) ? $details['Key'] : $details['Title'];
if (!$path || !is_dir($path)) {
throw new Exception($details['Path'] . ' is not a valid documentation directory');
}
$version = isset($details['Version']) ? $details['Version'] : '';
$branch = isset($details['Branch']) ? $details['Branch'] : '';
$langs = scandir($path);
if ($langs) {
$possible = i18n::get_common_languages(true);
foreach ($langs as $k => $lang) {
if (isset($possible[$lang])) {
$entity = Injector::inst()->create('DocumentationEntity', $key);
$entity->setPath(Controller::join_links($path, $lang, '/'));
$entity->setTitle($details['Title']);
$entity->setLanguage($lang);
$entity->setVersion($version);
$entity->setBranch($branch);
if (isset($details['Stable'])) {
$entity->setIsStable($details['Stable']);
}
if (isset($details['DefaultEntity'])) {
$entity->setIsDefaultEntity($details['DefaultEntity']);
}
$this->registeredEntities->push($entity);
}
}
}
}
}
示例7: getNextRecurringEvents
public function getNextRecurringEvents($event_obj, $datetime_obj, $limit = null)
{
$counter = sfDate::getInstance($datetime_obj->StartDate);
if ($event = $datetime_obj->Event()->DateTimes()->First()) {
$end_date = strtotime($event->EndDate);
} else {
$end_date = false;
}
$counter->tomorrow();
$dates = new ArrayList();
while ($dates->Count() != $this->OtherDatesCount) {
// check the end date
if ($end_date) {
if ($end_date > 0 && $end_date <= $counter->get()) {
break;
}
}
if ($event_obj->getRecursionReader()->recursionHappensOn($counter->get())) {
$dates->push($this->newRecursionDateTime($datetime_obj, $counter->date()));
}
$counter->tomorrow();
}
return $dates;
}
示例8: Count
public function Count()
{
$this->getIterator();
return parent::Count();
}
示例9: showHibImages
function showHibImages($maxCount = false, $recursive = true)
{
if ($maxCount == false) {
$maxCount = HeaderImageBanner::$hibMaxImages;
}
if (isset($this->hibCachedImages) && $this->hibCachedImages) {
while ($this->hibCachedImages->Count() > $maxCount) {
$this->hibCachedImages->pop();
}
return $this->hibCachedImages;
}
$images = new ArrayList($this->owner->hibImages()->toArray());
if ($recursive && $images->Count() == 0 && is_array(HeaderImageBanner::$hibDefaultToType)) {
foreach (HeaderImageBanner::$hibDefaultToType as $action) {
if (!isset($images) || count($images) == 0) {
switch ($action) {
case 'Parent':
if ($this->owner->hasMethod("Parent") && $this->owner->Parent()->hasMethod("showHibImages")) {
$images = $this->owner->Parent()->showHibImages(0, true);
}
break;
case 'SiteConfig':
$config = SiteConfig::current_site_config();
if ($config->hasMethod("showHibImages")) {
$images = $config->showHibImages(0, false);
}
break;
case 'Children':
$images = $this->hibImagesFromChildren();
if (isset($images)) {
$images->removeDuplicates("ID");
}
break;
}
}
}
}
$this->hibCachedImages = new ArrayList();
if ($images->Count() > 0) {
$keys = $images->column("ID");
while (($this->hibCachedImages->Count() < $maxCount || $maxCount == 0) && count($keys) > 0) {
$rndKey = array_rand($keys);
$this->hibCachedImages->push($images[$rndKey]);
unset($keys[$rndKey]);
}
}
return $this->hibCachedImages;
}
开发者ID:helpfulrobot,项目名称:exadium-silverstripe-module-header-image-banner,代码行数:48,代码来源:HeaderImageBanner.php
示例10: getManagedCompanies
public function getManagedCompanies()
{
$query = DB::query("SELECT Company.* from Company INNER JOIN Company_Administrators ON Company_Administrators.CompanyID=Company.ID AND Company_Administrators.MemberID={$this->owner->ID} INNER JOIN (\r\n SELECT DISTINCT(GroupID) FROM `Permission` WHERE `Code` IN\r\n ('MANAGE_COMPANY_PROFILE','MANAGE_COMPANY_LOGOS') ) PG ON PG.GroupID = Company_Administrators.GroupID");
$companies = new ArrayList();
if (!is_null($query) && $query->numRecords() > 0) {
for ($i = 0; $i < $query->numRecords(); $i++) {
$record = $query->nextRecord();
$companies->push(new $record['ClassName']($record));
}
}
$old_companies = Company::get()->filter(array('CompanyAdminID' => $this->owner->ID));
$joined_companies = new ArrayList();
if ($companies && $companies->Count() > 0) {
foreach ($companies as $company) {
$joined_companies->push($company);
}
}
if ($old_companies && $old_companies->Count() > 0) {
foreach ($old_companies as $company) {
$joined_companies->push($company);
}
}
return $joined_companies;
}