Skip to content

Commit

Permalink
version 0.4.0: now with polls too
Browse files Browse the repository at this point in the history
  • Loading branch information
bihor committed Feb 15, 2019
1 parent 489f5bf commit 33dcfea
Show file tree
Hide file tree
Showing 18 changed files with 335 additions and 23 deletions.
1 change: 1 addition & 0 deletions Classes/Controller/QuizController.php
Expand Up @@ -285,6 +285,7 @@ public function doAll(\Fixpunkt\FpMasterquiz\Domain\Model\Quiz $quiz) {
$persistenceManager->persistAll();
}
$pages = intval(ceil($questions / $questionsPerPage));
$debug .= "\nqs/qpn=" . $questions . '/' . $questionsPerPage . '=' . $pages;
$showAnswersNext = 0;
if ($page > $pages) {
// finale Auswertung ...
Expand Down
69 changes: 69 additions & 0 deletions Classes/Hooks/ItemsProcFunc.php
@@ -0,0 +1,69 @@
<?php
/***************************************************************
* Copyright notice
*
* (c) 2010 Georg Ringer <typo3@ringerge.org>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/*
* modified 2019 by Kurt Gusbeth
*/
namespace Fixpunkt\FpMasterquiz\Hooks;

/**
* Userfunc: Individuelles...
*
* @package fp_masterquiz
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*
*/
class ItemsProcFunc {

/**
* Itemsproc for templateLayouts
*
* @param array &$config configuration array
* @return void
*/
public function user_templateLayout(array &$config) {
$row = $this->getContentElementRow($config['row']['uid']);
// $pid = $config['row']['pid']; geht nicht mehr
$pid = $row['pid'];
$templateLayoutsUtility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Fixpunkt\\FpMasterquiz\\Utility\\TemplateLayout');
$templateLayouts = $templateLayoutsUtility->getAvailableTemplateLayouts($pid);
foreach ($templateLayouts as $layout) {
$additionalLayout = array(
$GLOBALS['LANG']->sL($layout[0], TRUE),
$layout[1]
);
array_push($config['items'], $additionalLayout);
}
}

/**
* Get tt_content record
*
* @param int $uid
* @return array
*/
protected function getContentElementRow($uid)
{
return \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('tt_content', $uid);
}
}
66 changes: 66 additions & 0 deletions Classes/Utility/TemplateLayout.php
@@ -0,0 +1,66 @@
<?php
/***************************************************************
* Copyright notice
*
* (c) 2014 Frans Saris <franssaris@gmail.com>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/*
* modified 2019 by Kurt Gusbeth
*/
namespace Fixpunkt\FpMasterQuiz\Utility;

/**
* TemplateLayout: Template-Layout per TSconfig
*
* @package fp_masterquiz
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*
*/
class TemplateLayout implements \TYPO3\CMS\Core\SingletonInterface {

/**
* Get available template layouts for a page
*
* @param int $pageUid
* @return array
*/
public function getAvailableTemplateLayouts($pageUid) {
$templateLayouts = array();
foreach($this->getTemplateLayoutsFromTsConfig($pageUid) as $templateKey => $title) {
$templateLayouts[] = array($title, $templateKey);
}
return $templateLayouts;
}

/**
* Get template layouts defined in TSconfig
*
* @param $pageUid
* @return array
*/
protected function getTemplateLayoutsFromTsConfig($pageUid) {
$templateLayouts = array();
$pagesTsConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig($pageUid);
if (isset($pagesTsConfig['tx_fpmasterquiz.']['templateLayouts.']) && is_array($pagesTsConfig['tx_fpmasterquiz.']['templateLayouts.'])) {
$templateLayouts = $pagesTsConfig['tx_fpmasterquiz.']['templateLayouts.'];
}
return $templateLayouts;
}
}
15 changes: 15 additions & 0 deletions Configuration/FlexForms/flexform_pi1.xml
Expand Up @@ -26,6 +26,21 @@
</config>
</TCEforms>
</switchableControllerActions>
<settings.templateLayout>
<TCEforms>
<label>LLL:EXT:fp_masterquiz/Resources/Private/Language/locallang_be.xlf:templateLayout</label>
<config>
<type>select</type>
<itemsProcFunc>Fixpunkt\FpMasterquiz\Hooks\ItemsProcFunc->user_templateLayout</itemsProcFunc>
<items>
<numIndex index="0" type="array">
<numIndex index="0"></numIndex>
<numIndex index="1"></numIndex>
</numIndex>
</items>
</config>
</TCEforms>
</settings.templateLayout>
<settings.startPageUid>
<TCEforms>
<label>LLL:EXT:fp_masterquiz/Resources/Private/Language/locallang_be.xlf:settings.startPageUid</label>
Expand Down
5 changes: 4 additions & 1 deletion Configuration/TypoScript/setup.ts
Expand Up @@ -57,8 +57,11 @@ plugin.tx_fpmasterquiz {
wrapQuestionTitle2 = </h4></div>
wrapQuestionDesc1 = <div class="mx-auto">
wrapQuestionDesc2 = </div>
wrapDone1 = <h4>
wrapDone2 = </h4>
}
overrideFlexformSettingsIfEmpty = startPageUid,defaultQuizUid,pagebrowser.itemsPerPage
templateLayout =
overrideFlexformSettingsIfEmpty = startPageUid,defaultQuizUid,templateLayout,pagebrowser.itemsPerPage
debug = 0
typeNum = {$plugin.tx_fpmasterquiz.settings.typeNum}
}
Expand Down
13 changes: 12 additions & 1 deletion Documentation/Administrator/Index.rst
Expand Up @@ -51,6 +51,17 @@ User results
FAQ
---

