Editing an event via REST would not capture the tags

- if a user is a tagger the tag should be created (if not existing on the current instance) and added to the event
pull/796/head
iglocska 2015-12-21 11:46:33 +01:00
parent cb42337f9b
commit 000449ee81
2 changed files with 35 additions and 0 deletions

View File

@ -1159,6 +1159,26 @@ class EventsController extends AppController {
}
}
}
if (isset($this->request->data['Event']['Tag']) && $this->userRole['perm_tagger']) {
foreach ($this->request->data['Event']['Tag'] as $tag) {
$tag_id = $this->Event->EventTag->Tag->captureTag($tag, $this->Auth->user());
if ($tag_id) {
$this->Event->EventTag->attachTagToEvent($this->Event->id, $tag_id);
} else {
$this->Log->create();
$this->Log->save(array(
'org' => $this->Auth->user('Organisation')['name'],
'model' => 'Event',
'model_id' => $this->Event->id,
'email' => $this->Auth->user('email'),
'action' => 'edit',
'user_id' => $this->Auth->user('id'),
'title' => 'Failed create or attach Tag ' . $tag['name'] . ' to the event.',
'change' => ''
));
}
}
}
// check if the exact proposal exists, if yes check if the incoming one is deleted or not. If it is deleted, remove the old proposal and replace it with the one marked for being deleted
// otherwise throw the new one away.
if (isset($this->request->data['Event']['ShadowAttribute'])) {

View File

@ -52,4 +52,19 @@ class EventTag extends AppModel {
$eventIDs = array_unique($eventIDs);
return $eventIDs;
}
public function attachTagToEvent($event_id, $tag_id) {
$existingAssociation = $this->find('first', array(
'recursive' => -1,
'conditions' => array(
'tag_id' => $tag_id,
'event_id' => $event_id
)
));
if (empty($existingAssociation)) {
$this->create();
if (!$this->save(array('event_id' => $event_id, 'tag_id' => $tag_id))) return false;
}
return true;
}
}