Skip to content

Commit

Permalink
fix: tidy up code
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Buckley committed Mar 1, 2024
1 parent cf16ab9 commit fc9b8cd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 28 deletions.
19 changes: 4 additions & 15 deletions system/modules/auth/models/AuthService.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,15 +507,14 @@ public function getGroups()
$rows = $this->_db->get("user")->where(['is_active' => 1, 'is_deleted' => 0, 'is_group' => 1])->fetchAll();

if ($rows) {
$objects = $this->fillObjects("User", $rows);

return $objects;
return $this->fillObjects("User", $rows);
}
return null;
}

public function getGroupMembers($group_id = null, $user_id = null)
{
$option = [];
if ($group_id) {
$option['group_id'] = $group_id;
}
Expand All @@ -524,22 +523,12 @@ public function getGroupMembers($group_id = null, $user_id = null)
$option['user_id'] = $user_id;
}

$groupMembers = $this->getObjects("GroupUser", $option, true);

if ($groupMembers) {
return $groupMembers;
}
return null;
return $this->getObjects("GroupUser", $option, true);
}

public function getGroupMemberById($id)
{
$groupMember = $this->getObject("GroupUser", $id);

if ($groupMember) {
return $groupMember;
}
return null;
return $this->getObject("GroupUser", $id);
}

public function getRoleForLoginUser($group_id, $user_id)
Expand Down
17 changes: 8 additions & 9 deletions system/modules/insights/actions/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,25 @@ function index_ALL(Web $w)
// check if this user is a member of a group (or parent group) with access to this insight report
$allMembers = InsightService::getInstance($w)->getAllMembersForInsightClass($insight_class);
foreach ($allMembers as $member) {
$userHasAccess = InsightService::getInstance($w)->checkUserAccess($w, $member->user_id, $user_id); // $member->user_id may be a user or a group
$userHasAccess = InsightService::getInstance($w)->checkUserAccess($member->user_id, $user_id); // $member->user_id may be a user or a group
if ($userHasAccess) {
break;
};
}
}
}
if ($userHasAccess) {
$row = [];
// add values to the row in the same order as the table headers
$row[] = HtmlBootstrap5::a('/insights/viewInsight/' . $insight_class, $insight->name);
$row[] = $modulename;
$row[] = $insight->description;
$row = [
HtmlBootstrap5::a('/insights/viewInsight/' . $insight_class, $insight->name),
$modulename,
$insight->description
];
// the actions column is used to hold buttons that link to actions per insight. Note the insight id is added to the href on these buttons.
$actions = [];
$button_group = HtmlBootstrap5::b("/insights/viewInsight/" . $insight_class, "View", null, "viewbutton", false, 'btn-sm btn-primary');
if (InsightService::getInstance($w)->isInsightOwner($user_id, $insight_class)) {
$button_group .= HtmlBootstrap5::b("/insights/manageMembers?insight_class=" . $insight_class, "Manage Members", null, " viewbutton", false, "btn-sm btn-secondary");
}
$actions[] = HtmlBootstrap5::buttonGroup($button_group);
$row[] = implode('', $actions);
$row[] = HtmlBootstrap5::buttonGroup($button_group);
$table[] = $row;
}
}
Expand Down
7 changes: 3 additions & 4 deletions system/modules/insights/models/InsightService.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function IsMember($insight_class_name, $user_id)
//retrieve a specific member matching the id given number
public function GetMemberForId($id)
{
return $this->GetObject('InsightMembers', $id);
return $this->getObject('InsightMembers', $id);
}

public function getInsightInstance(string $insight_class)
Expand All @@ -160,8 +160,7 @@ public function isInsightOwner($user_id, $insight_class)
public function date2db($date)
{
if ($date) {
$formatteddate = formatDate($date, 'Y-m-d');
return $formatteddate;
return formatDate($date, 'Y-m-d');
}
}

Expand Down Expand Up @@ -271,7 +270,7 @@ public function exportpdf($run_data, $title, $report_template_id = null, $layout
}
}
if (!empty($report_template_id) && !empty($templatedata)) {
$results = $this->w->Template->render(
$results = TemplateService::getInstance($this->w)->render(
$report_template_id,
["data" => $templatedata, "w" => $this->w, "POST" => $_POST]
);
Expand Down

0 comments on commit fc9b8cd

Please sign in to comment.