本文整理汇总了PHP中ArrayList::remove方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayList::remove方法的具体用法?PHP ArrayList::remove怎么用?PHP ArrayList::remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayList
的用法示例。
在下文中一共展示了ArrayList::remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: removeObserver
public function removeObserver(MyObserver $o)
{
$i = $this->observers->indexOf($o);
if ($i >= 0) {
$this->observers->remove($i);
}
}
示例2: updateFilteredEmailRecipients
public function updateFilteredEmailRecipients(ArrayList $recipients, $data, $form)
{
foreach ($recipients as $recipient) {
// check if condition set
if (($field = $recipient->ConditionField()) && $field->ID) {
// get field name
$fieldName = $field->Name;
// get condition value
$conditionValue = $recipient->ConditionFieldValue;
// get field value
$fieldValue = "";
if ($field->hasMethod('getValueFromData')) {
$fieldValue = $field->getValueFromData($data);
} else {
if (isset($data[$fieldName])) {
$fieldValue = $data[$fieldName];
}
}
// remove recipient if values don't match
if (trim($fieldValue) != trim($conditionValue)) {
$recipients->remove($recipient);
}
}
}
}
开发者ID:xini,项目名称:silverstripe-userforms-conditional-recipient,代码行数:25,代码来源:ConditionalRecipientUserDefinedFormExtension.php
示例3: testRemove
public function testRemove()
{
// Remove the following lines when you implement this test.
$this->object->remove(4);
$this->assertTrue($this->object->count() == 9);
$this->assertTrue($this->object->indexOf(4) == -1);
}
示例4: 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
示例5: testAddRemove
public function testAddRemove()
{
$list = new ArrayList(array(array('Key' => 1), array('Key' => 2)));
$list->add(array('Key' => 3));
$this->assertEquals($list->toArray(), array(array('Key' => 1), array('Key' => 2), array('Key' => 3)));
$list->remove(array('Key' => 2));
$this->assertEquals(array_values($list->toArray()), array(array('Key' => 1), array('Key' => 3)));
}
示例6: remove
/**
* Removes an item (or items) from the navigation tree
* @param string $label
* @param string $url
* @return NavigationNode
*/
public function remove($label)
{
foreach ($this->items as $item) {
if ($item->label == $label) {
$this->items->remove($item);
}
}
return $this;
}
示例7: removeAll
/**
* Empty the shopping cart object of all items.
*
*/
public function removeAll()
{
foreach ($this->items as $item) {
$this->items->remove($item);
}
}
示例8: 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;
}
示例9: calculate
public function calculate($infix)
{
$postfix = new ArrayList();
$stack = new ArrayList();
$i = 0;
$temp = "";
$type = $this->getType($infix[0]);
$lasttype = TType::OPERATION;
$infix = trim($infix);
while ($i < strlen($infix)) {
$type = $this->getType($infix[$i]);
$temp = "";
//Get Token name
while ($type == $this->getType($infix[$i])) {
$temp .= $infix[$i];
$i++;
if ($i == strlen($infix) || $type == TType::OPERATION || $infix[$i - 1] == '(') {
break;
}
}
//Negatives Vorzeichen zu -1* umgeschrieben (Bsp.: -3 => (-1)*3
if ($lasttype == TType::OPERATION && $type == TType::OPERATION) {
if ($temp == '-') {
$postfix->add(new Token("-1", TType::NUMBER));
$temp = "*";
} else {
$postfix->add(new Token("1", TType::NUMBER));
$temp = "*";
}
}
//Fehlender Operator vor Funktionen wird ergänzt
if ($type == TType::NUMBER && $lasttype == TType::FUNC || $type == TType::FUNC && $lasttype == TType::NUMBER) {
$i -= strlen($temp);
$type = TType::OPERATION;
$temp = "*";
}
//Add Token to Tokenlist
switch ($type) {
case TType::NUMBER:
$postfix->add(new Token($temp, $type));
break;
case TType::OPERATION:
for ($j = $stack->size() - 1; $j > -1; $j--) {
if ($this->getValue($temp) > $this->getValue($stack->get($j))) {
$stack->add($temp);
break;
} else {
$postfix->add(new Token($stack->get($j), TType::OPERATION));
$stack->remove($j);
}
}
if ($stack->size() == 0) {
$stack->add($temp);
}
break;
case TType::FUNC:
if (in_array($temp, $this->availableFunc)) {
$func = new FunctionC($temp);
$sub = substr($infix, $i);
$pos = $this->getLastBracket($sub);
$sub = substr($sub, 0, $pos);
while (strpos($sub, ',') !== false) {
$pos2 = strpos($sub, ',');
if (strlen($func->term) === false && $temp == "integral(") {
$func->term = substr($sub, 0, $pos2);
} else {
$func->parameters->add($this->calculate(substr($sub, 0, $pos2)));
}
$sub = substr($sub, $pos2 + 1);
}
$func->parameters->add($this->calculate($sub));
$i += $pos + 1;
$postfix->add(new Token(strval($func->calculate()), TType::NUMBER));
$type = TType::NUMBER;
}
if ($this->variable->size() != 0) {
foreach ($this->variable->arrayList as $v) {
if ($temp == $v->name) {
$postfix->add(new Token(strval($v->wert), TType::NUMBER));
$temp = "";
$type = TType::NUMBER;
}
}
}
break;
}
$lasttype = $type;
}
//Add operation stack to postfix
for ($j = $stack->size() - 1; $j > -1; $j--) {
$postfix->add(new Token($stack->get($j), TType::OPERATION));
$stack->remove($j);
}
//Calculate postfix--> result
/* Lese alle Tokens der postfix Liste nacheinander ein.
* Schreibe alle Zahlen in einen Stack, wird eine Operation gelesen, so führe die Operation mit den letzten
* beiden hinzugefügten Zahlen aus, lösche die beiden Zahlen und ersetze sie mit ihrem Ergebnis
*/
$result = 0.0;
for ($i = 0; $i < $postfix->size(); $i++) {
//.........这里部分代码省略.........
示例10: remove
public function remove($value)
{
$this->validTypeThrow($value);
return parent::remove($value);
}
示例11: getHandler
/**
* Handler for object read.
*
* The data object will be returned in the following format:
*
* <ClassName>
* <FieldName>Value</FieldName>
* ...
* <HasOneRelName id="ForeignID" href="LinkToForeignRecordInAPI" />
* ...
* <HasManyRelName>
* <ForeignClass id="ForeignID" href="LinkToForeignRecordInAPI" />
* <ForeignClass id="ForeignID" href="LinkToForeignRecordInAPI" />
* </HasManyRelName>
* ...
* <ManyManyRelName>
* <ForeignClass id="ForeignID" href="LinkToForeignRecordInAPI" />
* <ForeignClass id="ForeignID" href="LinkToForeignRecordInAPI" />
* </ManyManyRelName>
* </ClassName>
*
* Access is controlled by two variables:
*
* - static $api_access must be set. This enables the API on a class by class basis
* - $obj->canView() must return true. This lets you implement record-level security
*
* @todo Access checking
*
* @param String $className
* @param Int $id
* @param String $relation
* @return String The serialized representation of the requested object(s) - usually XML or JSON.
*/
protected function getHandler($className, $id, $relationName)
{
$sort = '';
if ($this->request->getVar('sort')) {
$dir = $this->request->getVar('dir');
$sort = array($this->request->getVar('sort') => $dir ? $dir : 'ASC');
}
$limit = array('start' => $this->request->getVar('start'), 'limit' => $this->request->getVar('limit'));
$params = $this->request->getVars();
$responseFormatter = $this->getResponseDataFormatter($className);
if (!$responseFormatter) {
return $this->unsupportedMediaType();
}
// $obj can be either a DataObject or a SS_List,
// depending on the request
if ($id) {
// Format: /api/v1/<MyClass>/<ID>
$obj = $this->getObjectQuery($className, $id, $params)->First();
if (!$obj) {
return $this->notFound();
}
if (!$obj->canView()) {
return $this->permissionFailure();
}
// Format: /api/v1/<MyClass>/<ID>/<Relation>
if ($relationName) {
$obj = $this->getObjectRelationQuery($obj, $params, $sort, $limit, $relationName);
if (!$obj) {
return $this->notFound();
}
// TODO Avoid creating data formatter again for relation class (see above)
$responseFormatter = $this->getResponseDataFormatter($obj->dataClass());
}
} else {
// Format: /api/v1/<MyClass>
$obj = $this->getObjectsQuery($className, $params, $sort, $limit);
}
$this->getResponse()->addHeader('Content-Type', $responseFormatter->getOutputContentType());
$rawFields = $this->request->getVar('fields');
$fields = $rawFields ? explode(',', $rawFields) : null;
if ($obj instanceof SS_List) {
$responseFormatter->setTotalSize($obj->dataQuery()->query()->unlimitedRowCount());
$objs = new ArrayList($obj->toArray());
foreach ($objs as $obj) {
if (!$obj->canView()) {
$objs->remove($obj);
}
}
return $responseFormatter->convertDataObjectSet($objs, $fields);
} else {
if (!$obj) {
$responseFormatter->setTotalSize(0);
return $responseFormatter->convertDataObjectSet(new ArrayList(), $fields);
} else {
return $responseFormatter->convertDataObject($obj, $fields);
}
}
}
示例12: deleteObserver
/**
* Exclui um observador do conjunto de observadores deste objeto.
* @param \Prime\util\Observer $o
*/
public function deleteObserver(Observer $o)
{
return $this->observers->remove($o);
}
示例13: remove
public function remove(MenuComponent $menuComponent)
{
$this->menuComponents->remove($menuComponent);
}
示例14: remove
public function remove()
{
$this->items->remove($this->position);
}
示例15: testDeleteWithException
/**
* This method tests that a exception is thrown if the
* object with the key, passed to the remove method as
* a parameter, does not exist in the ArrayList.
*
* @return void
*/
public function testDeleteWithException()
{
// initialize a new ArrayList
$list = new ArrayList();
// try to remove a not existing object from the ArrayList
try {
$list->remove(1);
$this->fail("Expect exception!");
} catch (\Exception $e) {
$this->assertEquals("Index 1 out of bounds", $e->getMessage());
}
}