Esempio n. 1
0
 public function testFromParser()
 {
     $q = new Doctrine_Query();
     $q->load('User u', true);
     $this->assertEqual($q->getSqlQueryPart('from'), array('entity e'));
     $this->assertEqual(count($q->getQueryComponents()), 1);
     $q->load('u.Phonenumber p', false);
     $this->assertEqual($q->getSqlQueryPart('from'), array('entity e', 'p' => 'LEFT JOIN phonenumber p ON e.id = p.entity_id'));
 }
Esempio n. 2
0
    /**
     * Load the table objects from the "from" info.
     *
     * @return array Array of Doctrine_Table objects.
     */
    private function _getTableInformation()
    {
        $tables = array();
        foreach ($this->_doctrineQuery->getDQLPart('from') as $str) {
            $str = trim($str);
            $parts = explode('JOIN ', $str);

            $operator = false;

            switch (trim($parts[0])) {
                case 'INNER':
                    $operator = ':';
                case 'LEFT':
                    array_shift($parts);
                    break;
            }

            $last = '';

            foreach ($parts as $k => $part) {
                $part = trim($part);

                if (empty($part)) {
                    continue;
                }

                $e = explode(' ', $part);

                if (end($e) == 'INNER' || end($e) == 'LEFT') {
                    $last = array_pop($e);
                }
                $part = implode(' ', $e);

                foreach (explode(',', $part) as $reference) {
                    $reference = trim($reference);
                    $e = explode(' ', $reference);
                    $e2 = explode('.', $e[0]);

                    if ($operator) {
                        $e[0] = array_shift($e2) . $operator . implode('.', $e2);
                    }

                    $tables[] = $this->_doctrineQuery->load(implode(' ', $e));
                }

                $operator = ($last == 'INNER') ? ':' : '.';
            }
        }

        return $tables;
    }
Esempio n. 3
0
 /**
  * @return Doctrine_Query  a Doctrine_Query object
  */
 public function getQueryObject()
 {
     $graph = new Doctrine_Query($this->getConnection());
     $graph->load($this->getComponentName());
     return $graph;
 }