require_once $path . '/symfony/util/sfToolkit.class.php';
require_once $path . '/symfony/util/sfInflector.class.php';
// Analyser classes
$path = dirname(__FILE__) . '/../../plugins/sfPropelQueryBuilderPlugin/modules/sfPropelQueryBuilder/lib';
require_once $path . '/CriteriaAnalyse.class.php';
require_once $path . '/ClauseGroup.class.php';
require_once $path . '/BadSubclause.class.php';
require_once $path . '/QuotedStringParser.class.php';
require_once $path . '/SubclauseParser.class.php';
$a = new sfException();
$t = new lime_test(12, new lime_output_color());
$t->diag('CriteriaAnalyse::analyse');
$ca = new CriteriaAnalyse();
// Simple statement with no brackets
$sql1 = "user.enabled = ''";
$result = $ca->analyse($sql1);
$g1 = new ClauseGroup();
$g1->addSubclause($sql1);
$t->ok($result->equal($g1), 'decode a valid single subclause, non-bracketed string');
// Negative numbers
$sql = 'user.score < -10';
$result = $ca->analyse($sql);
$g = new ClauseGroup();
$g->addSubclause($sql);
$t->ok($result->equal($g), 'decode a valid single subclause containing a -ve number');
// Compound AND statement
$clause1 = 'user.enabled = 1';
$clause2 = 'org.enabled = 1';
$sql = "{$clause1} AND {$clause2}";
$result = $ca->analyse($sql);
$g = new ClauseGroup();
 public function execute()
 {
     // If this is not a POST then redirect
     if ($this->getRequest()->getMethod() != sfRequest::POST) {
         $this->forward($this->getModuleName(), 'index');
     }
     // Get the input, moan and exit if there's nothing
     $this->input = trim($this->getRequestParameter('logic'));
     if ($this->input == '') {
         $this->getRequest()->setError('error', "Can't analyse nothing - try again!");
     }
     // Get some options
     $comments = $this->getRequestParameter('code_comments');
     $comments = isset($comments[0]);
     $concat = $this->getRequestParameter('concat_objects');
     $concat = isset($concat[0]);
     $showTree = $this->getRequestParameter('show_tree');
     $showTree = isset($showTree[0]);
     $type = $this->getRequestParameter('return_type');
     $loop = $this->getRequestParameter('demo_loop');
     $loop = isset($loop[0]);
     $resultSetType = $this->getRequestParameter('resultset_type');
     // Set the return type
     if ($type != CriteriaBuilder::RETURN_ARRAY) {
         $type = CriteriaBuilder::RETURN_RESULTSET;
     }
     // Set the ResultSet
     if ($resultSetType != CriteriaBuilder::RESULTSET_NUM) {
         $resultSetType = CriteriaBuilder::RESULTSET_ASSOC;
     }
     $cPrefix = $this->getRequestParameter('crit_prefix');
     // Set tree to nothing, in case error occurs within analyser
     $tree = null;
     try {
         $analyser = new CriteriaAnalyse();
         $tree = $analyser->analyse($this->input);
         $analyser = null;
     } catch (Exception $e) {
         $this->getRequest()->setError('error', $e->getMessage());
     }
     if (!$this->getRequest()->hasErrors()) {
         $builder = new CriteriaBuilder($cPrefix);
         $builder->comments = $comments;
         $builder->loop = $loop;
         $builder->concat = $concat;
         $builder->returnType = $type;
         $builder->resultSetType = $resultSetType;
         try {
             $code = $builder->build($tree);
         } catch (Exception $e) {
             $this->getRequest()->setError('error', $e->getMessage());
         }
     }
     if ($showTree) {
         $this->tree = print_r($tree, true);
     } else {
         $this->tree = null;
     }
     if (!$this->getRequest()->hasErrors()) {
         $this->code = print_r($code, true);
         $builder = null;
         // Execute code
         if (false) {
             eval($code);
         }
     }
     $this->setTemplate('index');
     return sfView::SUCCESS;
 }