1
alain01
Help to add a memberGroup test
  • 2013/11/14 16:32

  • alain01

  • Just can't stay away

  • Posts: 536

  • Since: 2003/6/20


Hi,
I need to test groups to allow certain actions in the new tinymce filemanager v4...
but it does not work ...

in a config.php (from the filemanager), :
create_folders false;
I would obviously add a test of belonging to group 1 (site administrators) to pass this variable
create_folders true,

If I insert in this config.php file:
Global $ xoopsUser;
$this-> assign ('authorised_groups', array (1)) / / the list of Authorised group id
$this
-> assign ('user_group'is_object ($ xoopsUser) $ xoopsUser-> GetGroups (): array (XOOPS_GROUP_ANONYMOUS));

if (
array_intersect ($ authorised_groups user_group)) {
create_folders true;
}

I have the following error:Quote:
Fatal error: Using $ this When not in object context in config.php on line 30 [/

What should I do?
Thank you!

2
redheadedrod
Re: Help to add a memberGroup test

A short tutorial about the use of $this.
class Foo {
    private 
$variable "Do This"
    public static 
$anotherVariable "Do That";
 
   function 
__construct($setVariable) {
        
$this->variable $setVariable;
        
self::$anotherVariable $setVariable;
   }
   function 
string toString() {
        return 
$this->variable self::$anotherVariable;
   }

}

In this example I show both a class variable and an instance variable.

The class variable in this case is noted with the static keyword and has to be accessed as in this example with the self::$another variable. A class variable is the same variable in every object that uses that class. So if you have 3 different objects of type Foo all three have the same value for $anotherVariable. Changing it in any of the objects will change it in every one. You actually do not need to create an object to use a class variable unless the class is an abstract class. You can NOT use self outside of a class because it will do nothing and will throw an error.

In this example you see an instance variable. This variable only exists when we create an object from this class thus creating an instance. Trying to access it directly from the class will throw an error similar to the one mentioned here. When you use the $this keyword it is refering to the object that contains the function that it resides in. I believe in PHP you HAVE to use $this to access the variable listed here as $variable and it can only be used within the class.

As an example with this class:
$newObject = new Foo();

$newObject->$variable "New value "

Foo::$anotherVariable "Another new Value";

echo 
$newObject->toString();


This would output:
New Value Another new Value


So in your code unless it resides within a class you can not use $this. Use the name of the object you are refering to. So in your example if that function is within $xoopsUser the proper way to use it is:
$xoopsUser -> assign('authorised_groups', array (1));

Also do not forget to use the ';' at the end of the line because it can create weird issues when you forget.

If you are doing this within a class which it does not appear to be the case here based on what you shared then it is likely the missing ';'.

I really should write that tutorial about classes...
Anyhow let me know if this helps...

The error you are getting makes me believe you are trying to use $this outside of a class which is the error you are getting. It has no clue what $this is.

3
alain01
Re: Help to add a memberGroup test
  • 2013/12/2 8:57

  • alain01

  • Just can't stay away

  • Posts: 536

  • Since: 2003/6/20


Tx, redheadedrod,
i read your tutorial, i 've understood what 's you explain, but it's hard to me to develop...

I coded in another way and it works :

// XOOPS 
// 1 : webmasters group
// 2 : members group
// 3 : anonymous group
// 4 : your 1st custom group
// ...
global $xoopsUser;  
$allowed_groups_upload=array(1,2); // id des groupes autorisés en upload 
$allowed_groups_createfolder=array(1); // id des groupes autorisés create folder 
if ($xoopsUser) {   
    
$usergroups $GLOBALS['xoopsUser']->getGroups();  
    
$result_upload array_intersect($usergroups$allowed_groups_upload);  
        if (
$result || $result!=null) {  
           
$upload_files=true;  
        }  
    
$result_createfolder array_intersect($usergroups$allowed_groups_createfolder);  
       if (
$result || $result!=null) {  
           
$create_folders=false;  
        }  

// XOOPS

4
iHackCode
Re: Help to add a memberGroup test

alain01 the logic doesn't look correct, and I would use the $xoopsUser object to keep it consistent.

Try this.
// XOOPS 
// 1 : webmasters group
// 2 : members group
// 3 : anonymous group
// 4 : your 1st custom group
// ...
global $xoopsUser;
$allowed_groups_upload=array(1,2); // id des groupes autorisés en upload 
$allowed_groups_createfolder=array(1); // id des groupes autorisés create folder 
$upload_files false;
$create_folders false;

if (
is_object($xoopsUser)) {   
   
$usergroups $xoopsUser->getGroups();    
   
$result_upload array_intersect($usergroups$allowed_groups_upload);  
   
   if(!empty(
$result_upload)){  
      
$upload_files true;  
   }
   
   
$result_createfolder array_intersect($usergroups$allowed_groups_createfolder);  
   
   if(!empty(
$result_createfolder)){  
      
$create_folders true;  
   }

// XOOPS

Login

Who's Online

316 user(s) are online (212 user(s) are browsing Support Forums)


Members: 0


Guests: 316


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits