/**
  * @param   mixed   $value
  * @param   int     $flag
  * @param   array   $order
  */
 public function __construct($value, $flag = ValueType::MODE_STRICT, array $order = null)
 {
     $this->setReadOnlyProperties($this::$_read_only);
     $this->flag = $flag;
     $this->order = $order;
     $this->reflector = ValueType::getReflector($value, $flag, $order);
 }
 /**
  * @param   callable   $value
  * @throws  \ReflectionException if the parameter is not a closure
  */
 public function __construct($value)
 {
     if (!ValueType::isCallable($value)) {
         throw new \ReflectionException(sprintf(__METHOD__ . ' expects parameter one to be callable, %s given', gettype($value)));
     }
     $this->setReadOnlyProperties($this::$_read_only);
     $this->callback = $value;
     $this->type = ValueType::getCallbackType($value);
     $this->_populate();
 }
示例#3
0
 static function typeof($v)
 {
     if ($v === null) {
         return ValueType::$TNull;
     }
     if (is_array($v)) {
         if (is_callable($v)) {
             return ValueType::$TFunction;
         }
         return ValueType::TClass(_hx_qtype("Array"));
     }
     if (is_string($v)) {
         if (_hx_is_lambda($v)) {
             return ValueType::$TFunction;
         }
         return ValueType::TClass(_hx_qtype("String"));
     }
     if (is_bool($v)) {
         return ValueType::$TBool;
     }
     if (is_int($v)) {
         return ValueType::$TInt;
     }
     if (is_float($v)) {
         return ValueType::$TFloat;
     }
     if ($v instanceof _hx_anonymous) {
         return ValueType::$TObject;
     }
     if ($v instanceof _hx_enum) {
         return ValueType::$TObject;
     }
     if ($v instanceof _hx_class) {
         return ValueType::$TObject;
     }
     $c = _hx_ttype(get_class($v));
     if ($c instanceof _hx_enum) {
         return ValueType::TEnum($c);
     }
     if ($c instanceof _hx_class) {
         return ValueType::TClass($c);
     }
     return ValueType::$TUnknown;
 }
 /**
  * Extending classes may define their own constructor and call this one first
  *
  * @param   mixed   $value
  * @param   int     $flag   A flag used by the `ValueType::getType()` method
  */
 public function __construct($value, $flag = ValueType::MODE_STRICT)
 {
     $this->setReadOnlyProperties($this::$_read_only);
     $this->value = $value;
     $this->type = ValueType::getType($value);
 }
示例#5
0
<?php

class ValueType extends Enum
{
    public static $TBool;
    public static function TClass($c)
    {
        return new ValueType("TClass", 6, array($c));
    }
    public static function TEnum($e)
    {
        return new ValueType("TEnum", 7, array($e));
    }
    public static $TFloat;
    public static $TFunction;
    public static $TInt;
    public static $TNull;
    public static $TObject;
    public static $TUnknown;
}
ValueType::$TBool = new ValueType("TBool", 3);
ValueType::$TFloat = new ValueType("TFloat", 2);
ValueType::$TFunction = new ValueType("TFunction", 5);
ValueType::$TInt = new ValueType("TInt", 1);
ValueType::$TNull = new ValueType("TNull", 0);
ValueType::$TObject = new ValueType("TObject", 4);
ValueType::$TUnknown = new ValueType("TUnknown", 8);
示例#6
0
 /**
  * @return ValueType
  */
 public function valueType()
 {
     return ValueType::FLOATING_POINT_TYPE();
 }
