How would i create this block?

How would i create this block?

by Kaiser Riaz -
Number of replies: 11

Hi guys iam interested in creating a similar block that is shown in this video



Did this person use javascript or YUI. I am in need of an example.  Another question i have is how does the input form get the string that is entered is it possible with the command get_string ? and does he use mformlib or just html form 

Average of ratings: -
In reply to Kaiser Riaz

Re: How would i create this block?

by Rosario Carcò -

If I see correctly, this is already a Moodle Block. So simply ask for it there if it was not published yet. Then you simply modify questions and answers.

This could also be a simple HTML-Block you can insert into every course. So you would only need to introduce your javascript-code into this HTML-Block and your are done. With this version the problem is that you can not insert it into every course unless you copy the hmtl/javascript code into each single HTML-Block.

So if you want this Block to appear in Moodle's Block-List, so that you can select and insert it into every course, you would have to program it as Moodle-Block.

Rosario

In reply to Rosario Carcò

Re: How would i create this block?

by Kaiser Riaz -

Hi i tried to search for the block on moodle but couldnt find anything about it so I am currently programming a moodle block and i was thinking of using moodle javascript book as a guide because it uses the YUI features like input ox text band button, which i think i can insert into a block not too sure. The book shows me a few methods on adding javascript to php pages but doesnt say how to add it into blocks. Is it possible if i can add YUI to blocks ? 

Also how would i get the inputted text from the input field?

In reply to Kaiser Riaz

Re: How would i create this block?

by Rosario Carcò -

a) to program a Moodle Block, the learning courve is very steep

b) best way is to take an existing block (search for it) that does more or less what you want to do and then start modifying line by line until it does, what you want to do.

c) you have to study also all the built in Moodle blocks, to see how it works

d) YUI and other javascript libraries are possible to integrate. You have to read the according docs

e) to send data back to the server you have to implement GET/PUT Forms

f) the question is, whether you need to send something back to the server or not. The example you show does certainly send NOTHING back to the server. I guess this is pure javascript containing every expected question and answer. There is no artificial intelligence behind it. If it were, then you would have a big job to do to reinvent human interaction parsing and "understanding" what humans ask and what the correct answer might be...

g) if you really send back data to the server, you would have the problem of reloading the page or part of it the whole time

Rosario

In reply to Rosario Carcò

Re: How would i create this block?

by Kaiser Riaz -

Hi rosario thanks for the reply. I think for now i will just make it similar to the example just ask the question that are stored in the code. If you have some spare time is it possible of giving me an example on how to do this. 

In reply to Kaiser Riaz

Re: How would i create this block?

by Kaiser Riaz -

I've been trying to add my javascript file to my block but it's giving me error messages. 

require_once(dirname(__FILE__) . '../../../config.php');
$PAGE->set_context(get_context_instance(CONTEXT_BLOCK));
$PAGE->set_url('localhost');
$PAGE->requires->js('blocks/helloworld/javascript/yui_test.js');

error: Undefined variable: PAGE

i also tried to use the require_js () it says its deprecerated so use the $PAGE->requires->js

In reply to Kaiser Riaz

Re: How would i create this block?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

If you are insid the block code, you should not be writing code like this. The block will already be inside another page, so no need for you to require config.php or set up $PAGE.

You should just be able to do $this->page->requires->js('blocks/helloworld/javascript/yui_test.js'); inside your code.

In reply to Kaiser Riaz

Re: How would i create this block?

by Rosario Carcò -

Please take this simple Block I use with youngsters to teach them how to program php and web directly in Moodle.

Rosario

Average of ratings: Useful (1)
In reply to Rosario Carcò

Re: How would i create this block?

by Kaiser Riaz -

thxs matewink

 

Do you think i could search for questions that are inputted by a the sql database and then reply back the asnwers? in your previous post you said it would be a problem when refreshing the page couldnt i use ajax so it wouldnt need to refresh the page

In reply to Kaiser Riaz

Re: How would i create this block?

by Rosario Carcò -

I do not konw AJAX , but I read the YUI docs when I was looking for a faster rendering of my siteNavigation Block. There is a technique to partially refresh the display by sending a request to the server. This could indeed help you to store the questions and answers on the server. Read in my siteNavigation Block thread if you need that YUI explanations I already forgot.

Rosario