Skip to content

Commit

Permalink
Refactoring REST calls and go to LMS external functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ildemartinez committed Jan 22, 2023
1 parent b846964 commit a4340d1
Show file tree
Hide file tree
Showing 8 changed files with 1,141 additions and 1,044 deletions.
8 changes: 8 additions & 0 deletions LMSBrowserHelperUnit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ procedure OpenEditProfileInBrowser(const aUser: TLMSUser;
// Edit course
procedure OpenEditCourseInBrowser(const aCourse: TLMSCourse);

// Services
procedure OpenExternalServices(const aLMS: tlms);

implementation

uses
Expand Down Expand Up @@ -79,4 +82,9 @@ procedure OpenEditCourseInBrowser(const aCourse: TLMSCourse);
[aCourse.id])), nil, nil, 0); // SW_SHOW);
end;

procedure OpenExternalServices(const aLMS: tlms);
begin
ShellExecute(0, 'open', PChar(aLMS.Host + ADMIN_SETTINGS_EXTERNALSERVICES), nil, nil, 0); // SW_SHOW);
end;

end.
3 changes: 3 additions & 0 deletions LMSConstsUnit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ interface
EDIT_PROFILE_IN_COURSE = '/user/editadvanced.php?id=%d&course=%d';
EDIT_COURSE = '/course/edit.php?id=%d';

// admin settings
ADMIN_SETTINGS_EXTERNALSERVICES = '/admin/settings.php?section=externalservices';

implementation

end.
1,952 changes: 976 additions & 976 deletions LMSExplorer.dproj

Large diffs are not rendered by default.

Binary file modified LMSExplorer.res
Binary file not shown.
71 changes: 48 additions & 23 deletions LMSFormUnit.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ object LMSForm: TLMSForm
Left = 0
Top = 0
Caption = 'LMSForm'
ClientHeight = 543
ClientWidth = 803
ClientHeight = 585
ClientWidth = 965
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Expand All @@ -16,32 +16,57 @@ object LMSForm: TLMSForm
OnClose = FormClose
PixelsPerInch = 96
TextHeight = 13
object TabControl1: TTabControl
object PageControl1: TPageControl
Left = 0
Top = 0
Width = 803
Height = 543
Width = 965
Height = 585
ActivePage = TabSheet2
Align = alClient
TabOrder = 0
Tabs.Strings = (
'Users')
TabIndex = 0
object Panel1: TPanel
Left = 4
Top = 24
Width = 795
Height = 25
Align = alTop
TabOrder = 0
object Edit1: TEdit
Left = 1
Top = 1
Width = 313
Height = 23
Align = alLeft
object TabSheet1: TTabSheet
Caption = 'Users'
object Panel1: TPanel
Left = 0
Top = 0
Width = 957
Height = 25
Align = alTop
TabOrder = 0
OnChange = Edit1Change
ExplicitHeight = 21
ExplicitTop = 8
object Edit1: TEdit
Left = 1
Top = 1
Width = 313
Height = 23
Align = alLeft
TabOrder = 0
OnChange = Edit1Change
ExplicitHeight = 21
end
end
end
object TabSheet2: TTabSheet
AlignWithMargins = True
Caption = 'Configuration'
ImageIndex = 1
object GroupBox1: TGroupBox
Left = 0
Top = 0
Width = 951
Height = 65
Align = alTop
Caption = 'Service configuration '
TabOrder = 0
object Button1: TButton
Left = 19
Top = 24
Width = 214
Height = 25
Caption = 'Got to LMS external service configuration'
TabOrder = 0
OnClick = Button1Click
end
end
end
end
Expand Down
17 changes: 15 additions & 2 deletions LMSFormUnit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ interface

type
TLMSForm = class(TForm)
TabControl1: TTabControl;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Panel1: TPanel;
Edit1: TEdit;
GroupBox1: TGroupBox;
Button1: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Edit1Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
fLMS: TLMS;
fUsers: TLMSUsers;
Expand All @@ -37,18 +42,26 @@ implementation
uses
System.JSON,

LMSBrowserHelperUnit,
LMSLogUnit;

{$R *.dfm}