示例#7
0
 /**
  * @throws FolderIDMissingException
  */
 public static function add_value_item($type_array, $category_array, $holder_class, $holder_id, $position_id)
 {
     global $user, $regional;
     if (class_exists($holder_class)) {
         $item_holder = new $holder_class($holder_id);
         if ($item_holder instanceof ItemHolderInterface) {
             $folder_id = $item_holder->get_item_holder_value("folder_id", $position_id);
         }
     }
     if (is_numeric($folder_id)) {
         if (count($type_array) != 1 and !$_POST['type_id']) {
             $result = array();
             $counter = 0;
             if (count($type_array) == 0) {
                 $value_obj = Value::get_instance(null);
                 $value_type_array = ValueType::list_entries();
                 foreach ($value_type_array as $key => $value) {
                     $value_type = new ValueType($value);
                     $result[$counter]['value'] = $value;
                     $result[$counter]['content'] = $value_type->get_name();
                     $counter++;
                 }
             } else {
                 foreach ($type_array as $key => $value) {
                     $value_type = new ValueType($value);
                     $result[$counter]['value'] = $value;
                     $result[$counter]['content'] = $value_type->get_name();
                     $counter++;
                 }
             }
         } elseif (count($type_array) != 1 and $_POST['type_id']) {
             $type_id = $_POST['type_id'];
         } else {
             $type_id = $type_array[0];
         }
         if (!$type_id) {
             $template = new HTMLTemplate("data/value_select_list.html");
             $paramquery = $_GET;
             $paramquery['nextpage'] = "1";
             $params = http_build_query($paramquery, '', '&#38;');
             $template->set_var("params", $params);
             $template->set_var("select", $result);
             if ($_POST['keywords']) {
                 $template->set_var("keywords", $_POST['keywords']);
             } else {
                 $template->set_var("keywords", "");
             }
             if ($_POST['description']) {
                 $template->set_var("description", $_POST['description']);
             } else {
                 $template->set_var("description", "");
             }
             $template->output();
         } else {
             $value_type = new ValueType($type_id);
             $template = new HTMLTemplate("data/value_add.html");
             $template->set_var("decimal_separator", $regional->get_decimal_separator());
             $template->set_var("thousand_separator", $regional->get_thousand_separator());
             $template->set_var("session_id", $_GET['session_id']);
             $template->set_var("folder_id", $folder_id);
             $template->set_var("type_id", $type_id);
             $template->set_var("get_array", serialize($_GET));
             if ($_GET['retrace']) {
                 $template->set_var("retrace", "index.php?" . http_build_query(Retrace::resolve_retrace_string($_GET['retrace'])));
             } else {
                 $template->set_var("retrace", "index.php?username="******"&session_id=" . $_GET['session_id']);
             }
             $template->set_var("title", $value_type->get_name());
             require_once "value_form.io.php";
             $value_form_io = new ValueFormIO(null, $type_id, $folder_id);
             $value_form_io->set_field_class("DataValueAddValues");
             $template->set_var("value", $value_form_io->get_content());
             if ($_POST['keywords']) {
                 $template->set_var("keywords", $_POST['keywords']);
             } else {
                 $template->set_var("keywords", "");
             }
             if ($_POST['description']) {
                 $template->set_var("description", $_POST['description']);
             } else {
                 $template->set_var("description", "");
             }
             $template->output();
         }
     } else {
         throw new FolderIDMissingException();
     }
 }
