Page 1 of 1

Cataloger "random" feature doesn't work if count=1

Posted: Wed Feb 21, 2007 6:49 pm
by vaughnt
CMSMS 1.0.4 , Cataloger 0.5.3

I want to pull one random item and display it on a page.

Using this fails:

Code: Select all

{cms_module module='Cataloger' action='random' sub_template='Vaughn-Category-1'  alias='/' count='1'}
gives seven empty item displays. Just the subtemplate code looped through 7 times with no values inserted.
Example: http://www.vaughnsphotoart.com/index.ph ... om-count-1

Using this works:

Code: Select all

{cms_module module='Cataloger' action='random' sub_template='Vaughn-Category-1'  alias='/' count='2'}
gives two random items.
Example: http://www.vaughnsphotoart.com/index.ph ... om-count-2

Here is the code of /modules/Cataloger/action.random.php ... it's short so I'm pasting the whole thing. You can see it has special code for handling when count=1 , but I'm not a programmer and can't diagnose it.

action.recent.php works fine, for what it's worth.

Code: Select all

<?php
                if (!isset($gCms)) exit;
                foreach ($params as $key=>$val)
                        {
                        $this->smarty->assign($key, $params[$key]);
                        }
                if (! isset($params['recurse']))
                        {
                        $params['recurse'] = 'items_all';
                        }
                
                list($curPage,$categoryItems) = $this->getCatalogItemsList($params);
                        
        $count = min(count($categoryItems),$params['count']);
        $thisUrl = $_SERVER['REQUEST_URI'];
        $thisUrl = preg_replace('/(\?)*(\&)*start=\d+/','',$thisUrl);
        if ($count == 1)
                {
                $categoryItems = $categoryItems[array_rand($categoryItems,1)];
                $this->smarty->assign('items',$categoryItems);
                }
        else if ($count == 0)
                {
                $this->smarty->assign('items',array());
                }
        else
                {
                $categoryItemKeys = array_rand($categoryItems, $count);
                $catTmp = array();
                foreach($categoryItemKeys as $thisKey)
                        {
                        array_push($catTmp,$categoryItems[$thisKey]);
                        }
                $this->smarty->assign('items',$catTmp);
                }
        
                
                echo $this->ProcessTemplateFromDatabase($this->getTemplateFromAlias($params['sub_template']));
?>

Thanks for any help you can give.

Re: Cataloger "random" feature doesn't work if count=1

Posted: Mon Mar 05, 2007 7:38 am
by jyin008
Can you explain how to use the random feature? I have tired it, but it didn't show any image at all.

Thanks

Re: Cataloger "random" feature doesn't work if count=1

Posted: Tue Mar 20, 2007 2:50 pm
by vaughnt
Yes, look at the above sample that works. It appears supplying a count greater than 1 is required until the bug is fixed.