コード例 #1
0
	//
	// LMS Get User Enrollment
	// args: contentID and callback
	// NOTE: sets only last item in list complete
	//

	public void LMSGetUserEnrollment( string contentID, LMSCourseInfoCallback callback=null )
	{
		if ( LMSIsValidLogin() == false )
		{
			string error = "LMSGetUserEnrollment(" + contentID + ") authkey not set or not valid!";
			UnityEngine.Debug.LogError(error);
			if ( callback != null )
				callback(false,error,contentID,null,null);
		}
		else
			StartCoroutine(lmsGetUserEnrollment(contentID,callback));
	}
コード例 #2
0
	IEnumerator lmsGetUserEnrollment( string contentID, LMSCourseInfoCallback callback  )
	{
		// make JSON
		JSONObject j = new JSONObject(JSONObject.Type.OBJECT);
		//number
		j.AddField("action", "User_Enrollments");
		// make param area
		JSONObject arr = new JSONObject(JSONObject.Type.ARRAY);
		j.AddField("params", arr);
		// add params
		arr.AddField ("content_id",contentID);
		// add authkey
		string keyNoQuotes = pingAuthKey.Replace ("\"","");
		j.AddField ("authKey",keyNoQuotes);
		// get bodystring
		string bodyString = j.print();
		
		// Create a download object
		string url = "http://" + URL + "statefull/get";
		WWW download = new WWW(url,Encoding.ASCII.GetBytes(bodyString),pingHeaders);
		yield return download;
		
		LMSDebug ("lmsGetUserEnrollment(" + contentID +")");
		LMSDebug ("lmsGetUserEnrollment(" + pingAuthKey + ") text=<" + download.text + "> error=<" + download.error + "> bodystring=<" + bodyString + ">");
		
		string DBResult;
		string DBErrorString;
		
		// create new list
		LMSCoursesUsingContent = new List<LMSCourseInfo>();
		
		if (download.error != null)
		{
			// save the error
			DBResult = "";
			DBErrorString = download.error;
			if ( callback != null )
				callback(false,"error",contentID,null,download);
		}
		else
		{
			DBResult = "ok";
			// decode
			JSONObject decoder = new JSONObject(download.text);
			if ( CheckReturn(decoder) == true )
			{
				var N = JSONNode.Parse(download.text);				
				JSONClass tryme = N["params"] as JSONClass; 
				if ( tryme != null && tryme.Count > 0 )
				{
					//string status=tryme[0];
					//string enrollment_id=tryme.Key(0);
					// this is new method syntax
					string status=tryme["course_status"];
					string enrollment_id=tryme["enrollment_id"];
					LMSCoursesUsingContent.Add (new LMSCourseInfo(contentID,enrollment_id.Replace("\"",""),"",status.Replace("\"","")));
				}
				// do callback
				if ( callback != null )
				{
					// if we have courses then send back list otherwise return null
					if ( LMSCoursesUsingContent.Count > 0 )
						callback(true,"enrolled",contentID,LMSCoursesUsingContent,download);
					else
						callback(true,"not_enrolled",contentID,null,download);
				}
			}
			else
			{
				var N = JSONNode.Parse(download.text);				
				string code = N["params"]["code"].ToString ().Replace ("\"",""); 
				string msg = N["params"]["msg"].ToString ().Replace ("\"",""); 
				LMSDebug("lmsGetUserEnrollment(" + contentID +") : code=<" + code + "> : msg=<" + msg + ">");
				// no enrollments, return reason why
				if ( callback != null )
					callback(true,msg,contentID,null,download);
			}
		}
	}
コード例 #3
0
	IEnumerator lmsGetCoursesUsingContent( string contentID, LMSCourseInfoCallback callback  )
	{
		//string bodyString = "{\"action\":\"Catalog_ContentAdoptingCourses\",\"params\":{\"content_id\":\"" + contentID + "\"},\"authKey\":" + pingAuthKey + "}";

		// make JSON
		JSONObject j = new JSONObject(JSONObject.Type.OBJECT);
		//number
		j.AddField("action", "Catalog_ContentAdoptingCourses");
		// make param area
		JSONObject arr = new JSONObject(JSONObject.Type.ARRAY);
		j.AddField("params", arr);
		// add params
		arr.AddField ("content_id",contentID);
		// add authkey
		string keyNoQuotes = pingAuthKey.Replace ("\"","");
		j.AddField ("authKey",keyNoQuotes);
		// get bodystring
		string bodyString = j.print();
		
		// Create a download object
		string url = "http://" + URL + "statefull/get";
		WWW download = new WWW(url,Encoding.ASCII.GetBytes(bodyString),pingHeaders);
		yield return download;

		LMSDebug ("lmsGetCoursesUsingContent(" + contentID +")");
		LMSDebug ("lmsGetCoursesUsingContent(" + pingAuthKey + ") text=<" + download.text + "> error=<" + download.error + "> bodystring=<" + bodyString + ">");

		string DBResult;
		string DBErrorString;

		// create new list
		LMSCoursesUsingContent = new List<LMSCourseInfo>();
		
		if (download.error != null)
		{
			// save the error
			DBResult = "";
			DBErrorString = download.error;
			if ( callback != null )
				callback(false,"error",contentID,null,download);
		}
		else
		{
			DBResult = "ok";
			// decode
			JSONObject decoder = new JSONObject(download.text);
			if ( CheckReturn(decoder) == true )
			{
				var N = JSONNode.Parse(download.text);
				// extract courses
				if ( N["params"] != null )
				{
					JSONClass tryme = N["params"]["adopting_courses"] as JSONClass;
					if ( tryme != null )
					{
						for( int i=0 ; i<tryme.Count ; i++)
						{
							JSONNode itemNode = N["params"]["adopting_courses"][i];
							if ( itemNode.Count > 0 )
							{
								LMSCoursesUsingContent.Add (new LMSCourseInfo(contentID/*tryme.Key(i)*/,itemNode[0]["course_enrollment_id"].ToString().Replace("\"",""),itemNode[0]["enrollment_date"].ToString().Replace("\"",""),itemNode[0]["course_status"].ToString().Replace("\"","")));
								#if DEBUG_LIST
								UnityEngine.Debug.LogError("key=" + tryme.Key(i) + " item=" + itemNode.ToString () + " count=" + itemNode.Count);
								UnityEngine.Debug.LogError("course_enrollment_id=" + itemNode[0]["course_enrollment_id"].ToString().Replace("\"",""));
								UnityEngine.Debug.LogError("enrollment_date=" + itemNode[0]["enrollment_date"].ToString().Replace("\"",""));
								UnityEngine.Debug.LogError("course_status=" + itemNode[0]["course_status"].ToString().Replace("\"",""));
								UnityEngine.Debug.LogError(">>>>");
								#endif
							}
						}			
					}
					else
						UnityEngine.Debug.LogError ("lmsGetCoursesUsingContent() : tryme==null");
				}
				else
					UnityEngine.Debug.LogError ("lmsGetCoursesUsingContent() : N[params]==null");
				// do callback
				if ( callback != null )
				{
					// if we have courses then send back list otherwise return null
					if ( LMSCoursesUsingContent.Count > 0 )
						callback(true,"enrolled",contentID,LMSCoursesUsingContent,download);
					else
						callback(true,"not_enrolled",contentID,null,download);
				}
			}
			else
			{
				if ( callback != null )
					callback(false,"error",contentID,null,download);
			}
		}
	}