/** * Add the model settings like the elementClass for this field. * * elementClass is overwritten when this field is read only, unless you override it again in getDataModelSettings() * * @param array $settings The settings set so far */ protected function addModelSettings(array &$settings) { $concatter = new \MUtil_Model_Type_ConcatenatedRow(parent::FIELD_SEP, ' ', false); $multi = explode(parent::FIELD_SEP, $this->_fieldDefinition['gtf_field_values']); $settings = $concatter->getSettings() + $settings; $settings['elementClass'] = 'MultiCheckbox'; $settings['multiOptions'] = array_combine($multi, $multi); }
/** * Set those settings needed for the browse display * * * @return \Gems_Model_OrganizationModel */ public function applyBrowseSettings() { $dbLookup = $this->util->getDbLookup(); $definitions = $this->loader->getUserLoader()->getAvailableStaffDefinitions(); $localized = $this->util->getLocalized(); $projectName = $this->project->getName(); $yesNo = $this->util->getTranslated()->getYesNo(); $this->resetOrder(); $this->set('gor_name', 'label', $this->_('Name')); $this->set('gor_location', 'label', $this->_('Location')); $this->set('gor_task', 'label', $this->_('Task'), 'description', sprintf($this->_('Task in %s project'), $projectName)); $this->set('gor_url', 'label', $this->_('Url')); $this->setIfExists('gor_url_base', 'label', $this->_("Default url's"), 'description', sprintf($this->_("Always switch to this organization when %s is accessed from one of these space separated url's. The first is used for mails."), $projectName)); $this->setIfExists('gor_code', 'label', $this->_('Organization code'), 'description', $this->_('Optional code name to link the organization to program code.')); $this->set('gor_provider_id', 'label', $this->_('Healtcare provider id'), 'description', $this->_('An interorganizational id used for import and export.')); $this->setIfExists('gor_active', 'label', $this->_('Active'), 'description', $this->_('Can the organization be used?'), 'multiOptions', $yesNo); $this->set('gor_contact_name', 'label', $this->_('Contact name')); $this->set('gor_contact_email', 'label', $this->_('Contact email')); // Determine order for details, but do not show in browse $this->set('gor_welcome'); $this->set('gor_signature'); $this->set('gor_create_account_template'); $this->set('gor_reset_pass_template'); $this->set('gor_has_login', 'label', $this->_('Login'), 'description', $this->_('Can people login for this organization?'), 'multiOptions', $yesNo); $this->set('gor_add_respondents', 'label', $this->_('Accepting'), 'description', $this->_('Can new respondents be added to the organization?'), 'multiOptions', $yesNo); $this->set('gor_has_respondents', 'label', $this->_('Respondents'), 'description', $this->_('Does the organization have respondents?'), 'multiOptions', $yesNo); $this->set('gor_respondent_group', 'label', $this->_('Respondent group'), 'description', $this->_('Allows respondents to login.'), 'multiOptions', $dbLookup->getAllowedRespondentGroups()); $this->set('gor_accessible_by', 'label', $this->_('Accessible by'), 'description', $this->_('Checked organizations see this organizations respondents.'), 'multiOptions', $dbLookup->getOrganizations()); $tp = new \MUtil_Model_Type_ConcatenatedRow(':', ', '); $tp->apply($this, 'gor_accessible_by'); $this->setIfExists('gor_allowed_ip_ranges'); if ($definitions && count($definitions) > 1) { $this->setIfExists('gor_user_class', 'label', $this->_('User Definition'), 'multiOptions', $definitions); } $this->setIfExists('gor_iso_lang', 'label', $this->_('Language'), 'multiOptions', $localized->getLanguages()); if ($this->_styles) { $this->setIfExists('gor_style', 'label', $this->_('Style'), 'multiOptions', $this->_styles); } return $this; }
/** * Returns a model that can be used to retrieve or save the data. * * @param boolean $detailed Create a model for the display of detailed item data or just a browse table * @param string $action The current action * @return \MUtil_Model_ModelAbstract */ public function getRoundModel($detailed, $action) { $model = $this->createRoundModel(); $translated = $this->util->getTranslated(); // Set the keys to the parameters in use. $model->setKeys(array(\MUtil_Model::REQUEST_ID => 'gro_id_track', \Gems_Model::ROUND_ID => 'gro_id_round')); if ($detailed) { $model->set('gro_id_track', 'label', $this->_('Track'), 'elementClass', 'exhibitor', 'multiOptions', $this->util->getTrackData()->getAllTracks); } $model->set('gro_id_survey', 'label', $this->_('Survey'), 'multiOptions', $this->util->getTrackData()->getAllSurveysAndDescriptions()); $model->set('gro_icon_file', 'label', $this->_('Icon')); $model->set('gro_id_order', 'label', $this->_('Order'), 'default', 10, 'validators[uni]', $model->createUniqueValidator(array('gro_id_order', 'gro_id_track'))); $model->set('gro_round_description', 'label', $this->_('Description'), 'size', '30'); //, 'minlength', 4, 'required', true); $list = $this->events->listRoundChangedEvents(); if (count($list) > 1) { $model->set('gro_changed_event', 'label', $this->_('After change'), 'multiOptions', $list); } $list = $this->events->listSurveyDisplayEvents(); if (count($list) > 1) { $model->set('gro_display_event', 'label', $this->_('Answer display'), 'multiOptions', $list); } $model->set('gro_active', 'label', $this->_('Active'), 'elementClass', 'checkbox', 'multiOptions', $translated->getYesNo()); $model->setIfExists('gro_code', 'label', $this->_('Round code'), 'description', $this->_('Optional code name to link the field to program code.'), 'size', 10); $model->addColumn("CASE WHEN gro_active = 1 THEN '' ELSE 'deleted' END", 'row_class'); $model->addColumn("CASE WHEN gro_organizations IS NULL THEN 0 ELSE 1 END", 'org_specific_round'); $model->addColumn('gro_organizations', 'organizations'); $model->set('organizations', 'label', $this->_('Organizations'), 'elementClass', 'MultiCheckbox', 'multiOptions', $this->util->getDbLookup()->getOrganizations(), 'data-source', 'org_specific_round'); $tp = new \MUtil_Model_Type_ConcatenatedRow('|', $this->_(', ')); $tp->apply($model, 'organizations'); switch ($action) { case 'create': $this->_ensureRounds(); if ($this->_rounds && ($round = end($this->_rounds))) { $model->set('gro_id_order', 'default', $round['gro_id_order'] + 10); } // Intentional fall through // break; // Intentional fall through // break; case 'edit': case 'show': $model->set('gro_icon_file', 'multiOptions', $translated->getEmptyDropdownArray() + $this->_getAvailableIcons()); $model->set('org_specific_round', 'label', $this->_('Organization specific round'), 'default', 0, 'multiOptions', $translated->getYesNo(), 'elementClass', 'radio'); break; default: $model->set('gro_icon_file', 'formatFunction', array('MUtil_Html_ImgElement', 'imgFile')); break; } return $model; }
/** * Creates a model for getModel(). Called only for each new $action. * * The parameters allow you to easily adapt the model to the current action. The $detailed * parameter was added, because the most common use of action is a split between detailed * and summarized actions. * * @param boolean $detailed True when the current action is not in $summarizedActions. * @param string $action The current action. * @return \MUtil_Model_ModelAbstract */ protected function createModel($detailed, $action) { $dbLookup = $this->util->getDbLookup(); $survey = null; $translated = $this->util->getTranslated(); $yesNo = $translated->getYesNo(); if ($detailed) { $surveyId = $this->_getIdParam(); if ($surveyId) { $survey = $this->loader->getTracker()->getSurvey($surveyId); } } $model = new \Gems_Model_JoinModel('surveys', 'gems__surveys', 'gus'); $model->addTable('gems__sources', array('gsu_id_source' => 'gso_id_source')); $model->setCreate(false); $model->addColumn("CASE WHEN gsu_survey_pdf IS NULL OR CHAR_LENGTH(gsu_survey_pdf) = 0 THEN 0 ELSE 1 END", 'gsu_has_pdf'); $model->addColumn(sprintf("CASE WHEN (gsu_status IS NULL OR gsu_status = '') THEN '%s' ELSE gsu_status END", $this->_('OK')), 'gsu_status_show', 'gsu_status'); $model->addColumn("CASE WHEN gsu_surveyor_active THEN '' ELSE 'deleted' END", 'row_class'); $model->resetOrder(); $model->set('gsu_survey_name', 'label', $this->_('Name'), 'elementClass', 'Exhibitor'); $model->set('gsu_survey_description', 'label', $this->_('Description'), 'elementClass', 'Exhibitor', 'formatFunction', array(__CLASS__, 'formatDescription')); $model->set('gso_source_name', 'label', $this->_('Source'), 'elementClass', 'Exhibitor'); $model->set('gsu_surveyor_active', 'label', $this->_('Active in source'), 'elementClass', 'Exhibitor', 'multiOptions', $yesNo); $model->set('gsu_status_show', 'label', $this->_('Status in source'), 'elementClass', 'Exhibitor'); $model->set('gsu_active', 'label', sprintf($this->_('Active in %s'), $this->project->getName()), 'elementClass', 'Checkbox', 'multiOptions', $yesNo); $model->set('gsu_id_primary_group', 'label', $this->_('Group'), 'description', $this->_('If empty, survey will never show up!'), 'multiOptions', $dbLookup->getGroups()); if ($detailed) { $model->addDependency('CanEditDependency', 'gsu_surveyor_active', array('gsu_active')); $model->set('gsu_active', 'validators[group]', new \MUtil_Validate_Require($model->get('gsu_active', 'label'), 'gsu_id_primary_group', $model->get('gsu_id_primary_group', 'label'))); } $model->set('gsu_insertable', 'label', $this->_('Insertable'), 'description', $this->_('Can this survey be manually inserted into a track?'), 'elementClass', 'Checkbox', 'multiOptions', $yesNo, 'onclick', 'this.form.submit()'); if ($detailed) { $model->set('gsu_valid_for_length', 'label', $this->_('Add to inserted end date'), 'description', $this->_('Add to the start date to calculate the end date when inserting.'), 'filter', 'Int'); $model->set('gsu_valid_for_unit', 'label', $this->_('Inserted end date unit'), 'description', $this->_('The unit used to calculate the end date when inserting the survey.'), 'multiOptions', $translated->getPeriodUnits()); $model->set('gsu_insert_organizations', 'label', $this->_('Insert organizations'), 'description', $this->_('The organizations where the survey may be inserted.'), 'elementClass', 'MultiCheckbox', 'multiOptions', $dbLookup->getOrganizations(), 'required', true); $ct = new \MUtil_Model_Type_ConcatenatedRow('|', $this->_(', ')); $ct->apply($model, 'gsu_insert_organizations'); // if ('edit' == $action) { // $element = new \Gems_JQuery_Form_Element_ToggleCheckboxes('toggleOrg', array('selector'=>'input[name^=gtr_organizations]')); // $element->setLabel($this->_('Toggle')); // $model->set('toggleOrg', 'elementClass', $element); // } $switches = array(0 => array('gsu_valid_for_length' => array('elementClass' => 'Hidden', 'label' => null), 'gsu_valid_for_unit' => array('elementClass' => 'Hidden', 'label' => null), 'gsu_insert_organizations' => array('elementClass' => 'Hidden', 'label' => null))); $model->addDependency(array('ValueSwitchDependency', $switches), 'gsu_insertable'); } if ($detailed) { $model->set('track_usage', 'label', $this->_('Usage'), 'elementClass', 'Exhibitor', 'noSort', true, 'no_text_search', true); $model->setOnLoad('track_usage', array($this, 'calculateTrackUsage')); $model->set('calc_duration', 'label', $this->_('Duration calculated'), 'elementClass', 'Html'); $model->setOnLoad('calc_duration', array($this, 'calculateDuration')); $model->set('gsu_duration', 'label', $this->_('Duration description'), 'description', $this->_('Text to inform the respondent, e.g. "20 seconds" or "1 minute".')); if ($survey instanceof \Gems_Tracker_Survey) { $surveyFields = $this->util->getTranslated()->getEmptyDropdownArray() + $survey->getQuestionList($this->locale->getLanguage()); $model->set('gsu_result_field', 'label', $this->_('Result field'), 'multiOptions', $surveyFields); // $model->set('gsu_agenda_result', 'label', $this->_('Agenda field')); } } else { $model->set('track_count', 'label', ' ', 'elementClass', 'Exhibitor', 'noSort', true, 'no_text_search', true); $model->setOnLoad('track_count', array($this, 'calculateTrackCount')); } $model->set('gsu_code', 'label', $this->_('Survey code'), 'description', $this->_('Optional code name to link the survey to program code.'), 'size', 10); $model->set('gsu_export_code', 'label', $this->_('Survey export code'), 'description', $this->_('A unique code indentifying this survey during track import'), 'size', 20); if ($detailed) { $events = $this->loader->getEvents(); $beforeOptions = $events->listSurveyBeforeAnsweringEvents(); if (count($beforeOptions) > 1) { $model->set('gsu_beforeanswering_event', 'label', $this->_('Before answering'), 'multiOptions', $beforeOptions, 'elementClass', 'Select'); } $completedOptions = $events->listSurveyCompletionEvents(); if (count($completedOptions) > 1) { $model->set('gsu_completed_event', 'label', $this->_('After completion'), 'multiOptions', $completedOptions, 'elementClass', 'Select'); } $displayOptions = $events->listSurveyDisplayEvents(); if (count($displayOptions) > 1) { $model->set('gsu_display_event', 'label', $this->_('Answer display'), 'multiOptions', $displayOptions, 'elementClass', 'Select'); } if ('show' !== $action || $survey->hasPdf()) { // Only the action changes from the current page // and the right to see the pdf is the same as // the right to see this page. $pdfLink = \MUtil_Html::create('a', array($this->getRequest()->getActionKey() => 'pdf'), array('class' => 'pdf', 'target' => '_blank', 'type' => 'application/pdf', 'onclick' => 'event.cancelBubble = true;')); $model->set('gsu_survey_pdf', 'label', 'Pdf', 'accept', 'application/pdf', 'destination', $this->loader->getPdf()->getUploadDir('survey_pdfs'), 'elementClass', 'File', 'extension', 'pdf', 'filename', $surveyId, 'required', false, 'itemDisplay', $pdfLink, 'validators[pdf]', new \MUtil_Validate_Pdf()); } } return $model; }
/** * Creates a model for getModel(). Called only for each new $action. * * The parameters allow you to easily adapt the model to the current action. The $detailed * parameter was added, because the most common use of action is a split between detailed * and summarized actions. * * @param boolean $detailed True when the current action is not in $summarizedActions. * @param string $action The current action. * @return \MUtil_Model_ModelAbstract */ protected function createModel($detailed, $action) { $model = new \MUtil_Model_TableModel('gems__locations'); $yesNo = $this->util->getTranslated()->getYesNo(); \Gems_Model::setChangeFieldsByPrefix($model, 'glo'); $model->setDeleteValues('glo_active', 0); $model->set('glo_name', 'label', $this->_('Location'), 'required', true); $model->set('glo_organizations', 'label', $this->_('Organizations'), 'description', $this->_('Checked organizations see this organizations respondents.'), 'elementClass', 'MultiCheckbox', 'multiOptions', $this->util->getDbLookup()->getOrganizations(), 'noSort', true); $tp = new \MUtil_Model_Type_ConcatenatedRow(':', ', '); $tp->apply($model, 'glo_organizations'); $model->setIfExists('glo_match_to', 'label', $this->_('Import matches'), 'description', $this->_("Split multiple import matches using '|'.")); $model->setIfExists('glo_code', 'label', $this->_('Location code'), 'size', 10, 'description', $this->_('Optional code name to link the location to program code.')); $model->setIfExists('glo_url', 'label', $this->_('Location url'), 'description', $this->_('Complete url for location: http://www.domain.etc'), 'validator', 'Url'); $model->setIfExists('glo_url_route', 'label', $this->_('Location route url'), 'description', $this->_('Complete url for route to location: http://www.domain.etc'), 'validator', 'Url'); $model->setIfExists('glo_address_1', 'label', $this->_('Street')); $model->setIfExists('glo_address_2', 'label', ' '); $model->setIfExists('glo_zipcode', 'label', $this->_('Zipcode'), 'size', 7, 'description', $this->_('E.g.: 0000 AA'), 'filter', new \Gems_Filter_DutchZipcode()); $model->setIfExists('glo_city', 'label', $this->_('City')); $model->setIfExists('glo_region', 'label', $this->_('Region')); $model->setIfExists('glo_iso_country', 'label', $this->_('Country'), 'multiOptions', $this->util->getLocalized()->getCountries()); $model->setIfExists('glo_phone_1', 'label', $this->_('Phone')); $model->setIfExists('glo_phone_2', 'label', $this->_('Phone 2')); $model->setIfExists('glo_phone_3', 'label', $this->_('Phone 3')); $model->setIfExists('glo_phone_4', 'label', $this->_('Phone 4')); $model->setIfExists('glo_active', 'label', $this->_('Active'), 'description', $this->_('Inactive means assignable only through automatich processes.'), 'elementClass', 'Checkbox', 'multiOptions', $yesNo); $model->setIfExists('glo_filter', 'label', $this->_('Filter'), 'description', $this->_('When checked appointments with these locations are not imported.'), 'elementClass', 'Checkbox', 'multiOptions', $yesNo); $model->addColumn("CASE WHEN glo_active = 1 THEN '' ELSE 'deleted' END", 'row_class'); return $model; }
/** * Creates a model for getModel(). Called only for each new $action. * * The parameters allow you to easily adapt the model to the current action. The $detailed * parameter was added, because the most common use of action is a split between detailed * and summarized actions. * * @param boolean $detailed True when the current action is not in $summarizedActions. * @param string $action The current action. * @return \MUtil_Model_ModelAbstract */ public function createModel($detailed, $action) { $model = new \MUtil_Model_TableModel('gems__roles'); $model->set('grl_name', 'label', $this->_('Name'), 'size', 15, 'minlength', 4); $model->set('grl_description', 'label', $this->_('Description'), 'size', 40); $model->set('grl_parents', 'label', $this->_('Parents')); $tpa = new \MUtil_Model_Type_ConcatenatedRow(',', ', '); $tpa->apply($model, 'grl_parents'); $model->setOnLoad('grl_parents', array(\Gems_Roles::getInstance(), 'translateToRoleNames')); $model->set('grl_privileges', 'label', $this->_('Privileges')); $tpr = new \MUtil_Model_Type_ConcatenatedRow(',', '<br/>'); $tpr->apply($model, 'grl_privileges'); if ($detailed) { $model->set('grl_name', 'validators[unique]', $model->createUniqueValidator('grl_name'), 'validators[nomaster]', new \MUtil_Validate_IsNot('master', $this->_('The name "master" is reserved'))); $model->set('grl_privileges', 'formatFunction', array($this, 'formatPrivileges')); if ('show' === $action) { $model->addColumn('grl_parents', 'inherited'); $tpa->apply($model, 'inherited'); $model->set('inherited', 'label', $this->_('Inherited privileges'), 'formatFunction', array($this, 'formatInherited')); $model->setOnLoad('inherited', array(\Gems_Roles::getInstance(), 'translateToRoleNames')); // Concatenated field, we can not use onload so handle transaltion to rolenames in the formatFunction $model->addColumn("CONCAT(COALESCE(grl_parents, ''), '\t', COALESCE(grl_privileges, ''))", 'not_allowed'); $model->set('not_allowed', 'label', $this->_('Not allowed'), 'formatFunction', array($this, 'formatNotAllowed')); } } else { $model->set('grl_privileges', 'formatFunction', array($this, 'formatLongLine')); } \Gems_Model::setChangeFieldsByPrefix($model, 'grl'); return $model; }
/** * Sets the labels, format functions, etc... * * @param boolean $detailed True when shopwing detailed information * @param boolean $edit When true use edit settings * @return \Gems_Tracker_Model_TrackModel */ public function applyFormatting($detailed = false, $edit = false) { $translated = $this->util->getTranslated(); $translator = $this->getTranslateAdapter(); if ($edit) { $dateFormat = \MUtil_Model_Bridge_FormBridge::getFixedOption('date', 'dateFormat'); } else { $dateFormat = $translated->dateFormatString; } $this->resetOrder(); $this->set('gtr_track_name', 'label', $translator->_('Name')); $this->set('gtr_track_class', 'label', $translator->_('Track Engine'), 'multiOptions', $this->tracker->getTrackEngineList($detailed)); $this->set('gtr_survey_rounds', 'label', $translator->_('Surveys')); $this->set('gtr_active', 'label', $translator->_('Active'), 'multiOptions', $translated->getYesNo()); $this->set('gtr_date_start', 'label', $translator->_('From'), 'dateFormat', $dateFormat, 'formatFunction', $translated->formatDate); $this->set('gtr_date_until', 'label', $translator->_('Use until'), 'dateFormat', $dateFormat, 'formatFunction', $translated->formatDateForever); $this->setIfExists('gtr_code', 'label', $translator->_('Track code'), 'size', 10, 'description', $translator->_('Optional code name to link the track to program code.')); if ($detailed) { $events = $this->loader->getEvents(); $caList = $events->listTrackCalculationEvents(); if (count($caList) > 1) { $this->setIfExists('gtr_calculation_event', 'label', $translator->_('Before (re)calculation'), 'multiOptions', $caList); } $coList = $events->listTrackCompletionEvents(); if (count($coList) > 1) { $this->setIfExists('gtr_completed_event', 'label', $translator->_('After completion'), 'multiOptions', $coList); } $bfuList = $events->listTrackBeforeFieldUpdateEvents(); if (count($bfuList) > 1) { $this->setIfExists('gtr_beforefieldupdate_event', 'label', $translator->_('Before field update'), 'multiOptions', $bfuList); } $fuList = $events->listTrackFieldUpdateEvents(); if (count($fuList) > 1) { $this->setIfExists('gtr_fieldupdate_event', 'label', $translator->_('After field update'), 'multiOptions', $fuList); } $this->setIfExists('gtr_organizations', 'label', $translator->_('Organizations'), 'elementClass', 'MultiCheckbox', 'multiOptions', $this->util->getDbLookup()->getOrganizationsWithRespondents(), 'required', true); $ct = new \MUtil_Model_Type_ConcatenatedRow('|', $translator->_(', ')); $ct->apply($this, 'gtr_organizations'); } if ($edit) { $this->set('toggleOrg', 'elementClass', 'ToggleCheckboxes', 'selectorName', 'gtr_organizations'); $this->set('gtr_track_name', 'minlength', 4, 'size', 30, 'validators[unique]', $this->createUniqueValidator('gtr_track_name')); } return $this; }
/** * Set those settings needed for the detailed display * * @return \Gems\Tracker\Model\FieldMaintenanceModel (continuation pattern) */ public function applyDetailSettings() { $this->applyBrowseSettings(true); $this->_addLoadDependency = true; $this->set('gtf_id_track', 'label', $this->_('Track'), 'multiOptions', $this->util->getTrackData()->getAllTracks()); $this->set('gtf_field_description', 'label', $this->_('Description'), 'description', $this->_('Optional extra description to show the user.')); $this->set('gtf_track_info_label', 'label', $this->_('Add name to description')); $this->set('htmlUse', 'label', ' '); // But do always transform gtf_calculate_using on load and save // as otherwise we might not be sure what to do $contact = new \MUtil_Model_Type_ConcatenatedRow(self::FIELD_SEP, '; ', false); $contact->apply($this, 'gtf_calculate_using'); // Clean up data always show in browse view, but not always in detail views $this->set('gtf_create_track', 'label', null); $switches = array(0 => array('gtf_track_info_label' => array('elementClass' => 'Hidden', 'label' => null))); $this->addDependency(array('ValueSwitchDependency', $switches), 'gtf_to_track_info'); }