Example #1
0
 protected function compileCode(&$code)
 {
     $code .= 'return ';
     if ($this->value !== null) {
         $this->value->compileCode($code);
     }
 }
Example #2
0
 protected function compileCode(&$code)
 {
     if ($this->isUnpacked) {
         $code .= '...';
     }
     $this->value->compileCode($code);
 }
Example #3
0
 protected function compileType(&$code, Expression $typeExpression)
 {
     if ($typeExpression instanceof ValueExpression) {
         $code .= $typeExpression->getValue();
     } else {
         $typeExpression->compileCode($code);
     }
 }
Example #4
0
 public function testIsValid()
 {
     $this->assertTrue($this->singleSimpleExp->isValid());
     $this->assertTrue($this->singleNestedExp->isValid());
     $this->assertTrue($this->multipleSimpleExp->isValid());
     $this->assertTrue($this->multipleNestedExp->isValid());
     $this->assertFalse($this->wrongExp->isValid());
 }
 /**
  * Returns the next valid date after the provided $dateTime object.
  *
  * @param DateTime $dateTime
  * @return DateTime
  */
 public function getNextOccurrence(\DateTime $dateTime)
 {
     $firstNextOccurrnece = $this->firstExpression->getNextOccurrence($dateTime);
     if (!$this->contains($firstNextOccurrnece)) {
         $firstNextOccurrnece = $this->getNextOccurrence($firstNextOccurrnece);
     }
     return $firstNextOccurrnece;
 }
Example #6
0
 /**
  * @param   mixed   $value
  * @param   string  $operator
  * @param   boolean $iscolumn
  */
 protected function addCondition($value, $operator, $iscolumn)
 {
     if ($iscolumn && is_string($value)) {
         $expr = new Expression($this->compiler);
         $value = $expr->column($value);
     }
     $this->havingClause->addCondition($this->aggregate, $value, $operator, $this->separator);
 }
Example #7
0
 /**
  * add
  * 
  * @param Expression $expr 
  * @access public
  * @return void
  */
 public function add(Expression $expr)
 {
     if (!$expr instanceof OrderExpression) {
         throw new \InvalidArgumentException('OrderClause only accept OrderExpression as its part.');
     }
     // internal Expression has to be an unique by field
     $this->expressions[$expr->getField()->getName()] = $expr;
     return $this;
 }
Example #8
0
 public function test_caching()
 {
     $e = '$_0 < $_1';
     $x = new Expression($e);
     // different objects w/ same expression...
     $y = new Expression($e);
     // ... should have same callable
     $this->assertSame($x->getCallable(), $y->getCallable());
 }
Example #9
0
 protected function compileCode(&$code)
 {
     $this->value->compileCode($code);
     $code .= '[';
     if ($this->index !== null) {
         $this->index->compileCode($code);
     }
     $code .= ']';
 }
Example #10
0
 protected function compileCode(&$code)
 {
     if ($this->name instanceof ValueExpression && self::isNormalSyntaxName($this->name->getValue())) {
         $code .= '$' . $this->name->getValue();
     } else {
         $code .= '${';
         $this->name->compileCode($code);
         $code .= '}';
     }
 }
Example #11
0
 protected function compileCode(&$code)
 {
     if ($this->name instanceof ValueExpression) {
         $code .= $this->name->getValue();
     } else {
         $this->name->compileCode($code);
     }
     $code .= '(';
     $code .= implode(',', self::compileAll($this->arguments));
     $code .= ')';
 }
 protected function compileCode(&$code)
 {
     $code .= '(';
     $this->leftOperand->compileCode($code);
     $code .= ' ' . $this->operator . ' ';
     if ($this->operator === Operators\Binary::IS_INSTANCE_OF && $this->rightOperand instanceof ValueExpression) {
         $code .= $this->rightOperand->getValue();
     } else {
         $this->rightOperand->compileCode($code);
     }
     $code .= ')';
 }
