Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Adds free text options. Adds MIT License.
Browse files Browse the repository at this point in the history
  • Loading branch information
tute committed Jul 13, 2010
1 parent 7b42bcd commit 73a3bbb
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 11 deletions.
21 changes: 21 additions & 0 deletions MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
== MIT License

Copyright (c) 2010 [Eugenio Costa - tutecosta AT google mail]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 6 additions & 0 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ I'm currently actively developing it.
h3. Currently relies on:

* Inflection ('opcion' => 'opciones') (@bootstrap.php@)

Type of questions:
# Yes / No
# Values 1 to 5
# Free text
# Custom options (developing)
11 changes: 8 additions & 3 deletions frage.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ CREATE TABLE `fr_encuestas` (
--

INSERT INTO `fr_encuestas` (`id`, `nombre`) VALUES
(1, 'About CakePHP plugins');
(1, 'About CakePHP plugins'),
(2, 'About frage plugin');

-- --------------------------------------------------------

Expand All @@ -54,7 +55,9 @@ CREATE TABLE `fr_preguntas` (

INSERT INTO `fr_preguntas` (`id`, `fr_encuesta_id`, `pregunta`, `tipo`) VALUES
(1, 1, 'Do you use CakePHP plugins?', 1),
(2, 1, 'How much?', 2);
(2, 1, 'How much?', 2),
(3, 1, 'Do you find them better than plain CakePHP? Why?', 3),
(4, 2, 'Will you help me improving it?', 1);

-- --------------------------------------------------------

Expand All @@ -76,7 +79,9 @@ CREATE TABLE `fr_opciones` (
--

INSERT INTO `fr_opciones` (`id`, `fr_pregunta_id`, `opcion`, `tipo`) VALUES
(1, 0, '', 1), (2, 0, 'No', 1);
(1, 0, '', 1), (2, 0, 'No', 1), -- Yes / No
(3, 0, 1, 2), (4, 0, 2, 2), (5, 0, 3, 2), (6, 0, 4, 2), (7, 0, 5, 2), -- 1 to 5
(8, 0, 'FR_TEXT', 3); -- free text

-- --------------------------------------------------------

Expand Down
6 changes: 3 additions & 3 deletions views/encuestas/index.ctp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<div id="frage">
<h2>Encuestas</h2>
<ul>
<?
Expand All @@ -6,10 +7,9 @@ foreach ($encuestas as $e) {
. $functions->abm($e['Encuesta']['id'], 'encuestas');
$functions->listar_preguntas($e['Pregunta']);
echo "</li>\n";

// $functions->show_options(1);
}
?>
</ul>

<p><a href="/frage/encuestas/add">Nueva encuesta</a></p>
<p><a href="/frage/encuestas/add">Nueva encuesta</a> - <a href="/frage/preguntas/add">Nueva pregunta</a></p>
</div>
20 changes: 15 additions & 5 deletions views/helpers/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function abm($id, $controller, $enclosed = null) {
return $abm;
}

function listar_preguntas($pregs) {
function listar_preguntas($pregs, $show_options = true) {
/* Load HTML helper */
App::import('Helper', 'Html');
$html = new HtmlHelper();
Expand All @@ -24,16 +24,26 @@ function listar_preguntas($pregs) {
echo "\n <ul>\n";
foreach ($pregs as $p) {
echo ' <li><a href="/frage/preguntas/edit/'.$p['id'].'">' . $p['pregunta'] . "</a> "
. $this->abm($p['id'], 'preguntas') . "</li>\n";
. $this->abm($p['id'], 'preguntas')
. $this->show_options($p['tipo'], $p['id'])
. "</li>\n";
}
echo ' </ul>';
}
}

function show_options($tipo) {
pr(ClassRegistry::init('Opcion')->find('all', array(
function show_options($tipo, $pid) {
$options = ClassRegistry::init('Opcion')->find('all', array(
'conditions' => array('Opcion.tipo' => $tipo)
)));
));
$opts = '';
foreach ($options as $opt) {
if ($tipo == 1 or $tipo == 2)
$opts .= "<label><input type=\"radio\" id=\"pr_$pid\" name=\"pr_$pid\" value=\"{$opt['Opcion']['id']}\"> {$opt['Opcion']['opcion']}</label> ";
if ($tipo == 3)
$opts .= "<label><input type=\"text\" id=\"pr_$pid\" name=\"pr_$pid\"></label> ";
}
return $opts;
}

}
Expand Down

0 comments on commit 73a3bbb

Please sign in to comment.