Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Using Poll for Quizzes View modes: 
User avatar
Member
Member
theplastictoy - 8/23/2011 9:48:04 AM
   
Using Poll for Quizzes
Hi all,

We need to implement a Widget that allows for both Polls and Quizzes. The difference is that, when a quiz is used, instead of showing the vote count, we show if the answer is correct or wrong.

Apart from changing the Poll web part, we also need to implement some way of chosing a correct answer in the backend.

Anyone has any experience building something simillar and wants to share know-how?

Any feedback would be greatly appreciated.

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 8/24/2011 4:08:31 AM
   
RE:Using Poll for Quizzes
Hi,

first of all you will need to clone a poll web part. It uses PollView control which source code you can find in ~/CMSModules/Polls/Controls/PollView.ascx. You can copy paste it and rename for example QuizView. Then in the cloned poll web part change path to control to use your QuizView.

Now you will need to add a custom field IsCorrectAnswerto Polls_PollAnswer table. This can be done easily using field editor in the Site Manager - Development - System tables. The table is not visible in this location by default. To change it you need to update column ClassShowAsSystemTable in the CMS_Class table. Look for class with name Polls - PollAnswer and change value of column ClassShowAsSystemTable to True. Now you are able to add a custo boolean field into table.

Now you can modify UI of the CMS Desk - Tools - Polls - <edit poll> answers:

1. First of all you need to change grid definition in the file ~/CMSModules/Polls/Controls/AnswerList.xml and add a following line into xml file:

<column source="IsCorrectAnswer" caption="$IsCorrectAnswer$" wrap="false" />


2. Now you can change AnswerList file in the same location:

- in the Page_Load method add a column name:
uniGrid.Columns = "AnswerID, AnswerText, AnswerCount, AnswerEnabled, IsCorrectAnswer";

3. Finally, to be able to modify value of your answer modify AnswerEdit file:
- to Set fields section (around 202 line) add a line with SetValue:

          
// Set the fields
pollAnswerObj.AnswerEnabled = chkAnswerEnabled.Checked;
pollAnswerObj.AnswerText = txtAnswerText.Text.Trim();
pollAnswerObj.AnswerCount = ValidationHelper.GetInteger(this.txtVotes.Text, 0);
pollAnswerObj.SetValue("IsCorrectAnswer", chckCorrect.Checked);


- chckCorrect is an additional control inserted on markup:
        
<tr>
<td class="FieldLabel">
<cms:LocalizedLabel runat="server" ID="LocalizedLabel1" EnableViewState="false"
Text="CorrectAnswer" DisplayColon="true" />
</td>
<td>
<asp:CheckBox ID="chckCorrect" runat="server" Checked="true" />
</td>
</tr>


- and in Load field section add a line with ValidationHelper (around line 150):

// Load the fields
txtAnswerText.Text = pollAnswerObj.AnswerText;
chkAnswerEnabled.Checked = pollAnswerObj.AnswerEnabled;
txtVotes.Text = pollAnswerObj.AnswerCount.ToString();
chckCorrect.Checked = ValidationHelper.GetBoolean(pollAnswerObj.GetValue("IsCorrectAnswer"),false);
plcVotes.Visible = true;


The last thing is to modify your Quiz view control to check if the selected value is correct and display and provide an appropriate information to your user.

Best regards,
Ivana Tomanickova

User avatar
Member
Member
theplastictoy - 8/24/2011 4:52:32 AM
   
RE:Using Poll for Quizzes
Hi Ivana,

Thanks for the super-detailed explanation! :) This is a major help.

In our case, there's more than one website on the same kentico installation, but this shouldn't break any existing usage of the Poll part, correct?

Many thanks,
Ricardo

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 8/24/2011 5:17:53 AM
   
RE:Using Poll for Quizzes
Hi,

it will modify the Tools part (for each site), but the poll web part itself should not be effected in case you create a cloned copy of it and copy of control it is using. But you are right. To do not have any issue in the future, it would be better if you created a custom module: How to create a custom module in Kentico CMS This way you will be able to export the quizz module and apply hotfixes.
As for your custom module development - you will need to copy and rename the polls files.

Best regards,
Ivana Tomanickova

User avatar
Member
Member
theplastictoy - 8/24/2011 8:12:47 AM
   
RE:Using Poll for Quizzes
Guess I'll go with the custom module solution. A bit more work to do, but way more reusable and less impact on the overall system.

Many thanks for the wonderful support.

Regards,
Ricardo

User avatar
Member
Member
theplastictoy - 8/24/2011 10:47:29 AM
   
RE:Using Poll for Quizzes
Hi Ivana,

One last question: i'm going to need some SQL tables for storing data. Custom tables are not an option, as it's not possible to add foreign keys to them (if I'm wrong, correct me).

Is there a preferred way of adding custom sql tables for a custom module?

Thanks,
Ricardo

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 8/27/2011 4:49:14 AM
   
RE:Using Poll for Quizzes
Hi,

you can add a foreign key reference to custom tables, but only on database level. Then they will not be editable in a UI. When you create a custom table it has some fields created by default, which are probably not needed in this case.

Therefore you could create document types tables and store values using data class API:
data layer code example

As for foreign key reference - there is no way how add them in UI - it has to be done directly in the database.

Best regards,
Ivana Tomanickova