示例#8
0
 /**
  * @param string $action
  * @return string
  */
 public static function get_data_browser_link_html_and_button_handler($action)
 {
     global $regional;
     $html;
     $html_caption;
     $button_handler;
     $button_handler_caption;
     $template;
     $paramquery = $_GET;
     unset($paramquery['run']);
     switch ($action) {
         case "value_add":
             if (!isset($_POST['folder_id']) && !isset($_POST['value_array'])) {
                 //second call (from additional script; loads template)
                 require_once "core/modules/data/io/value_form.io.php";
                 $value_form_io = new ValueFormIO(null, $_POST['type_id'], $_POST['folder_id']);
                 $value_form_io->set_field_class("DataValueAddValues");
                 return $value_form_io->get_content();
             }
             if (isset($_POST['value_array'])) {
                 //third call (from add button; creates value)
                 return self::add_value($_POST['folder_id'], $_POST['type_id'], $_POST['value_array']);
             }
             require_once "core/include/data/value/access/value_type.access.php";
             $types = ValueType_Access::list_entries();
             $options = array();
             $counter = 0;
             foreach ($types as $key => $value) {
                 if ($value == 2) {
                     continue;
                 }
                 $value_type = new ValueType($value);
                 $options[$counter]['value'] = $value;
                 $options[$counter]['content'] = $value_type->get_name();
                 $options[$counter]['selected'] = "";
                 $options[$counter]['disabled'] = "";
                 $counter++;
             }
             $template = new HTMLTemplate("data/value_add_window.html");
             $template->set_var("option", $options);
             $html = $template->get_string();
             $html_caption = "Add Value";
             $button_handler_template = new JSTemplate("data/js/value_add_window.js");
             $button_handler_template->set_var("session_id", $_GET['session_id']);
             $button_handler_template->set_var("folder_id", $_POST['folder_id']);
             $button_handler = $button_handler_template->get_string();
             $button_handler_caption = "Add";
             $additional_script_template = new JSTemplate("data/js/value_add_window_additional.js");
             $additional_script_template->set_var("decimal_separator", $regional->get_decimal_separator());
             $additional_script_template->set_var("thousand_separator", $regional->get_thousand_separator());
             $additional_script_template->set_var("session_id", $_GET['session_id']);
             $additional_script = $additional_script_template->get_string();
             $array = array("content" => $html, "content_caption" => $html_caption, "handler" => $button_handler, "handler_caption" => $button_handler_caption, "additional_script" => $additional_script);
             return json_encode($array);
             break;
         case "value_delete":
             if (isset($_POST['sure'])) {
                 self::delete_value($_POST['value_id']);
             } else {
                 $template = new HTMLTemplate("data/value_delete_window.html");
                 $button_handler_template = new JSTemplate("data/js/value_delete_window.js");
                 $button_handler_template->set_var("session_id", $_GET['session_id']);
                 $button_handler_template->set_var("value_id", $_POST['value_id']);
                 $button_handler = $button_handler_template->get_string();
                 $button_handler_caption = "Delete";
                 $html_caption = "Delete Value";
                 $html = $template->get_string();
             }
             break;
         case "permission":
             require_once "data.ajax.php";
             if (isset($_POST['permissions'])) {
                 $success = DataAjax::change_permission(json_decode($_POST['permissions']), "Value");
                 return $success;
             } else {
                 $permission = DataAjax::permission_window();
                 $button_handler_template = new JSTemplate("data/js/value_permission_window.js");
                 $button_handler_template->set_var("session_id", $_GET['session_id']);
                 $button_handler_template->set_var("value_id", $_POST['value_id']);
                 $button_handler = $button_handler_template->get_string();
                 $button_handler_caption = "Change";
                 $html_caption = "Change permission";
                 $html = $permission;
             }
             break;
     }
     $array = array("content" => $html, "content_caption" => $html_caption, "handler" => $button_handler, "handler_caption" => $button_handler_caption);
     return json_encode($array);
 }
示例#9
0
 /**
  * @return ValueType
  */
 public function valueType()
 {
     return ValueType::INTEGER_TYPE();
 }
示例#10
0
 /**
  * @return ValueType
  */
 public function valueType()
 {
     return ValueType::BOOLEAN_TYPE();
 }
