/**
  * 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)
 {
     $currentLanguage = $this->locale->getLanguage();
     $model = $this->loader->getModels()->getCommtemplateModel($currentLanguage);
     $commTargets = $this->loader->getMailTargets();
     $model->set('gct_target', 'label', $this->_('Mail Target'), 'multiOptions', $commTargets, 'Gems_Default_CommTemplateAction', 'translateTargets');
     $model->set('gct_name', 'label', $this->_('Name'), 'size', 50);
     $translationModel = new \MUtil_Model_TableModel('gems__comm_template_translations', 'gctt');
     if ($action === 'index') {
         $translationModel->set('gctt', 'label', $this->_('Subject'), 'size', 50, 'formatFunction', array('Gems_Default_CommTemplateAction', 'displayMultipleSubjects'));
     } else {
         $translationModel->set('gctt_subject', 'label', $this->_('Subject'), 'size', 50);
     }
     if ($detailed) {
         $translationModel->set('gctt_body', 'label', $this->_('Message'), 'elementClass', 'textarea', 'decorators', array('CKEditor'), 'rows', 4, 'formatFunction', array('Gems_Default_CommTemplateAction', 'bbToHtml'));
     }
     if ($this->project->getEmailMultiLanguage()) {
         $allLanguages = $this->util->getLocalized()->getLanguages();
         ksort($allLanguages);
         $requiredRows = array();
         foreach ($allLanguages as $code => $language) {
             $requiredRows[]['gctt_lang'] = $code;
         }
     } else {
         $defaultLanguage = $this->project->getLocaleDefault();
         $requiredRows[]['gctt_lang'] = $defaultLanguage;
         $translationModel->setFilter(array('gctt_lang' => $defaultLanguage));
     }
     $model->set('gct_code', 'label', $this->_('Template code'), 'size', 50, 'description', $this->_('Optional code name to link the template to program code.'));
     $transformer = new \MUtil_Model_Transform_RequiredRowsTransformer();
     $transformer->setRequiredRows($requiredRows);
     $translationModel->addTransformer($transformer);
     $model->addModel($translationModel, array('gct_id_template' => 'gctt_id_template'), 'gctt');
     return $model;
 }
Ejemplo n.º 2
0
 /**
  * To upgrade from 143 to 15 we need to do some work:
  * 1. execute db patches 42 and 43
  * 2. create new tables
  */
 public function Upgrade143to150()
 {
     $this->_batch->addTask('Db_AddPatches', 42);
     $this->_batch->addTask('Db_AddPatches', 43);
     $this->_batch->addTask('Db_CreateNewTables');
     $this->_batch->addTask('Echo', $this->_('Syncing surveys for all sources'));
     //Now sync the db sources to allow limesurvey source to add a field to the tokentable
     $model = new \MUtil_Model_TableModel('gems__sources');
     $data = $model->load(false);
     foreach ($data as $row) {
         $this->_batch->addTask('Tracker_SourceSyncSurveys', $row['gso_id_source']);
     }
     return true;
 }
 /**
  * This could fail when date format is interpreted incorrect (bug #703)
  */
 public function testPostDataToDbEn()
 {
     $this->setLocaleTo('en');
     $model = $this->getModel();
     $row = $model->loadFirst();
     $date = $row['grs_birthday'];
     $postData = $date->get($this->_model->get('grs_birthday', 'dateFormat'));
     $postRow = array('grs_birthday' => $postData) + $row;
     $postRow = $this->_model->processAfterLoad(array($postRow), false, true);
     $rowsaved = $model->save($postRow);
     $this->assertEquals($row['grs_birthday']->get('yyyy-MM-dd'), $rowsaved[0]['grs_birthday']->get('yyyy-MM-dd'));
 }
 /**
  * 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)
 {
     $rcLib = $this->util->getReceptionCodeLibrary();
     $yesNo = $this->util->getTranslated()->getYesNo();
     $model = new \MUtil_Model_TableModel('gems__reception_codes');
     $model->copyKeys();
     // The user can edit the keys.
     $model->set('grc_id_reception_code', 'label', $this->_('Code'), 'size', '10');
     $model->set('grc_description', 'label', $this->_('Description'), 'size', '30');
     $model->set('grc_success', 'label', $this->_('Is success code'), 'multiOptions', $yesNo, 'elementClass', 'CheckBox', 'description', $this->_('This reception code is a success code.'));
     $model->set('grc_active', 'label', $this->_('Active'), 'multiOptions', $yesNo, 'elementClass', 'CheckBox', 'description', $this->_('Only active codes can be selected.'));
     if ($detailed) {
         $model->set('desc1', 'elementClass', 'Html', 'label', ' ', 'value', \MUtil_Html::create('h4', $this->_('Can be assigned to')));
     }
     $model->set('grc_for_respondents', 'label', $this->_('Respondents'), 'multiOptions', $yesNo, 'elementClass', 'CheckBox', 'description', $this->_('This reception code can be assigned to a respondent.'));
     $model->set('grc_for_tracks', 'label', $this->_('Tracks'), 'multiOptions', $yesNo, 'elementClass', 'CheckBox', 'description', $this->_('This reception code can be assigned to a track.'));
     $model->set('grc_for_surveys', 'label', $this->_('Tokens'), 'multiOptions', $rcLib->getSurveyApplicationValues(), 'description', $this->_('This reception code can be assigned to a token.'));
     if ($detailed) {
         $model->set('desc2', 'elementClass', 'Html', 'label', ' ', 'value', \MUtil_Html::create('h4', $this->_('Additional actions')));
     }
     $model->set('grc_redo_survey', 'label', $this->_('Redo survey'), 'multiOptions', $rcLib->getRedoValues(), 'description', $this->_('Redo a survey on this reception code.'));
     $model->set('grc_overwrite_answers', 'label', $this->_('Overwrite existing consents'), 'multiOptions', $yesNo, 'elementClass', 'CheckBox', 'description', $this->_('Remove the consent from already answered surveys.'));
     if ($detailed) {
         $model->set('grc_id_reception_code', 'validator', $model->createUniqueValidator('grc_id_reception_code'));
         $model->set('grc_description', 'validator', $model->createUniqueValidator('grc_description'));
     }
     if ($this->project->multiLocale) {
         $model->set('grc_description', 'description', 'ENGLISH please! Use translation file to translate.');
     }
     \Gems_Model::setChangeFieldsByPrefix($model, 'grc');
     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)
 {
     $translated = $this->util->getTranslated();
     $model = new \MUtil_Model_TableModel('gems__tracks');
     $model->set('gtr_track_name', 'label', $this->_('Track'));
     $model->set('gtr_survey_rounds', 'label', $this->_('Survey #'));
     $model->set('gtr_date_start', 'label', $this->_('From'), 'dateFormat', $translated->formatDate, 'tdClass', 'date');
     $model->set('gtr_date_until', 'label', $this->_('Until'), 'dateFormat', $translated->formatDateForever, 'tdClass', 'date');
     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__groups');
     // Add id for excel export
     if ($action == 'excel') {
         $model->set('ggp_id_group', 'label', 'id');
     }
     $model->set('ggp_name', 'label', $this->_('Name'), 'size', 15, 'minlength', 4, 'validator', $model->createUniqueValidator('ggp_name'));
     $model->set('ggp_description', 'label', $this->_('Description'), 'size', 40);
     $model->set('ggp_role', 'label', $this->_('Role'), 'multiOptions', $this->util->getDbLookup()->getRoles());
     $yesNo = $this->util->getTranslated()->getYesNo();
     $model->set('ggp_group_active', 'label', $this->_('Active'), 'multiOptions', $yesNo, 'elementClass', 'Checkbox');
     $model->set('ggp_staff_members', 'label', $this->_('Staff'), 'multiOptions', $yesNo, 'elementClass', 'Checkbox');
     $model->set('ggp_respondent_members', 'label', $this->_('Respondents'), 'multiOptions', $yesNo, 'elementClass', 'Checkbox');
     $model->set('ggp_allowed_ip_ranges', 'label', $this->_('Allowed IP Ranges'), 'description', $this->_('Separate with | example: 10.0.0.0-10.0.0.255 (subnet masks are not supported)'), 'size', 50, 'validator', new \Gems_Validate_IPRanges(), 'maxlength', 500);
     \Gems_Model::setChangeFieldsByPrefix($model, 'ggp');
     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__consents');
     $model->copyKeys();
     // The user can edit the keys.
     $model->set('gco_description', 'label', $this->_('Description'), 'size', '10');
     $model->set('gco_order', 'label', $this->_('Order'), 'size', '10', 'description', $this->_('Determines order of presentation in interface.'), 'validator', 'Digits');
     $model->set('gco_code', 'label', $this->_('Consent code'), 'multiOptions', $this->util->getConsentTypes(), 'description', $this->_('Internal code, not visible to users, copied with the token information to the source.'));
     if ($detailed) {
         $model->set('gco_description', 'validator', $model->createUniqueValidator('gco_description'));
         $model->set('gco_order', 'validator', $model->createUniqueValidator('gco_order'));
     }
     if ($this->project->multiLocale) {
         $model->set('gco_description', 'description', 'ENGLISH please! Use translation file to translate.');
     }
     \Gems_Model::setChangeFieldsByPrefix($model, 'gco');
     return $model;
 }
 /**
  * The place to check if the data set in the snippet is valid
  * to generate the snippet.
  *
  * When invalid data should result in an error, you can throw it
  * here but you can also perform the check in the
  * checkRegistryRequestsAnswers() function from the
  * {@see \MUtil_Registry_TargetInterface}.
  *
  * @return boolean
  */
 public function hasHtmlOutput()
 {
     if (!$this->multiTracks) {
         return false;
     }
     if (!$this->trackData) {
         if (!$this->trackId) {
             if ($this->trackEngine instanceof \Gems_Tracker_Engine_TrackEngineInterface) {
                 $this->trackId = $this->trackEngine->getTrackId();
             } else {
                 return false;
             }
         }
         $trackModel = new \MUtil_Model_TableModel('gems__tracks');
         $this->trackData = $trackModel->loadFirst(array('gtr_id_track' => $this->trackId));
     } elseif (!$this->trackId) {
         $this->trackId = $this->trackData['gtr_id_track'];
     }
     return parent::hasHtmlOutput();
 }
 /**
  * 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)
 {
     $tracker = $this->loader->getTracker();
     $model = new \MUtil_Model_TableModel('gems__sources');
     $model->set('gso_source_name', 'label', $this->_('Name'), 'description', $this->_('E.g. the name of the project - for single source projects.'), 'size', 15, 'minlength', 4, 'validator', $model->createUniqueValidator('gso_source_name'));
     $model->set('gso_ls_url', 'label', $this->_('Source Url'), 'default', 'http://', 'description', $this->_('For creating token-survey url.'), 'size', 50, 'validators[unique]', $model->createUniqueValidator('gso_ls_url'), 'validators[url]', new \MUtil_Validate_Url());
     $sourceClasses = $tracker->getSourceClasses();
     end($sourceClasses);
     $model->set('gso_ls_class', 'label', $this->_('Adaptor class'), 'default', key($sourceClasses), 'multiOptions', $sourceClasses);
     $model->set('gso_ls_adapter', 'label', $this->_('Database Server'), 'default', substr(get_class($this->db), strlen('Zend_Db_Adapter_')), 'description', $this->_('The database server used by the source.'), 'multiOptions', $tracker->getSourceDatabaseClasses());
     $model->set('gso_ls_table_prefix', 'label', $this->_('Table prefix'), 'default', 'ls__', 'description', $this->_('Do not forget the underscores.'), 'size', 15);
     if ($detailed) {
         $in_gems = $this->_('Leave empty for the Gems database.');
         $model->set('gso_ls_dbhost', 'label', $this->_('Database host'), 'description', $in_gems, 'size', 15);
         $model->set('gso_ls_database', 'label', $this->_('Database'), 'description', $in_gems, 'size', 15);
         $model->set('gso_ls_username', 'label', $this->_('Database Username'), 'description', $in_gems, 'size', 15);
         $model->set('gso_ls_password', 'label', $this->_('Database Password'), 'elementClass', 'Password', 'repeatLabel', $this->_('Repeat password'), 'required', false, 'size', 15);
         if ('create' == $action) {
             $model->set('gso_ls_password', 'description', $in_gems, 'renderPassword', true);
         } else {
             $model->set('gso_ls_password', 'description', $this->_('Enter only when changing'), 'renderPassword', false);
         }
         $type = new \Gems_Model_Type_EncryptedField($this->project, true);
         $type->apply($model, 'gso_ls_password', 'gso_encryption');
         $model->set('gso_ls_charset', 'label', $this->_('Charset'), 'description', $in_gems, 'size', 15);
         $model->set('gso_active', 'label', $this->_('Active'), 'default', 0, 'multiOptions', $this->util->getTranslated()->getYesNo());
     }
     $model->set('gso_status', 'label', $this->_('Status'), 'default', 'Not checked', 'elementClass', 'Exhibitor');
     $model->set('gso_last_synch', 'label', $this->_('Last synchronisation'), 'elementClass', 'Exhibitor');
     \Gems_Model::setChangeFieldsByPrefix($model, 'gso');
     return $model;
 }
Ejemplo n.º 10
0
 public function testHasTwoTables()
 {
     $model = $this->getNestedModel();
     $rows = $model->load();
     // error_log(print_r($rows, true));
     $this->assertCount(3, $rows);
     $this->assertCount(2, $rows[0]['n2']);
     $this->assertCount(0, $rows[1]['n2']);
     $this->assertCount(3, $rows[2]['n2']);
     $model = new MUtil_Model_TableModel('n2');
     $rows = $model->load();
     $this->assertCount(5, $rows);
 }
Ejemplo n.º 11
0
 /**
  * The maximum length of the result field
  *
  * @return int
  */
 protected function _getResultFieldLength()
 {
     if (null !== $this->resultFieldLength) {
         return $this->resultFieldLength;
     }
     if (null !== self::$staticResultFieldLength) {
         $this->resultFieldLength = self::$staticResultFieldLength;
         return $this->resultFieldLength;
     }
     $model = new \MUtil_Model_TableModel('gems__tokens');
     self::$staticResultFieldLength = $model->get('gto_result', 'maxlength');
     $this->resultFieldLength = self::$staticResultFieldLength;
     return $this->resultFieldLength;
 }
