add new post

add new post

by Leen Q. -
Number of replies: 4

Hello,

I need a way to add a new post to a discussion forum by php code ... I tried forum_add_new_post function

but I couldn't use it well .. is there anyone that used this function before? or have another way to do the target?

Average of ratings: -
In reply to Leen Q.

Re: add new post

by Dan Poltawski -
What was the problem you faced? Did you get an error message? Did you have debug set to developer level?
In reply to Dan Poltawski

Re: add new post

by Leen Q. -

Thanks a lot Mr. Dan I solved the problem  (it was with the $post object that I created in the code)  smile

However.. do you know how I can get the url of profile picture for a particular user from moodle?

I need to display the user picture in my application

I found "user_picture" function which display the user image only .. I need the url !!! or even the picture file name

In reply to Leen Q.

Re: add new post

by Dan Poltawski -
Its complicated wink

You should be able to do it by creating an instance of the user_picture class and calling get_url(). (Look at that class in lib/outputcomponents.php).

(Edit: I see you've asked in another thread).
Average of ratings: Useful (1)
In reply to Leen Q.

Re: add new post

by Leen Q. -

Hello,, I'm sorry sad


I used the following function from moodle :

forum_add_new_post($post, null, $message);

to add new post for a new discussion forum


I generated the following object called $post in order to get the information that are needed 

$post = new stdClass();
$post->course         = "5";
$post->forum         = "2";
$post->discussion    = "19";
$post->parent        = "19";
$post->d_subject     = "a new test";
$post->subject       = 'Re: '.$post->d_subject;
$post->message       = 'Test .. Add new post';
$post->messageformat = 1;
$post->messagetrust  = 0;
$post->groupid = -1;
$post->itemid  = 0;


in the beginning I didn't have any problem with this .. but today when I tried to rewrite it I found the error in the attached image.

all my old file has been deleted by mistake from one week only ... I collected my codes again but I have problem with this ... I didn't remember how I solved its problem sad

there's something missing here, maybe the post object is not correct, right?


waiting you ... the time will finish soon sad


Attachment Untitled-1.png