/** * Validates a participant. * @param int $id id of the registration entry * @param string $code validation code * @param array $formParams * @return array $response */ public function validate($id, $code) { $registration = $this->getResource()->fetchRow($id); if ($registration['code'] === $code) { $values = Zend_Json::decode($registration['values']); // get the participant resource and store values in the database $participantModel = new Meetings_Model_Participants(); $id = $participantModel->getResource()->insertRow($values); $participant = $participantModel->getResource()->fetchRow($id); // delete from registration table $this->getResource()->deleteRow($id); $meetingsModel = new Meetings_Model_Meetings(); $meeting = $meetingsModel->getResource()->fetchRow($values['meeting_id']); $mailValues = array('to' => $participant['email'], 'meeting' => $meeting['title'], 'firstname' => $participant['firstname'], 'lastname' => $participant['lastname'], 'affiliation' => $participant['affiliation'], 'email' => $participant['email'], 'arrival' => $participant['arrival'], 'departure' => $participant['departure']); foreach ($meeting['participant_detail_keys'] as $d) { if (in_array(Meetings_Model_ParticipantDetailKeys::$types[$d['type_id']], array('radio', 'select'))) { $options = Zend_Json::decode($d['options']); $mailValues[$d['key']] = $options[$participant['details'][$d['key']]]; } else { if (in_array(Meetings_Model_ParticipantDetailKeys::$types[$d['type_id']], array('checkbox', 'multiselect'))) { $options = Zend_Json::decode($d['options']); $values = array(); foreach (Zend_Json::decode($participant['details'][$d['key']]) as $value_id) { $values[] = $options[$value_id]; } $mailValues[$d['key']] = $values; } else { $mailValues[$d['key']] = $participant['details'][$d['key']]; } } } foreach ($meeting['contribution_types'] as $contribution_type) { if (!empty($participant['contributions'][$contribution_type])) { $mailValues[$contribution_type . '_title'] = $participant['contributions'][$contribution_type]['title']; $mailValues[$contribution_type . '_abstract'] = $participant['contributions'][$contribution_type]['abstract']; } else { $mailValues[$contribution_type . '_title'] = '---'; } } $this->getModelHelper('mail')->send('meetings.register', $mailValues); return array('status' => 'ok'); } else { return array('status' => 'error', 'error' => 'user or code is not valid'); } }
/** * Updates an participant. * @param int $id id of the participant * @param array $formParams * @return array $response */ public function update($id, array $formParams = array()) { // get participant from the database $entry = $this->getResource()->fetchRow($id); if (empty($entry)) { throw new Daiquiri_Exception_NotFound(); } // get the meeting $meetingsModel = new Meetings_Model_Meetings(); $meeting = $meetingsModel->getResource()->fetchRow($entry['meeting_id']); $participantStatusModel = new Meetings_Model_ParticipantStatus(); $participantStatus = $participantStatusModel->getResource()->fetchValues('status'); // create the form object $form = new Meetings_Form_Participants(array('submit' => 'Update participant', 'meeting' => $meeting, 'entry' => $entry, 'status' => $participantStatus)); // valiadate the form if POST if (!empty($formParams)) { if ($form->isValid($formParams)) { // get the form values $values = $form->getValues(); // process the details $values['details'] = array(); foreach ($meeting['participant_detail_keys'] as $detailKey) { if (is_array($values[$detailKey['key']])) { $values['details'][$detailKey['id']] = Zend_Json::encode($values[$detailKey['key']]); } else { if ($values[$detailKey['key']] === null) { $values['details'][$detailKey['id']] = Zend_Json::encode(array()); } else { $values['details'][$detailKey['id']] = $values[$detailKey['key']]; } } unset($values[$detailKey['key']]); } $values['contributions'] = array(); foreach ($meeting['contribution_types'] as $contributionTypeId => $contributionType) { if ($values[$contributionType . '_bool'] === '1') { $values['contributions'][$contributionTypeId] = array('title' => $values[$contributionType . '_title'], 'abstract' => $values[$contributionType . '_abstract']); } else { $values['contributions'][$contributionTypeId] = false; } //$values['details'][$key_id] = $values[$key]; unset($values[$contributionType . '_bool']); unset($values[$contributionType . '_title']); unset($values[$contributionType . '_abstract']); } // store the values in the database $this->getResource()->updateRow($id, $values); return array('status' => 'ok'); } else { return $this->getModelHelper('CRUD')->validationErrorResponse($form); } } return array('form' => $form, 'status' => 'form'); }
/** * Updates an contribution. * @param int $id id of the contribution * @param array $formParams * @return array $response */ public function update($id, array $formParams = array()) { // get participant from the database $entry = $this->getResource()->fetchRow($id); if (empty($entry)) { throw new Daiquiri_Exception_NotFound(); } // get the meeting $meetingsModel = new Meetings_Model_Meetings(); $meeting = $meetingsModel->getResource()->fetchRow($entry['meeting_id']); // get the participants for this meeting $participantsModel = new Meetings_Model_Participants(); $dbRows = $participantsModel->getResource()->fetchRows(array('where' => array('meeting_id = ?' => $meeting['id']), 'order' => 'lastname ASC')); $participants = array(); foreach ($dbRows as $dbRow) { $participants[$dbRow['id']] = "{$dbRow['lastname']}, {$dbRow['firstname']} <{$dbRow['email']}>"; } // create the form object $form = new Meetings_Form_Contributions(array('submit' => 'Update contribution', 'meeting' => $meeting, 'participants' => $participants, 'entry' => $entry)); // valiadate the form if POST if (!empty($formParams)) { if ($form->isValid($formParams)) { // get the form values $values = $form->getValues(); // store the values in the database $this->getResource()->updateRow($id, $values); return array('status' => 'ok'); } else { return $this->getModelHelper('CRUD')->validationErrorResponse($form); } } return array('form' => $form, 'status' => 'form'); }
/** * Initializes the database with the init data for the meetings module. */ public function init() { // create contribution types $meetingsContributionTypeModel = new Meetings_Model_ContributionTypes(); if ($meetingsContributionTypeModel->getResource()->countRows() == 0) { foreach ($this->_init->options['init']['meetings']['contributionTypes'] as $contributionType) { $a = array('contribution_type' => $contributionType); $r = $meetingsContributionTypeModel->create($a); $this->_check($r, $a); } } // create participant detail keys $meetingsParticipantDetailKeyModel = new Meetings_Model_ParticipantDetailKeys(); if ($meetingsParticipantDetailKeyModel->getResource()->countRows() == 0) { foreach ($this->_init->options['init']['meetings']['participantDetailKeys'] as $a) { $a['type_id'] = array_search($a['type'], Meetings_Model_ParticipantDetailKeys::$types); unset($a['type']); $r = $meetingsParticipantDetailKeyModel->create($a); $this->_check($r, $a); } } // create participant status $meetingsParticipantStatusModel = new Meetings_Model_ParticipantStatus(); if ($meetingsParticipantStatusModel->getResource()->countRows() == 0) { foreach ($this->_init->options['init']['meetings']['participantStatus'] as $participantStatus) { $a = array('status' => $participantStatus); $r = $meetingsParticipantStatusModel->create($a); $this->_check($r, $a); } } // create meetings $meetingsMeetingModel = new Meetings_Model_Meetings(); if ($meetingsMeetingModel->getResource()->countRows() == 0) { foreach ($this->_init->options['init']['meetings']['meetings'] as $a) { $a['contribution_type_id'] = array(); foreach ($a['contribution_types'] as $contribution_type) { $id = $meetingsContributionTypeModel->getResource()->fetchId(array('where' => array('`contribution_type` = ?' => $contribution_type))); $a['contribution_type_id'][] = $id; } unset($a['contribution_types']); $a['participant_detail_key_id'] = array(); foreach ($a['participant_detail_keys'] as $participant_detail_key) { $id = $meetingsParticipantDetailKeyModel->getResource()->fetchId(array('where' => array('`key` = ?' => $participant_detail_key))); $a['participant_detail_key_id'][] = $id; } unset($a['participant_detail_keys']); $r = $meetingsMeetingModel->create($a); $this->_check($r, $a); } } // create participants $meetingsParticipantsModel = new Meetings_Model_Participants(); if ($meetingsParticipantsModel->getResource()->countRows() == 0) { $participantStatusIds = array_flip($meetingsParticipantStatusModel->getResource()->fetchValues('status')); foreach ($this->_init->options['init']['meetings']['participants'] as $a) { $slug = $a['meeting_slug']; unset($a['meeting_slug']); $a['status_id'] = $participantStatusIds[$a['status']]; unset($a['status']); $r = $meetingsParticipantsModel->create($slug, $a); $this->_check($r, $a); } } }