I was getting a bug where the "top videos" block wasn't getting put in the right order. So this patch fixed that problem for me and also orders it based on the download_counter + the play_counter. It could be changed so there is seperate "most played" and "most downloaded" blocks, if people think that is a good idea i could do it. So if no one sees any problems with this new code i'll commit it to CVS.

Original code:

function video_block_list($type = 'top') {
  $orderby = ($type == 'new') ? 'n.created' : 'v.download_counter';
  return node_title_list(db_query_range(db_rewrite_sql(
      "SELECT DISTINCT(n.nid), n.title FROM {node} n, {video} v
      WHERE n.type = 'video' AND n.status = 1 AND n.moderate = 0
      ORDER by $orderby DESC"),0, 10));
}

Updated code:

function video_block_list($type = 'top') {
  $orderby = ($type == 'new') ? 'n.created' : 'v.download_counter + v.play_counter';
  return node_title_list(db_query_range(db_rewrite_sql(
      "SELECT n.nid, n.title FROM {node} n, {video} v
      WHERE n.nid = v.nid AND n.type = 'video' AND n.status = 1 AND n.moderate = 0
      ORDER BY $orderby DESC"),0, 10));
}
CommentFileSizeAuthor
#5 video.module.block.patch4.56 KBLukeLast
#1 video.module_0.patch1020 bytesLukeLast

Comments

LukeLast’s picture

StatusFileSize
new1020 bytes

Here it is in patch form.

fax8’s picture

Status: Needs review » Reviewed & tested by the community

+1 for me. feel free to commit.

Also like the idea to add most played, most downloaded. but still leave top videos.
which sums played and downloaded counters.

LukeLast’s picture

committed a couple patches to CVS.

I'll look at adding the 2 extra blocks. Do you know how to get options displayed on the block options page? I was thinking it would be a good idea to have an option defining how many items should be shown in the block there.

LukeLast’s picture

Status: Reviewed & tested by the community » Fixed
LukeLast’s picture

Status: Fixed » Needs review
StatusFileSize
new4.56 KB

Here are the updated block functions. This patch basically adds "Most played videos" and "Most downloaded" blocks, as well as adding an option in the block configuration page to set the number of videos to list in each block and allows the customization of the block display title.

Here are the updated functions.

function video_block($op = 'list', $delta = 0, $edit = array()) {
  if ($op == 'list') {
    $blocks[0]['info'] = t('Latest videos');
    $blocks[1]['info'] = t('Top videos');
    $blocks[2]['info'] = t('Most played videos');
    $blocks[3]['info'] = t('Most downloaded');
    return $blocks;
  }
  elseif ($op == 'view') {
    switch ($delta) {
      case 0:
        return array(
          'subject' => variable_get('video_block_title_0', t('Latest videos')),
          'content' => video_block_list($delta)
        );
      case 1:
        return array(
          'subject' => variable_get('video_block_title_1', t('Top videos')),
          'content' => video_block_list($delta)
        );
      case 2:
        return array(
          'subject' => variable_get('video_block_title_2', t('Most played videos')),
          'content' => video_block_list($delta)
        );
      case 3:
        return array(
          'subject' => variable_get('video_block_title_3', t('Most downloaded')),
          'content' => video_block_list($delta)
        );
    }
  }
  elseif ($op == 'configure') {
    switch ($delta) { //Get the default title of the block incase the variable is not set yet.
      case 0:
        $default_title = t('Latest videos');
        break;
      case 1:
        $default_title = t('Top videos');
        break;
      case 2:
        $default_title = t('Most played videos');
        break;
      case 3:
        $default_title = t('Most downloaded');
    }
    $output = form_textfield(t('Block display title'), 'video_block_title',
      variable_get("video_block_title_$delta", $default_title), 20, 40);
    $output .= form_select(t('Number of videos to list in block'), 'video_block',
      variable_get("video_block_limit_$delta", 10),
      drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)));
    return $output;
  }
  elseif ($op == 'save') {
    variable_set("video_block_title_$delta", $edit['video_block_title']);
    variable_set("video_block_limit_$delta", $edit['video_block']);
  }
}

function video_block_list($delta = 0) {
  switch ($delta) {
    case 0:
      $orderby = 'n.created';
      break;
    case 1:
      $orderby = 'v.download_counter + v.play_counter';
      break;
    case 2:
      $orderby = 'v.play_counter';
      break;
    case 3:
      $orderby = 'v.download_counter';
  }
  return node_title_list(db_query_range(db_rewrite_sql("SELECT n.nid, n.title FROM {node} n, {video} v
    WHERE n.nid = v.nid AND n.type = 'video' AND n.status = 1 AND n.moderate = 0 ORDER BY $orderby DESC"),
    0, variable_get("video_block_limit_$delta", 10)));
}

I've tested everything and it's been working nicely. If no one can see any problems i'll commit it to CVS.

LukeLast’s picture

Status: Needs review » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)