示例#11
0
 /**
  * @throws ValueTypeIDMissingExcpetion
  */
 public static function delete()
 {
     if ($_GET['id']) {
         if ($_GET['sure'] != "true") {
             $template = new HTMLTemplate("data/admin/value_template/delete.html");
             $paramquery = $_GET;
             $paramquery['sure'] = "true";
             $params = http_build_query($paramquery);
             $template->set_var("yes_params", $params);
             $paramquery = $_GET;
             unset($paramquery['sure']);
             unset($paramquery['action']);
             unset($paramquery['id']);
             $params = http_build_query($paramquery, '', '&#38;');
             $template->set_var("no_params", $params);
             $template->output();
         } else {
             $paramquery = $_GET;
             unset($paramquery['sure']);
             unset($paramquery['action']);
             unset($paramquery['id']);
             $params = http_build_query($paramquery, '', '&#38;');
             $value_type = new ValueType($_GET['id']);
             if ($value_type->delete()) {
                 Common_IO::step_proceed($params, "Delete Value Template", "Operation Successful", null);
             } else {
                 Common_IO::step_proceed($params, "Delete Value Template", "Operation Failed", null);
             }
         }
     } else {
         throw new ValueTypeIDMissingExcpetion();
     }
 }
示例#12
0
 /**
  * @return ValueType
  */
 public function valueType()
 {
     return ValueType::STRING_TYPE();
 }
