public function read(Model $model, $queryData = array(), $recursive = null)
 {
     parent::read($model, $queryData, $recursive);
     $services = array();
     if (!empty($queryData['conditions']['servicos'])) {
         if (is_array($queryData['conditions']['servicos'])) {
             foreach ($queryData['conditions']['servicos'] as $servico) {
                 $services[] = $this->services[$servico];
             }
         } else {
             $services = $this->services[$queryData['conditions']['servicos']];
         }
     } else {
         // SET DEFAULT FORMAT
         $this->format = ECTFormatos::FORMATO_CAIXA_PACOTE;
     }
     if (!empty($queryData['conditions']['formato'])) {
         $this->format = $queryData['conditions']['formato'];
     }
     // GET VALUES
     $return = $this->_getECTValues($queryData['conditions']['altura'], $queryData['conditions']['comprimento'], $queryData['conditions']['largura'], $queryData['conditions']['peso'], $queryData['conditions']['ceporigem'], $queryData['conditions']['cep'], $services, $this->format);
     // CONVERTS ARRAY ITERATOR TO ARRAY
     $return = iterator_to_array($return, true);
     // CONVERT ARRAY OBJECTS TO ARRAY
     $return = $this->_toArray($return);
     // INSERT MODEL NAME AND RETURNS
     return $this->_fixReturn($return);
 }
Exemple #2
0
 /**
  * Reads from cache if it exists. If not, it falls back to the original
  * datasource to retrieve the data and cache it for later
  *
  * @param Model $Model
  * @param array $queryData
  * @param integer $recursive
  * @return array Results
  * @see DataSource::read()
  */
 public function read(Model $Model, $queryData = array(), $recursive = null)
 {
     $this->_resetSource($Model);
     $key = $this->_key($Model, $queryData);
     $results = Cache::read($key, $this->config['config']);
     if ($results === false) {
         $results = $this->source->read($Model, $queryData, $recursive);
         // compress before storing
         if (isset($this->config['gzip'])) {
             Cache::write($key, gzcompress(serialize($results)), $this->config['config']);
         } else {
             Cache::write($key, $results, $this->config['config']);
         }
         $this->_map($Model, $key);
     } else {
         // uncompress data from cache
         if (isset($this->config['gzip'])) {
             $results = unserialize(gzuncompress($results));
         }
     }
     return $results;
 }
Exemple #3
0
 /**
  * Reads from cache if it exists. If not, it falls back to the original
  * datasource to retrieve the data and cache it for later
  *
  * @param Model $model
  * @param array $query
  * @param int $recursive
  * @return array Results
  * @see DataSource::read()
  */
 public function read(Model $model, $query = array(), $recursive = null)
 {
     // Resets the model's datasource to the original
     $model->setDataSource(ConnectionManager::getSourceName($this->source));
     $key = $this->_key($model, $query);
     $results = Cache::read($key, $this->config['config']);
     if ($results === false) {
         $results = $this->source->read($model, $query, $recursive);
         // compress before storing
         if ($this->_useGzip()) {
             Cache::write($key, gzcompress(serialize($results)), $this->config['config']);
         } else {
             Cache::write($key, $results, $this->config['config']);
         }
         $this->_map($model, $key);
     } else {
         // uncompress data from cache
         if ($this->_useGzip()) {
             $results = unserialize(gzuncompress($results));
         }
     }
     Cache::set(null, $this->config['config']);
     return $results;
 }