#issue #237 closed

parent 1604f61d
......@@ -55,7 +55,7 @@ public class PCBDBHelper extends SQLiteOpenHelper {
* @see PCBDBHelper#getCurrentUser()
*/
public void setCurrentUser(User user) {
Log.i(LOG_TAG,"user "+user.get_name_stu()+" "+user.get_json_attrs());
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());
......@@ -168,7 +168,7 @@ public class PCBDBHelper extends SQLiteOpenHelper {
+"','"+params.getBoolean("active")
+"','"+params.getBoolean("categories")
+"')";
Log.i(LOG_TAG,"Scene to be inserted: "+sql_scene);
Log.i(LOG_TAG,"Scene to be inserted: "+sql_scene+" scenes:"+params.getBoolean("categories"));
getWritableDatabase().execSQL(sql_scene);
//Added
......@@ -187,14 +187,37 @@ 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.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;
}
/**
* Return if a given scene has categories
* @param id_scene
* @return
*/
private boolean getHasCategories(int id_scene){
SQLiteDatabase db = this.getReadableDatabase();
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");
}
else has_categories=false;
return has_categories;
}
/**
* the collection (set of pictos) of the current student
*
* @see com.yottacode.pictogram.dao.Picto
......@@ -205,8 +228,8 @@ public class PCBDBHelper extends SQLiteOpenHelper {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM collection_detail WHERE id_stu = "+id_stu+" AND id_scene = "+id_scene,null);
Log.i(LOG_TAG, "Local recovering " + cursor.getCount() + " pictos for student " + id_stu + " from local DB");
Cursor cursor = db.rawQuery("SELECT id_stu, id_picto, id_scene, id_stupicto, url, translation, attributes FROM collection_detail WHERE id_stu = "+id_stu+" AND id_scene = "+id_scene,null);
Log.i(LOG_TAG, "Local recovering " + cursor.getCount() + " pictos for student " + id_stu + " from local DB Scene:"+id_scene);
cursor.moveToFirst();
if (cursor.getCount()>0) do{
Picto picto = new Picto(cursor.getInt(1), cursor.getString(4), cursor.getInt(3), new JSONObject(cursor.getString(6)));
......@@ -214,7 +237,7 @@ public class PCBDBHelper extends SQLiteOpenHelper {
}while (cursor.moveToNext());
cursor.close();
//db.close(); <--no es necesario cerrar la bbdd https://groups.google.com/forum/#!msg/android-developers/NwDRpHUXt0U/jIam4Q8-cqQJ
vocabulary.setHas_categories(getHasCategories(id_scene));
return vocabulary;
}
......@@ -233,7 +256,7 @@ public class PCBDBHelper extends SQLiteOpenHelper {
values.put("id_stu", id_stu);
db.beginTransaction();
for (Picto picto : vocabulary) {
Log.i(LOG_TAG,"inserting "+picto.get_id()+":"+picto.get_translation()+":"+picto.get_json_attrs()+"-id_sce: "+getActiveSceneForStudent(id_stu));
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());
......
......@@ -3,7 +3,6 @@ package com.yottacode.pictogram.dao;
import android.content.Context;
import android.graphics.Bitmap;
import com.yottacode.pictogram.net.PictoUploader;
import com.yottacode.pictogram.tools.Img;
import org.json.JSONException;
......@@ -31,7 +30,6 @@ public class User {
public final static class JSON_STUDENT_ATTTRS{
public enum delivery {clean, one, many}
static String ID_ACTIVE_SCENE = "id_active_scene";
static String INPUT_FEEDBACK = "input_feedback";
static String INPUT_SELECTION = "input_selection";
static String PICTOGRAM_SIZE ="size";
......
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