Example #13
0
 public function quoteTable($value)
 {
     if ($value instanceof Criterion) {
         $value = new Expression('( ' . $value->createSql() . ' )');
     }
     if ($value instanceof Expression) {
         return $value->toString();
     }
     $this->separator = '';
     $this->implodeGlue = '.';
     return $this->_quote(explode('.', $value));
 }
Example #14
0
 protected function compileCode(&$code)
 {
     $code .= '(';
     $this->condition->compileCode($code);
     $code .= ' ? ';
     if ($this->ifTrue !== null) {
         $this->ifTrue->compileCode($code);
     }
     $code .= ' : ';
     $this->ifFalse->compileCode($code);
     $code .= ')';
 }
 /**
  * @param RuleConditionExpression $rce
  * @param array $contextMap
  * @return mixed
  */
 function evaluate($rce, $contextMap)
 {
     $operator = strtoupper($rce->operator);
     $evaluator = $this->getEvaluator($operator);
     if (!$evaluator) {
         throw new MockApiException("unsupported condition operator '" . $operator . '"', ErrorInfo::UNSUPPORTED_CONDITION_OPERATOR);
     }
     $exp = new Expression();
     $exp->setLeft($this->getOperandValue($rce->left, $contextMap));
     $exp->setRight($this->getOperandValue($rce->right, $contextMap));
     $exp->setOperator($operator);
     return $evaluator->evaluate($exp);
 }
 function getFilteredResultSet(&$masterResultSet, &$sqlQuery)
 {
     global $g_sqlSingleRecFuncs;
     $parser = new SqlParser($sqlQuery->where_expr);
     $king_expr = new Expression();
     $current_expr =& $king_expr;
     while (!is_empty_str($elem = $parser->parseNextElementRaw())) {
         // function ?
         if (in_array(strtoupper($elem), $g_sqlSingleRecFuncs)) {
             $current_expr->expr_str .= $elem;
             $elem = $parser->parseNextElementRaw();
             if ($elem != "(") {
                 print_error_msg("( expected after " . $current_expr->expr_str);
                 return null;
             }
             $current_expr->expr_str .= $elem;
             while (!is_empty_str($elem = $parser->parseNextElementRaw()) && $elem != ")") {
                 $current_expr->expr_str .= $elem;
             }
             $current_expr->expr_str .= $elem . " ";
             continue;
         }
         if ($elem == "(") {
             $current_expr->expr_str .= " % ";
             unset($new_expr);
             $new_expr = new Expression("");
             $current_expr->addChild($new_expr);
             $new_expr->setParent($current_expr);
             unset($current_expr);
             $current_expr =& $new_expr;
         } else {
             if ($elem == ")") {
                 unset($tmp);
                 $tmp =& $current_expr->getParent();
                 unset($current_expr);
                 $current_expr =& $tmp;
             } else {
                 // no spaces on .'s
                 if ($elem == ".") {
                     remove_last_char($current_expr->expr_str);
                     $current_expr->expr_str .= $elem;
                 } else {
                     $current_expr->expr_str .= $elem . " ";
                 }
             }
         }
     }
     return $king_expr->getFilteredResultSet($masterResultSet, $sqlQuery);
 }
Example #17
0
 protected function compileCode(&$code)
 {
     $this->value->compileCode($code);
     $code .= '->';
     if ($this->name instanceof ValueExpression && self::isNormalSyntaxName($this->name->getValue())) {
         $code .= $this->name->getValue();
     } else {
         $code .= '{';
         $this->name->compileCode($code);
         $code .= '}';
     }
     $code .= '(';
     $code .= implode(',', self::compileAll($this->arguments));
     $code .= ')';
 }
