public function removeObserver(MyObserver $o)
 {
     $i = $this->observers->indexOf($o);
     if ($i >= 0) {
         $this->observers->remove($i);
     }
 }
 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);
             }
         }
     }
 }
Ejemplo n.º 3
0
 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);
 }
 /**
  * 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;
 }
Ejemplo n.º 5
0
 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)));
 }
Ejemplo n.º 6
0
 /**
  * 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;
 }
 /**
  * Empty the shopping cart object of all items.
  *
  */
 public function removeAll()
 {
     foreach ($this->items as $item) {
         $this->items->remove($item);
     }
 }
 /**
  * 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;
 }
Ejemplo n.º 9
0
 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++) {
         switch ($postfix->get($i)->type) {
             case TType::NUMBER:
                 $stack->add($postfix->get($i)->name);
                 break;
             case TType::OPERATION:
                 switch ($postfix->get($i)->name) {
                     case "+":
                         $result = doubleval($stack->get($stack->size() - 2)) + doubleval($stack->get($stack->size() - 1));
                         break;
                     case "-":
                         $result = doubleval($stack->get($stack->size() - 2)) - doubleval($stack->get($stack->size() - 1));
                         break;
                     case "*":
                         $result = doubleval($stack->get($stack->size() - 2)) * doubleval($stack->get($stack->size() - 1));
                         break;
                     case "/":
                         $result = doubleval($stack->get($stack->size() - 2)) / doubleval($stack->get($stack->size() - 1));
                         break;
                     case "%":
                         $result = doubleval($stack->get($stack->size() - 2)) % doubleval($stack->get($stack->size() - 1));
                         break;
                     case "^":
                         $result = pow(doubleval($stack->get($stack->size() - 2)), doubleval($stack->get($stack->size() - 1)));
                         break;
                 }
                 $stack->remove($stack->size() - 2);
                 $stack->remove($stack->size() - 1);
                 $stack->add(strval($result));
                 break;
         }
     }
     return doubleval($stack->get(0));
 }
Ejemplo n.º 10
0
 public function remove($value)
 {
     $this->validTypeThrow($value);
     return parent::remove($value);
 }
 /**
  * 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);
         }
     }
 }
Ejemplo n.º 12
0
 /**
  * Exclui um observador do conjunto de observadores deste objeto.
  * @param \Prime\util\Observer $o
  */
 public function deleteObserver(Observer $o)
 {
     return $this->observers->remove($o);
 }
 public function remove(MenuComponent $menuComponent)
 {
     $this->menuComponents->remove($menuComponent);
 }
 public function remove()
 {
     $this->items->remove($this->position);
 }
Ejemplo n.º 15
0
 /**
  * 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());
     }
 }
Ejemplo n.º 16
0
// IList::offsetGet
try {
    echo "Getting #-1\n";
    Debug::dump($list[-1]);
} catch (Exception $e) {
    echo get_class($e), ': ', $e->getMessage(), "\n\n";
}
try {
    echo "Getting #0\n";
    Debug::dump($list[0]);
} catch (Exception $e) {
    echo get_class($e), ': ', $e->getMessage(), "\n\n";
}
// IList::remove
echo "Removing Larry\n";
Debug::dump($list->remove($larry));
echo "Removing Larry second time\n";
Debug::dump($list->remove($larry));
// IList::offsetUnset
try {
    echo "Removing using unset\n";
    unset($list[-1]);
} catch (Exception $e) {
    echo get_class($e), ': ', $e->getMessage(), "\n\n";
}
try {
    echo "Removing using unset\n";
    unset($list[1]);
} catch (Exception $e) {
    echo get_class($e), ': ', $e->getMessage(), "\n\n";
}