/** * @see parent::checkProperty() */ function checkProperty($object) { $propValue = CMbFieldSpec::checkNumeric($object->{$this->fieldName}, false); if ($propValue === null) { return "N'est pas une valeur décimale"; } if (!preg_match("/^([0-9]+)(\\.[0-9]{0,4}){0,1}\$/", $propValue)) { return "N'est pas un pourcentage"; } return null; }
/** * @see parent::checkProperty() */ function checkProperty($object) { $value = $object->{$this->fieldName}; // Has to be numeric $value = CMbFieldSpec::checkNumeric($value, true); if ($value === null) { return "N'est pas une chaîne numérique"; } // Only two options if ($value !== 0 && $value != 1) { return "Ne peut être différent de 0 ou 1"; } return null; }
/** * @see parent::checkProperty() */ function checkProperty($object) { if ($this->notNull && $this->nullify) { return "Spécifications de propriété incohérentes entre 'notNull' et 'nullify'"; } $fieldName = $this->fieldName; $propValue = CMbFieldSpec::checkNumeric($object->{$fieldName}, true); if ($propValue === null || $object->{$fieldName} === "") { return "N'est pas une référence (format non numérique)"; } if ($propValue == 0) { return "ne peut pas être une référence nulle"; } if ($propValue < 0) { return "N'est pas une référence (entier négatif)"; } if (!$this->class and !$this->meta) { return "Type d'objet cible on défini"; } $class = $this->class; if ($meta = $this->meta) { $class = $object->{$meta}; } // Gestion des objets étendus ayant une pseudo-classe $ex_object = CExObject::getValidObject($class); if ($ex_object) { if (!$this->unlink && !$ex_object->load($propValue)) { return "Objet référencé de type '{$class}' introuvable"; } } else { if (!is_subclass_of($class, "CStoredObject")) { return "La classe '{$class}' n'est pas une classe d'objet enregistrée"; } /** @var CStoredObject $ref */ $ref = new $class(); if (!$this->unlink && !$ref->idExists($propValue)) { return "Objet référencé de type '{$class}' introuvable"; } } return null; }
/** * @see parent::getFormHtmlElement() */ function getFormHtmlElement($object, $params, $value, $className) { $form = CMbArray::extract($params, "form"); $increment = CMbArray::extract($params, "increment"); $showPlus = CMbArray::extract($params, "showPlus"); $fraction = CMbArray::extract($params, "fraction"); $showFraction = CMbArray::extract($params, "showFraction"); $deferEvent = CMbArray::extract($params, "deferEvent"); $bigButtons = CMbArray::extract($params, "bigButtons"); $readonly = CMbArray::get($params, "readonly"); $field = CMbString::htmlSpecialChars($this->fieldName); $min = CMbArray::extract($params, "min"); if ($min === null) { $min = CMbFieldSpec::checkNumeric($this->min, false); } $max = CMbArray::extract($params, "max"); if ($max === null) { $max = CMbFieldSpec::checkNumeric($this->max, false); } $new_value = CMbArray::extract($params, "value"); if ($new_value !== null) { $value = $new_value; } $decimals = CMbArray::extract($params, "decimals", $this->decimals); if ($decimals == null) { $decimals = isset($this->precise) ? 4 : 2; } $step = CMbArray::extract($params, "step"); $step = CMbFieldSpec::checkNumeric($step, false); CMbArray::defaultValue($params, "size", 4); if ($form && $increment && !$readonly) { $sHtml = $this->getFormElementText($object, $params, ($value >= 0 && $showPlus ? '+' : '') . ($value == 0 && $showPlus ? '0' : $value), $className, "number"); $sHtml .= ' <script type="text/javascript"> Main.add(function(){ var element = $(document.forms["' . $form . '"]["' . $field . '"]); if ($(element.form).isReadonly()) return; element.addSpinner({'; if ($step) { $sHtml .= "step: {$step},"; } if ($decimals) { $sHtml .= "decimals: {$decimals},"; } if ($this->pos) { $sHtml .= "min: 0,"; } elseif (isset($min)) { $sHtml .= "min: {$min},"; } if (isset($max)) { $sHtml .= "max: {$max},"; } if ($deferEvent) { $sHtml .= "deferEvent: true,"; } if ($bigButtons) { $sHtml .= "bigButtons: true,"; } if ($showPlus) { $sHtml .= "showPlus: true,"; } if ($fraction) { $sHtml .= "fraction: true,"; } if ($showFraction) { $sHtml .= "showFraction: true,"; } $sHtml .= '_:0 // IE rules }); }); </script>'; } else { $sHtml = $this->getFormElementText($object, $params, $value, $className, "number"); } return $sHtml; }
/** * @see parent::updatePlainFields() */ function updatePlainFields() { $group = CGroups::loadCurrent(); if ($this->_poids_g) { $this->poids = round($this->_poids_g / 1000, 2); } foreach (self::$list_constantes as $_constant => &$_params) { // If field is a if ($this->{$_constant} === null && empty($_params["formfields"])) { continue; } if (isset($_params["formfields"])) { $conv = 1.0; if (isset($_params['conversion'])) { $form_field_unite = '_' . $_params["unit_config"]; $_unite = $this->{$form_field_unite}; // Si le champ n'a pas de valeur, on regarde en config if (!$_unite) { $_unite = CAppUI::conf('dPpatients CConstantesMedicales ' . $_params["unit_config"], $group); } $conv = self::getConv($_constant, $_unite); } $_parts = array(); $_empty = true; foreach ($_params["formfields"] as $_formfield) { if (empty($this->{$_formfield}) && !is_numeric($this->{$_formfield})) { break; } $_empty = false; $_value = $this->{$_formfield}; $_value = CMbFieldSpec::checkNumeric($_value, false); if ($conv != 1.0) { $_value = round($_value / $conv, self::CONV_ROUND_UP); } $_parts[] = $_value; } // no value at all if ($_empty) { $this->{$_constant} = ""; } elseif (count($_parts) != count($_params["formfields"])) { $this->{$_constant} = ""; } else { $this->{$_constant} = implode("|", $_parts); } } } parent::updatePlainFields(); }
/** * @see parent::updatePlainFields() */ function updatePlainFields() { parent::updatePlainFields(); if ($this->value !== null) { $value_type = $this->loadRefValueType(); if ($value_type->datatype === "NM") { $this->value = CMbFieldSpec::checkNumeric($this->value, false); } } }
/** * Get observation results for this object * * @param CMbObject $object Reference object * @param bool $utf8 Encode data int UTF-8 * * @return array|CObservationResultSet[] */ static function getResultsFor(CMbObject $object, $utf8 = true) { $request = new CRequest(); $request->addTable("observation_result"); $request->addSelect("*"); $request->addLJoin(array("observation_result_set" => "observation_result_set.observation_result_set_id = observation_result.observation_result_set_id", "user_log" => "observation_result_set.observation_result_set_id = user_log.object_id AND\r\n user_log.object_class = 'CObservationResultSet' AND user_log.type = 'create'", "users" => "users.user_id = user_log.user_id")); $request->addWhere(array("observation_result_set.context_class" => "= '{$object->_class}'", "observation_result_set.context_id" => "= '{$object->_id}'")); $request->addOrder("observation_result_set.datetime"); $request->addOrder("observation_result.observation_result_id"); $results = $object->_spec->ds->loadList($request->makeSelect()); $times = array(); $data = array(); foreach ($results as $_result) { $_time = CMbDate::toUTCTimestamp($_result["datetime"]); $times[$_time] = $_result["datetime"]; $unit_id = $_result["unit_id"] ? $_result["unit_id"] : "none"; $label = null; if ($_result["label_id"]) { $label_obj = new CSupervisionGraphAxisValueLabel(); $label_obj->load($_result["label_id"]); $label = $label_obj->title; } $float_value = $_result["value"]; $float_value = CMbFieldSpec::checkNumeric($float_value, false); $_user_name = $_result["user_first_name"] . " " . $_result["user_last_name"]; $data[$_result["value_type_id"]][$unit_id][] = array(0 => $_time, 1 => $float_value, "ts" => $_time, "value" => $_result["value"], "datetime" => $_result["datetime"], "file_id" => $_result["file_id"], "set_id" => $_result["observation_result_set_id"], "result_id" => $_result["observation_result_id"], "label_id" => $_result["label_id"], "label" => $utf8 ? utf8_encode($label) : $label, "user_id" => $_result["user_id"], "user" => $utf8 ? utf8_encode($_user_name) : $_user_name); } return array($data, $times); }
/** * Check a length strictly positive one-byte value * * @param mixed $length Value to check * * @return mixed Cast value, null on failure */ static function checkLengthValue($length) { if (!($length = CMbFieldSpec::checkNumeric($length))) { return null; } if ($length < 1 || $length > 255) { return null; } return $length; }