Commit 83219b6c by german

Cambios al recuperar la escena activa de un estudiante de la bbdd del PCB (Falta…

Cambios al recuperar la escena activa de un estudiante de la bbdd del PCB (Falta mirar el issue #248)
parent de0b59c2
......@@ -51,7 +51,6 @@ public abstract class Action {
Log.d("TIMESTAMP-----------> ", datetime.format(currentTime));
if (PCBcontext.getPcbdb().getCurrentUser().has_supervisor()) {
jsonObject.put(param_id_sup, PCBcontext.getPcbdb().getCurrentUser().get_id_sup());
Log.i("TAG_PRUEBAS","ACTION_ID_SCENE: "+PCBcontext.getPcbdb().getCurrentUser().get_active_scene());
jsonObject.put(param_id_scene, PCBcontext.getPcbdb().getCurrentUser().get_active_scene());
}
//TODO Decidir qué almacenar con DEVICE
......
......@@ -55,7 +55,6 @@ public class PCBDBHelper extends SQLiteOpenHelper {
* @see PCBDBHelper#getCurrentUser()
*/
public void setCurrentUser(User user) {
Log.i(LOG_TAG,"user "+user.get_name_stu()+" "+" Scene:"+user.get_active_scene()+" attributes:"+user.get_json_attrs());
this.currentUser = user;
PCBcontext.getDevice().setLastStuId(user.get_id_stu());
if (user.is_supervisor()) PCBcontext.getDevice().setLastSupId(user.get_id_sup());
......@@ -163,7 +162,7 @@ public class PCBDBHelper extends SQLiteOpenHelper {
String sql_scene="INSERT OR REPLACE INTO scene VALUES ("
+params.getInt("id")
+","+params.getInt("supervisor")
+","+params.get("student")
+","+params.getInt("student")
+",'"+params.getString("name")
+"','"+params.getBoolean("active")
+"','"+params.getBoolean("categories")
......@@ -172,7 +171,9 @@ public class PCBDBHelper extends SQLiteOpenHelper {
getWritableDatabase().execSQL(sql_scene);
//Added
//PCBcontext.getPcbdb().getCurrentUser().set_active_scene(params.getInt("id"));
sql_scene = "UPDATE student SET id_scene = "+params.getInt("id")+" WHERE id = "+params.getInt("student");
getWritableDatabase().execSQL(sql_scene);
} catch (JSONException e) {
e.printStackTrace();
Log.e(LOG_TAG,"Error setting active scene:"+e.getMessage());
......@@ -186,16 +187,10 @@ public class PCBDBHelper extends SQLiteOpenHelper {
*/
public int getActiveSceneForStudent(int id_stu){
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT id FROM scene WHERE id_stu = "+id_stu,null);
Cursor cursor = db.rawQuery("SELECT id_scene FROM student WHERE id = "+id_stu,null);
cursor.moveToFirst();
int id;
if(cursor.getCount() > 0){
id=cursor.getInt(0);
Log.e(LOG_TAG," Active scene id:"+id);
return cursor.getInt(0);
}
return -1;
Log.i(LOG_TAG,"Scene: "+cursor.getInt(0)+"-- For student: "+id_stu);
return cursor.getInt(0);
}
/**
......@@ -209,7 +204,6 @@ public class PCBDBHelper extends SQLiteOpenHelper {
Cursor cursor = db.query("scene",new String[]{"categories"},"id=?",new String[]{String.valueOf(id_scene)},null,null,null,null);
boolean has_categories;
cursor.moveToFirst();
int id;
if(cursor.getCount() > 0){
has_categories=cursor.getString(0).equals("true");
}
......@@ -223,8 +217,8 @@ public class PCBDBHelper extends SQLiteOpenHelper {
* @see com.yottacode.pictogram.dao.Picto
*/
public Vocabulary getStudentVocabulary(Vocabulary vocabulary ) throws JSONException {
int id_stu = this.getCurrentUser().get_id_stu();
int id_scene = this.getCurrentUser().get_active_scene();
int id_stu = this.currentUser.get_id_stu();
int id_scene = getActiveSceneForStudent(id_stu);
SQLiteDatabase db = this.getReadableDatabase();
......@@ -258,9 +252,8 @@ public class PCBDBHelper extends SQLiteOpenHelper {
for (Picto picto : vocabulary) {
Log.i(LOG_TAG,"inserting "+picto.get_id()+":"+picto.get_translation()+":"+picto.get_json_attrs()+"-id_sce: "+PCBcontext.getPcbdb().getCurrentUser().get_active_scene());
values.put("id_picto", picto.get_id());
values.put("id_scene", PCBcontext.getPcbdb().getCurrentUser().get_active_scene());
values.put("id_scene", getActiveSceneForStudent(id_stu));
values.put("id_stupicto", picto.get_stupicto_id());
values.put("url", picto.get_url());
values.put("translation",picto.get_translation());
......
......@@ -251,22 +251,11 @@ public class User {
* @return The id of the active scene of this student
*/
public int get_active_scene() {
/*try {
return this.attributes_stu.getInt(JSON_STUDENT_ATTTRS.ID_ACTIVE_SCENE);
} catch (JSONException e) {
e.printStackTrace();
}
return -1;*/
return this.id_scene_stu;
}
public void set_active_scene(int id) {
//try {
this.id_scene_stu = id;
//this.attributes_stu.put(JSON_STUDENT_ATTTRS.ID_ACTIVE_SCENE,id);
/*} catch (JSONException e) {
e.printStackTrace();
}*/
this.id_scene_stu = id;
}
/**
*
......
......@@ -77,7 +77,6 @@ public final class PCBcontext {
@Override
public void change(User updatedStudent) {
Log.i(getClass().getCanonicalName(),"ID: "+updatedStudent.get_active_scene()+"--ID_UPDAT:"+PCBcontext.getPcbdb().getCurrentUser().get_active_scene());
PCBcontext.getDevice().insertUser(updatedStudent);
if (updatedStudent.is_picto_size_big()!=getPcbdb().getCurrentUser().is_picto_size_big() || PCBcontext.getVocabulary().has_categories() != vocabulary.has_categories()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment