/** * Returns a text element for autosearch. Can be overruled. * * The form / html elements to search on. Elements can be grouped by inserting null's between them. * That creates a distinct group of elements * * @param array $data The $form field values (can be usefull, but no need to set them) * @return array Of \Zend_Form_Element's or static tekst to add to the html or null for group breaks. */ protected function getAutoSearchElements(array $data) { $elements = parent::getAutoSearchElements($data); $orgs = $this->currentUser->getRespondentOrganizations(); if (count($orgs) > 1) { $elements[] = $this->_createSelectElement('gap_id_organization', $orgs, $this->_('(all organizations)')); } $locations = $this->loader->getAgenda()->getLocations(); if (count($locations) > 1) { $elements[] = $this->_createSelectElement('gap_id_location', $locations, $this->_('(all locations)')); } $elements[] = null; $this->_addPeriodSelectors($elements, 'gap_admission_time'); return $elements; }
/** * Dispaly an appoitment as text * * @param value $value * @return string */ public function showAppointment($value) { if (!$value) { return $this->_('Unknown'); } if ($value instanceof \Gems_Agenda_Appointment) { $appointment = $value; } else { $appointment = $this->loader->getAgenda()->getAppointment($value); } if ($appointment instanceof \Gems_Agenda_Appointment) { if (!$this->menu instanceof \Gems_Mail) { $this->menu = $this->loader->getMenu(); } $menuItem = $this->menu->findAllowedController('appointment', 'show'); if ($menuItem) { if (!$this->request) { $this->request = \Zend_Controller_Front::getInstance()->getRequest(); } $href = $menuItem->toHRefAttribute(array('gap_id_appointment' => $appointment->getId()), $this->request); if ($href) { return \MUtil_Html::create('a', $href, $appointment->getDisplayString()); } } return $appointment->getDisplayString(); } return $value; }
/** * Returns the changes to the model for this field that must be made in an array consisting of * * <code> * array(setting1 => $value1, setting2 => $value2, ...), * </code> * * By using [] array notation in the setting array key you can append to existing * values. * * Use the setting 'value' to change a value in the original data. * * When a 'model' setting is set, the workings cascade. * * @param array $context The current data this object is dependent on * @param boolean $new True when the item is a new record not yet saved * @return array (setting => value) */ public function getDataModelDependyChanges(array $context, $new) { if ($this->isReadOnly()) { return null; } $agenda = $this->loader->getAgenda(); $empty = $this->util->getTranslated()->getEmptyDropdownArray(); $output['multiOptions'] = $empty + $agenda->getActivities($context['gr2t_id_organization']); return $output; }
/** * Returns the changes that must be made in an array consisting of * * <code> * array( * field1 => array(setting1 => $value1, setting2 => $value2, ...), * field2 => array(setting3 => $value3, setting4 => $value4, ...), * </code> * * By using [] array notation in the setting name you can append to existing * values. * * Use the setting 'value' to change a value in the original data. * * When a 'model' setting is set, the workings cascade. * * @param array $context The current data this object is dependent on * @param boolean $new True when the item is a new record not yet saved * @return array name => array(setting => value) */ public function getChanges(array $context, $new) { // Only change anything when there are filters $filters = $this->loader->getAgenda()->getFilterList(); if (!$filters) { return array(); } // Load utility $translated = $this->util->getTranslated(); $output['gtf_id_order'] = array('description' => $this->_('The display and processing order of the fields.') . "\n" . $this->_('When using automatic filters the fields are ALWAYS filled with appointments in ascending order.')); $output['htmlCalc'] = array('label' => ' ', 'elementClass' => 'Exhibitor'); $output['gtf_filter_id'] = array('label' => $this->_('Automatic link'), 'description' => $this->_('Automatically link an appointment when it passes this filter.'), 'elementClass' => 'Select', 'multiOptions' => $translated->getEmptyDropdownArray() + $filters, 'onchange' => 'this.form.submit();'); if ($context['gtf_filter_id']) { $periodUnits = $this->util->getTranslated()->getPeriodUnits(); $output['gtf_min_diff_length'] = array('label' => $this->_('Minimal time difference'), 'description' => $this->_('Difference with the previous appointment or track start date, can be negative but not zero'), 'elementClass' => 'Text', 'required' => true, 'filters[int]' => 'Int', 'validators[isnot]' => new \MUtil_Validate_IsNot(0, $this->_('This value may not be zero!'))); $output['gtf_min_diff_unit'] = array('label' => $this->_('Minimal difference unit'), 'elementClass' => 'Select', 'multiOptions' => $periodUnits); $output['gtf_max_diff_exists'] = array('label' => $this->_('Set a maximum time difference'), 'elementClass' => 'Checkbox', 'onclick' => 'this.form.submit();'); if ($context['gtf_max_diff_exists']) { $output['gtf_max_diff_length'] = array('label' => $this->_('Maximum time difference'), 'elementClass' => 'Text', 'required' => false, 'filters[int]' => 'Int'); if ($context['gtf_min_diff_length'] < 0) { $output['gtf_max_diff_length']['description'] = $this->_('Must be negative, just like the minimal difference.'); $output['gtf_max_diff_length']['validators[lt]'] = new \Zend_Validate_LessThan(0); } else { $output['gtf_max_diff_length']['description'] = $this->_('Must be positive, just like the minimal difference.'); $output['gtf_max_diff_length']['validators[gt]'] = new \Zend_Validate_GreaterThan(0); } $output['gtf_max_diff_unit'] = array('label' => $this->_('Maximum difference unit'), 'elementClass' => 'Select', 'multiOptions' => $periodUnits); } // $output['gtf_after_next'] = array( // 'label' => $this->_('Link ascending'), // 'description' => $this->_('Automatically linked appointments are added in ascending (or otherwise descending) order; starting with the track start date.'), // 'elementClass' => 'Checkbox', // 'multiOptions' => $translated->getYesNo(), // ); $output['gtf_uniqueness'] = array('label' => $this->_('Link unique'), 'description' => $this->_('Can one appointment be used in multiple fields?'), 'elementClass' => 'Radio', 'multiOptions' => array(0 => $this->_('No: repeatedly linked appointments are allowed.'), 1 => $this->_('Track instances may link only once to an appointment.'), 2 => $this->_('Tracks of this type may link only once to an appointment.'))); $output['gtf_create_track'] = array('elementClass' => 'Checkbox', 'label' => $this->_('Create track'), 'onclick' => 'this.form.submit();'); if ($context['gtf_create_track']) { $output['gtf_create_wait_days'] = array('label' => $this->_('Days between tracks'), 'description' => $this->_('Any previous track must have an end date at least this many days in the past.'), 'elementClass' => 'Text'); } } return $output; }
/** * Process the data and do what must be done * * Storing the changed $values is handled by the calling function. * * @param \Gems_Tracker_RespondentTrack $respTrack Gems respondent track object * @param int $userId The current userId * @return void */ public function processFieldUpdate(\Gems_Tracker_RespondentTrack $respTrack, $userId) { $agenda = $this->loader->getAgenda(); $change = false; $token = $respTrack->getFirstToken(); if (!$token) { return; } do { if ($token->isCompleted()) { continue; } $appId = $respTrack->getRoundAfterAppointmentId($token->getRoundId()); // Not a round without appointment id if ($appId !== false) { if ($appId) { $appointment = $agenda->getAppointment($appId); } else { $appointment = null; } if ($appointment && $appointment->isActive()) { $newCode = \GemsEscort::RECEPTION_OK; $newText = null; } else { $newCode = 'skip'; $newText = $this->_('Skipped until appointment is set'); } $oldCode = \GemsEscort::RECEPTION_OK === $newCode ? 'skip' : \GemsEscort::RECEPTION_OK; $curCode = $token->getReceptionCode()->getCode(); // \MUtil_Echo::track($token->getTokenId(), $curCode, $oldCode, $newCode); if ($oldCode === $curCode && $curCode !== $newCode) { $change = true; $token->setReceptionCode($newCode, $newText, $userId); } } } while ($token = $token->getNextToken()); if ($change) { $respTrack->refresh(); } }
/** * Calculate the field value using the current values * * @param array $currentValue The current value * @param array $fieldData The other known field values * @param array $trackData The currently available track data (track id may be empty) * @return mixed the new value */ public function calculateFieldValue($currentValue, array $fieldData, array $trackData) { $calcUsing = $this->getCalculationFields($fieldData); if ($calcUsing) { $agenda = $this->loader->getAgenda(); // Get the used fields with values foreach (array_filter($calcUsing) as $value) { $appointment = $agenda->getAppointment($value); if ($appointment->exists) { return $appointment->getAdmissionTime(); } } } return $currentValue; }
/** * A ModelAbstract->setOnLoad() function that concatenates the * value if it is an array. * * @see \MUtil_Model_ModelAbstract * * @param mixed $value The value being saved * @param boolean $isNew True when a new item is being saved * @param string $name The name of the current field * @param array $context Optional, the other values being saved * @param boolean $isPost True when passing on post data * @return string Desciption */ protected function loadCalculationSources($value, $isNew = false, $name = null, array $context = array(), $isPost = false) { if ($isPost) { return $value; } if (isset($context['gtf_filter_id']) && $context['gtf_filter_id']) { $filters = $this->loader->getAgenda()->getFilterList(); if (isset($filters[$context['gtf_filter_id']])) { return $filters[$context['gtf_filter_id']]; } else { return sprintf($this->_("Non-existing filter %s"), $context['gtf_filter_id']); } } if (isset($context['gtf_calculate_using']) && $context['gtf_calculate_using']) { $count = substr_count($context['gtf_calculate_using'], '|') + 1; return sprintf($this->plural('%d field', '%d fields', $count), $count); } return $value; }
/** * Calculate the field value using the current values * * @param array $currentValue The current value * @param array $fieldData The other known field values * @param array $trackData The currently available track data (track id may be empty) * @return mixed the new value */ public function calculateFieldValue($currentValue, array $fieldData, array $trackData) { $calcUsing = $this->getCalculationFields($fieldData); if ($calcUsing) { $agenda = $this->loader->getAgenda(); // Get the used fields with values foreach (array_filter($calcUsing) as $value) { $appointment = $agenda->getAppointment($value); if ($appointment->exists) { return $appointment->getAdmissionTime(); } } } if ($currentValue instanceof \MUtil_Date) { return $currentValue; } if ($currentValue) { return \MUtil_Date::ifDate($currentValue, array($this->getDateFormat(), $this->getStorageFormat())); } }
/** * Save a single model item. * * @param array $newValues The values to store for a single model item. * @param array $filter If the filter contains old key values these are used * to decide on update versus insert. * @return array The values as they are after saving (they may change). */ public function save(array $newValues, array $filter = null) { // When appointment id is not set, then check for existing instances of // this appointment using the source information if (!isset($newValues['gap_id_appointment']) && isset($newValues['gap_id_in_source'], $newValues['gap_id_organization'], $newValues['gap_source'])) { $sql = "SELECT gap_id_appointment\n FROM gems__appointments\n WHERE gap_id_in_source = ? AND gap_id_organization = ? AND gap_source = ?"; $id = $this->db->fetchOne($sql, array($newValues['gap_id_in_source'], $newValues['gap_id_organization'], $newValues['gap_source'])); if ($id) { $newValues['gap_id_appointment'] = $id; } } $oldChanged = $this->getChanged(); $returnValues = parent::save($newValues, $filter); if ($this->getChanged() && $this->getChanged() !== $oldChanged) { if ($this->isAutoTrackUpdate()) { $appointment = $this->loader->getAgenda()->getAppointment($returnValues); $this->_changedTokenCount += $appointment->updateTracks(); } } // \MUtil_Echo::track($this->_changedTokenCount); return $returnValues; }
/** * Get an appointment object * * @param mixed $appointmentData Appointment id or array containing appintment data * @return \Gems_Agenda_Appointment */ public function getAppointment($appointmentData) { return $this->loader->getAgenda()->getAppointment($appointmentData); }