Ejemplo n.º 1
0
 /**
  * 
  * Adds a Google API key to collection
  * @param string $domain
  * @param string $key
  */
 public function addAPIKey($domain, $key)
 {
     if (null === $this->_keys) {
         $this->_keys = new CMap();
     }
     $this->_keys->add($domain, $key);
 }
Ejemplo n.º 2
0
 /**
  * 
  * Locates IP information
  * @param string $ip address. If null, it will locate the IP of request
  */
 public function locate($ip = null)
 {
     if (null === $ip) {
         $ip = $_SERVER['REMOTE_ADDR'];
     }
     $host = str_replace('{IP}', $ip, $this->_service);
     $host = str_replace('{CURRENCY}', $this->_currency, $host);
     $response = $this->fetch($host);
     if (!is_null($response) && is_array($response)) {
         $this->_data->mergeWith($response);
         $this->_data->add('ip', $ip);
         return true;
     }
     return true;
 }
Ejemplo n.º 3
0
 /**
  * 
  * Add a FeedItem to the main class
  * 
  * @param  object  instance of EFeedItemAbstract class
  */
 public function addItem(EFeedItemAbstract $item)
 {
     if (null === $this->feedElements->itemAt('items')) {
         $this->feedElements->add('items', new CTypedList('EFeedItemAbstract'));
     }
     $this->feedElements->itemAt('items')->add($item);
 }
Ejemplo n.º 4
0
 /**
  * Adds an item into the map.
  * This method overrides the parent implementation by
  * checking the item to be inserted is of certain type.
  * @param integer $index the specified position.
  * @param mixed $item new item
  * @throws CException If the index specified exceeds the bound,
  * the map is read-only or the element is not of the expected type.
  */
 public function add($index, $item)
 {
     if ($item instanceof $this->_type) {
         parent::add($index, $item);
     } else {
         throw new CException(Yii::t('yii', 'CTypedMap<{type}> can only hold objects of {type} class.', array('{type}' => $this->_type)));
     }
 }
Ejemplo n.º 5
0
 /**
  * @since v1.0.8
  */
 public function __set($name, $value)
 {
     if ($this->hasEmbeddedDocuments() && isset(self::$_embeddedConfig[get_class($this)][$name])) {
         if (is_array($value)) {
             // Late creation of embedded documents on first access
             if (is_null($this->_embedded->itemAt($name))) {
                 $docClassName = self::$_embeddedConfig[get_class($this)][$name];
                 $doc = new $docClassName($this->getScenario());
                 $doc->setOwner($this);
                 $this->_embedded->add($name, $doc);
             }
             return $this->_embedded->itemAt($name)->attributes = $value;
         } else {
             if ($value instanceof EMongoEmbeddedDocument) {
                 return $this->_embedded->add($name, $value);
             }
         }
     } else {
         parent::__set($name, $value);
     }
 }
 /**
  * Adds an item to the collection.
  * This method overrides the parent implementation to ensure
  * only configuration arrays, strings, or {@link CFormElement} objects
  * can be stored in this collection.
  * @param mixed key
  * @param mixed value
  * @throws CException if the value is invalid.
  */
 public function add($key, $value)
 {
     if (is_array($value)) {
         if (is_string($key)) {
             $value['name'] = $key;
         }
         if ($this->_forButtons) {
             $class = $this->_form->buttonElementClass;
             $element = new $class($value, $this->_form);
         } else {
             if (!isset($value['type'])) {
                 $value['type'] = 'text';
             }
             if ($value['type'] === 'string') {
                 unset($value['type'], $value['name']);
                 $element = new CFormStringElement($value, $this->_form);
             } else {
                 if (!strcasecmp(substr($value['type'], -4), 'form')) {
                     $class = $value['type'] === 'form' ? get_class($this->_form) : Yii::import($value['type']);
                     $element = new $class($value, null, $this->_form);
                 } else {
                     $class = $this->_form->inputElementClass;
                     $element = new $class($value, $this->_form);
                 }
             }
         }
     } else {
         if ($value instanceof CFormElement) {
             if (property_exists($value, 'name') && is_string($key)) {
                 $value->name = $key;
             }
             $element = $value;
         } else {
             $element = new CFormStringElement(array('content' => $value), $this->_form);
         }
     }
     parent::add($key, $element);
     $this->_form->addedElement($key, $element, $this->_forButtons);
 }