Example #18
0
 public function testErrors()
 {
     $form = Form::create()->add(Primitive::ternary('flag')->setFalseValue('0')->setTrueValue('1'))->add(Primitive::integer('old')->required())->addRule('someRule', Expression::between(FormField::create('old'), '18', '35'));
     //empty import
     $form->import(array())->checkRules();
     //checking
     $expectingErrors = array('old' => Form::MISSING, 'someRule' => Form::WRONG);
     $this->assertEquals($expectingErrors, $form->getErrors());
     $this->assertEquals(Form::MISSING, $form->getError('old'));
     $this->assertEquals(Form::WRONG, $form->getError('someRule'));
     $this->assertTrue($form->hasError('old'));
     $this->assertFalse($form->hasError('flag'));
     //drop errors
     $form->dropAllErrors();
     $this->assertEquals(array(), $form->getErrors());
     //import wrong data
     $form->clean()->importMore(array('flag' => '3', 'old' => '17'))->checkRules();
     //checking
     $expectingErrors = array('flag' => Form::WRONG, 'someRule' => Form::WRONG);
     $this->assertEquals($expectingErrors, $form->getErrors());
     $this->assertTrue($form->hasError('someRule'));
     //marking good and custom check errors
     $form->markGood('someRule')->markCustom('flag', 3);
     $this->assertEquals(array('flag' => 3), $form->getErrors());
     $this->assertFalse($form->hasError('someRule'));
     $this->assertNull($form->getError('someRule'));
     $this->assertEquals(3, $form->getError('flag'));
     //import right data
     $form->dropAllErrors()->clean()->importMore(array('flag' => '1', 'old' => '35'));
     //checking
     $this->assertEquals(array(), $form->getErrors());
 }
 public function testInsertFromSelect()
 {
     $dialect = $this->getDbByType('PgSQL')->getDialect();
     $select = OSQL::select()->from('test_table2')->get('field3')->get('field_7')->andWhere(Expression::gt('field2', DBValue::create('33')));
     $insert = OSQL::insert()->setSelect($select)->into('test_table')->set('field2', 2)->set('field16', 3);
     $this->assertEquals($insert->toDialectString($dialect), 'INSERT INTO "test_table" ("field2", "field16") (' . 'SELECT "test_table2"."field3", "test_table2"."field_7" ' . 'FROM "test_table2" WHERE ("field2" > \'33\')' . ')');
 }
Example #20
0
 /**
  * Get style of element
  *
  * @return string style of Element
  */
 protected function getStyle()
 {
     $htmlClass = $this->m_cssClass ? "class='" . $this->m_cssClass . "' " : "class='editcombobox'";
     /* 
             $width = $this->m_Width ? $this->m_Width : 146;
             $this->m_WidthInput = ($width-18).'px';
             $this->m_Width = $width.'px';
             $style = "position: absolute; width: $this->m_Width; z-index: 1; clip: rect(auto, auto, auto, $this->m_WidthInput);";
     */
     if ($this->m_Style) {
         $style .= $this->m_Style;
     }
     if (!isset($style) && !$htmlClass) {
         return null;
     }
     if (isset($style)) {
         $formObj = $this->getFormObj();
         $style = Expression::evaluateExpression($style, $formObj);
         $style = "style='{$style}'";
     }
     if ($htmlClass) {
         $style = $htmlClass . " " . $style;
     }
     return $style;
 }
 private function getSome()
 {
     for ($i = 1; $i < 3; ++$i) {
         $this->assertTrue(TestUser::dao()->getByLogic(Expression::eq('city_id', $i)) == TestUser::dao()->getById($i));
     }
     $this->assertEquals(count(TestUser::dao()->getPlainList()), count(TestCity::dao()->getPlainList()));
 }
 function testExpression()
 {
     // Expression 1
     $exp = new Expression('x => x > 10');
     $this->assertTrue($exp->execute(20));
     $this->assertFalse($exp->execute(5));
     // Expression 2 ( Lambda Expression )
     $exp = new Expression(function ($x) {
         return is_string($x);
     });
     $this->assertFalse($exp->execute(10));
     $this->assertTrue($exp->execute('Hello'));
     // Expression 3
     $exp = new Expression('user => user->name == "Alireza" AND user->id == 12');
     $this->assertTrue($exp->execute((object) ['name' => 'Alireza', 'id' => 12]));
 }
