praca-test-tasks/1.php/method.php
2023-03-12 01:21:25 +03:00

39 lines
1.0 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
include "./logic/mysql-realization.php";
function output ($root = "") {
$itemIerarchyId = ""; // Без этого параметра у нас будет выводиться с единицы, а не с номера элемента в общей иерархии
$model = new Model(
new RealizationMySQL(
"127.0.0.1", // Адрес базы данных MySQL
"root", // Логин
"root", // Пароль
"realizations-db" // База данных
)
);
if ($root == "" || $root == null) {
$root = null;
}
else {
$modelElementsForSearch = $model->getModelElement(null, true);
foreach ($modelElementsForSearch as $i) {
if ($i['id'] == $root) {
$itemIerarchyId = $i['id'];
$root = $i['root_id'];
break;
}
}
}
$modelElements = $model->getModelElement($root, true, $itemIerarchyId);
$outputList = array();
foreach ($modelElements as $item) {
$outputList[] = $item['id'] . ' ' . $item['data'];
}
return implode("\n", $outputList);
}
?>