procedure TLMSForm.Button1Click(Sender: TObject);
begin
OpenExternalServices(self.fLMS);
end;

constructor TLMSForm.Create(Owner: TComponent);
begin
inherited;

PageControl1.ActivePageIndex := 0;

fUsers := TLMSUsers.Create;

fLMSUsersTreeView := TLMSUsersTreeView.Create(self);
fLMSUsersTreeView.Parent := TabControl1;
fLMSUsersTreeView.Parent := TabSheet1;
fLMSUsersTreeView.Align := alClient;
fLMSUsersTreeView.LMSUsers := fUsers;
end;
Expand Down
28 changes: 22 additions & 6 deletions LMSNetworkUnit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ TLMSCourse = class
constructor Create(const LMS: TLMS);

procedure RefreshEnrolledUsers;
function GetCourseRoles(aCourseRoles: TStringlist): cardinal;
procedure GetCourseRoles(aCourseRoles: TStringlist);
function GetUserCountByRol(const aRole: string): cardinal;

// Pointer to the LMS parent
Expand Down Expand Up @@ -123,6 +123,9 @@ TLMS = class(TComponent)
procedure SetUser(const Value: string);
function GetHost: string;

procedure MyOnFunctionNotAdded(Sender: TLMSRestMoodle;
const aFunctionName: string);

public
Id: string;
autoconnect: boolean;
Expand Down Expand Up @@ -243,6 +246,7 @@ function TLMS.connected: boolean;
constructor TLMS.Create(Owner: TComponent);
begin
aLMSConnection := TLMSRestMoodle.Create(self);
aLMSConnection.OnFunctionNotAdded := MyOnFunctionNotAdded;

categories := TList<TLMSCategory>.Create;
courses := TList<TLMSCourse>.Create;
Expand Down Expand Up @@ -286,13 +290,14 @@ procedure TLMS.GetCourses;
aCourse: TLMSCourse;
aCourses: TJSonArray;
course: TJSONValue;
aCourseCategory: TLMSCategory;
begin
log('Retrieving LMS Courses - may take some time');
aCourses := aLMSConnection.GetCourses;

if aCourses <> nil then
begin
log(aCourses.ToString);
//log(aCourses.ToString);
for course in aCourses do
begin
aCourse := TLMSCourse.Create(self);
Expand All @@ -308,8 +313,13 @@ procedure TLMS.GetCourses;
aCourse.fullname := course.GetValue<string>('fullname');
aCourse.displayname := course.GetValue<string>('displayname');
aCourse.groupmode := course.GetValue<cardinal>('groupmode');
GetCategoryById(course.GetValue<cardinal>('categoryid'))
.fcourses.add(aCourse);

// Have to check because the category function service could not be enable
aCourseCategory := GetCategoryById
(course.GetValue<cardinal>('categoryid'));
if aCourseCategory <> nil then
aCourseCategory.fcourses.add(aCourse);
//

end;
end;
Expand Down Expand Up @@ -349,6 +359,12 @@ function TLMS.GetUsersByFirstName(var aLMSUsers: TLMSUsers;
result := aLMSUsers.count;
end;

procedure TLMS.MyOnFunctionNotAdded(Sender: TLMSRestMoodle;
const aFunctionName: string);
begin
log('error not service function not defined ' +afunctionname+ ' please added it in the LMS service functions');
end;

function TLMS.GetHost: string;
begin
result := aLMSConnection.Host;
Expand Down Expand Up @@ -431,7 +447,7 @@ constructor TLMSCourse.Create(const LMS: TLMS);

end;

function TLMSCourse.GetCourseRoles(aCourseRoles: TStringlist): cardinal;
procedure TLMSCourse.GetCourseRoles(aCourseRoles: TStringlist);
var
aUser: TLMSUser;
begin
Expand Down Expand Up @@ -465,7 +481,7 @@ procedure TLMSCourse.RefreshEnrolledUsers;

if aUsers <> nil then
begin
log(aUsers.ToString);
//log(aUsers.ToString);
for User in aUsers do
begin
aUser := TLMSUser.Create;
Expand Down
Loading

0 comments on commit a4340d1

Please sign in to comment.