Since unflagged content comes in with a flag weight of 0, it makes the sort "ascending" less than optimal since uflagged content comes up first. It would be great to have another views sort option, flagged / not-flagged. That way, you could first sort on flagged items and then by ascending.

Moving to flag queue

Comments

lyricnz’s picture

Normally you would be selecting only those items that were flagged, but okay...

You can set the default weight to whatever you want, can you set it higher?

Unflagged content actually has weight=NULL, while flagged content would have weight=0. Although the default sort uses (views) views_handler_field_numeric, which treats these equivalently. I'm not much of a views expert, so can't yet see how to provide multiple sort handlers to views...

lyricnz’s picture

Okay, the only way I can see to do this, is to make a custom views sort handler, with a new option, that knows about how to put NULL at the top of bottom.

lyricnz’s picture

Status: Active » Needs review
StatusFileSize
new1.9 KB

Phew! I just wrote a new sort handler for Flag Weights that allows you to select whether Flagged content appears at the top or bottom of unflagged content, or naturally wherever it hands. Please try!

chrisschaub’s picture

Awesome, you beat me to it!! Will try tonight.

chrisschaub’s picture

Ok, I've been testing this. I needed to modify the orderby like this ...

$this->query->add_orderby(NULL, $this->table_alias . '.' . $this->real_field . ' IS NULL', $this->options['flagorder']);
$this->query->add_orderby(NULL, $this->table_alias . '.' . $this->real_field, $this->options['flagorder']);

I had to add one more to then sort by the flag's weight.

lyricnz’s picture

StatusFileSize
new1.92 KB

Ahh, I forget to call parent query() - updated patch attached.

chrisschaub’s picture

Hmm, not quite working with patch. I still need the line ...

  function query() {
    if ($this->options['flagorder'] != 'NONE') {
      $this->ensure_my_table();
      $this->query->add_orderby(NULL, $this->table_alias . '.' . $this->real_field . ' IS NULL', $this->options['flagorder']);
      $this->query->add_orderby(NULL, $this->table_alias . '.' . $this->real_field, $this->options['flagorder']);
    }
  }

because it's the order of the order clause. The first part has to be the ordering of the null fields, then the ordering of the flag weights. So, the parent query's orderby would have to come after the null orderby, I think.

I think you have to "unshift" the null orderby clause to be the first orderby clause of the parent query.

chrisschaub’s picture

Just needed to move the parent::query to be after the adding the IS NULL orderby statement, so the IS NULL is first:

  function query() {
    if ($this->options['flagorder'] != 'NONE') {
      $this->ensure_my_table();
      $this->query->add_orderby(NULL, $this->table_alias . '.' . $this->real_field . ' IS NULL', $this->options['flagorder']);
      parent::query();
    }
  }

I think this assures that the parent orderby gets added after the IS NULL statement. Seems to work for me and the view queries look correct.

lyricnz’s picture

StatusFileSize
new1.92 KB

OK. Shows I didn't really look at the ordering, besides first/last... ;)

The parent:: call should be outside the if() clause - so that the results get ordered properly when the flagorder is not set.

chrisschaub’s picture

It's working now for me, thanks.

lyricnz’s picture

Committed to D7

lyricnz’s picture

Status: Needs review » Fixed
vankod’s picture

Please tell me how to configure Flag Weights + Draggable Views in Drupal 7?

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

In wrong queue