Example #23
0
 protected function getStyle()
 {
     $formobj = $this->getFormObj();
     $htmlClass = Expression::evaluateExpression($this->m_cssClass, $formobj);
     $htmlClass = "CLASS='{$htmlClass}'";
     if (!$htmlClass) {
         $htmlClass = null;
     }
     $style = '';
     if ($this->m_Style) {
         $style .= $this->m_Style;
     }
     if (!isset($style) && !$htmlClass) {
         return null;
     }
     if (isset($style)) {
         $style = Expression::evaluateExpression($style, $formobj);
         $style = "STYLE='{$style}'";
     }
     if ($formobj->m_Errors[$this->m_Name]) {
         $htmlClass = "CLASS='" . $this->m_cssErrorClass . "'";
     }
     if ($htmlClass) {
         $style = $htmlClass . " " . $style;
     }
     return $style;
 }
 public function dropList()
 {
     $dao = $this->container->getDao();
     DBPool::getByDao($dao)->queryNull(OSQL::delete()->from($this->container->getHelperTable())->where(Expression::eq($this->container->getParentIdField(), $this->container->getParentObject()->getId())));
     $dao->uncacheLists();
     return $this;
 }
Example #25
0
 /**
  * Initialize Node
  *
  * @param array $rec
  * @return void
  */
 function __construct($rec)
 {
     $this->m_Id = $rec['Id'];
     $this->m_PId = $rec['PId'];
     $this->m_Name = $rec['title'];
     $this->m_Module = $rec['module'];
     $this->m_Description = $rec['description'];
     $this->m_URL = $rec['link'];
     if (strpos($this->m_URL, '{') === 0) {
         $this->m_URL = Expression::evaluateExpression($this->m_URL, $this);
     } else {
         if (!empty($this->m_URL)) {
             if (strpos($this->m_URL, '/') === 0) {
                 $this->m_URL = APP_INDEX . $this->m_URL;
             } else {
                 $this->m_URL = APP_INDEX . '/' . $this->m_URL;
             }
         }
     }
     $this->m_URL_Match = $rec['alias'];
     //$this->m_CssClass = $rec['Id'];
     $this->m_IconImage = $rec['icon'];
     $this->m_IconCSSClass = $rec['icon_css'];
     $this->m_Access = $rec['access'];
     $this->translate();
     // translate for multi-language support
 }
