private Filter filterUserAssignedByOthers(
      Context context, ProducteevUser user, long currentUserId) {
    String title = context.getString(R.string.producteev_FEx_responsible_title, user.toString());
    ContentValues values = new ContentValues();
    values.put(Metadata.KEY.name, ProducteevTask.METADATA_KEY);
    values.put(ProducteevTask.ID.name, 0);
    values.put(ProducteevTask.CREATOR_ID.name, 0);
    values.put(ProducteevTask.RESPONSIBLE_ID.name, user.getId());
    Filter filter =
        new Filter(
            user.toString(),
            title,
            new QueryTemplate()
                .join(ProducteevDataService.METADATA_JOIN)
                .where(
                    Criterion.and(
                        MetadataCriteria.withKey(ProducteevTask.METADATA_KEY),
                        TaskCriteria.isActive(),
                        TaskCriteria.isVisible(),
                        Criterion.not(ProducteevTask.CREATOR_ID.eq(currentUserId)),
                        ProducteevTask.RESPONSIBLE_ID.eq(user.getId()))),
            values);

    return filter;
  }
  /** @param context */
  public static Filter filterFromList(
      Context context, ProducteevDashboard dashboard, long currentUserId) {
    String dashboardTitle = dashboard.getName();
    String title = dashboard.getName();
    ContentValues values = new ContentValues();
    values.put(Metadata.KEY.name, ProducteevTask.METADATA_KEY);
    values.put(ProducteevTask.DASHBOARD_ID.name, dashboard.getId());
    values.put(ProducteevTask.ID.name, 0);
    values.put(ProducteevTask.CREATOR_ID.name, 0);
    values.put(ProducteevTask.RESPONSIBLE_ID.name, 0);
    Filter filter;
    if (currentUserId != -1)
      filter =
          new Filter(
              dashboardTitle,
              title,
              new QueryTemplate()
                  .join(ProducteevDataService.METADATA_JOIN)
                  .where(
                      Criterion.and(
                          MetadataCriteria.withKey(ProducteevTask.METADATA_KEY),
                          TaskCriteria.isActive(),
                          TaskCriteria.isVisible(),
                          Criterion.or(
                              ProducteevTask.CREATOR_ID.eq(currentUserId),
                              ProducteevTask.RESPONSIBLE_ID.eq(currentUserId)),
                          ProducteevTask.DASHBOARD_ID.eq(dashboard.getId()))),
              values);
    else
      filter =
          new Filter(
              dashboardTitle,
              title,
              new QueryTemplate()
                  .join(ProducteevDataService.METADATA_JOIN)
                  .where(
                      Criterion.and(
                          MetadataCriteria.withKey(ProducteevTask.METADATA_KEY),
                          TaskCriteria.isActive(),
                          TaskCriteria.isVisible(),
                          ProducteevTask.DASHBOARD_ID.eq(dashboard.getId()))),
              values);

    return filter;
  }
Exemple #3
0
  @Override
  public void applyToFilter(Filter filter) {
    String query = filter.getSqlQuery();

    query = query.replaceAll("ORDER BY .*", "");
    query =
        query
            + String.format(
                " ORDER BY %s, %s, %s, %s",
                Task.DELETION_DATE, Task.COMPLETION_DATE, getOrderString(), Task.CREATION_DATE);
    query = query.replace(TaskCriteria.isVisible().toString(), Criterion.all.toString());

    filter.setFilterQueryOverride(query);
  }
  /**
   * Cursor with the following columns
   *
   * <ol>
   *   <li>task title, string
   *   <li>task importance color, int android RGB color
   *   <li>task due date (was: preferred due date), long millis since epoch
   *   <li>task due date (was: absolute due date), long millis since epoch
   *   <li>task importance, integer from 0 to 3 (0 => most important)
   *   <li>task id, long
   *   <li>task tags, string tags separated by |
   * </ol>
   *
   * @return cursor as described above
   */
  public Cursor getTasks() {

    MatrixCursor ret = new MatrixCursor(TASK_FIELD_LIST);

    TodorooCursor<Task> cursor =
        taskService.query(
            Query.select(Task.ID, Task.TITLE, Task.IMPORTANCE, Task.DUE_DATE)
                .where(Criterion.and(TaskCriteria.isActive(), TaskCriteria.isVisible()))
                .orderBy(SortHelper.defaultTaskOrder())
                .limit(MAX_NUMBER_OF_TASKS));
    try {
      int[] importanceColors = Task.getImportanceColors(ctx.getResources());
      Task task = new Task();
      for (int i = 0; i < cursor.getCount(); i++) {
        cursor.moveToNext();
        task.readFromCursor(cursor);

        StringBuilder taskTags = new StringBuilder();
        TodorooCursor<Metadata> tagCursor = TagService.getInstance().getTags(task.getId());
        try {
          for (tagCursor.moveToFirst(); !tagCursor.isAfterLast(); tagCursor.moveToNext())
            taskTags.append(tagCursor.get(TagService.TAG)).append(TAG_SEPARATOR);
        } finally {
          tagCursor.close();
        }

        Object[] values = new Object[7];
        values[0] = task.getValue(Task.TITLE);
        values[1] = importanceColors[task.getValue(Task.IMPORTANCE)];
        values[2] = task.getValue(Task.DUE_DATE);
        values[3] = task.getValue(Task.DUE_DATE);
        values[4] = task.getValue(Task.IMPORTANCE);
        values[5] = task.getId();
        values[6] = taskTags.toString();

        ret.addRow(values);
      }
    } finally {
      cursor.close();
    }

    return ret;
  }