- Are there any APIs or Hooks?
- Are there any APIs?

No.

- How can I change the translations text? Here an TypoScript example:

::

plugin.tx_fpmasterquiz._LOCAL_LANG.de.text.yourAnswers = Deine Abstimmung:
plugin.tx_fpmasterquiz._LOCAL_LANG.de.text.allAnswers = Bisherige Abstimmung:

- How can I rename or hide some fields in the Backend?

See chapter “Configuration / Page TSConfig”.
30 changes: 30 additions & 0 deletions Documentation/Configuration/Index.rst
Expand Up @@ -63,6 +63,9 @@ Properties
template.wrapQuestionTitle2 string Wrap for the question title. </h4></div>
template.wrapQuestionDesc1 string Wrap for the question description. <div class="mx-auto">
template.wrapQuestionDesc2 string Wrap for the question description. </div>
template.wrapDone1 string Wrap for the done-msg at the final page. <h4>
template.wrapDone2 string Wrap for the done-msg at the final page. </h4>
templateLayout integer See in chapter PageTSconfig.
overrideFlexformSettings... string Fields that should be overwritten if empty. startPageUid,...
debug boolean Show debug data at the page. 0
typeNum integer Type of the AJAX-call. Don´t change it. 190675
Expand Down Expand Up @@ -122,6 +125,25 @@ showAnswerPage
No answer page will be shown after every submit.


.. _Poll:

Poll
""""

With this TypoScript you can configure a simple poll with a pie chart as result::

plugin.tx_fpmasterquiz.persistence.storagePid = 279
plugin.tx_fpmasterquiz.settings.startPageUid = 279
plugin.tx_fpmasterquiz.settings.defaultQuizUid = 9
plugin.tx_fpmasterquiz.settings.showAnswerPage = 0
plugin.tx_fpmasterquiz.settings.showAnswersAtFinalPage = 1
plugin.tx_fpmasterquiz.settings.showCorrectAnswers = 0
plugin.tx_fpmasterquiz.settings.showAllAnswers = 1
plugin.tx_fpmasterquiz.settings.showPoints = 0
plugin.tx_fpmasterquiz.settings.templateLayout = 1
plugin.tx_fpmasterquiz.settings.template.wrapDone1 = <div class="hidden">
plugin.tx_fpmasterquiz.settings.template.wrapDone2 = </div>

.. _configuration-faq:

FAQ
Expand All @@ -130,3 +152,11 @@ FAQ
- What about the evaluation of a quiz?

This can be configured at every quiz.


.. toctree::
:maxdepth: 5
:titlesonly:
:glob:

PageTSconfig/Index
63 changes: 63 additions & 0 deletions Documentation/Configuration/PageTSconfig/Index.rst
@@ -0,0 +1,63 @@
.. include:: ../../Includes.txt

.. ==================================================
.. FOR YOUR INFORMATION
.. --------------------------------------------------
.. -*- coding: utf-8 -*- with BOM.
.. ==================================================
.. DEFINE SOME TEXTROLES
.. --------------------------------------------------
.. role:: underline
.. role:: typoscript(code)
.. role:: ts(typoscript)
:class: typoscript
.. role:: php(code)


Page TSconfig
^^^^^^^^^^^^^

- You can use the Page TSconfig to define some template layouts.

Example
~~~~~~~

Here an example with 2 layouts for your templates:

::

tx_fpmasterquiz.templateLayouts {
0 = Standard-Layout
1 = Layout for a poll with a pie chart
}


- You can use every number and description for the layouts.
- Now you can select a layout in the FlexForm of every page.
- Finally you can use now different layouts in your templates.

Example
~~~~~~~

Here an example for a template (extract) with 2 layouts:

::

<f:if condition="{settings.templateLayout} == 1">
<f:then>
show a pie chart
</f:then>
<f:else>
show only text
</f:else>
</f:if>

- Furthermore you can use TSconfig to rename or hide quiz-fields. Here two examples:

::

TCEFORM.tx_fpmasterquiz_domain_model_question.explanation.disabled = 1
TCEFORM.tx_fpmasterquiz_domain_model_quiz.about.label = Description for the list view

You find the TSconfig when you edit a page. Go to the tab Ressources.
11 changes: 5 additions & 6 deletions README.md
@@ -1,15 +1,14 @@
# fp_masterquiz

version 0.3.7
version 0.4.0

TYPO3 extension to create a quiz or test. The participant result will be saved in the DB too and can be deleted automatically via Scheduler.
TYPO3 extension to create a quiz, poll or test. The participant result will be saved in the DB too and can be deleted automatically via Scheduler.

It is the official successor extension of myquizpoll.
Currently it is only a beta release. Please give me feedback.
This extension is not backward compatible to myquizpoll!
This extension is not backward compatible to myquizpoll, but there is a simple import-task for myquizpoll-questions.

Features: a quiz or test can be played by submitting a form or by submitting an AJAX-request.
Features: a quiz, poll or test can be played by submitting a form or by submitting an AJAX-request.

You find the documentation at typo3.org: https://docs.typo3.org/typo3cms/extensions/fp_masterquiz/

Last feature: show all answers and own answer at the final page.
Last feature: templateLayout with a pie chart.
3 changes: 3 additions & 0 deletions Resources/Private/Language/de.locallang_be.xlf
Expand Up @@ -15,6 +15,9 @@
<trans-unit id="template.show">
<target>Ein bestimmtes Quiz anzeigen (speichern! | Datensatzsammlung muss dennoch gewählt werden)</target>
</trans-unit>
<trans-unit id="templateLayout">
<target>Template-Layout (siehe Doku):</target>
</trans-unit>
<trans-unit id="settings.startPageUid">
<target>Startseite des Quiz:</target>
</trans-unit>
Expand Down
3 changes: 3 additions & 0 deletions Resources/Private/Language/locallang_be.xlf
Expand Up @@ -15,6 +15,9 @@
<trans-unit id="template.show">
<source>Shown one selected quiz (save the plugin! | you need to select the storage folder too)</source>
</trans-unit>
<trans-unit id="templateLayout">
<source>Template layout (see manual):</source>
</trans-unit>
<trans-unit id="settings.startPageUid">
<source>Start page of a quiz:</source>
</trans-unit>
Expand Down
36 changes: 36 additions & 0 deletions Resources/Private/Partials/Question/Chart.html
@@ -0,0 +1,36 @@
<html xmlns:f="https://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
<div id="pollChart"></div>
<script>
var options = {
//title: {
// text: '{selection.question.title}',
// align: 'left'
//},
chart: {
width: 492,
type: 'pie',
},
labels: [<f:for each="{selection.question.answers}" as="answer3" iteration="iter3">'{answer3.title}'<f:if condition="{iter3.isLast}"><f:then></f:then><f:else>,</f:else></f:if></f:for>],
series: [<f:for each="{selection.question.answers}" as="answer3" iteration="iter3">{answer3.allAnswers}<f:if condition="{iter3.isLast}"><f:then></f:then><f:else>,</f:else></f:if></f:for>],
responsive: [{
breakpoint: 480,
options: {
chart: {
width: 200
},
legend: {
position: 'bottom'
}
}
}]
}

var chart = new ApexCharts(
document.querySelector("#pollChart"),
options
);

chart.render();
</script>
</html>

0 comments on commit 33dcfea

Please sign in to comment.