00001
00002
00003
00004
00005
00006
00007
00008
00009 #import "Moodle.h"
00010 #import "MoodleAuthenticator.h"
00011 #import "MoodleCallProtocol.h"
00012
00013 @implementation Moodle
00014
00015 @dynamic loggedIn;
00016
00017 - (id) init
00018 {
00019 self = [super init];
00020
00021 if (nil != self) {
00022 protocol = [[MoodleCallProtocol alloc] init];
00023 call = [[RMCall alloc] initWithProtocol:protocol];
00024 }
00025
00026 return self;
00027 }
00028
00029 - (void) dealloc
00030 {
00031 [authenticator release];
00032 [session release];
00033 [call release];
00034 [protocol release];
00035 [super dealloc];
00036 }
00037
00038 - (void) sync
00039 {
00040 protocol.async = NO;
00041 }
00042
00043 -(void) login:(NSString*) username password:(NSString*) password
00044 {
00045 if (nil != authenticator && nil != session) {
00046 [self logout];
00047 }
00048 authenticator = [[MoodleAuthenticator alloc]
00049 initWithUsername:username password:password];
00050 session = [[RMSession alloc] initWithAuthenticator:authenticator
00051 call:call];
00052 [session authenticate];
00053 }
00054
00055 - (BOOL) loggedIn
00056 {
00057 return session.authenticated;
00058 }
00059
00060 -(void) logout
00061 {
00062 [session call:@"logout" arguments:nil];
00063 [authenticator release];
00064 authenticator = nil;
00065 [session release];
00066 session = nil;
00067 }
00068
00069 -(void) getCourses:(id)delegate
00070 {
00071 [session call:@"get_courses" arguments:nil delegate:delegate];
00072 }
00073
00074 -(void) getCourse:(NSInteger) courseId delegate:(id)delegate
00075 {
00076 [session call:@"get_courses"
00077 arguments:[NSDictionary dictionaryWithObjectsAndKeys:
00078 [NSNumber numberWithInt:courseId], @"value",
00079 @"id", @"idfield", nil]
00080 delegate:delegate];
00081 }
00082
00083 -(void) getMyCourses:(id)delegate
00084 {
00085 [session call:@"get_my_courses" arguments:nil delegate:delegate];
00086 }
00087
00088 -(void) getResources:(NSInteger) courseId delegate:(id)delegate
00089 {
00090 [session call:@"get_resources"
00091 arguments:[NSDictionary dictionaryWithObjectsAndKeys:
00092 [NSArray arrayWithObject:[NSNumber numberWithInt:courseId]], @"value",
00093 @"id", @"idfield", nil]
00094 delegate:delegate];
00095 }
00096
00097 -(void) getTeachers:(NSInteger) courseId delegate:(id)delegate
00098 {
00099 [session call:@"get_teachers"
00100 arguments:[NSDictionary dictionaryWithObjectsAndKeys:
00101 [NSNumber numberWithInt:courseId], @"value",
00102 @"id", @"idfield", nil]
00103 delegate:delegate];
00104 }
00105
00106 -(void) getStudents:(NSInteger) courseId delegate:(id)delegate
00107 {
00108 [session call:@"get_students"
00109 arguments:[NSDictionary dictionaryWithObjectsAndKeys:
00110 [NSNumber numberWithInt:courseId], @"value",
00111 @"id", @"idfield", nil]
00112 delegate:delegate];
00113 }
00114
00115 -(void) getActivities:(NSInteger) courseId delegate:(id)delegate
00116 {
00117 [session call:@"get_activities"
00118 arguments:[NSDictionary dictionaryWithObjectsAndKeys:
00119 [NSNumber numberWithInt:courseId], @"value",
00120 @"id", @"idfield", nil]
00121 delegate:delegate];
00122 }
00123
00124 -(void) getLastChanges:(NSInteger) courseId delegate:(id)delegate
00125 {
00126 [session call:@"get_last_changes"
00127 arguments:[NSDictionary dictionaryWithObjectsAndKeys:
00128 [NSNumber numberWithInt:courseId], @"value",
00129 @"id", @"idfield", nil]
00130 delegate:delegate];
00131 }
00132
00133
00134 @end