Skip to content

Commit

Permalink
Merge pull request #10 from DreamSpawn/participant-notes
Browse files Browse the repository at this point in the history
Participant notes
  • Loading branch information
DreamSpawn authored Dec 18, 2019
2 parents bc2843d + a2ffe43 commit c2379a4
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 64 deletions.
41 changes: 24 additions & 17 deletions include/controllers/participant_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,24 +471,31 @@ public function visTextedit()
$this->page->setTemplate('noResults');
} else {
$this->page->textfield = $this->vars['textfield'];
$var = $this->page->textfield;
$this->page->textcontent = $deltager->$var;
$this->page->deltager = $deltager;
switch ($var) {
case 'admin_note':
$this->page->field = 'noter <strong>om</strong> deltageren';
break;
case 'deltager_note':
$this->page->field = 'beskeder <strong>fra</strong> deltageren';
break;
case 'beskeder':
$this->page->field = 'beskeder <strong>til</strong> deltageren';
break;
case 'paid_note':
$this->page->field = 'økonomi-noter';
break;
default:
$this->page->field = e($var);

if (preg_match("/deltager_note_(\w+)/",$this->page->textfield,$matches)) {
$var = $matches[1];
$this->page->textcontent = $deltager->note->$var->content;
$this->page->field = $deltager->note->$var->name;
} else {
$var = $this->page->textfield;
$this->page->textcontent = $deltager->$var;
switch ($var) {
case 'admin_note':
$this->page->field = 'noter <strong>om</strong> deltageren';
break;
case 'deltager_note':
$this->page->field = 'beskeder <strong>fra</strong> deltageren';
break;
case 'beskeder':
$this->page->field = 'beskeder <strong>til</strong> deltageren';
break;
case 'paid_note':
$this->page->field = 'økonomi-noter';
break;
default:
$this->page->field = e($var);
}
}
$this->page->setTitle('Rediger ' . strip_tags($this->page->field));
}
Expand Down
39 changes: 39 additions & 0 deletions include/entities/deltagere.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,23 @@ class Deltagere extends DBObject implements AgeFulfilment
'ungdomsskole' => 'Ungdomsskole/klub',
);

/**
* Contains display names for different notes
*
* @var array
*/
protected $note_names = [
'da' => [
'comment' => 'Andre kommentarer',
'gds' => 'Kommentarer til GDS'
],
'en' => [
'comment' => 'Other comments',
'gds' => 'Comments regarding GDS'
]
];


/**
* Name of database table
*
Expand Down Expand Up @@ -125,6 +142,22 @@ public function __get($var)

return $this->calculated_age = $diff->format('%y');

} elseif($var == 'note') {
if (!isset($this->note_obj)) {
if ($note_obj = json_decode($this->deltager_note)) {
$this->note_obj = new stdClass();
} else {
$this->note_obj = null;
}
foreach($note_obj as $key => $value) {
$this->note_obj->$key = new stdClass();
$this->note_obj->$key->content = $value;
$this->note_obj->$key->name = isset($this->note_names['da'][$key]) ? $this->note_names['da'][$key] : $key;
$this->note_obj->$key->name_en = isset($this->note_names['en'][$key]) ? $this->note_names['en'][$key] : $key;
}
}
return $this->note_obj;

} elseif (array_key_exists($var, $this->storage)) {
return parent::__get($var);

Expand Down Expand Up @@ -1615,4 +1648,10 @@ public function isSingleDayParticipant()
return $x->isEntrance() && !$x->isDayTicket();
})) === 0;
}

public function setNote($name, $content) {
$note = json_decode($this->deltager_note);
$note->$name = $content;
parent::__set('deltager_note', json_encode($note));
}
}
2 changes: 2 additions & 0 deletions include/migrations/1027-deltager-note-json.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
UPDATE deltagere SET deltager_note = CONCAT('{"note" :"', deltager_note, '"}' );
ALTER TABLE deltagere MODIFY deltager_note JSON;
76 changes: 42 additions & 34 deletions include/models/participant_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1085,11 +1085,15 @@ protected function indgangMadDeletes($array_name, $entity_name, $field_name, Req
*/
public function updateDeltagerNote($deltager, $field, RequestVars $post)
{
if (!in_array($field, array('deltager_note', 'admin_note', 'beskeder', 'paid_note', 'medical_note'))) {
return false;
}
if (preg_match("/deltager_note_(\w+)/", $field, $matches)) {
$deltager->setNote($matches[1], $post->$field);
} else{
if (!in_array($field, array('deltager_note', 'admin_note', 'beskeder', 'paid_note', 'medical_note'))) {
return false;
}

$deltager->$field = $post->$field;
$deltager->$field = $post->$field;
}
return $deltager->update();
}

