Forums | Mahara Community

Developers /
My Forum posts plugin


Wullie's profile picture
Posts: 252

09 December 2011, 4:10

Hi,

I would like to develop (unless someone has already developed one) a plugin that pulls through all of a users forum posts together into one place to be added as an artefact on a page (depending on which forums/groups that the user selects from a form).

I have it started and I have a few questions

1) Whats the best way to pull out the page owner userid so that I can match this to the poster id from the forum?

2) What's the difference between a blocktype and an artefact, so that I know where this should be placed?

3) I know that I'll have to be aware of viewing permissions (e.g student X posts in forums for 5 groups, lecturer Y is owner of 3 of those groups, so should only be able to see posts from those 3 groups). What's the best way for me to handle this?

Thanks in advance

Gregor Anželj's profile picture
Posts: 349

09 December 2011, 5:15

1) $USER->get('id')

2) You create an artefact, when you expect that users will do/create some content/artefacts within Mahara. When you expect that users have created some content elswhere and you just want to e.g. embed that content inside Mahara view/page, than you create a blocktype.

In your case you should create a blocktype, but because you will pull forum posts I think it would be most appropriate, that you create a bolcktype of an artefact (forum in this case, but forum stuff is inside htdocs/interaction, and not htdocs/artefact/forum). So maybe  you should start at

htdocs/interaction/blocktype/userposts or
htdocs/interaction/blocktpye/alluserposts

You should check with core developer team, if that is OK (I mean, if you could create a blocktype inside htdocs/interaction, since there isn't any yet.) Than take a look at htdocs/artefact/{artefactname}/blocktype sub-direcrories to get an idea, how to start...

HTH,
Gregor

Kristina Hoeppner's profile picture
Posts: 4863

09 December 2011, 17:40

Hello Wullie,

That sounds like a great idea. Sometimes it's really frustrating when you can't find a forum post when you only know which person posted it.

One additional cool feature would be to be able to see all forum posts of a person when you click on a link below their name in the forums. That would be where I would start to see all posts of a person. Otherwise, you'd always have to rely on the person themselves to put it into a block on a page (profile?) where you can see it.

Do you want to make this block available in all pages or just on the profile page like the wall? Not all blocks are visible in all contexts (cf. http://manual.mahara.org/en/latest/blocks/context.html ).

Do you already have an idea of how to display the forum posts? Whether to display posts only from one or two etc. specific forums?

Cheers

Kristina

Wullie's profile picture
Posts: 252

12 December 2011, 3:06

Kristina,

Glad you like the idea.

I had actually envisaged it being a block able to be added to any created page.

One of my lecturers asked if there was a way he could group all of a students posts together so that he could grade his/her contributions to the forums, which I thought was a reasonable idea.

With regards to clicking on their name to get all posts, I'm not sure where I'd need to start with that.

With regards to displaying, I was thinking of using the existing Recent Forum Posts block (and adapting the form to be multiple forums to select rather than just one, although I'll need to ask how to do that) and the block would check the page owner ID against the forum post ID and only display those posts (poss adding a link at the bottom to view more than last 5 posts or something similar).

Hope that makes sense

Kristina Hoeppner's profile picture
Posts: 4863

18 December 2011, 15:24

Hello Wullie,

Sorry for the late reply.

1. Group posts: Thanks for the explanation. It makes sens to have the posts then not just on the profile page, but also on any portfolio page. Being able to multi-select the forums which you wish to display becomes necessary then. I would have also suggested the Recent Forum Posts block.

2.The number of posts you want to display could be flexible like in the recent journal posts.

3. Posts by a person when clicking on their name: I guess that is more difficult as we don't have any page in Mahara where to display such information. It would pretty much be the display of all forum posts by that person but not on a page that the user created.

Unfortunately, I can't help with any coding ideas.

All the best and I look forward to seeing what you come up with.

Cheers

Kristina

Wullie's profile picture
Posts: 252

13 December 2011, 10:01

OK,

I've managed to get it split to per user displaying forum posts for each selected group.

My next question is how to get more than 1 group selected.

For reference, I am using the current 'recentforumposts' block as a starter position and from looking at the code, I need to figure out how to get more than one group selection out of the get_group() function into an array and then I can loop through each of the groups to display.

At the moment, in the configuration block, the group selection is done by selecting a single instance from a drop-down box. Is there any suggestions or blocks I can look at that have checkboxes for multiple selections?

Any help, as always, would be greatly appreciated.

Thanks

Wullie's profile picture
Posts: 252

15 December 2011, 10:19

OK, on the user group selection, I've figured that I need to change the type to chekbox, but I've no ideas about pieforms and not sure what settings need to be applied to populate each of the group names.

Anyone any ideas?

Gregor Anželj's profile picture
Posts: 349

16 December 2011, 1:34

I don't think you need to change type to checkbox. I believe you should leave it as select and add multiple option like this (see lines around 150):

$elements['groupid'] =  array(
'type'  => 'select',
  'title' => get_string('group', 'blocktype.recentforumposts'),
    'options' => $choosablegroups,
    'collapseifoneoption' => false,
    'defaultvalue' => $groupid,
    'rules' => array(
    'required' => true,
    ),
    'multiple' => true,
);

This should allow user to select more than one option in select drop-down box by holding SHIFT or CTRL key and clicking the options...

HTH,
Gregor

Wullie's profile picture
Posts: 252

16 December 2011, 9:02

Thanks Gregor,

I had a hunch that there would be a simple solution and I was overthinking it and it turns out to be the case.

So, after adapting that and adding/tweaking a lot of arrays and then a v quick getting up to speed on smarty (at least enough to get me by), I've completed my plugin.

At the moment, this is in my /blocktype folder where I'll leave it to do more testing, but I'm wondering who would be the best person to speak to re: best location for it (you said yourself that possibly in the /interaction/blocktype would be better)?

Thanks again for your help.

Wullie's profile picture
Posts: 252

19 December 2011, 5:54

Gregor,

At the moment, the instance_config_form  is proving a bit of a pain for me. Normally, I can put in print_r statements to see what is going on with the data on the page and can code from there, but when I try to put those into the instance_config form function, it hangs when I click to configure so I can't see what's going on.

My issue at the moment is that the default value in the $elements assignment above is not populating because I have more than one group selected (and even if not, because the group selection is an array, none are selected).

I had hoped to see what values were appearing where and had hoped to assign the default value to each previously selected value/group, but can't see what is going on.

Any suggestions a) why the print_r statement hangs my config form, b) how I can fix it to see what values are in the variables/arrays and c) can I assign an array to the default value and how do I do that?

Thanks in advance

13 results