本文整理汇总了PHP中ArrayList::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayList::exists方法的具体用法?PHP ArrayList::exists怎么用?PHP ArrayList::exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayList
的用法示例。
在下文中一共展示了ArrayList::exists方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testExists
public function testExists()
{
$list = new ArrayList();
$this->assertFalse($list->exists());
$list = new ArrayList(array(1, 2, 3));
$this->assertTrue($list->exists());
}
示例2: 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;
}
示例3: Form
public function Form()
{
$menu = $this->getProductMenu();
$selections = new ArrayList();
foreach ($menu->GroupSortedSelections() as $mps) {
if ($mps->Product()->exists() && $mps->Product()->canPurchase()) {
$selections->push($mps);
}
}
if (!$selections->exists()) {
return;
}
$gselections = new Menu_GroupedList($selections);
$fields = new FieldList(QuantitiesSelectionField::create("Selections", "", $gselections));
$actions = new FieldList(new FormAction("save", _t("MenuPage.SAVE", "Save")));
$form = new Form($this, "Form", $fields, $actions);
$this->dataRecord->extend("updateMenuSelectionForm", $form);
return $form;
}
示例4: getPostageAreas
/**
* Function to find relevent postage rates, based on supplied country and
* zip/postal code data.
*
* We make this a function as part of Commerce Controller, as there are
* several points in the payment/order process that will make use of this
* functionality
*
* @param $country String listing the country to search, this has to be an ISO 3166 code
* @param $zipcode String listing the zip/postage code to filter by
*/
public function getPostageAreas($country, $zipcode)
{
$return = new ArrayList();
$countries = new ArrayList();
$cart = ShoppingCart::create();
$all_rates = $this->SiteConfig()->PostageAreas();
// First find all area's for this country directly (no wildcards)
foreach ($all_rates as $rate) {
if (!(strpos(strtolower($rate->Country), strtolower($country)) === false)) {
$countries->add($rate);
}
}
// If we have no countries in the list specificly, then check for wildcards
if (!$countries->exists()) {
foreach ($all_rates as $rate) {
if ($rate->Country == "*") {
$countries->add($rate);
}
}
}
// If we have a list of countries check them for post codes
foreach ($countries as $rate) {
$rate_codes = explode(",", $rate->ZipCode);
foreach ($rate_codes as $rate_to_check) {
$curr_length = strlen($rate_to_check);
if (strtolower(substr($zipcode, 0, $curr_length)) == strtolower($rate_to_check)) {
$return->add($rate);
}
}
}
// If we still don't have anything to return, check or list of countries
// for a wildcard
if (!$return->exists()) {
foreach ($countries as $rate) {
if ($rate->ZipCode == "*") {
$return->add($rate);
}
}
}
// Now we have a list of locations, start checking for additional
// rules an remove if not applicable.
$total_cost = str_replace(",", "", $cart->SubTotalCost());
$total_weight = str_replace(",", "", $cart->TotalWeight());
$total_items = str_replace(",", "", $cart->TotalItems());
$max_cost = 0;
$max_weight = 0;
$max_items = 0;
// First loop through and find items that are invalid
foreach ($return as $location) {
if ($location->Calculation == "Price" && (double) $total_cost < $location->Unit) {
$return->remove($location);
}
if ($location->Calculation == "Weight" && (double) $total_weight < $location->Unit) {
$return->remove($location);
}
if ($location->Calculation == "Items" && (double) $total_items < $location->Unit) {
$return->remove($location);
}
}
// Now find max values based on units
foreach ($return as $location) {
if ($location->Calculation == "Price" && $location->Unit > $max_cost) {
$max_cost = $location->Unit;
}
if ($location->Calculation == "Weight" && $location->Unit > $max_weight) {
$max_weight = $location->Unit;
}
if ($location->Calculation == "Items" && $location->Unit > $max_items) {
$max_items = $location->Unit;
}
}
// Now loop through again and calculate which brackets each
// Location fits in
foreach ($return as $location) {
if ($location->Calculation == "Price" && $location->Unit < $max_cost) {
$return->remove($location);
}
if ($location->Calculation == "Weight" && $location->Unit < $max_weight) {
$return->remove($location);
}
if ($location->Calculation == "Items" && $location->Unit < $max_items) {
$return->remove($location);
}
}
return $return;
}
示例5: php
/**
* Check that current product variation is valid
*
* @param Array $data Submitted data
* @return Boolean Returns TRUE if the submitted data is valid, otherwise FALSE.
*/
public function php($data)
{
$valid = parent::php($data);
$fields = $this->form->Fields();
//Check that variation exists if necessary
$form = $this->form;
$request = $this->form->getRequest();
//Get product variations from options sent
//TODO refactor this
$productVariations = new ArrayList();
$options = $request->postVar('Options');
$product = DataObject::get_by_id($data['ProductClass'], $data['ProductID']);
$variations = $product ? $product->Variations() : new ArrayList();
if ($variations && $variations->exists()) {
foreach ($variations as $variation) {
$variationOptions = $variation->Options()->map('AttributeID', 'ID')->toArray();
if ($options == $variationOptions && $variation->isEnabled()) {
$productVariations->push($variation);
}
}
}
if ((!$productVariations || !$productVariations->exists()) && $product && $product->requiresVariation()) {
$this->form->sessionMessage(_t('ProductForm.VARIATIONS_REQUIRED', 'This product requires options before it can be added to the cart.'), 'bad');
//Have to set an error for Form::validate()
$this->errors[] = true;
$valid = false;
return $valid;
}
//Validate that base currency is set for this cart
$config = ShopConfig::current_shop_config();
if (!$config->BaseCurrency) {
$this->form->sessionMessage(_t('ProductForm.BASE_CURRENCY_NOT_SET', 'The currency is not set.'), 'bad');
//Have to set an error for Form::validate()
$this->errors[] = true;
$valid = false;
}
return $valid;
}
示例6: testExists
/**
* This method tests that the exists method
* returns TRUE if the values exists in the
* ArrayList.
*
* @return void
*/
public function testExists()
{
// initialize two new ArrayList's
$list = new ArrayList();
// add different values to the ArrayList
$list->add("test");
$list->add(1);
// check for the values
$this->assertTrue($list->exists(0));
$this->assertTrue($list->exists(1));
}