jDownloadsownloads.com

Advertisement
Advertisement:

Author Topic: Mapping native "Viewing access levels" to jdownloads 'groups'  (Read 7928 times)

0 Members and 1 Guest are viewing this topic.

Offline marcodings

  • Newbie
  • *
  • Posts: 20
Hi,

Just wanted to share my temp fix for mapping joomla native "Viewing access levels" to the jdownloads groups.
I got a headache keeping both "systems" in sync and waiting for a permanent solution by jdownloads itself i created a "manual" fix.
The fix affect jdownloads groups that have "exacly" the same name as an existing viewing access level in joomla, the members
authorised at the viewing level are "looked up and inserted" into the jdownloads groups.

Code: [Select]
            // Get a db connection.
            $db = JFactory::getDbo();
            $now = JFactory::getDate();
             
            $query = $db
                ->getQuery(true)
                ->select(array('title','rules'))
                ->from('#__viewlevels')
                ->innerJoin('#__jdownloads_groups ON #__viewlevels.title = #__jdownloads_groups.groups_name');             
            $db->setQuery($query);             
            $group_viewlevels = $db->loadObjectList();
           
            if ($group_viewlevels!=null) {
                // we have jdownloads groups, matching viewlevels
                foreach ($group_viewlevels as $group_viewlevel) {
                    //printf("%s %s\n",$group_viewlevel->title,$group_viewlevel->rules);
                   
                    //Get a list of all the users in the groups   
                    $query = $db
                        ->getQuery(true)
                        ->select(array('user_id'))
                        ->from('#__user_usergroup_map')
                        ->where('group_id IN (' . implode(',',json_decode($group_viewlevel->rules)) . ')');                       
                    $db->setQuery($query);                     
                    $usergroup_mapping = $db->loadObjectList();
                   
                    //process each group
                    $userlist=array();
                    if ($usergroup_mapping != null) {
                        foreach ($usergroup_mapping as $usergroup_map) {
                            $userlist[]=$usergroup_map->user_id;
                        };
                    }
                    //update jdownloads with users if not empty
                    if(!empty($userlist)) {
                        // printf("%s\n",implode(',', array_unique($userlist)));
                        $fields     = array('groups_members=\''. implode(',', array_unique($userlist)) .'\'',
                                            'groups_description=\'autosynced:'.$now.'\'',
                                            'groups_access=1');
                        $conditions = array('groups_name=\''. $group_viewlevel->title . '\'');
                        $query = $db->getQuery(true);
                        $query->update('#__jdownloads_groups')
                            ->set($fields)
                            ->where($conditions);
                        $db->setQuery($query);                         
                        try {
                            $result = $db->execute();
                            // Use $db->execute() for Joomla 3.0.
                        } catch (Exception $e) {
                            printf("UPDATE ERROR %s",$query);                           
                        }
                    }
                };
            }

Use the code in a article or custom html module to execute, or put it in a cli application..

Yes i understand i could automate it more, provide the module and whatnot.. However relying
on a speedy release of a new version i spare myself the effort at this time.

Hope it is of use to anybody..

Offline iafe2003

  • Newbie
  • *
  • Posts: 3
I need help.
excuse my English.
What should I do to integrate it into joomla?
can you explain it more simple. please.

thank you very much

Offline Arno

  • Administrator
  • ***
  • Posts: 12.110
    • jDownloads.com
Hi,
i will try to create a short plugin for this.
Wait a day or two.
Best Regards / Gruß
Arno
Please make a Donation for jDownloads and/or write a review on the Joomla! Extensions directory!

Offline iafe2003

  • Newbie
  • *
  • Posts: 3
thank you very much!

Offline Arno

  • Administrator
  • ***
  • Posts: 12.110
    • jDownloads.com
Okay, here is it.
Tested with Joomla 2.5 and 3.1.
Please try it and post here your results.

Many thanks at marcodings...  ;)
Best Regards / Gruß
Arno
Please make a Donation for jDownloads and/or write a review on the Joomla! Extensions directory!

Offline iafe2003

  • Newbie
  • *
  • Posts: 3
works fine on joomla 2.5.
no problems.
keep trying with more access levels.
Thank you very much for your time and response.

Offline Arno

  • Administrator
  • ***
  • Posts: 12.110
    • jDownloads.com
I have found again a small bug in the component when you delete all users from a group and have fixed it.
Will publish later a fixed component release and also publish a newer plugin in download area.
Best Regards / Gruß
Arno
Please make a Donation for jDownloads and/or write a review on the Joomla! Extensions directory!

 

Advertisement