Expand Down Expand Up @@ -1849,36 +1853,40 @@ public function makeJeditableUpdate(Deltagere $participant, RequestVars $post)

$this->factory('IdTemplate')->cleanIdTemplateParticipantCache($participant);

switch ($post->id) {
case 'birthdate':
$parsed = strtotime($post->value);
$participant->birthdate = $parsed ? date('Y-m-d', $parsed) : '0000-00-00';
break;
case 'address':
$participant->adresse1 = $post->value;
break;
case 'name':
$parts = explode(' ', $post->value);
if (count($parts) > 1) {
$participant->efternavn = array_pop($parts);
$participant->fornavn = implode(' ', $parts);
} else {
$participant->fornavn = $parts[0];
$participant->efternavn = '';
}
break;
case 'brugerkategori_id':
$category = $this->createEntity('BrugerKategorier')->findById($post->value);
$return_value = $category->navn;
$participant->brugerkategori_id = $category->id;
break;

case 'participant-template':
$this->updateParticipantIdTemplate($participant, intval($post->value));
break;

default:
$participant->{$post->id} = $post->value;
if (preg_match("/deltager_note_(\w+)/",$post->id, $matches)) {
$participant->setNote($matches[1], $post->value);
} else {
switch ($post->id) {
case 'birthdate':
$parsed = strtotime($post->value);
$participant->birthdate = $parsed ? date('Y-m-d', $parsed) : '0000-00-00';
break;
case 'address':
$participant->adresse1 = $post->value;
break;
case 'name':
$parts = explode(' ', $post->value);
if (count($parts) > 1) {
$participant->efternavn = array_pop($parts);
$participant->fornavn = implode(' ', $parts);
} else {
$participant->fornavn = $parts[0];
$participant->efternavn = '';
}
break;
case 'brugerkategori_id':
$category = $this->createEntity('BrugerKategorier')->findById($post->value);
$return_value = $category->navn;
$participant->brugerkategori_id = $category->id;
break;

case 'participant-template':
$this->updateParticipantIdTemplate($participant, intval($post->value));
break;

default:
$participant->{$post->id} = $post->value;
}
}

$this->log("Deltager #{$participant->id} fik opdateret " . $post->id . " af {$this->getLoggedInUser()->user}", 'Deltager', $this->getLoggedInUser());
Expand Down
14 changes: 10 additions & 4 deletions include/templates/api/confirmationdata.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,16 @@ case 'a':
<tr><td>Jeg vil gerne have en plads i arrangørsovesalen: </td><td>Ja</td></tr>
<?php endif;?>
<?php if ($this->participant->skills) : ?>
<tr><td>Evner/skills du kan og vil hjælpe med: </td><td><?= e($this->participant->skills);?></td></tr>
<?php endif;?>
<?php if ($this->participant->deltager_note) : ?>
<tr><td>Andre kommentarer: </td><td><?= e($this->participant->deltager_note);?></td></tr>
<tr><td>Evner/skills du kan og vil hjælpe med: </td><td><?=e($this->participant->skills)?></td></tr>
<?php endif;?>
<?php if ($this->participant->deltager_note) :
if($this->deltager->note) :
foreach($this->deltager->note as $note) : ?>
<tr><td><?=$note->name?>: </td><td><?=e($note->content)?></td></tr>
<?php endforeach;
else : ?>
<tr><td>Andre kommentarer: </td><td><?=e($this->participant->deltager_note)?></td></tr>
<?php endif; ?>
<?php endif;?>
<?php if ($this->participant->rig_onkel === 'ja') : ?>
<tr><td>Rig tante/onkel (støtter Fastaval med 300kr.) </td><td>Ja</td></tr>
Expand Down
10 changes: 8 additions & 2 deletions include/templates/api/confirmationdataen.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,14 @@ case 'a':
<?php if ($this->participant->skills) : ?>
<tr><td>Any skills you can and would like to help Fastaval with: </td><td><?= e($this->participant->skills);?></td></tr>
<?php endif;?>
<?php if ($this->participant->deltager_note) : ?>
<tr><td>Other comments: </td><td><?= e($this->participant->deltager_note);?></td></tr>
<?php if ($this->participant->deltager_note) :
if($this->deltager->note) :
foreach($this->deltager->note as $note) : ?>
<tr><td><?=$note->name_en?>: </td><td><?=e($note->content)?></td></tr>
<?php endforeach;
else : ?>
<tr><td>Other comments: </td><td><?= e($note);?></td></tr>
<?php endif; ?>
<?php endif;?>
<?php if ($this->participant->rig_onkel === 'ja') : ?>
<tr><td>I am a rich aunty/uncle (supporting Fastaval with 300kr.) </td><td>Yes</td></tr>
Expand Down
16 changes: 10 additions & 6 deletions include/templates/participant/visdeltager.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,6 @@ $this->registerLateLoadJS('participant.js');
<p class="editable textarea" id="admin_note"><?= nl2br(htmlspecialchars($this->deltager->admin_note, ENT_QUOTES));?></p>
</fieldset>
</div>
<div id='note2' class='note'>
<fieldset>
<legend>Deltagerens noter (til Fastaval) - <a href="<?= $this->url('edit_deltager_note', array('textfield' => 'deltager_note', 'id' => $this->deltager->id));?>">Ret/slet</a></legend>
<p class="editable textarea" id="deltager_note"><?= nl2br(htmlspecialchars($this->deltager->deltager_note, ENT_QUOTES));?></p>
</fieldset>
</div>
<div id='note3' class='note'>
<fieldset>
<legend>Beskeder til deltageren (fra Fastaval) - <a href="<?= $this->url('edit_deltager_note', array('textfield' => 'beskeder', 'id' => $this->deltager->id));?>">Ret/slet</a></legend>
Expand All @@ -343,6 +337,16 @@ $this->registerLateLoadJS('participant.js');
</fieldset>
</div>
<div class='clearit'></div>
<?php if($this->deltager->note) : ?>
<?php foreach($this->deltager->note as $key => $note) : ?>
<div id='note_<?=$key?>' class='note'>
<fieldset>
<legend><?=$note->name?> - <a href="<?= $this->url('edit_deltager_note', array('textfield' => 'deltager_note_'.$key, 'id' => $this->deltager->id));?>">Ret/slet</a></legend>
<p class="editable textarea" id="deltager_note_<?=$key?>"><?= nl2br(htmlspecialchars($note->content, ENT_QUOTES));?></p>
</fieldset>
</div>
<?php endforeach; ?>
<?php endif;?>
</div>
<?php endif;?>
<?php if (!($this->payment_edit || ($this->is_read_only && !$this->is_read_only_activity))) :?>
Expand Down
2 changes: 1 addition & 1 deletion include/templates/participant/vistextedit.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<fieldset>
<legend>Rediger <?php echo $this->field;?></legend>
<form method='post' action="<?php echo $this->url('update_deltager_note', array('textfield' => $this->textfield, 'id' => $this->deltager->id));?>">
<textarea class='' name='<?php echo $this->textfield;?>'><?php echo e($this->deltager->{$this->textfield});?></textarea>
<textarea class='' name='<?php echo $this->textfield;?>'><?php echo e($this->textcontent);?></textarea>
<input type='submit' class='centersubmits' value='Opdater' name='update_note' />
</form>
</fieldset>
Expand Down

0 comments on commit c2379a4

Please sign in to comment.