Ejemplo n.º 7
0
 public function add($name, $cookie = null)
 {
     if ($name instanceof CHttpCookie) {
         $cookieName = $name->name;
         $cookieObject = $name;
     } else {
         $cookieName = (string) $name;
         $cookieObject = $cookie;
     }
     if ($cookieObject instanceof CHttpCookie) {
         $this->remove($cookieName);
         parent::add($cookieName, $cookieObject);
         if ($this->_initialized) {
             $this->addCookie($cookieObject);
         }
     } else {
         throw new CException(Yii::t('yii', 'CHttpCookieCollection can only hold CHttpCookie objects.'));
     }
 }
 /**
  * Adds an item into the map.
  * This overrides the parent implementation by converting the key to lower case first if {@link caseSensitive} is false.
  * @param mixed $key key
  * @param mixed $value value
  */
 public function add($key, $value)
 {
     if ($this->caseSensitive) {
         parent::add($key, $value);
     } else {
         parent::add(strtolower($key), $value);
     }
 }
Ejemplo n.º 9
0
 /**
  * Updates the position in the shopping cart
  * If the position was previously added, then it will be updated in shopping cart,
  * if the position was not previously in the cart, it will be added there.
  * If the count of less than 1, the position will be deleted.
  *
  * @param IECartPosition $position
  * @param int $quantity
  */
 public function updateStored(IECartPosition $position, $quantity)
 {
     if ($this->objSectorCiudad !== null) {
         $key = $position->getId();
         $position->generate(array('objSectorCiudad' => $this->objSectorCiudad, 'codigoPerfil' => $this->codigoPerfil));
         $position->setQuantityStored($quantity);
         if ($position->getQuantity(true) + $position->getQuantity(false) < 1) {
             $this->remove($key);
         } else {
             parent::add($key, $position);
         }
         $this->applyDiscounts();
         $this->onUpdatePoistion(new CEvent($this));
         $this->saveState();
         return true;
     }
     return false;
 }
Ejemplo n.º 10
0
 public function getVisibleItems()
 {
     $visibleItems = new CMap();
     foreach ($this->getItems() as $id => $item) {
         if ($item->getVisible() === true) {
             $visibleItems->add($id, $item);
         }
     }
     return $visibleItems;
 }
Ejemplo n.º 11
0
 public function actionGetGroceryRate()
 {
     $inquiry = new InquiryForm('api-rate-grocery');
     $req = Yii::app()->request;
     $inquiryMap = new CMap();
     $inquiryMap->add('receiver_postal', $req->getQuery('receiver_postal'));
     $inquiryMap->add('service_code', $req->getQuery('service_code'));
     $inquiry->setAttributes($inquiryMap->toArray());
     if (!$inquiry->validate()) {
         echo CJSON::encode($this->statusError($inquiry->getErrors()));
         Yii::app()->end();
     }
     $service_code = ProductService::model()->findByAttributes(array('code' => strtoupper($inquiry->service_code)));
     if (!$service_code instanceof ProductService) {
         echo CJSON::encode($this->statusError('No Service Available'));
         Yii::app()->end();
     } else {
         if ($service_code->code != 'LSX' && $service_code->code != 'HRX') {
             echo CJSON::encode($this->statusError('This service is not available'));
             Yii::app()->end();
         }
     }
     $routing = IntraCityRouting::model()->findByAttributes(array('postcode' => $inquiry->receiver_postal));
     if ($routing instanceof IntraCityRouting) {
         $area = Area::getZoneID($inquiry->receiver_postal, 'postcode');
         if (!$area) {
             echo CJSON::encode($this->statusError('No Available Service'));
             Yii::app()->end();
         }
         $rates = RateCity::getCityRate(ProductService::ProductCityCourier, $routing->code, 5);
         $rate = array();
         foreach ($rates as $key) {
             if ($key['service_code'] == $inquiry->service_code) {
                 $rate = $key;
             }
         }
         $product = 'City Courier';
         echo CJSON::encode($this->statusSuccess(array('service_type' => $product, 'rate' => $rate)));
         Yii::app()->end();
     } else {
         $result = array('status' => 'success', 'result' => $data);
     }
     echo CJSON::encode($result);
     Yii::app()->end();
 }
