Ejemplo n.º 1
0
 /**
  * execute
  * executes the query and populates the data set
  *
  * @param string $params
  * @return Doctrine_Collection            the root collection
  */
 public function execute($params = array(), $hydrationMode = null)
 {
     if ($this->_cache) {
         $cacheDriver = $this->getCacheDriver();
         $dql = $this->getDql();
         // calculate hash for dql query
         $hash = md5($dql . var_export($params, true));
         $cached = $this->_expireCache ? null : $cacheDriver->fetch($hash);
         if ($cached === null) {
             // cache miss
             $stmt = $this->_execute($params);
             $array = $this->parseData2($stmt, self::HYDRATE_ARRAY);
             $cached = $this->getCachedForm($array);
             $cacheDriver->save($hash, $cached, $this->_timeToLive);
         } else {
             $cached = unserialize($cached);
             $this->_tableAliases = $cached[2];
             $array = $cached[0];
             $map = array();
             foreach ($cached[1] as $k => $v) {
                 $e = explode('.', $v[0]);
                 if (count($e) === 1) {
                     $map[$k]['table'] = $this->_conn->getTable($e[0]);
                 } else {
                     $map[$k]['parent'] = $e[0];
                     $map[$k]['relation'] = $map[$e[0]]['table']->getRelation($e[1]);
                     $map[$k]['table'] = $map[$k]['relation']->getTable();
                 }
                 if (isset($v[1])) {
                     $map[$k]['agg'] = $v[1];
                 }
             }
             $this->_aliasMap = $map;
         }
     } else {
         $stmt = $this->_execute($params);
         if (is_integer($stmt)) {
             return $stmt;
         }
         $array = $this->parseData2($stmt, $hydrationMode);
     }
     return $array;
 }
Ejemplo n.º 2
0
 /**
  * Get the classname to return. Most often this is just the options['name']
  *
  * Check the subclasses option and the inheritanceMap for each subclass to see
  * if all the maps in a subclass is met. If this is the case return that
  * subclass name. If no subclasses match or if there are no subclasses defined
  * return the name of the class for this tables record.
  *
  * @todo this function could use reflection to check the first time it runs
  * if the subclassing option is not set.
  *
  * @return string The name of the class to create
  * @deprecated
  */
 public function getClassnameToReturn()
 {
     if (!isset($this->_options['subclasses'])) {
         return $this->_options['name'];
     }
     foreach ($this->_options['subclasses'] as $subclass) {
         $table = $this->_conn->getTable($subclass);
         $inheritanceMap = $table->getOption('inheritanceMap');
         $nomatch = false;
         foreach ($inheritanceMap as $key => $value) {
             if (!isset($this->_data[$key]) || $this->_data[$key] != $value) {
                 $nomatch = true;
                 break;
             }
         }
         if (!$nomatch) {
             return $table->getComponentName();
         }
     }
     return $this->_options['name'];
 }