Author Topic: Categories pagination  (Read 767 times)

0 Members and 1 Guest are viewing this topic.

Offline remati

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Categories pagination
« on: March 01, 2013, 08:18:35 PM »
Has anyone been able to paginate the categories.tpl page?

I tried adding:

{categories
var=$categories
amount=20
paginate=true
pagination=$pagination}

But that doesn't seem to do the trick. Seems like there needs to be some php code changes to the classes/Template/Compiler.php file.

I tried editing some of the code in the CompileCategoriesTag function to match the CompileVideosTag function since it does pagination. Here is what I currently have:

Code: [Select]
private static function CompileCategoriesTag($attributes)
{
    self::VerifyHasAttributes($attributes, 'categories');

    // Set defaults
    $attributes = array_merge(array('amount' => 25,
                                    'startswith' => null,
                                    'alphabetize' => false,
                                    'paginate' => false,
                                    'page' => '$g_page_number',
                                    'sort' => '`name`'),
                              $attributes);

    self::VerifyRequiredAttributes(array('var'), $attributes, 'categories');
    self::VerifyVariableAttributes(array('var', 'pagination'), $attributes, 'categories');

    $attributes['var'] = self::ParseVars($attributes['var']);
    $attributes['alphabetize'] = self::ToBoolean($attributes['alphabetize']);
    $attributes['paginate'] = self::ToBoolean($attributes['paginate']);

    $DB = GetDB();
    $wheres = array();
    $binds = array();

    // Handle startswith option
    if( !empty($attributes['startswith']) )
    {
        $wheres[] = '`name` LIKE ?';
        $binds[] = self::ParseVarsInString($attributes['startswith']) . " . '%'";
    }

    // Handle custom fields
    foreach( preg_grep('~^_~', array_keys($attributes)) as $field )
    {
        $field = substr($field, 1);

        if( $DB->QueryCount('SELECT COUNT(*) FROM `tbx_category_custom_schema` WHERE `name`=?', array($field)) < 1 )
        {
            throw new CompilerException("Custom field with name '" . $field . "' does not exist");
        }

        $wheres[] = "`$field`=" . self::ParseVarsInString($attributes["_$field"]);
    }

    // Build the query
    $query = "SELECT * FROM `tbx_category` JOIN `tbx_category_custom` USING (`category_id`) LEFT JOIN `tbx_upload` ON `upload_id`=`image_id` " .
             (!empty($wheres) ? 'WHERE ' . join(' AND ', $wheres) . ' ' : '') .
             "ORDER BY " . $attributes['sort'];

    // Handle paginate option
    if( $attributes['paginate'] === true )
    {
        if( isset($attributes['pagination']) )
        {
            $attributes['pagination'] = self::ParseVars($attributes['pagination']);
        }

        $attributes['page'] = self::ParseVars($attributes['page']);

        return self::PHP_START . String::NEWLINE_UNIX .
               '$DB = GetDB();' . String::NEWLINE_UNIX .
               "\$x_result = \$DB->QueryWithPagination($query, array(" . join(',', $binds) . "), " . $attributes['page'] . ", " . $attributes['amount'] . ");" . String::NEWLINE_UNIX .
               (isset($attributes['pagination']) ? $attributes['pagination'] . ' = $x_result;' . String::NEWLINE_UNIX : '') .
               $attributes['var'] . " = \$DB->FetchAll(\$x_result['handle']);" . String::NEWLINE_UNIX .
               self::PHP_END;
    }
    else
    {
        $query .= ' LIMIT ' . $attributes['amount'];

        return self::PHP_START . String::NEWLINE_UNIX .
               '$DB = GetDB();' . String::NEWLINE_UNIX .
               $attributes['var'] . " = \$DB->FetchAll('$query', array(" . join(',', $binds) . "));"  . String::NEWLINE_UNIX .
               ($attributes['alphabetize'] ? "usort(" . $attributes['var'] . ", create_function('\$a, \$b', 'return strcmp(\$a[\\'name\\'], \$b[\\'name\\']);'));". String::NEWLINE_UNIX : '') .
               self::PHP_END;
    }

}

There might be something wrong with the $query mysql because it doesn't seem to work and makes the pages blank. Any suggestions?

Unofficial JMB Support Forums

Categories pagination
« on: March 01, 2013, 08:18:35 PM »


Tags:
 

Related Topics

  Subject / Started by Replies Last post
6 Replies
1671 Views
Last post September 12, 2012, 08:42:04 PM
by gigasexo
0 Replies
782 Views
Last post August 11, 2013, 01:24:48 PM
by darkorns
2 Replies
2497 Views
Last post November 17, 2013, 11:35:05 PM
by Zealotry
0 Replies
734 Views
Last post December 23, 2013, 09:40:04 AM
by punaniman
0 Replies
1137 Views
Last post October 24, 2016, 05:01:03 AM
by tupshr