/** * @param $class_name string * @param $search string * @param $exclude_properties string[] * @param $prefix string * @param $depth integer * @return Reflection_Property[] */ protected function searchProperties($class_name, $search, $exclude_properties = [], $prefix = '', $depth = 0) { $class = new Reflection_Class($class_name); $all_properties = $this->getProperties($class); $first_properties = []; $properties = []; $more_properties = []; foreach ($all_properties as $property) { if (!isset($exclude_properties[$property->name])) { $property_path = $prefix . $property->name; if ($property->name == $search || $property_path == $search) { $first_properties[$property_path] = $property; $matches = true; } else { preg_match('|^' . $search . '|', strtolower(strSimplify(Loc::tr($property->name), SP)), $matches); preg_match('|^' . $search . '|', strtolower(strSimplify(Loc::tr($prefix . $property_path), DOT . SP)), $matches2); if ($matches || $matches2) { $properties[$property_path] = $property; $matches = true; } else { preg_match('|' . $search . '|', strtolower(strSimplify(Loc::tr($property_path), DOT . SP)), $matches); if ($matches) { $more_properties[$property_path] = $property; } } } if ($depth < $this->max_depth && !$matches) { $type = $property->getType(); if ($type->isClass()) { $property_class = $type->getElementTypeAsString(); $is_component = isA($property_class, Component::class); $exclude_sub_properties = $is_component ? call_user_func([$property_class, 'getCompositeProperties'], $class_name) : []; $parent_classes[] = $class_name; $sub_properties = $this->searchProperties($type->getElementTypeAsString(), $search, $exclude_sub_properties, $property->name . DOT, $depth + 1); foreach ($sub_properties as $sub_property) { if (!isset($exclude_properties[$sub_property->name])) { $more_properties[] = new Reflection_Property($class_name, $property->name . DOT . $sub_property->path); } } } } } } $properties = array_merge($first_properties, $properties, $more_properties); return $properties; }
/** * @param $class_name string * @param $property_path string * @param $use_reverse_translation boolean if true, will try reverse translation of property names * @param $properties_alias string[] $property_path = string[string $property_alias] * @return string */ public static function propertyPathOf($class_name, $property_path, $use_reverse_translation = false, $properties_alias = null) { if (isset($properties_alias) && isset($properties_alias[$property_path])) { $property_path = $properties_alias[$property_path]; } elseif ($use_reverse_translation) { $property_class_name = $class_name; $property_names = []; foreach (explode(DOT, $property_path) as $property_name) { if ($asterisk = substr($property_name, -1) == '*') { $property_name = substr($property_name, 0, -1); } $property = null; $property_name = Names::displayToProperty($property_name); try { $property = new Reflection_Property($property_class_name, $property_name); } catch (ReflectionException $e) { $translated_property_name = Names::displayToProperty(Loc::rtr($property_name, $property_class_name)); try { $property = new Reflection_Property($property_class_name, $translated_property_name); $property_name = $translated_property_name; } catch (ReflectionException $e) { } } $property_names[] = $property_name . ($asterisk ? '*' : ''); if (!isset($property)) { break; } $property_class_name = $property->getType()->getElementTypeAsString(); } $property_path = join(DOT, $property_names); } return $property_path; }
/** * @return Head */ protected function buildHead() { $head = new Head(); $row = new Row(); foreach ($this->properties as $property) { if (!$property->getType()->isMultiple() || $property->getType()->getElementTypeAsString() != $property->getFinalClass()->name) { $cell = new Header_Cell(Loc::tr(Names::propertyToDisplay($property->getAnnotation('alias')->value), $this->class_name)); $row->addCell($cell); } } $head->addRow($row); return $head; }
/** * Translate content of html options in Html_Option objects * * @param $result string */ public function translateOptionContent(&$result) { if (trim($result)) { $result = Loc::tr($result); } }
/** * @param $list_settings Data_List_Settings * @return string[] key is property path, value is title */ protected function getTitles(Data_List_Settings $list_settings) { $locale = Locale::current(); $titles = []; foreach ($list_settings->properties_path as $property_path) { $titles[$property_path] = str_replace('_', SP, isset($list_settings->properties_title[$property_path]) ? $list_settings->properties_title[$property_path] : (isset($locale) ? Loc::tr($property_path) : $property_path)); $key = array_search($property_path, $list_settings->properties_path); if ($key !== false) { $titles[$key] = str_replace('_', SP, $titles[$property_path]); } } return $titles; }
/** * @return Head */ protected function buildHead() { $head = new Head(); $row = new Row(); foreach ($this->properties as $property) { $cell = new Header_Cell(Loc::tr(Names::propertyToDisplay($property->getAnnotation('alias')->value), $this->class_name)); $row->addCell($cell); } $head->addRow($row); return $head; }
/** * @param $format boolean * @return Element */ protected function buildInteger($format = true) { $input = new Input($this->getFieldName(), $format ? Loc::integerToLocale($this->value) : $this->value); if ($this->readonly) { $input->setAttribute('readonly'); } $input->addClass('integer'); $input->addClass('autowidth'); return $input; }
/** * @param $csv_file string * @param $errors string[] * @return array */ public static function readCsvFile($csv_file, &$errors = []) { $lines = []; $row = 0; $f = fopen($csv_file, 'r'); if ($f) { while ($buf = fgetcsv($f)) { $row++; if (($column = array_search('#REF!', $buf)) !== false) { $column++; $errors[] = str_replace(['$1', '$2'], [$row, $column], Loc::tr('unsolved reference at row $1 and column $2')); } $lines[] = $buf; } } fclose($f); return $lines; }
/** * Returns a value with application of current locales * * @param $template Template * @return object */ public function getLoc(Template $template) { foreach ($template->objects as $object) { if (is_object($object)) { if ($object instanceof Date_Time) { return Loc::dateToLocale($object); } else { $property_name = reset($template->var_names); if (method_exists(get_class($object), $property_name)) { $method = new Reflection_Method(get_class($object), $property_name); return Loc::methodToLocale($method, reset($template->objects)); } else { $property = new Reflection_Property(get_class($object), $property_name); return Loc::propertyToLocale($property, reset($template->objects)); } } break; } } return reset($object); }