Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

can some one help me, please?

edited March 2012 in Vanilla 2.0 - 2.8

hi I'm new in this so I need a little help...
i'm using vanilla to create a new forum but I need that all the Discussion to have a picture, so I decided to create a new table in DB called gnd_discussion_picture(id_discussion,picture_name) but I don't have Idea where do I need to add the code insert and consult this data when some one create a Discussion or when all the Discussion are called to display.

so I need to know how vanilla receives the request to receive the new image, how it transport the info between layers(controllers, etc) and how to insert and consult this data, tanks.

Best Answer

  • Options
    jspautschjspautsch Themester ✭✭✭
    edited March 2012 Answer ✓

    You don't need to create a whole new table for this, you can define a plugin and inside it add a column to the Discussion table:

    class DiscussionPicture extends Gdn_Plugin
    {
        public function Setup()
        {
            $this->Structure();
        }
    
        public function Structure()
        {
            Gdn::Structure()
            ->Table('Discussion')
            ->Column('PicturePath', 'varchar(255)')
            ->Set();
        }
    }
    

    That column would contain a path to where the image is located.

    Then to display an image on the discussion listing, you need to create an event handler (If you look at /applications/vanilla/views/discussions/helper_functions.php there are 3 events that might work depending on where you want to display the image: BeforeDiscussionContent, AfterDiscussionTitle, and BeforeDiscussionMeta) in your plugin to add in the image code, something like this:

    public function DiscussionsController_BeforeDiscussionContent_Handler($Sender)
    {
        $Discussion = $Sender->EventArguments['Discussion'];
        echo '<img src="' . $Discussion->PicturePath . '">';
    }
    

    Using DiscussionsController should work, but try Base if it doesn't.

    Adding the form elements to allow users to select a discussion picture is probably the most difficult part, you would need to hook into an event on the discussion form, you can look through /applications/vanilla/views/post/discussion.php to see what events are there (e.g. DiscussionFormOptions). You can look through that view to get an idea of what the syntax is for adding form elements, and you can also look at /applications/dashboard/views/profile/picture.php to see how to do a file upload form.

    Also take a look at the Vanilla Wiki to learn more about how Vanilla works.

Answers

  • Options
    mcu_hqmcu_hq yippie ki-yay ✭✭✭
    edited March 2012

    There is no easy event to hook into for this modification. Look into /categories/all.php in your views folder. Find this:

    ($Category->Depth == 1)

    Then you will need to load your image depending on the CatID.

    The rest of your questions sound like you have not read any documentation. Read through the example plugin and you should know what to do.

  • Options
    jspautschjspautsch Themester ✭✭✭
    edited March 2012 Answer ✓

    You don't need to create a whole new table for this, you can define a plugin and inside it add a column to the Discussion table:

    class DiscussionPicture extends Gdn_Plugin
    {
        public function Setup()
        {
            $this->Structure();
        }
    
        public function Structure()
        {
            Gdn::Structure()
            ->Table('Discussion')
            ->Column('PicturePath', 'varchar(255)')
            ->Set();
        }
    }
    

    That column would contain a path to where the image is located.

    Then to display an image on the discussion listing, you need to create an event handler (If you look at /applications/vanilla/views/discussions/helper_functions.php there are 3 events that might work depending on where you want to display the image: BeforeDiscussionContent, AfterDiscussionTitle, and BeforeDiscussionMeta) in your plugin to add in the image code, something like this:

    public function DiscussionsController_BeforeDiscussionContent_Handler($Sender)
    {
        $Discussion = $Sender->EventArguments['Discussion'];
        echo '<img src="' . $Discussion->PicturePath . '">';
    }
    

    Using DiscussionsController should work, but try Base if it doesn't.

    Adding the form elements to allow users to select a discussion picture is probably the most difficult part, you would need to hook into an event on the discussion form, you can look through /applications/vanilla/views/post/discussion.php to see what events are there (e.g. DiscussionFormOptions). You can look through that view to get an idea of what the syntax is for adding form elements, and you can also look at /applications/dashboard/views/profile/picture.php to see how to do a file upload form.

    Also take a look at the Vanilla Wiki to learn more about how Vanilla works.

Sign In or Register to comment.