示例#13
0
 /**
  * @see ValueInterface::get_value_shape()
  * @return array
  */
 public function get_value_shape($value_type_id = null, $folder_id = null)
 {
     if ($this->value and $this->value_id or is_numeric($value_type_id)) {
         if ($folder_id == null and $this->value_id) {
             $folder_id = $this->get_parent_folder_id();
         }
         if (is_numeric($value_type_id)) {
             $value_type = new ValueType($value_type_id);
         } else {
             $value_type = new ValueType($this->value->get_type_id());
         }
         $olvdl = new Olvdl($value_type->get_template_id());
         $xml_array = $olvdl->get_xml_array();
         $return_array = array();
         $format_counter = 0;
         if ($this->array_contains_each_statements($xml_array)) {
             $xml_array = $this->resolve_each_statements($xml_array, $folder_id);
         }
         if (is_array($xml_array) and count($xml_array) >= 1) {
             foreach ($xml_array as $key => $value) {
                 $value[0] = trim(strtolower($value[0]));
                 $value[1] = trim(strtolower($value[1]));
                 $value[2] = trim(strtolower($value[2]));
                 if ($value[1] == "format" and $value[2] != "#") {
                     $in_format = true;
                     $line_counter = 0;
                     $format_max_column = 0;
                     $return_array[$format_counter] = array();
                     $return_array[$format_counter]['type'] = "format";
                     if ($value[3]['colspan']) {
                         $colspan_array = array();
                         $colspan_array = explode(",", $value[3]['colspan']);
                         $colspan_array_count = 0;
                     }
                 }
                 if ($value[1] == "format" and $value[2] == "#") {
                     if ($in_format == true) {
                         $return_array[$format_counter]['max_column'] = $format_max_column;
                         $in_format = false;
                         $format_counter++;
                         $element_counter = 0;
                         if ($colspan_array) {
                             unset($colspan_array);
                             unset($colspan_array_count);
                         }
                     }
                 }
                 if ($value[1] == "line" and $value[2] != "#") {
                     if ($in_format == true) {
                         $in_line = true;
                         $element_counter = 0;
                         $line_max_column = 0;
                         $return_array[$format_counter][$line_counter] = array();
                         $return_array[$format_counter][$line_counter]['type'] = "line";
                         if ($value[3]['colspan']) {
                             $colspan_array = array();
                             $colspan_array = explode(",", $value[3]['colspan']);
                             $return_array[$format_counter][$line_counter]['colspan'] = array();
                             $return_array[$format_counter][$line_counter]['colspan'] = $colspan_array;
                         }
                     }
                 }
                 if ($value[1] == "line" and $value[2] == "#") {
                     if ($in_format == true and $in_line == true) {
                         $return_array[$format_counter][$line_counter]['max_column'] = $line_max_column;
                         if ($format_max_column < $line_max_column) {
                             $format_max_column = $line_max_column;
                         }
                         $in_line = false;
                         $line_counter++;
                         $element_counter = 0;
                         if ($colspan_array) {
                             unset($colspan_array);
                             unset($colspan_array_count);
                         }
                     } else {
                         $return .= "<br />\n";
                     }
                 }
                 if ($value[1] == "print" and $value[2] != "#") {
                     $element_array = array();
                     if ($value[3]['format']) {
                         $element_array['format'] = $value[3]['format'];
                     }
                     if ($value[3]['width']) {
                         $element_array['width'] = $value[3]['width'];
                     }
                     $element_array['value'] = array();
                     if ($value[3]['value'] and !$value[3]['var']) {
                         array_push($element_array['value'], $value[3]['value']);
                     } elseif (!$value[3]['value'] and $value[3]['var']) {
                         $value_var = new ValueVar($folder_id);
                         $value_var_content = $value_var->get_content($value[3]['var']);
                         if (!is_array($value_var_content)) {
                             array_push($element_array['value'], $value_var_content);
                         } else {
                             array_push($element_array['value'], "Error: Array is given");
                         }
                     }
                     if ($in_line == true and $in_format == true) {
                         $return_array[$format_counter][$line_counter][$element_counter]['type'] = "element";
                         $return_array[$format_counter][$line_counter][$element_counter]['element'] = "print";
                         $return_array[$format_counter][$line_counter][$element_counter]['content'] = $element_array;
                         $element_counter++;
                         $line_max_column++;
                     } else {
                         $return_array[$format_counter]['type'] = "element";
                         $return_array[$format_counter]['element'] = "print";
                         $return_array[$format_counter]['content'] = $element_array;
                         $format_counter++;
                     }
                     unset($element_array);
                 }
                 if ($value[1] == "field" and $value[2] != "#") {
                     if ($value[3]['name']) {
                         $element_array['name'] = $value[3]['name'];
                     }
                     if ($value[3]['display_name']) {
                         $element_array['display_name'] = $value[3]['display_name'];
                     }
                     if ($value[3]['default']) {
                         $element_array['default'] = $value[3]['default'];
                     }
                     if ($value[3]['format']) {
                         $element_array['format'] = $value[3]['format'];
                     }
                     if ($value[3]['set']) {
                         $element_array['set'] = $value[3]['set'];
                     }
                     // Type of the input
                     if ($value[3]['vartype']) {
                         switch ($value[3]['vartype']) {
                             case "integer":
                             case "int":
                                 $element_array['vartype'] = "integer";
                                 break;
                             case "float":
                                 $element_array['vartype'] = "float";
                                 break;
                             default:
                                 $element_array['vartype'] = "string";
                                 break;
                         }
                     } else {
                         $element_array['vartype'] = "string";
                     }
                     // Minimum and Maximum Input (possbile with integer and float only)
                     if ($value[3]['min_value'] and ($element_array['vartype'] == "integer" or $element_array['vartype'] == "float")) {
                         if (is_numeric($value[3]['min_value'])) {
                             $element_array['min_value'] = $value[3]['min_value'];
                         }
                     }
                     if ($value[3]['max_value'] and ($element_array['vartype'] == "integer" or $element_array['vartype'] == "float")) {
                         if (is_numeric($value[3]['max_value'])) {
                             $element_array['max_value'] = $value[3]['max_value'];
                         }
                     }
                     if ($element_array['max_value'] and $element_array['min_value']) {
                         if ($element_array['max_value'] < $element_array['min_value']) {
                             // Removes min_value and max_value if it is impossible to fulfill it
                             $element_array['min_value'] = null;
                             $element_array['max_value'] = null;
                         }
                     }
                     // Displayed length of the field
                     if ($value[3]['length']) {
                         $element_array['length'] = $value[3]['length'];
                     } else {
                         $element_array['length'] = 30;
                     }
                     // Requirement of the field
                     if ($value[3]['requirement']) {
                         switch ($value[3]['requirement']) {
                             case "required":
                                 $element_array['requirement'] = 1;
                                 break;
                             case "important":
                                 $element_array['requirement'] = 2;
                                 break;
                             default:
                                 $element_array['requirement'] = 0;
                                 break;
                         }
                     } else {
                         $element_array['requirement'] = 0;
                     }
                     // Size of a textarea
                     if ($value[3]['size']) {
                         $sizeArray = explode(",", $value[3]['size']);
                         $field_cols = $sizeArray[0];
                         $field_rows = $sizeArray[1];
                         unset($sizeArray);
                     } else {
                         $field_cols = 64;
                         $field_rows = 15;
                     }
                     $element_array['size'] = array();
                     $element_array['size']['cols'] = $field_cols;
                     $element_array['size']['rows'] = $field_rows;
                     $element_array['value'] = array();
                     if ($value[3]['type']) {
                         switch (trim(strtolower($value[3]['type']))) {
                             case "textarea":
                                 $element_array['type'] = "textarea";
                                 break;
                             case "checkbox":
                                 $element_array['type'] = "checkbox";
                                 break;
                             case "dropdown":
                                 $element_array['type'] = "dropdown";
                                 if ($value[3]['value'] and !$value[3]['var']) {
                                     $value_array = explode(";;", $value[3]['value']);
                                     $value_array_length = substr_count($value[3]['value'], ";;");
                                     for ($i = 0; $i <= $value_array_length; $i++) {
                                         array_push($element_array['value'], $value_array[$i]);
                                     }
                                 } elseif (!$value[3]['value'] and $value[3]['var']) {
                                     $value_var = new ValueVar($folder_id);
                                     $value_var_content = $value_var->get_content($value[3]['var']);
                                     if (is_array($value_var_content) and count($value_var_content) >= 1) {
                                         foreach ($value_var_content as $value_var_key => $value_var_value) {
                                             if (!is_array($value_var_value)) {
                                                 array_push($element_array['value'], $value_var_value);
                                             }
                                         }
                                     }
                                 }
                                 break;
                             default:
                                 $element_array['type'] = "textfield";
                                 break;
                         }
                     } else {
                         $element_array['type'] = "textfield";
                     }
                     if ($in_line == true and $in_format == true) {
                         $return_array[$format_counter][$line_counter][$element_counter]['type'] = "element";
                         $return_array[$format_counter][$line_counter][$element_counter]['element'] = "field";
                         $return_array[$format_counter][$line_counter][$element_counter]['content'] = $element_array;
                         $element_counter++;
                         $line_max_column++;
                     } else {
                         $return_array[$format_counter]['type'] = "element";
                         $return_array[$format_counter]['element'] = "field";
                         $return_array[$format_counter]['content'] = $element_array;
                         $format_counter++;
                     }
                 }
             }
             return $return_array;
         } else {
             return null;
         }
     } else {
         return null;
     }
 }
示例#14
0
 /**
  * @return ValueType
  */
 public function valueType()
 {
     return ValueType::NULL_TYPE();
 }
示例#15
0
 /**
  * @see ItemListenerInterface::get_generic_name()
  * @param string $type
  * @param array $type_array
  * @return string
  */
 public static function get_generic_name($type, $type_array)
 {
     if ($type == "file") {
         return "File";
     } elseif ($type == "parameter") {
         if (is_array($type_array) and count($type_array) == 1) {
             $parameter_template_id = ParameterTemplate::get_id_by_internal_name($type_array[0]);
             if (is_numeric($parameter_template_id)) {
                 $parameter_template = new ParameterTemplate($parameter_template_id);
                 if (($parameter_name = $parameter_template->get_name()) != null) {
                     return "" . $parameter_name;
                 } else {
                     return "Parameter";
                 }
             } else {
                 return "Parameter";
             }
         } else {
             return "Parameter";
         }
     } else {
         if (is_array($type_array) and count($type_array) == 1) {
             $value_type = new ValueType($type_array[0]);
             if (($value_name = $value_type->get_name()) != null) {
                 return "" . $value_name;
             } else {
                 return "Value";
             }
         } else {
             return "Value";
         }
     }
 }