OpenSource For You

The solution

-

Design: On the click of a button, the names of all the users registered on the site should be displayed on the screen. Using the MVC pattern, we can divide the design into three components: 1. Forms to display the button and the result. 2. Class/es that provide/s functions to store and retrieve the data to be used for processing the input and producing the output. 3. A controller to maintain a link between the forms and the classes. The controller will decide which function to call and what data to send or retrieve to/ from the class/es. The model is independen­t of the view, i.e., it is unaware of the current form being displayed to the user. The model interacts only with the controller, although it is, in a way, associated with the view as well.

Please note, since Moodle provides its own APIs to connect to the database and perform database operations, we need not explicitly write the code to do so.

Code: The user should be provided with an interface to view all the users. This can be achieved with the help of a form that consists of a button with the text ‘List All Users’.

When the user clicks on the button, the controller will retrieve all the users’ details from the model, which will retrieve the details from the database on the server. The result will be given back to the view to make appropriat­e changes on the form.

Hence, the model class will contain methods as follows (the entire code has not been specified):

The following is the code for the view, with a list and a button:

Newspapers in English

Newspapers from India