Page 1 of 1

[SOLVED] Call module from UDT - User Defined Tag? -- Uploads module

Posted: Fri Jan 18, 2008 2:48 am
by nivekiam
I think I know how to call a module from a UDT:

global $gCms;
$uploadsd = $gCms->modules['Uploads']['object'];
if( $uploadsd )
  {....

I think I even know how to call functions from that module.  But my question has to do more specifically with the Uploads module.  Trying to help out Vin here: http://forum.cmsmadesimple.org/index.ph ... 176.0.html has really got me playing with UDTs and Events.  WOW, what an awesome system!!!

Anyway, the question.  There doesn't appear to be a specific function in the Uploads module that creates the category.  Calguy1000, who I hope pops in here,  mentions something here http://forum.cmsmadesimple.org/index.ph ... l#msg83262 about this specifically.  Can I just call the action.do_addcategory.php file somehow?  How do I pass it the data it needs?  There are functions for most other actions for the Uploads module, but not for addcategory.  At least nothing that I can see.

Thanks in advance for any input here.

Re: Call module from UDT - User Defined Tag? -- Uploads module

Posted: Fri Jan 18, 2008 2:58 am
by calguy1000
$uploadsmodule->DoAction(....); should do the trick

Re: Call module from UDT - User Defined Tag? -- Uploads module

Posted: Fri Jan 18, 2008 3:56 am
by nivekiam
Thanks.

This is where my lack of programming skills kicks in.  There's something wrong with what I'm doing.

When I try to save I get "unexpected T_VARIABLE" on line 14.  I've tried the following just to see if I can get it to save:
    $uploadsmodule->DoAction('do_addcategory', $params);
    $uploadsmodule->DoAction("do_addcategory");
    $uploadsmodule->DoAction('do_addcategory');
    $uploadsmodule->DoAction(do_addcategory);
    $uploadsmodule->DoAction(addcategory);
    $uploadsmodule

So I know something is wrong with that variable.  But I don't know what I'm missing or I've done wrong.  I tried putting it into debug mode, but nothing pops out at me.

Here's the entire bit of code

Code: Select all

//
// Grab CMS object
//
global $gCms;
$name =& $params['name'];
$uploadsmodule = $gCms->modules['Uploads']['object'];

if( $uploadsmodule )
  {
    mkdir("/path/to/uploads/$name", 0700);
    $params = array (
        'input_category' => $name
    )
    $uploadsmodule->DoAction('do_addcategory', $params);
  }

Re: Call module from UDT - User Defined Tag? -- Uploads module

Posted: Sat Jan 19, 2008 2:31 pm
by Vin
Thanks nivekiam!

Looking at your code, I think the problem lies in the $params['name']. Are you sure you've initialized it? (How do you call the tag? From (testing) page, or the Events? In page, you would have to do something like {user_defined_tag name='name_of_the_category'} or something like that, in Events you have to respect the parametres given by the Event (written in (?) in the table with overview of events).

Anyway,I think I've figured it out for the tag. This is what I call for OnCreateUser event:

Code: Select all

global $gCms;
  if( !isset( $gCms->modules['Uploads'] ) || !isset( $gCms->modules['Uploads']['object'] ) )
    {
       return;
    }
  $uploads = $gCms->modules['Uploads']['object'];
  //now parametres
  $name =& $params['name'];
  $params["input_categoryname"]=$params["input_categorypath"] =& $name;
  $uploads->DoAction('do_addcategory', "", $params);
The "" part is because of $id parametre, to be honest, I'm not sure what it means; an id of the page?
Of course, I'd need similar tags for OnUpdateUser etc. as well.

Re: Call module from UDT - User Defined Tag? -- Uploads module

Posted: Sat Jan 19, 2008 4:46 pm
by nivekiam
Awesome thanks!  You've given me a bit more insight into how things work here.  That's a lot less code than what was posted in that other topic and it's more maintainable as if the code to create the category and such ever change the UDT automatically has those changes so long as the name of the action doesn't change ;)

Re: Call module from UDT - User Defined Tag? -- Uploads module

Posted: Sat Jan 19, 2008 4:55 pm
by calguy1000
Or I don't change the parameters

Re: Call module from UDT - User Defined Tag? -- Uploads module

Posted: Sun Jan 20, 2008 5:47 pm
by nivekiam
I guess I choose a poor name for the variable.  I just noticed that do_addcategory is specifically looking for the data from inside an array.

So you would have created a new array to pass to do_addcategory?

I would just like to know what's best practice.

Also, is there a way to make it not redirect to Files tab on Front End File Management (Uploads).  I was able to get it to redirect back to the Users tab on FEU by creating an OnCreateCategory event and using this as my UDT:

$feusers = $gCms->modules['FrontEndUsers']['object'];
$feusers ->myRedirectionToTab( $id, 'users');

However, using that same code in the UDT called by the OnCreateUser event to create a category doesn't seem to work.  It seems I'm in a different scope once the action to create the category is called, or execution of the rest of the UDT stops after that action is called.  I'm not sure and I don't know how to test for that.

o.k.  So I had the UDT try creating a directory before the action is called and after the action is called.  The directory (test_before) before the action is called was created, but the directory (test_after) after the action is called is not.

Can you give a bit more insight into how this works and what's going on or where the best place to ask or read up on this is at?  I've read all the documentation on the wiki I can find and it doesn't go very in depth into this, at least not yet.

Thanks

Re: Call module from UDT - User Defined Tag? -- Uploads module

Posted: Sun Jan 20, 2008 5:55 pm
by calguy1000
I think the uploads action that creates the category is doing it's own redirect so therefore anything after the DoAction call in your udt wouldn't be executed.

And yes, I would create a parameters array to pass into the DoAction call.

Re: Call module from UDT - User Defined Tag? -- Uploads module

Posted: Sun Jan 20, 2008 8:34 pm
by nivekiam
Thanks for the info.  Yes I looked at the uploads action.do_addcategory, it does a redirect as it's last action.

Re: [SOLVED] Call module from UDT - User Defined Tag? -- Uploads module

Posted: Wed Jan 30, 2008 5:42 pm
by Vin
I realized I need to have the files to be listable, but it looks like there's some kind of bug in Uploads