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

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.
Locked
nivekiam

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

Post 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.
Last edited by nivekiam on Sun Jan 20, 2008 9:11 pm, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

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

Post by calguy1000 »

$uploadsmodule->DoAction(....); should do the trick
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
nivekiam

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

Post 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);
  }
Vin

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

Post 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.
Last edited by Vin on Sat Jan 19, 2008 2:33 pm, edited 1 time in total.
nivekiam

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

Post 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 ;)
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

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

Post by calguy1000 »

Or I don't change the parameters
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
nivekiam

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

Post 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
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

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

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
nivekiam

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

Post by nivekiam »

Thanks for the info.  Yes I looked at the uploads action.do_addcategory, it does a redirect as it's last action.
Vin

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

Post 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
Locked

Return to “CMSMS Core”