/** * Load extra data not from the model into the form */ protected function loadFormData() { parent::loadFormData(); $this->loadMailer(); if (isset($this->formData['gctt'])) { $multi = false; if (count($this->formData['gctt']) > 1) { $multi = true; $allLanguages = $this->util->getLocalized()->getLanguages(); } $preview = $this->getPreview($this->formData['gctt']); $this->formData['preview_html'] = $preview['html']; $this->formData['preview_text'] = $preview['text']; } if (!isset($this->formData['to'])) { $organization = $this->mailer->getOrganization(); $this->formData['to'] = $this->formData['from'] = null; if ($organization->getEmail()) { $this->formData['to'] = $this->formData['from'] = $organization->getEmail(); } elseif ($this->project->getSiteEmail()) { $this->formData['to'] = $this->formData['from'] = $this->project->getSiteEmail(); } } $this->formData['available_fields'] = $this->mailElements->displayMailFields($this->mailer->getMailFields()); }
/** * 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; }
/** * * @param boolean $detailed True when the current action is not in $summarizedActions. * @param string $action The current action. * @param int $defaultOrgId The default organization id or null if current organization * @return \Gems_Model_StaffModel */ public function applySettings($detailed, $action, $defaultOrgId) { $this->resetOrder(); $dbLookup = $this->util->getDbLookup(); $editing = $action == 'edit' || $action == 'create'; $translated = $this->util->getTranslated(); $user = $this->loader->getCurrentUser(); $yesNo = $translated->getYesNo(); if ($editing) { $ucfirst = new \Zend_Filter_Callback('ucfirst'); if ($this->project->isLoginShared()) { $this->set('gsf_login', 'validator', $this->createUniqueValidator('gsf_login', array('gsf_id_user'))); } else { // per organization $this->set('gsf_login', 'validator', $this->createUniqueValidator(array('gsf_login', 'gsf_id_organization'), array('gsf_id_user'))); } } else { $ucfirst = null; } $this->set('gsf_login', 'label', $this->_('Username'), 'minlength', 4, 'required', true, 'size', 15); if ($user->hasPrivilege('pr.staff.see.all') || !$editing) { // Select organization $options = $dbLookup->getOrganizations(); } else { $options = $user->getAllowedOrganizations(); } $this->set('gsf_id_organization', 'label', $this->_('Organization'), 'multiOptions', $options, 'required', true); if ($detailed) { $this->set('gsf_first_name', 'label', $this->_('First name'), 'filters[ucfirst]', $ucfirst); $this->set('gsf_surname_prefix', 'label', $this->_('Surname prefix'), 'description', $this->_('de, van der, \'t, etc...')); $this->set('gsf_last_name', 'label', $this->_('Last name'), 'required', true, 'filters[ucfirst]', $ucfirst); } else { $this->set('name', 'label', $this->_('Name')); } $this->set('gsf_gender', 'label', $this->_('Gender'), 'elementClass', 'Radio', 'multiOptions', $translated->getGenders(), 'separator', ' '); $this->set('gsf_email', 'label', $this->_('E-Mail'), 'itemDisplay', array('MUtil_Html_AElement', 'ifmail'), 'size', 30, 'validators[email]', 'SimpleEmail'); $this->set('gsf_id_primary_group', 'label', $this->_('Primary function'), 'multiOptions', $editing ? $user->getAllowedStaffGroups() : $dbLookup->getStaffGroups()); if ($detailed) { // Now try to load the current organization and find out if it has a default user definition // otherwise use the defaultStaffDefinition $organization = $this->loader->getOrganization($defaultOrgId ? $defaultOrgId : $user->getCurrentOrganizationId()); $this->set('gsf_id_organization', 'default', $organization->getId()); $this->set('gul_user_class', 'label', $this->_('User Definition'), 'default', $organization->get('gor_user_class', $this->defaultStaffDefinition), 'multiOptions', $this->loader->getUserLoader()->getAvailableStaffDefinitions()); if ($editing) { $this->set('gul_user_class', 'order', 1, 'required', true); } $this->set('gsf_iso_lang', 'label', $this->_('Language'), 'default', $this->project->locale['default'], 'multiOptions', $this->util->getLocalized()->getLanguages()); $this->set('gul_can_login', 'label', $this->_('Can login'), 'default', 1, 'description', $this->_('Users can only login when this box is checked.'), 'elementClass', 'Checkbox', 'multiOptions', $yesNo); $this->set('gsf_logout_on_survey', 'label', $this->_('Logout on survey'), 'description', $this->_('If checked the user will logoff when answering a survey.'), 'elementClass', 'Checkbox', 'multiOptions', $yesNo); $this->set('gsf_mail_watcher', 'label', $this->_('Check cron job mail'), 'description', $this->_('If checked the user will be mailed when the cron job does not run on time.'), 'elementClass', 'Checkbox', 'multiOptions', $yesNo); } $this->set('gsf_active', 'label', $this->_('Active'), 'elementClass', 'None', 'multiOptions', $yesNo); $this->setDeleteValues('gsf_active', 0, 'gul_can_login', 0); if (!$user->hasPrivilege('pr.staff.edit.all')) { $this->set('gsf_id_organization', 'elementClass', 'Exhibitor'); } return $this; }
/** * Set those settings needed for the detailed display * * @return \Gems_Model_RespondentModel */ public function applyDetailSettings() { $dbLookup = $this->util->getDbLookup(); $localized = $this->util->getLocalized(); $translated = $this->util->getTranslated(); if ($this->loginCheck) { $this->addLoginCheck(); } $this->resetOrder(); if ($this->has('gr2o_id_organization')) { $this->set('gr2o_id_organization', 'label', $this->_('Organization'), 'tab', $this->_('Identification'), 'multiOptions', $this->currentUser->getRespondentOrganizations()); $this->set('gr2o_id_organization', 'default', $this->currentUser->getCurrentOrganizationId()); if (count($this->currentUser->getAllowedOrganizations()) == 1) { $this->set('gr2o_id_organization', 'elementClass', 'Exhibitor'); } } // The SSN if ($this->hashSsn !== self::SSN_HIDE) { $this->set('grs_ssn', 'label', $this->_('SSN'), 'tab', $this->_('Identification')); } $this->setIfExists('gr2o_patient_nr', 'label', $this->_('Respondent number'), 'tab', $this->_('Identification')); $this->setIfExists('grs_initials_name', 'label', $this->_('Initials')); $this->setIfExists('grs_first_name', 'label', $this->_('First name')); $this->setIfExists('grs_surname_prefix', 'label', $this->_('Surname prefix'), 'description', $this->_('de, ibn, Le, Mac, von, etc...')); $this->setIfExists('grs_last_name', 'label', $this->_('Last name')); $this->setIfExists('grs_partner_surname_prefix', 'label', $this->_('Partner surname prefix'), 'description', $this->_('de, ibn, Le, Mac, von, etc...')); $this->setIfExists('grs_partner_last_name', 'label', $this->_('Partner last name')); $this->setIfExists('grs_gender', 'label', $this->_('Gender'), 'multiOptions', $translated->getGenderHello()); $this->setIfExists('grs_birthday', 'label', $this->_('Birthday'), 'dateFormat', \Zend_Date::DATE_MEDIUM); $this->setIfExists('grs_email', 'label', $this->_('E-Mail'), 'tab', $this->_('Contact information')); $this->setIfExists('gr2o_mailable', 'label', $this->_('May be mailed'), 'elementClass', 'radio', 'separator', ' ', 'multiOptions', $translated->getYesNo()); $this->setIfExists('gr2o_treatment', 'label', $this->_('Treatment')); $this->setIfExists('gr2o_comments', 'label', $this->_('Comments')); $this->setIfExists('grs_address_1', 'label', $this->_('Street')); $this->setIfExists('grs_address_2', 'label', ' '); // \MUtil_Echo::track($this->getItemsOrdered(), $this->getOrder('grs_email')); $this->setIfExists('grs_zipcode', 'label', $this->_('Zipcode')); $this->setIfExists('grs_city', 'label', $this->_('City')); $this->setIfExists('grs_iso_country', 'label', $this->_('Country'), 'multiOptions', $localized->getCountries()); $this->setIfExists('grs_phone_1', 'label', $this->_('Phone')); $this->setIfExists('grs_phone_2', 'label', $this->_('Phone 2')); $this->setIfExists('grs_phone_3', 'label', $this->_('Phone 3')); $this->setIfExists('grs_phone_4', 'label', $this->_('Phone 4')); $this->setIfExists('grs_iso_lang', 'label', $this->_('Language'), 'multiOptions', $localized->getLanguages(), 'tab', $this->_('Settings'), 'default', $this->project->getLocaleDefault()); $this->setIfExists('gr2o_consent', 'label', $this->_('Consent'), 'default', $this->util->getDefaultConsent(), 'description', $this->_('Has the respondent signed the informed consent letter?'), 'multiOptions', $dbLookup->getUserConsents()); $changers = $this->getChangersList(); $this->setIfExists('gr2o_opened', 'label', $this->_('Opened'), 'dateFormat', \Zend_Date::DATE_MEDIUM, 'default', '', 'elementClass', 'None', 'formatFunction', array($translated, 'formatDateTime')); $this->setIfExists('gr2o_opened_by', 'label', $this->_('Opened'), 'elementClass', 'None', 'multiOptions', $changers); $this->setIfExists('gr2o_changed', 'label', $this->_('Changed on'), 'dateFormat', \Zend_Date::DATE_MEDIUM, 'default', '', 'formatFunction', array($translated, 'formatDateTime')); $this->setIfExists('gr2o_changed_by', 'label', $this->_('Changed by'), 'multiOptions', $changers); $this->setIfExists('gr2o_created', 'label', $this->_('Creation date'), 'dateFormat', \Zend_Date::DATE_MEDIUM, 'default', '', 'formatFunction', array($translated, 'formatDateTime')); $this->setIfExists('gr2o_created_by', 'label', $this->_('Creation by'), 'multiOptions', $changers); return $this; }
/** * 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'), 'tab', $this->_('General')); $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_resp_change_event', 'label', $this->_('Respondent change event'), 'multiOptions', $this->loader->getEvents()->listRespondentChangedEvents()); $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; }
/** * 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) { // Export all if ('excel' === $action) { $detailed = true; } if ($detailed) { $year = $this->_('Year'); $month = $this->_('Month'); $fields[$year] = new \Zend_Db_Expr("YEAR(gr2o_created)"); $fields[$month] = new \Zend_Db_Expr("MONTH(gr2o_created)"); } $consents = $this->util->getDbLookup()->getUserConsents(); $deleteds = array('' => '') + $this->util->getReceptionCodeLibrary()->getRespondentDeletionCodes(); $sql = "SUM(CASE WHEN grc_success = 1 AND gr2o_consent = '%s' THEN 1 ELSE 0 END)"; foreach ($consents as $consent => $translated) { $fields[$translated] = new \Zend_Db_Expr(sprintf($sql, $consent)); } $fields[$this->_('Total OK')] = new \Zend_Db_Expr("SUM(CASE WHEN grc_success = 1 THEN 1 ELSE 0 END)"); $sql = "SUM(CASE WHEN gr2o_reception_code = '%s' THEN 1 ELSE 0 END)"; foreach ($deleteds as $code => $translated) { $fields[$translated] = new \Zend_Db_Expr(sprintf($sql, $code)); } $fields[$this->_('Dropped')] = new \Zend_Db_Expr("SUM(CASE WHEN grc_success = 0 THEN 1 ELSE 0 END)"); $fields[$this->_('Total')] = new \Zend_Db_Expr("COUNT(*)"); $select = $this->db->select(); $select->from('gems__respondent2org', $fields)->joinInner('gems__reception_codes', 'gr2o_reception_code = grc_id_reception_code', array())->joinInner('gems__organizations', 'gr2o_id_organization = gor_id_organization', array('gor_name', 'gor_id_organization')); $select->group(array('gor_name', 'gor_id_organization')); if ($detailed) { $select->group(array($fields[$year], $fields[$month])); } $model = new \MUtil_Model_SelectModel($select, 'consent-plan'); $model->setKeys(array('gor_id_organization')); $model->resetOrder(); $model->set('gor_name', 'label', $this->_('Organization')); foreach ($fields as $field => $expr) { $model->set($field, 'label', $field, 'tdClass', 'rightAlign', 'thClass', 'rightAlign'); } foreach ($deleteds as $code => $translated) { $model->set($translated, 'tdClass', 'rightAlign smallTime', 'thClass', 'rightAlign smallTime'); } foreach (array($this->_('Total OK'), $this->_('Dropped'), $this->_('Total')) as $name) { $model->set($name, 'itemDisplay', \MUtil_Html::create('strong'), 'tableHeaderDisplay', \MUtil_Html::create('em'), 'tdClass', 'rightAlign selectedColumn', 'thClass', 'rightAlign selectedColumn'); } if ($detailed) { $model->set($month, 'formatFunction', $this->util->getLocalized()->getMonthName); } // Only show organisations the user is allowed to see $allowed = $this->currentUser->getAllowedOrganizations(); $model->setFilter(array('gr2o_id_organization' => array_keys($allowed))); // \MUtil_Model::$verbose = true; return $model; }
protected function setTableHeader(\MUtil_Model_Bridge_TableBridge $bridge, \MUtil_Lazy_RepeatableInterface $repeater, $columnClass) { $baseurl = $bridge->getBaseUrl(); // Left cell with period types $th = $bridge->th($this->_('Period'), ' '); $th->class = 'middleAlign'; $thdiv = $th->span()->spaced(); // array('class' => 'rightFloat')); $contents = $this->getDateLabels(); foreach ($this->getDateDescriptions() as $letter => $title) { if (isset($contents[$letter])) { $content = $contents[$letter]; } else { $content = strtolower($this->_($letter)); } if ($letter == $this->dateType) { $thdiv->span($content, array('class' => 'browselink btn btn-primary btn-xs disabled')); } else { $thdiv->a(array(self::DATE_TYPE => $letter, self::DATE_FACTOR => $this->dateFactorChanges[$letter]) + $baseurl, $content, array('class' => 'browselink btn btn-default btn-xs', 'title' => $title)); } } // Repeating column switch ($this->dateType) { case 'D': // $header = $repeater->period_1; $header = $repeater->period_1->call($this->util->getTranslated()->formatDate); break; case 'W': $header = array($repeater->period_1, \MUtil_Html::create()->br(), \MUtil_Lazy::call('sprintf', $this->_('week %s'), $repeater->period_2)); break; case 'M': $header = array($repeater->period_1, \MUtil_Html::create()->br(), $repeater->period_2->call($this->util->getLocalized()->getMonthName)); break; case 'Y': $header = $repeater->period_1; break; default: throw new \Gems_Exception_Coding('Incorrect date_type value: ' . $this->dateType); // $this->_getParam('date_type', 'W')); } $th = $bridge->th(); $th->class = array($this->dataCellClass, $columnClass); $th->a(array(self::DATE_FACTOR => $repeater->date_factor, \MUtil_Model::AUTOSEARCH_RESET => null) + $baseurl, $header); $th->setRepeater($repeater); $th->setRepeatTags(true); $baseurl[\Gems_Selector_DateSelectorAbstract::DATE_FACTOR] = $repeater->date_factor; $baseurl[\Gems_Selector_DateSelectorAbstract::DATE_GROUP] = null; $th->onclick = array('location.href=\'', new \MUtil_Html_HrefArrayAttribute($baseurl), '\';'); }