Exemple #1
0
 /**
  * Adds a search parameter to the StatementBuilder, or other InputOutput-extending class instance, located at $this->build_args
  * @param string $target Column name
  * @param string $t_table Table name
  * @param mixed $value Primitive or scalar array. Condition or threshold records must meet in the search
  * @param string $operator ModelCaller const
  */
 protected function makeSearchRequest($target, $t_table, $value, $operator)
 {
     \Segment\utilities\Utilities::areArgumentsValid(__METHOD__, func_get_args(), $this);
     $clmn_n = $this->build_args->getClassName('Column');
     $tbl_n = $this->build_args->getClassName('Table');
     $descrip = $this->controller->getDescription();
     $search_func_n = $this->getRestSearch($operator);
     if (is_array($value)) {
         for ($i = count($value) - 1; $i > -1; $i--) {
             if (is_array($v) && $this->isModelCallerClassName(key($v))) {
                 $caller_name = key($v);
                 $new_caller = new $caller_name($v[$caller_name]);
                 $value[$i] = $new_caller->build_args->getStatement();
             }
             if (!is_scalar($value[$i]) && !is_a($value[$i], 'Statement')) {
                 $value[$i] = NULL;
             }
         }
     }
     switch (strtolower(trim($operator))) {
         case ModelCaller::EQUAL:
             $temp_value = is_array($value) ? $value[0] : $value;
             $clmn = new $clmn_n(new $tbl_n(Segment\Model\production\__DB_NAME__, $t_table), $target);
             $type = $descrip->getType($clmn);
             $value_class_n = ucfirst($type) . "Value";
             settype($temp_value, $type);
             $this->build_args->addSearchEqual($clmn, new $value_class_n($temp_value));
             break;
         case ModelCaller::NEQUAL:
             $temp_value = is_array($value) ? $value[0] : $value;
             $clmn = new $clmn_n(new $tbl_n(Segment\Model\production\__DB_NAME__, $t_table), $target);
             $type = $descrip->getType($clmn);
             $value_class_n = ucfirst($type) . "Value";
             settype($temp_value, $type);
             $this->build_args->addSearchNotEqual($clmn, $temp_value);
             break;
         case ModelCaller::EQUALANY:
             $temp_value = is_array($value) ? $value : [$value];
             $clmn = new $clmn_n(new $tbl_n(Segment\Model\production\__DB_NAME__, $t_table), $target);
             $type = $descrip->getType($clmn);
             $value_class_n = ucfirst($type) . "Value";
             end($temp_value);
             for ($i = key($temp_value); $i > -1; $i--) {
                 settype($temp_value[$i], $type);
                 $temp_value[$i] = new $value_class_n($temp_value[$i]);
             }
             $temp_value = new AnyAllValues(...$temp_value);
             $this->build_args->addSearchNotEqual($clmn, $temp_value);
             break;
         case ModelCaller::GREATER:
             $temp_value = is_array($value) ? $value[0] : $value;
             $clmn = new $clmn_n(new $tbl_n(Segment\Model\production\__DB_NAME__, $t_table), $target);
             $type = $descrip->getType($clmn);
             $value_class_n = ucfirst($type) . "Value";
             settype($temp_value, $type);
             $this->build_args->addSearchGreater($clmn, TRUE, $temp_value);
             break;
         case ModelCaller::GREATEQ:
             $temp_value = is_array($value) ? $value[0] : $value;
             $clmn = new $clmn_n(new $tbl_n(Segment\Model\production\__DB_NAME__, $t_table), $target);
             $type = $descrip->getType($clmn);
             $value_class_n = ucfirst($type) . "Value";
             settype($temp_value, $type);
             $this->build_args->addSearchGreater($clmn, FALSE, $temp_value);
             break;
         case ModelCaller::GREATANY:
             $temp_value = is_array($value) ? $value : [$value];
             $clmn = new $clmn_n(new $tbl_n(Segment\Model\production\__DB_NAME__, $t_table), $target);
             $type = $descrip->getType($clmn);
             $value_class_n = ucfirst($type) . "Value";
             end($temp_value);
             for ($i = key($temp_value); $i > -1; $i--) {
                 settype($temp_value[$i], $type);
                 $temp_value[$i] = new $value_class_n($temp_value[$i]);
             }
             $temp_value = new AnyAllValues(...$temp_value);
             $this->build_args->addSearchGreaterAny($clmn, $temp_value);
             break;
         case ModelCaller::GREATALL:
             $temp_value = is_array($value) ? $value : [$value];
             $clmn = new $clmn_n(new $tbl_n(Segment\Model\production\__DB_NAME__, $t_table), $target);
             $type = $descrip->getType($clmn);
             $value_class_n = ucfirst($type) . "Value";
             end($temp_value);
             for ($i = key($temp_value); $i > -1; $i--) {
                 settype($temp_value[$i], $type);
                 $temp_value[$i] = new $value_class_n($temp_value[$i]);
             }
             $this->build_args->addSearchGreaterAll(new $clmn_n(new $tbl_n(Segment\Model\production\__DB_NAME__, $t_table), $target), new AnyAllValues(...$temp_value));
             break;
         case ModelCaller::LESSER:
             $temp_value = is_array($value) ? $value[0] : $value;
             $clmn = new $clmn_n(new $tbl_n(Segment\Model\production\__DB_NAME__, $t_table), $target);
             $type = $descrip->getType($clmn);
             $value_class_n = ucfirst($type) . "Value";
             settype($temp_value, $type);
             $this->build_args->addSearchLesser($clmn, TRUE, new $value_class_n($temp_value));
             break;
         case ModelCaller::LESSEQ:
             $temp_value = is_array($value) ? $value[0] : $value;
             $clmn = new $clmn_n(new $tbl_n(Segment\Model\production\__DB_NAME__, $t_table), $target);
             $type = $descrip->getType($clmn);
             $value_class_n = ucfirst($type) . "Value";
             settype($temp_value, $type);
             $this->build_args->addSearchLesser($clmn, FALSE, new $value_class_n($value));
             break;
         case ModelCaller::LESSANY:
             $temp_value = is_array($value) ? $value : [$value];
             $clmn = new $clmn_n(new $tbl_n(Segment\Model\production\__DB_NAME__, $t_table), $target);
             $type = $descrip->getType($clmn);
             $value_class_n = ucfirst($type) . "Value";
             end($temp_value);
             for ($i = key($temp_value); $i > -1; $i--) {
                 settype($temp_value[$i], $type);
                 $temp_value[$i] = new $value_class_n($temp_value[$i]);
             }
             $this->build_args->addSearchLesserAny($clmn, new AnyAllValues(...$temp_value));
             break;
         case ModelCaller::LESSALL:
             $temp_value = is_array($value) ? $value : [$value];
             $clmn = new $clmn_n(new $tbl_n(Segment\Model\production\__DB_NAME__, $t_table), $target);
             $type = $descrip->getType($clmn);
             $value_class_n = ucfirst($type) . "Value";
             end($temp_value);
             for ($i = key($temp_value); $i > -1; $i--) {
                 settype($temp_value[$i], $type);
                 $temp_value[$i] = new $value_class_n($temp_value[$i]);
             }
             $this->build_args->addSearchLesserAll($clmn, new AnyAllValues(...$temp_value));
             break;
         case ModelCaller::BETWEEN:
             $temp1 = is_array($value) && isset($value[0]) ? $value[0] : $value;
             $temp2 = is_array($value) && isset($value[1]) ? $value[1] : NULL;
             $clmn = new $clmn_n(new $tbl_n(Segment\Model\production\__DB_NAME__, $t_table), $target);
             $type = $descrip->getType($clmn);
             $value_class_n = ucfirst($type) . "Value";
             settype($temp1, $type);
             settype($temp2, $type);
             $temp1 = new $value_class_n($temp1);
             $temp2 = new $value_class_n($temp2);
             $this->build_args->addSearchBetween($clmn, new BetweenValues($temp1, $temp2));
             break;
         case ModelCaller::NBETWEEN:
             $temp1 = is_array($value) && isset($value[0]) ? $value[0] : $value;
             $temp2 = is_array($value) && isset($value[1]) ? $value[1] : NULL;
             $clmn = new $clmn_n(new $tbl_n(Segment\Model\production\__DB_NAME__, $t_table), $target);
             $type = $descrip->getType($clmn);
             $value_class_n = ucfirst($type) . "Value";
             settype($temp1, $type);
             settype($temp2, $type);
             $temp1 = new $value_class_n($temp1);
             $temp2 = new $value_class_n($temp2);
             $this->build_args->addSearchNotBetween($clmn, new BetweenValues($temp1, $temp2));
             break;
         default:
             throw new \InvalidArgumentException(__CLASS__ . '::' . __METHOD__ . " expects fourth argument to" . " be a const of ModelCaller. Provided: " . print_r($operator, TRUE));
     }
 }
Exemple #2
0
 protected static function getInstantiateMCFunc()
 {
     /**
      * @param callable $model_call
      * @param \Segment\utilities\RestRequest $args
      * @return \Segment\Model\production\ModelCaller
      * @var \Segment\Controller\Controller $this
      */
     return ['instantiateModelCall' => function (callable $model_call, \Segment\utilities\RestRequest $args) {
         $answer = new $model_call();
         $name = 'set';
         foreach ($args as $key => $value) {
             $name_parts = explode("_", $key);
             \Segment\utilities\Utilities::traversableArrayWalk($name_parts, "\\Segment\\utilities\\Utilities::callableUCFirst");
             $name .= implode("", $name_parts);
             $answer->{$name}($value);
         }
         return $answer;
     }];
 }
Exemple #3
0
 public function __clone()
 {
     $this->queue = \Segment\utilities\Utilities::arrayCopy($this->queue);
 }