Example #26
0
 /**
  * Render, draw the control according to the mode
  *
  * @return string HTML text
  */
 public function render()
 {
     $value = $this->m_Value ? $this->m_Value : $this->getText();
     $disabledStr = $this->getEnabled() == "N" ? "READONLY=\"true\"" : "";
     $style = $this->getStyle();
     $func = $this->getFunction();
     $optionList = $this->renderList();
     $htmlClass = Expression::evaluateExpression($this->m_cssClass, $formobj);
     $htmlClass = "CLASS='{$htmlClass}'";
     $sHTML .= "<div class=\"div_" . $this->m_cssClass . "\" style=\"float:left;\">";
     if ($this->m_ReadOnly == 'Y') {
         $display_input = "style=\"display:none;\"";
         $display_span = "";
     } else {
         $display_span = "style=\"display:none;\"";
         $display_input = "";
     }
     $sHTML .= "<div {$display_span}>";
     $sHTML .= "<span ID=\"span_" . $this->m_Name . "\"  {$this->m_HTMLAttr} {$style}\n\t\t        \t\t\tonclick=\"if(\$('" . $this->m_Name . "_list').visible()){\$('" . $this->m_Name . "_list').hide();\$('" . $this->m_Name . "').className='" . $this->m_cssClass . "'}else{\$('" . $this->m_Name . "_list').show();\$('" . $this->m_Name . "').className='" . $this->m_cssFocusClass . "'}\"\n\t\t        \t\t\tonmouseover=\"\$('span_" . $this->m_Name . "').className='" . $this->m_cssHoverClass . "'\"\n\t\t        \t\t\tonmouseout=\"\$('span_" . $this->m_Name . "').className='" . $this->m_cssClass . "'\"\n\t\t        \t\t\t>" . $this->m_DefaultDisplayValue . "</span>";
     $sHTML .= "</div>";
     $sHTML .= "<div {$display_input}>";
     $sHTML .= "<INPUT NAME=\"" . $this->m_Name . "\" ID=\"" . $this->m_Name . "\" VALUE=\"" . $value . "\" {$disabledStr} {$this->m_HTMLAttr} {$style} {$func}\n\t\t        \t\t\tonclick=\"if(\$('" . $this->m_Name . "_list').visible()){\$('" . $this->m_Name . "_list').hide();\$('" . $this->m_Name . "').className='" . $this->m_cssClass . "'}else{\$('" . $this->m_Name . "_list').show();\$('" . $this->m_Name . "').className='" . $this->m_cssFocusClass . "'}\"\n\t\t        \t\t\tonmouseover=\"\$('" . $this->m_Name . "').className='" . $this->m_cssHoverClass . "'\"\n\t\t        \t\t\tonmouseout=\"\$('" . $this->m_Name . "').className='" . $this->m_cssClass . "'\"\n\t\t        \t\t\t/>";
     $sHTML .= "</div>";
     $sHTML .= $optionList;
     $sHTML .= "</div>";
     $sHTML .= "<script>\$('" . $this->m_Name . "_list').hide()</script>";
     return $sHTML;
 }
 public static function increment(DAOConnected &$object, array $fields, $refreshCurrent = true, $query = null)
 {
     $objectDao = $object->dao();
     if ($query) {
         $updateQuery = $query;
     } else {
         $updateQuery = OSQL::update()->setTable($objectDao->getTable())->where(Expression::eqId('id', $object));
     }
     $mapping = $objectDao->getProtoClass()->getMapping();
     foreach ($mapping as $field => $column) {
         if (isset($fields[$field])) {
             $updateQuery->set($column, Expression::add($column, $fields[$field]));
         }
     }
     $updateCount = DBPool::getByDao($objectDao)->queryCount($updateQuery);
     if ($query) {
         $objectDao->uncacheLists();
     } else {
         $objectDao->uncacheById($object->getId());
     }
     if ($refreshCurrent && !$query) {
         $object = $objectDao->getById($object->getId());
     }
     return $updateCount;
 }
 public function testWithObjects()
 {
     $criteria = Criteria::create(TestUser::dao())->add(Expression::containsIp(IpRange::create('192.168.1.1-192.168.1.255'), 'ip'))->addProjection(Projection::property('id'));
     $this->assertEquals($criteria->toDialectString(PostgresDialect::me()), 'SELECT "test_user"."id" FROM "test_user" WHERE "test_user"."ip" <<= \'192.168.1.1-192.168.1.255\'');
     $criteria = Criteria::create(TestInternetProvider::dao())->add(Expression::containsIp('range', IpAddress::create('42.42.42.42')))->addProjection(Projection::property('id'));
     $this->assertEquals($criteria->toDialectString(PostgresDialect::me()), 'SELECT "test_internet_provider"."id" FROM "test_internet_provider" WHERE \'42.42.42.42\' <<= "test_internet_provider"."range"');
 }
 /**
  * @return SelectQuery
  **/
 protected function joinHelperTable(SelectQuery $query)
 {
     $uc = $this->container;
     if (!$query->hasJoinedTable($uc->getHelperTable())) {
         $query->join($uc->getHelperTable(), Expression::eq(new DBField($uc->getParentTableIdField(), $uc->getDao()->getTable()), new DBField($uc->getChildIdField(), $uc->getHelperTable())));
     }
     return $query->andWhere(Expression::eq(new DBField($uc->getParentIdField(), $uc->getHelperTable()), new DBValue($uc->getParentObject()->getId())));
 }
Example #30
0
 /**
  * Get text of element
  *
  * @return string
  */
 protected function getText()
 {
     if ($this->m_Text == null) {
         return null;
     }
     $formObj = $this->getFormObj();
     return Expression::evaluateExpression($this->m_Text, $formObj);
 }