I added terms to the channel vocabulary. They were 11,12,13,14,15. While they did all display in the grid they were out of numerical order. You can see what I'm talking about here: http://dev-scheduletest1.gotpantheon.com/schedules?month=2014-06-01

Comments

bagelche’s picture

This would be very helpful as our channels are also listed out of numerical order.

avguy’s picture

I tried everything I could think of to sort the channels in the table header and I'm not having any luck. Has there been any more progress on adding a feature to allow that sort?

kreynen’s picture

I don't think it's possible to order the grouping field in a calendar view like this. Instead, the columns need to be reordered in http://cgit.drupalcode.org/cm_tv_schedules/tree/templates/calendar-day.t...

Right at the beginning to the template, after the end of the comments...

 * evenly over the remaining 90% of the table.
 */
?>

You can add...

<?php 
//reorder columns to match taxonomy weight
$reordered_columns = array();
//this only works if the term is linked using taxonomy/term/%"
foreach ($columns as $key => $column):
  $termlinkparts = explode('taxonomy/term/' , $column);
  $tidparts = explode('"' , $termlinkparts[1]);
  $tid = $tidparts[0];
  $term = taxonomy_term_load($tid);
  $reordered_columns[$term->weight] = $column;
endforeach;
ksort($reordered_columns);
$columns = $reordered_columns;
?>

The rest of the template can be left the same. That function parses the term id out of the link, but I'm not really sure why the terms are linked in the first place. Even on http://retn.org/schedules/day, the channel links go to pages like http://retn.org/channel/retn-16-south that only displays the taxonomy term's title. Because taxonomies are fieldable, these pages group be used to display a description of the channel and the linked term might make sense... but I think the link should be removed completely.

If the link is removed, the term object would need to be loaded using taxonomy_get_term_by_name isn't of parsing the link for the tid. For that, you'd add this after the comments and before the HTML div class="calendar-calendar starts...

<?php 
//reorder columns to match taxonomy weight
$reordered_columns = array();
//this only works if the term is not linked
foreach ($columns as $key => $column):
  $vocabulary = taxonomy_vocabulary_load(variable_get('cm_airing_channel_vid'));
  $term = taxonomy_get_term_by_name($column, $vocabulary->machine_name);
  $tid = key($term);
  $reordered_columns[$term[$tid]->weight] = $column;
endforeach;
ksort($reordered_columns);
$columns = $reordered_columns;
?>

I'm sure there is some combination of this that would work regardless of whether the field_airing_channel is linked or not. I didn't submit this as a patch because the code that's needed depends on the field_airing_channel settings. Including the linked or unlinked version would return errors for the other configuration option. Because this can be implemented at the theme level, it also easy to modify without hacking the module's template file. If you copy the calendar-day.tpl.php file into the template directory of your own theme, you can add this code to the template there. That way when the cm_tv_schedules module is updated, it doesn't overwrite your changes.

Hope this helps.

avguy’s picture

I applied the first code snippet in Comment 3 to the calendar template where directed. I got this:

Notice: Undefined offset: 1 in include() (line 37 of /srv/bindings/cc60c9bd2f374ed4bb1cdca128c516af/code/sites/all/modules/cm_tv_schedules/templates/calendar-day.tpl.php).
Notice: Trying to get property of non-object in include() (line 40 of /srv/bindings/cc60c9bd2f374ed4bb1cdca128c516af/code/sites/all/modules/cm_tv_schedules/templates/calendar-day.tpl.php).

avguy’s picture

@kreynen's solution in 3 worked when I added the second snippet and set the view to format the Channel as just plain text.

avguy’s picture

Here's a patch updating the views formatter and adding the second code snippet from 3.

bagelche’s picture

@kreynen implemented snippet #2 for us and now the channels are in the correct order on http://amherstmedia.org/schedules.

emilyf’s picture

Status: Active » Needs work

Most of this snippet works and the second approach is ideal - removing the channel links makes sense. However, this snippet has an issue in that if more than 1 term in the channel taxonomy have not been manually ordered, it will only output one column with the default weight of 0. So let's say you had 5 channels, and you had dragged 3 around on the administration area to order them how you want, but the other two you left alone. Or, more likely, if you have 2 channels that you order manually, then later you add two more channels and they show up correctly on the channel taxonomy administration page so you don't reorder them, they retain the weight of 0. With this snippet, it will only output one of the 2 with the weight of 0.

This could lead to some end user confusion and banging of heads against the wall when people aren't seeing all their channels. I'm sure there is a pretty simple way to rewrite this snippet to account for multiple zero weights, but I won't have time to test that out tonight and this is overdue for a release. If anyone wants to take a stab at that, please feel free and upon more complete testing will roll it into next release.