Hallo Zusammen,
ich hab Skripte für ein Abhängigkeit erstellt:
Controller.php:
abhängigkeit.html.twig:
Jetzt wenn ich neue Abhängigkeit auswähle gibt Fehler in Json:
Hinweis: Datenbank schon auch richtig erstellt.
ich hab Skripte für ein Abhängigkeit erstellt:
Controller.php:
PHP-Code:
/**
* @Route("/create_dependencies")
*/
public function create_dependencies(Request $request, CmdbService $service)
{
$result = new \stdClass();
$result->state = "error";
$result->message = "Bitte wählen Sie mindestens eine Abhängigkeit aus";
$process_id = $request->get("id");
$dependencies = $request->get('dependencies');
if($process_id != null)
{
$db_dependencies = [];
$conn = $service->getEm()->getConnection();
$sql = "select * from boarding_process_template_dependency bptd where bptd.boarding_process_template = :id";
$stmt = $conn->prepare($sql);
$resultSet = $stmt->executeQuery([
"id" => $process_id
]);
if($resultSet->rowCount() > 0)
{
$db_dependencies = $resultSet->fetchAllAssociative();
}
/** check the selected dependencies **/
if($dependencies != null && count($dependencies) > 0)
{
$success = true;
if($db_dependencies != null && count($db_dependencies) > 0)
{
$mod_dependencies = [];
$del_dependencies = [];
$new_dependencies = [];
foreach ($db_dependencies as $db_dependency)
{
$foundDependencies = array_filter($dependencies, function ($dep) use($db_dependency)
{
return $dep["depended_id"] == $db_dependency["boarding_process_template_dependency"];
});
/** modified **/
if($foundDependencies != null && count($foundDependencies) > 0)
{
array_push($mod_dependencies, $foundDependencies[array_keys($foundDependencies)[0]]);
}
else
{
/** deleted **/
array_push($del_dependencies, $db_dependency);
}
}
foreach ($dependencies as $dep)
{
if($db_dependencies == null && count($db_dependencies) <= 0)
{
array_push($new_dependencies, $dep);
}
else
{
$foundDependencies = array_filter($db_dependencies, function($db_dep) use($dep)
{
return $db_dep["boarding_process_template_dependency"] == $dep["depended_id"];
});
if($foundDependencies == null || count($foundDependencies) <= 0)
{
array_push($new_dependencies, $dep);
}
}
}
/** delete dependencies from db **/
if($del_dependencies != null && count($del_dependencies) > 0)
{
foreach ($del_dependencies as $del_dependency)
{
$sql = "delete from boarding_process_template_dependency where boarding_process_template = :id and boarding_process_template_dependency = :dependency_id";
$stmt = $conn->prepare($sql);
if(!$stmt->executeQuery(["id" => $process_id, "dependency_id" => $del_dependency["boarding_process_template_dependency"]]))
{
$success = false;
}
}
}
/** update dependencies in db **/
if($mod_dependencies != null && count($mod_dependencies) > 0)
{
foreach ($mod_dependencies as $mod_dependency)
{
$sql = "update
boarding_process_template_dependency set
state = :state,
created_date = :created_date,
created_by = :created_by
where
boarding_process_template = :id and
boarding_process_template_dependency = :dependency_id";
$stmt = $conn->prepare($sql);
if(!$stmt->executeQuery([
"state" => $mod_dependency["state"],
"created_date" => date("Y-m-d H:i:s"),
"created_by" => App::authUser()->getId(),
"id" => $process_id,
"dependency_id" => $mod_dependency["depended_id"]]))
{
$success = false;
}
}
}
/** create dependencies in db **/
if($new_dependencies != null && count($new_dependencies) > 0)
{
foreach ($new_dependencies as $new_dependency)
{
$sql = "insert into
boarding_process_template_dependency(boarding_process_template, boarding_process_template_dependency, state, created_by)
values(:proces_id, :dependency_id, :state, :created_by)";
$stmt = $conn->prepare($sql);
$stmt->executeQuery([
"proces_id" => $process_id,
"dependency_id" => $new_dependency["depended_id"],
"state" => $new_dependency["state"],
"created_by" => App::authUser()->getId()
]);
}
}
}
else
{
/** create dependencies in db **/
foreach ($dependencies as $dep)
{
$sql = "insert into
boarding_process_template_dependency(boarding_process_template, boarding_process_template_dependency, state, created_by)
values(:proces_id, :dependency_id, :state, :created_by)";
$stmt = $conn->prepare($sql);
if(!$stmt->executeQuery([
"proces_id" => $process_id,
"dependency_id" => $dep["depended_id"],
"state" => $dep["state"],
"created_by" => App::authUser()->getId()
]))
{
$success = false;
}
}
}
if($success)
{
$result->state = "success";
$result->message = "Die Daten wurden erfolgreich aktualisiert";
}
else
{
$result->state = "error";
$result->message = "Die Daten konnten nicht aktualisiert werden";
}
}
/** delete all dependencies for process template, because no one was selected by user **/
else
{
$sql = "delete from boarding_process_template_dependency where boarding_process_template = :id";
$stmt = $conn->prepare($sql);
if($stmt->executeQuery(["id" => $process_id]))
{
$result->state = "success";
$result->message = "Die Daten wurden erfolgreich aktualisiert";
}
else
{
$result->state = "error";
$result->message = "Die Daten konnten nicht aktualisiert werden";
}
}
}
header("Content-Type: application/json");
echo json_encode($result);exit;
}
abhängigkeit.html.twig:
HTML-Code:
<div class="modal modal-process-dependencies" tabindex="-1" role="dialog"> <div class="modal-dialog modal-lg" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title"><span class="process-name"></span> - Abhängigkeiten</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Schließen"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <table> <thead> <tr> <th style="width: 100px">Abhängigkeit</th> <th>Process</th> <th style="width: 200px">Zustand</th> </tr> </thead> <tbody class="table-processes"></tbody> </table> </div> <div class="modal-footer"> <input type="hidden" class="process-template-id"> <div class="modal-status" style="z-index: 1"></div> <button type="button" class="btn btn-primary btn-save" style="z-index: 2">Speichern</button> <button type="button" class="btn btn-secondary btn-cancel" data-dismiss="modal" style="z-index: 2">Abbrechen</button> </div> </div> </div> </div>
Jetzt wenn ich neue Abhängigkeit auswähle gibt Fehler in Json:
state | "error" |
message | "Bitte wählen Sie mindestens eine Abhängigkeit aus" |
Kommentar