Exemple #1
0
 public function field($field, $value = null)
 {
     if ($this->is(State::READONLY)) {
         $value = null;
     }
     if (DevValue::isNotEmpty($value)) {
         $this->dispatch(Event::CHANGE);
     }
     return parent::field($field, $value);
 }
 public function behavior($behavior, $callback = null)
 {
     if (is_string($behavior) && DevValue::isNotEmpty($behavior)) {
         if (strpos($behavior, 'Do') === 0) {
             $behavior = new Action($behavior);
         } elseif (strpos($behavior, 'Is') === 0) {
             $behavior = new State($behavior);
         } elseif (strpos($behavior, 'On') === 0) {
             $behavior = new Event($behavior);
         } else {
             $behavior = new Behavior($behavior);
         }
     }
     parent::behavior($behavior, $callback);
 }
 public function behavior($behavior, $callback = null)
 {
     if (is_string($behavior) && DevValue::isNotEmpty($behavior)) {
         $behavior = new Behavior($behavior);
     }
     if (!$behavior instanceof Behavior) {
         throw new InvalidArgumentException("Invalid Behavior Type");
     }
     $this->_behaviors->add($behavior);
     if ($callback) {
         try {
             $this->handler(new Handler($behavior, $callback));
         } catch (InvalidArgumentException $e) {
             error_log($e->getMessage());
         }
     }
 }
Exemple #4
0
 private function whereCase($table = '', $member, $value = '')
 {
     $tables = $this->tables();
     $table = DevValue::isNull($table) ? $tables[0] : $table;
     $where = '';
     $where_r = array();
     $fields = $this->table($table);
     $condition = $this->condition($member);
     $condition_str = is_array($condition) ? $condition[0] : $condition;
     if (DevValue::isNotEmpty($this->field($member)) && array_key_exists($member, $fields)) {
         //Allow for fulltext searches
         if (strtoupper($condition_str) == 'MATCH') {
             $match_var = $this->conditionKey($member);
             if (strpos($match_var, ',')) {
                 $match_r = explode(',', $match_var);
                 foreach ($match_r as $c => $d) {
                     $match_r[$c] = "{$table}." . trim($d);
                 }
                 $match_str = implode(', ', $match_r);
             } elseif (array_key_exists($member, $this->_conditions)) {
                 $match_str = "{$table}.{$member}";
             }
             if (is_array($value)) {
                 foreach ($value as $a) {
                     if (DevValue::isNotNull($a)) {
                         $where_r[] = "MATCH({$match_str}) AGAINST (" . MysqlLink::sanitize($a) . ")";
                     }
                 }
                 $where = implode(' OR ', $where_r);
             } else {
                 $where = "MATCH({$match_str}) AGAINST (" . MysqlLink::sanitize($value) . ")";
             }
         } elseif (strtoupper($condition_str) == 'IN') {
             if (is_array($value)) {
                 foreach ($value as $a) {
                     if (DevValue::isNotNull($a)) {
                         $where_r[] = $table . ".{$member} " . (array_key_exists($member, $this->_conditions) ? "{$condition} " : "= ") . $a;
                     }
                     $where = implode(' OR ', $where_r);
                 }
             } else {
                 $where = $table . ".{$member} " . (array_key_exists($member, $this->_conditions) ? $condition : " = ") . "( {$value} )";
             }
         } elseif (strtoupper($condition_str) == 'NOT IN') {
             if (is_array($value)) {
                 foreach ($value as $a) {
                     if (DevValue::isNotNull($a)) {
                         $where_r[] = $table . ".{$member} " . (array_key_exists($member, $this->_conditions) ? "{$condition} " : "= ") . $a;
                     }
                     $where = implode(' OR ', $where_r);
                 }
             } else {
                 $where = $table . ".{$member} " . (array_key_exists($member, $this->_conditions) ? $condition : " = ") . "( {$value} )";
             }
         } else {
             if (is_array($value)) {
                 $count = 0;
                 foreach ($value as $a) {
                     if (DevValue::isNotNull($a)) {
                         $temp_where = '';
                         $condition_str = array_key_exists($member, $this->_conditions) ? is_array($condition) ? $condition[$count] : $condition : " = ";
                         if ($condition_str == 'Like' || $condition_str == '^') {
                             $a = "{$a}%";
                             $condition_str = "LIKE";
                         } elseif ($condition_str == 'likE' || $condition_str == '$') {
                             $a = "%{$a}";
                             $condition_str = "LIKE";
                         } elseif (strtoupper($condition_str) == 'LIKE' || $condition_str == "*") {
                             $a = "%{$a}%";
                             $condition_str = "LIKE";
                         } elseif (strtoupper($condition_str) == 'NOT LIKE' || $condition_str == "!") {
                             $a = "%{$a}%";
                             $condition_str = "NOT LIKE";
                         }
                         $temp_where = $table . ".{$member} " . $condition_str;
                         $temp_where .= MysqlLink::sanitize($a);
                         $where_r[] = $temp_where;
                         $count++;
                     }
                 }
                 $where = implode(is_array($condition) ? ' AND ' : ' OR ', $where_r);
             } else {
                 //$where = $table . ".$member " . ( ( array_key_exists( $member, $this->_conditions ) ) ? $condition : " = " );
                 $where = $table . ".{$member} " . ($condition ? $condition : ' = ');
                 if ($condition_str == 'Like') {
                     $value = "{$value}%";
                 } elseif ($condition_str == 'likE') {
                     $value = "%{$value}";
                 } elseif (strtoupper($condition_str) == 'LIKE') {
                     $value = "%{$value}%";
                 } elseif (strtoupper($condition_str) == 'NOT LIKE') {
                     $value = "%{$value}%";
                 }
                 $where .= MysqlLink::sanitize($value);
             }
         }
         if (DevValue::isNotNull($where)) {
             $where = "({$where}) ";
         }
     }
     return $where;
 }