Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Event Calendar + File Download


Go to End


1168 Views

Avatar
sav_ss

Community Member, 11 Posts

22 December 2010 at 3:58pm

Hi All,

I have the event calendar module installed, I like it very much and I would like to extend it a bit so that I can allow a file download associated with a calendar event (eg. Download a registration form). I have made the following changes and I need some help figuring out why they didn't work:

CalendarEvent.php

    static $has_many = array (
        ...
        'Resources' => 'Resource'
    );

My resource class is exactly as found at http://doc.silverstripe.org/modules:dataobjectmanager (excepting I included different categories).
    public function getCMSFields()
    {
        $f = parent::getCMSFields();
        ...
        $manager = new FileDataObjectManager(
            $this,
            'Resources',
            'Resource',
            'Attachment',
            array(
                'Name' => 'Name', 
                'Description' => 'Description', 
                'Category' => 'Category'
            ), 
            'getCMSFields_forPopup'
        );
        $f->addFieldToTab("Root.Content.Files",$manager);
        return $f;

    }

When I log onto the CMS the extra 'Files' tab is there for a calendar event as expected, I can go about choosing a file to upload and in list or grid view I can see the file once it's uploaded. The problem I have is (and this might be related to why I cant get the file to show up on the website) when I click on the file a new popup-type window shows with the darkened background but it displays a Silverstripe error:

[User Error] Couldn't run query: SELECT "Resource"."ClassName", "Resource"."Created", "Resource"."LastEdited", "Resource"."Name", "Resource"."Description", "Resource"."Category", "Resource"."AttachmentID", "Resource"."ResourcePageID", "Resource"."ID", CASE WHEN "Resource"."ClassName" IS NOT NULL THEN "Resource"."ClassName" ELSE 'Resource' END AS "RecordClassName" FROM "Resource" WHERE ("ParentID" = '97') Unknown column 'ParentID' in 'where clause'

It's got me buggered.
I'm hoping I can display the file download on the website by modifying CalendarEvent.ss with:

    <% if Resources %>
    <ul>
        <% control Resources %>
            <li>$Name</li>  // Need to know how to hyperlink here.  $Attachment.URL ??
        <% end_control %>
    </ul>
    <% else %>
        <p>This calendar event has no attachments.</p>
    <% end_if %>

I'm new at php and not entirely sure if that's the correct usage of a control block. I'm wondering,
<% control Resources %>
should fetch me an array of Resource objects? How can I find out what member attributes of Resource I can access?

That's a rather long-winded description of the problem, I hope it's clear. Help at this stage would be much appreciated.

Cheers!