Ejemplo n.º 12
0
 /**
  * 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;
 }
 /**
  * Get a model to store the config
  *
  * @param boolean $valueMask MAsk the password or if false decrypt it
  * @return \Gems_Model_JoinModel
  */
 protected function getConfigModel($valueMask = true)
 {
     if (!$this->_configModel) {
         $model = new \MUtil_Model_TableModel('gems__radius_config', 'config');
         // $model = new \Gems_Model_JoinModel('config', 'gems__radius_config', 'grcfg');
         $model->setIfExists('grcfg_ip', 'label', $this->translate->_('IP address'), 'required', true);
         $model->setIfExists('grcfg_port', 'label', $this->translate->_('Port'), 'required', true);
         $model->setIfExists('grcfg_secret', 'label', $this->translate->_('Shared secret'), 'description', $this->translate->_('Enter only when changing'), 'elementClass', 'password', 'required', false, 'repeatLabel', $this->translate->_('Repeat password'));
         $type = new \Gems_Model_Type_EncryptedField($this->project, $valueMask);
         $type->apply($model, 'grcfg_secret', 'grcfg_encryption');
         $this->_configModel = $model;
     }
     return $this->_configModel;
 }
Ejemplo n.º 14
0
 public function save(array $newValues, array $filter = null)
 {
     // Allow to add default fields to any new track
     if ($defaultFields = $this->getDefaultFields()) {
         $keys = $this->getKeys();
         $keys = array_flip($keys);
         $missing = array_diff_key($keys, $newValues);
         // On copy track the key exists but is null
         $newValues = parent::save($newValues, $filter);
         if (!empty($missing)) {
             // We have an insert!
             $foundKeys = array_intersect_key($newValues, $missing);
             // Now get the fieldmodel
             $engine = $this->loader->getTracker()->getTrackEngine($foundKeys['gtr_id_track']);
             $fieldmodel = $engine->getFieldsMaintenanceModel(true, 'create');
             $lastOrder = 0;
             foreach ($defaultFields as $field) {
                 // Load defaults
                 $record = $fieldmodel->loadNew();
                 $record['gtf_id_order'] = $lastOrder + 10;
                 $record = $field + $record;
                 // Add defaults to the new field
                 $record = $fieldmodel->save($record);
                 $lastOrder = $record['gtf_id_order'];
                 // Save order for next record
             }
         }
     } else {
         $newValues = parent::save($newValues, $filter);
     }
     return $newValues;
 }