Skip to content

Commit

Permalink
replace with has, further narrowing
Browse files Browse the repository at this point in the history
  • Loading branch information
kingjia90 committed Aug 26, 2024
1 parent 31bac96 commit 0fa0a7e
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,14 @@ public function getOrCreateOutputConfigAction(Request $request)
$config = OutputDefinition::getById($request->query->getInt('config_id'));
$class = null;
if (!$config) {
if (is_numeric($request->query->get('class_id'))) {
$class = ClassDefinition::getById($request->query->getInt('class_id'));
} else {
if ($request->query->has('class_id')) {
$class = ClassDefinition::getByName($request->query->getString('class_id'));
}
if (!$class) {
throw new \Exception('Class ' . $request->query->get('class_id') . ' not found.');
throw new \Exception('Class ' . $request->query->getString('class_id') . ' not found.');
}

$config = OutputDefinition::getByObjectIdClassIdChannel($request->query->get('objectId'), $class->getId(), $request->query->get('channel'));
$config = OutputDefinition::getByObjectIdClassIdChannel($request->query->getInt('objectId'), $class->getId(), $request->query->getString('channel'));
}

if ($config) {
Expand All @@ -237,9 +235,9 @@ public function getOrCreateOutputConfigAction(Request $request)
return $this->jsonResponse(['success' => true, 'outputConfig' => $config]);
} else {
$config = new OutputDefinition();
$config->setChannel($request->query->get('channel'));
$config->setChannel($request->query->getString('channel'));
$config->setClassId($class->getId());
$config->setObjectId($request->query->get('objectId'));
$config->setObjectId($request->query->getInt('objectId'));
$config->save();

return $this->jsonResponse(['success' => true, 'outputConfig' => $config]);
Expand Down Expand Up @@ -403,8 +401,8 @@ private function getFieldDefinition($attributeName, $objectClass)
public function getFieldDefinitionAction(Request $request)
{
try {
$objectClass = ClassDefinition::getById($request->query->get('class_id'));
$def = $this->getFieldDefinition($request->query->get('key'), $objectClass);
$objectClass = ClassDefinition::getById($request->query->getString('class_id'));
$def = $this->getFieldDefinition($request->query->getString('key'), $objectClass);

return $this->jsonResponse(['success' => true, 'fieldDefinition' => $def]);
} catch (\Exception $e) {
Expand Down Expand Up @@ -469,7 +467,7 @@ private function getFilteredClassDefinitionList(Request $request): ClassDefiniti
{
$classList = new ClassDefinition\Listing();

if ($request->request->getString('class_id')) {
if ($request->request->has('class_id')) {
$classList->setCondition('id = ?', $request->request->getString('class_id'));
} elseif (!empty($this->defaultGridClasses)) {
$allowedClassIds = [];
Expand Down

0 comments on commit 0fa0a7e

Please sign in to comment.