Example #1
0
 /**
  * Parses order conditions of a query.
  *
  * @return void
  * @throws SparqlParserException
  */
 protected function parseOrderCondition()
 {
     $valList = array();
     $val = array();
     while (strtolower(current($this->tokens)) != 'limit' & strtolower(current($this->tokens)) != false & strtolower(current($this->tokens)) != 'offset') {
         switch (strtolower(current($this->tokens))) {
             case "desc":
                 $this->_fastForward();
                 $this->_fastForward();
                 if ($this->varCheck(current($this->tokens))) {
                     $val['val'] = current($this->tokens);
                 } else {
                     throw new SparqlParserException("Variable expected in ORDER BY clause. ", null, key($this->tokens));
                 }
                 $this->_fastForward();
                 if (current($this->tokens) != ')') {
                     throw new SparqlParserException("missing ')' in ORDER BY clause.", null, key($this->tokens));
                 }
                 $val['type'] = 'desc';
                 $this->_fastForward();
                 break;
             case "asc":
                 $this->_fastForward();
                 $this->_fastForward();
                 if ($this->varCheck(current($this->tokens))) {
                     $val['val'] = current($this->tokens);
                 } else {
                     throw new SparqlParserException("Variable expected in ORDER BY clause. ", null, key($this->tokens));
                 }
                 $this->_fastForward();
                 if (current($this->tokens) != ')') {
                     throw new SparqlParserException("missing ')' in ORDER BY clause.", null, key($this->tokens));
                 }
                 $val['type'] = 'asc';
                 $this->_fastForward();
                 break;
             default:
                 if ($this->varCheck(current($this->tokens))) {
                     $val['val'] = current($this->tokens);
                     $val['type'] = 'asc';
                 } else {
                     throw new SparqlParserException("Variable expected in ORDER BY clause. ", null, key($this->tokens));
                 }
                 $this->_fastForward();
                 break;
         }
         $valList[] = $val;
     }
     prev($this->tokens);
     $this->query->setSolutionModifier('order by', $valList);
 }