Exemplo n.º 1
0
 function _testQueryPathNodeRoot()
 {
     // get class map of eptAuthor
     $this->assertTrue($cm = $this->m->getClassMap('eptAuthor'));
     // create alias generator
     $this->assertTrue($am = new epQueryAliasManager());
     // create a root node
     $this->assertTrue($root = new epQueryPathRoot($cm, $alias = false, epQueryPathRoot::PRIMARY, $am));
     // check if class map is set
     $this->assertTrue($cm === $root->getMap());
     // check if alias is set
     $this->assertTrue($alias = $am->getClassAlias('eptAuthor'));
     $this->assertTrue($alias == $root->getAlias());
     // --- 1 ---
     // test find last node on path .contact.zipcode
     $this->assertFalse($node1 = $root->findNode('.contact.zipcode'));
     // insert the path to root
     $this->assertTrue($node1 = $root->insertPath('.contact.zipcode'));
     // returned node should be epQueryPathField
     $this->assertTrue($node1 instanceof epQueryPathField);
     $this->assertTrue($node1->getName() == 'zipcode');
     $this->assertTrue($node1->getMap()->getName() == 'zipcode');
     $this->assertTrue($node1->getParent()->getName() == 'contact');
     $this->assertTrue($node1->getParent()->getMap()->getName() == 'contact');
     // test findNode again
     $this->assertTrue($node1 = $root->findNode('.contact.zipcode'));
     $this->assertTrue($node1 instanceof epQueryPathField);
     $this->assertTrue($node1->getName() == 'zipcode');
     $this->assertTrue($node1->getMap()->getName() == 'zipcode');
     $this->assertTrue($node1->getParent()->getName() == 'contact');
     $this->assertTrue($node1->getParent()->getMap()->getName() == 'contact');
     // --- 2 ---
     // test find last node on path .contact.phone
     $this->assertFalse($node2 = $root->findNode('.contact.phone'));
     // insert the path to root
     $this->assertTrue($node2 = $root->insertPath('.contact.phone'));
     // returned node should be epQueryPathField
     $this->assertTrue($node2 instanceof epQueryPathField);
     $this->assertTrue($node2->getName() == 'phone');
     $this->assertTrue($node2->getMap()->getName() == 'phone');
     $this->assertTrue($node2->getParent()->getName() == 'contact');
     $this->assertTrue($node2->getParent()->getMap()->getName() == 'contact');
     // test findNode again
     $this->assertTrue($node2 = $root->findNode('.contact.phone'));
     $this->assertTrue($node2 instanceof epQueryPathField);
     $this->assertTrue($node2->getName() == 'phone');
     $this->assertTrue($node2->getMap()->getName() == 'phone');
     $this->assertTrue($node2->getParent()->getName() == 'contact');
     $this->assertTrue($node2->getParent()->getMap()->getName() == 'contact');
     // the two paths should share .contact
     $this->assertTrue(($parent =& $node1->getParent()) === $node2->getParent());
     $this->assertTrue(2 == count($parent->getChildren()));
     $this->assertTrue($node1 === $parent->getChild('zipcode'));
     $this->assertTrue($node2 === $parent->getChild('phone'));
 }
Exemplo n.º 2
0
 /**
  * Quotes primitive value with its primitve variable (alias.var)
  * @param mixed $v
  * @param string $pvar
  * @return true|string (error message if string)
  */
 public function quoteVar(&$v, &$pvar)
 {
     // unquote pvar
     $pvar_ = $this->_unquote($pvar);
     // split primitive var to alias and var
     list($alias, $var) = @explode('.', $pvar_);
     if (!$alias || !$var) {
         return "invalid primitive var '{$pvar}'";
     }
     // get the class for alias
     if (!($class = $this->am->getClass($alias))) {
         return "no class found for alias '{$alias}'";
     }
     // get class map
     if (!($cm = $this->proot->getClassMap($class))) {
         return "no class map for '{$class}'";
     }
     // is var 'oid'?
     if ($var == 'oid') {
         // replace var name with column name
         $pvar = $this->quoteId($alias) . '.' . $this->quoteId($cm->getOidColumn());
         return true;
     }
     // get field map (for non-oid field)
     if (!($fm = $cm->getField($var))) {
         return "no field map for '{$class}::{$var}'";
     }
     // replace var name with column name
     $pvar = $this->quoteId($alias) . '.' . $this->quoteId($fm->getColumnName());
     // quote value
     $v = $this->quote($v, $fm);
     return true;
 }