Ejemplo n.º 12
0
 /**
  * Add item to the favorite
  * @param IEFavoritePosition $position
  */
 public function put(IEFavoritePosition $position)
 {
     parent::add($position->getId(), $position->id);
     $this->saveState();
 }
Ejemplo n.º 13
0
 /**
  *
  */
 public function getBlocks($regionId, $visibleOnly = true)
 {
     $instance = self::getInstance();
     $blocks = new CMap();
     if ($instance->regions->contains($regionId)) {
         foreach ($instance->regions[$regionId] as $blockId => $block) {
             if ($visibleOnly) {
                 if ($block->getVisible() === false) {
                     continue;
                 }
             }
             $blocks->add($blockId, $block);
         }
     }
     return self::sortBlocks($blocks);
 }
Ejemplo n.º 14
0
 public function updateCount(IECartPosition $position, $count)
 {
     if (!$position instanceof CComponent) {
         throw new InvalidArgumentException('invalid argument 1, product must implement CComponent interface');
     }
     $key = $position->getId();
     $position->detachBehavior("CartPosition");
     $position->attachBehavior("CartPosition", new ECartPositionBehaviour());
     $position->setRefresh($this->refresh);
     $position->count = $count;
     $position->calculatePriceForThisCount();
     parent::add($key, $position);
     $this->applyDiscounts();
     $this->onUpdatePosition(new CEvent($this));
     $this->saveState();
 }
Ejemplo n.º 15
0
 /**
  * Updates the position in the shopping cart
  * If position was previously added, then it will be updated in shopping cart,
  * if position was not previously in the cart, it will be added there.
  * If count is less than 1, the position will be deleted.
  *
  * @param IECartPosition $position
  * @param int $quantity
  */
 public function update(IECartPosition $position, $quantity)
 {
     if (!$position instanceof CComponent) {
         throw new InvalidArgumentException('invalid argument 1, product must implement CComponent interface');
     }
     $key = $position->getId();
     $position->detachBehavior("CartPosition");
     $position->attachBehavior("CartPosition", new ECartPositionBehaviour());
     $position->setRefresh($this->refresh);
     $position->setQuantity($quantity);
     if ($position->getQuantity() < 1) {
         $this->remove($key);
     } else {
         parent::add($key, $position);
     }
     $this->applyDiscounts();
     $this->onUpdatePosition(new CEvent($this));
     $this->saveState();
 }
Ejemplo n.º 16
0
 public function testCanNotAddWhenReadOnly()
 {
     $map = new CMap(array(), true);
     $this->setExpectedException('CException');
     $map->add('key', 'value');
 }
Ejemplo n.º 17
0
 /**
  * Adds a cookie with the specified name.
  * This overrides the parent implementation by performing additional
  * operations for each newly added CHttpCookie object.
  * @param mixed $name Cookie name.
  * @param CHttpCookie $cookie Cookie object.
  * @throws CException if the item to be inserted is not a CHttpCookie object.
  */
 public function add($name, $cookie)
 {
     if ($cookie instanceof CHttpCookie) {
         $this->remove($name);
         parent::add($name, $cookie);
         if ($this->_initialized) {
             $this->addCookie($cookie);
         }
     } else {
         throw new CException(Yii::t('yii', 'CHttpCookieCollection can only hold CHttpCookie objects.'));
     }
 }
Ejemplo n.º 18
0
 /**
  * Updates the position in the shopping cart
  * If position was previously added, then it will be updated in shopping cart,
  * if position was not previously in the cart, it will be added there.
  * If count is less than 1, the position will be deleted.
  *
  * @param IECartPosition $position
  * @param int $quantity
  */
 public function update(IECartPosition $position, $quantity)
 {
     $key = $position->getId();
     $position->detachBehavior("CartPosition");
     $position->attachBehavior("CartPosition", new ECartPositionBehaviour());
     $position->setRefresh($this->refresh);
     $position->setQuantity($quantity);
     if ($position->getQuantity() < 1) {
         $this->remove($key);
     } else {
         parent::add($key, $position);
     }
     $this->applyDiscounts();
     $this->saveState();
     $this->eventManager->fire(CartEvents::CART_UPDATE, new CartEvent(Yii::app()->getUser(), $this));
 }