[FEU, Uploads] Help upgrading a UDT for CMSMS 2.x

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
jamaa
Forum Members
Forum Members
Posts: 10
Joined: Fri Oct 09, 2015 1:29 pm

[FEU, Uploads] Help upgrading a UDT for CMSMS 2.x

Post by jamaa »

I need help upgrading a UDT for CMSMS 2.x

The UDT was originally posted here.

It is called as follows in the template:

Code: Select all

{feu_upload_cats userid=feu_smarty::get_current_userid() permit='1' assign='categories'}
The result of the UDT was then assigned to the variable $categories in the template.

The UDT looks like this:

Code: Select all

# UDT to return the list of FEU uploads categories a FEU user has access to, (or not).
#$params['userid']; # The numeric FEU user id.
#$params['permit']; # 1 -> return permitted categories, 0 -> return not permitted categories.
#$params['prefix'] ; # An optional prefix to add to each returned category name.

$smarty =& cmsms()->GetSmarty();
$db =& cmsms()->GetDb();

$ug = array();    #List of groups the user belongs to.
$cg = array();    #List of groups having access to a category.
$test = array();  #The intersection of ug and cg.
$cn = array();    #List of categories the user has access to, (or not).

$permit = $params['permit']; #1 -> return permitted categories, 0 -> return not permitted categories.

#Find all groups the user belongs to.
$sql = 'SELECT groupid FROM cms_module_feusers_belongs WHERE userid="' . $params['userid'] .'";';
$dbresult =& $db->Execute($sql);
while ($dbresult && $row = $dbresult->FetchRow()) {
  $ug[] = $row['groupid'];
}

#Find all category names and the list of groups having access to each category.
$sql = 'SELECT upload_category_name,upload_category_groups FROM  cms_module_uploads_categories WHERE upload_category_listable="1" ORDER BY upload_category_description;';
$dbresult =& $db->Execute($sql);

#For each category, match the list of groups having access with the list of groups the user belongs to.
while ($dbresult && $row = $dbresult->FetchRow()) {
  $cg = split( '[,]', $row['upload_category_groups']);
  $test = array_intersect( $ug, $cg);
  if ( (count($test) > 0 && $permit > 0) || (count($test) == 0 && $permit == 0) ) {
     $cn[] = $params['prefix'] . $row['upload_category_name'];
  }
}

if ( empty($params['assign']) ) {
  echo join( $cn, ','); #Return list of categories as a string.
} else {
  $smarty->assign( $params['assign'], $cn); #Return list of categories as an array.
}
As far as I know, $smarty->assign no longer works in CMSMS 2? What is the current proper way to assign the result of the UDT to a variable in the template calling the UDT?
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1978
Joined: Mon Jan 29, 2007 4:47 pm

Re: [FEU, Uploads] Help upgrading a UDT for CMSMS 2.x

Post by Jo Morg »

jamaa wrote:As far as I know, $smarty->assign no longer works in CMSMS 2? What is the current proper way to assign the result of the UDT to a variable in the template calling the UDT?
It still works, however the $smarty variable is already in scope and re-assigning it breaks the code. And the code is relatively old too...
I would start by replacing:

Code: Select all

$smarty =& cmsms()->GetSmarty();
$db =& cmsms()->GetDb();
by

Code: Select all

$db = cmsms()->GetDb();
The rest of the UDT will probably still work, but no warranties.
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
jamaa
Forum Members
Forum Members
Posts: 10
Joined: Fri Oct 09, 2015 1:29 pm

Re: [FEU, Uploads] Help upgrading a UDT for CMSMS 2.x

Post by jamaa »

Thanks for the reply, seems to work for now!
Post Reply

Return to “Modules/Add-Ons”