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

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
vaughnt
Forum Members
Forum Members
Posts: 82
Joined: Tue Jun 13, 2006 2:05 pm

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

Post 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.
--
My photography: http://vaughnsphotoart.com
Festiva Resorts: http://www.festiva.travel
jyin008

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

Post 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
vaughnt
Forum Members
Forum Members
Posts: 82
Joined: Tue Jun 13, 2006 2:05 pm

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

Post 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.
--
My photography: http://vaughnsphotoart.com
Festiva Resorts: http://www.festiva.travel
Post Reply

Return to “CMSMS Core”