Page Resources Module (where do I hook in)

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
pembo13
New Member
New Member
Posts: 3
Joined: Wed Feb 04, 2009 9:56 pm

Page Resources Module (where do I hook in)

Post by pembo13 »

I haven't seen a module that does this yet, so I am here to find out  how I would go about implementing such a thing.

I would like to allow my users to 'attach' resources to any content type, at least pages and news.

Example use case:
1) User creates a new page
2) Users adds page content and other information
3) User 'attaches' file to page
4) User 'attaches' external link to page
5) User saves page
6) User views page (3 column layout)
7) Right most column has a of the attached links.

This may be doable with the existing system, if so, I'd appreciate a point in that direction. If it isn't, I am prepared to develop the appropriate module to do this.

The module would need to add an 'Attachments' tab to the content type pages (Pages, News). And the module would also need to have a smart tag that I can include in the template. So I am would like to know what is a good module to use as a starting point, and what module hooks/actions would I need to get this behavior.
User avatar
plger
Forum Members
Forum Members
Posts: 196
Joined: Wed Oct 15, 2008 10:38 am

Re: Page Resources Module (where do I hook in)

Post by plger »

As my two cents, I see three kinds of solutions:

A) If you wanted to stick to the cms core and keep it as simple as possible, you could create a page structure like this :
- Page
-  - Links
-  -  - Link1
-  -  - Link2
-  - Files
-  -  - File1
-  -  - File2
where Link1,Link2,File1,File2 are of content-type External link (linking to your urls or to your independently uploaded files)
Then all you need is to create a MenuManager template to display the children of your page.
As for news, the news module already allows you to add custom fields... but as you don't know the number of files and probably don't want to add 20 custom fields, we're having a problem.

B) You could create a new content type which manages this, but as there is much less documentation on this, the creation of content types isn't so easy as other modules. I've done it only twice, and only took the normal content type and added some modifications, so I'm not exactly in the best position to give advices on that. But aside from the difficulty of creating it, this is the ideal solution, as it would allow you to add your 'Attachments' tab to the edit content page. Once again, though, you'd have to find another solution for the news module.
If you choose to do this, you must use RegisterContentType in the module's SetParameters() to register your content type class. As for the class itself, I'd suggest taking a look at the normal content type in lib/classes/contenttypes/Content.inc.php.

C) What seems to me the easiest (but maybe not what you'd like) would be to create a module that manages attachments : when you want to add an attachment, you go to this module, get a list of content pages and news, and choose to add an attachment to it. The attachment is linked to the page or news id, and as such you could easily retrieve them within the page or new's template through a module tag with the specific id. This would be very easy to code, but the downside is that your attachments aren't edited at the same place as the page.
The documentation ( http://wiki.cmsmadesimple.org/index.php/Developers ), the modulemaker module (in the forge), and any good content module (as an example) should help you create the basic structure. As for what is specific to your module, it goes down to retrieving the page and news to put them in combo box or something, and uploading/managing files, all of which is rather simple (should you choose to do this, I can give you the basic code for that)

Hope this helps the discussion,
Pierre-Luc
pembo13
New Member
New Member
Posts: 3
Joined: Wed Feb 04, 2009 9:56 pm

Re: Page Resources Module (where do I hook in)

Post by pembo13 »

Sweet. Thanks for the response.

I really needed some point to start with.

I like your Option C, as everyone I've spoken to so far seems very vague on 'content types'

I'll be attempting Option C this weekend. Any specific modules would be good examples? The only problem I for see is determining the appropriate page/news id esp. with "pretty urls" on.
User avatar
plger
Forum Members
Forum Members
Posts: 196
Joined: Wed Oct 15, 2008 10:38 am

Re: Page Resources Module (where do I hook in)

Post by plger »

Determining the appropriate page or news id is no problem. The cms always knows on which page it is, so we just have to ask it ( $gCms->variables['content_id'] ). As to the news id, in the news detail template you can access it via $entry->id .

I hope I'm not ripping you of the fun, but I'veI created something on the fly with my module maker and modified it. I'd suggest you to start there... I've uploaded it on http://www.chpb.info/ressources-1.1.xml (it won't stay they for months).
pembo13
New Member
New Member
Posts: 3
Joined: Wed Feb 04, 2009 9:56 pm

Re: Page Resources Module (where do I hook in)

Post by pembo13 »

Thanks. That just meant to give me an example of the structure right? I can't actually download the source files with that, can I?
User avatar
plger
Forum Members
Forum Members
Posts: 196
Joined: Wed Oct 15, 2008 10:38 am

Re: Page Resources Module (where do I hook in)

Post by plger »

If you install it in the cms, all the source files will are deployed in modules/ressources.
Post Reply

Return to “Developers Discussion”