/**
  * Create the mail template model
  */
 public function __construct()
 {
     parent::__construct('maillog', 'gems__log_respondent_communications');
     $this->addTable('gems__respondents', array('grco_id_to' => 'grs_id_user'));
     $this->addTable('gems__respondent2org', array('grco_id_to' => 'gr2o_id_user', 'grco_organization' => 'gr2o_id_organization'));
     $this->addLeftTable('gems__staff', array('grco_id_by' => 'gsf_id_user'));
     $this->addLeftTable('gems__tokens', array('grco_id_token' => 'gto_id_token'));
     $this->addLeftTable('gems__reception_codes', array('gto_reception_code' => 'grc_id_reception_code'));
     $this->addLeftTable('gems__tracks', array('gto_id_track' => 'gtr_id_track'));
     $this->addLeftTable('gems__surveys', array('gto_id_survey' => 'gsu_id_survey'));
     $this->addLeftTable('gems__groups', array('gsu_id_primary_group' => 'ggp_id_group'));
     $this->addLeftTable(array('gems__staff', 'staff_by'), array('gto_by' => 'staff_by.gsf_id_user'));
     $this->addLeftTable('gems__track_fields', array('gto_id_relationfield' => 'gtf_id_field', 'gtf_field_type = "relation"'));
     // Add relation fields
     $this->addLeftTable('gems__respondent_relations', array('gto_id_relation' => 'grr_id', 'gto_id_respondent' => 'grr_id_respondent'));
     // Add relation
     $this->addColumn("TRIM(CONCAT(\n                COALESCE(CONCAT(grs_last_name, ', '), '-, '),\n                COALESCE(CONCAT(grs_first_name, ' '), ''),\n                COALESCE(grs_surname_prefix, '')\n                ))", 'respondent_name');
     $this->addColumn("CASE WHEN gems__staff.gsf_id_user IS NULL\n                THEN '-'\n                ELSE\n                    CONCAT(\n                        COALESCE(gems__staff.gsf_last_name, ''),\n                        ', ',\n                        COALESCE(gems__staff.gsf_first_name, ''),\n                        COALESCE(CONCAT(' ', gems__staff.gsf_surname_prefix), '')\n                    )\n                END", 'assigned_by');
     $this->addColumn('CASE WHEN staff_by.gsf_id_user IS NULL THEN
                 COALESCE(gems__track_fields.gtf_field_name, ggp_name)
                 ELSE CONCAT_WS(
                     " ",
                     staff_by.gsf_first_name,
                     staff_by.gsf_surname_prefix,
                     COALESCE(staff_by.gsf_last_name, "-")
                     )
                 END', 'filler');
 }
 /**
  * Create a model that joins two or more tables
  *
  * @param string $name An alternative name for the model
  */
 public function __construct($name = 'staff')
 {
     parent::__construct('staff', 'gems__staff', 'gsf', true);
     $this->addColumn(new \Zend_Db_Expr("CONCAT(\n                    COALESCE(CONCAT(gsf_last_name, ', '), '-, '),\n                    COALESCE(CONCAT(gsf_first_name, ' '), ''),\n                    COALESCE(gsf_surname_prefix, '')\n                    )"), 'name');
     $this->addColumn(new \Zend_Db_Expr("CASE WHEN gsf_email IS NULL OR gsf_email = '' THEN 0 ELSE 1 END"), 'can_mail');
     $this->addColumn(new \Zend_Db_Expr("CASE WHEN gsf_active = 1 THEN '' ELSE 'deleted' END"), 'row_class');
 }
 /**
  * Constructor
  *
  * @param array|mixed $styles
  */
 public function __construct($styles = array())
 {
     parent::__construct('organization', 'gems__organizations', 'gor');
     $this->_styles = $styles;
     $this->setDeleteValues('gor_active', 0, 'gor_add_respondents', 0);
     $this->addColumn("CASE WHEN gor_active = 1 THEN '' ELSE 'deleted' END", 'row_class');
     \Gems_Model::setChangeFieldsByPrefix($this, 'gor');
 }
 /**
  * Self constructor
  */
 public function __construct()
 {
     // gems__respondents MUST be first table for INSERTS!!
     parent::__construct('appointments', 'gems__appointments', 'gap');
     $this->addTable('gems__respondent2org', array('gap_id_user' => 'gr2o_id_user', 'gap_id_organization' => 'gr2o_id_organization'), 'gr20', false);
     $this->addColumn(new \Zend_Db_Expr("'appointment'"), \Gems_Model::ID_TYPE);
     $this->setKeys(array(\Gems_Model::APPOINTMENT_ID => 'gap_id_appointment'));
 }
 public function __construct($name = null, $startTable = null, $fieldPrefix = null, $saveable = null)
 {
     parent::__construct('respondent_relation', 'gems__respondent_relations', 'grr');
     $this->addTable('gems__respondent2org', array('gr2o_id_user' => 'grr_id_respondent'), null, false);
     $keys = $this->_getKeysFor('gems__respondent2org');
     $keys['rid'] = 'grr_id';
     $this->setKeys($keys);
     // Do not really delete but make inactive so we can always display old relations
     $this->setDeleteValues('grr_active', 0);
 }
 public function __construct(\Gems_Tracker_Survey $survey, \Gems_Tracker_Source_SourceInterface $source)
 {
     parent::__construct($survey->getName(), 'gems__tokens', 'gto');
     $this->addTable('gems__reception_codes', array('gto_reception_code' => 'grc_id_reception_code'));
     $this->addColumn('CASE WHEN grc_success = 1 AND gto_valid_from <= CURRENT_TIMESTAMP AND gto_completion_time IS NULL AND (gto_valid_until IS NULL OR gto_valid_until >= CURRENT_TIMESTAMP) THEN 1 ELSE 0 END', 'can_be_taken');
     $this->addColumn("CASE WHEN grc_success = 1 THEN '' ELSE 'deleted' END", 'row_class');
     $this->source = $source;
     $this->survey = $survey;
     $this->addAnswersToModel();
 }
 public function __construct(\Gems_Tracker_Survey $survey, \Gems_Tracker_Source_SourceInterface $source)
 {
     parent::__construct($survey->getName(), 'gems__tokens', 'gto');
     $this->addTable('gems__reception_codes', array('gto_reception_code' => 'grc_id_reception_code'));
     // Add relations
     $this->addLeftTable('gems__track_fields', array('gto_id_relationfield' => 'gtf_id_field', 'gtf_field_type = "relation"'));
     // Add relation fields
     $this->addLeftTable('gems__respondent_relations', array('gto_id_relation' => 'grr_id', 'gto_id_respondent' => 'grr_id_respondent'));
     // Add relation
     $this->set('grr_name', 'column_expression', new Zend_Db_Expr('CONCAT_WS(" ", gems__respondent_relations.grr_first_name, gems__respondent_relations.grr_last_name)'));
     $this->addColumn('CASE WHEN grc_success = 1 AND gto_valid_from <= CURRENT_TIMESTAMP AND gto_completion_time IS NULL AND (gto_valid_until IS NULL OR gto_valid_until >= CURRENT_TIMESTAMP) THEN 1 ELSE 0 END', 'can_be_taken');
     $this->addColumn("CASE WHEN grc_success = 1 THEN '' ELSE 'deleted' END", 'row_class');
     $this->source = $source;
     $this->survey = $survey;
     $this->addAnswersToModel();
 }
 public function __construct()
 {
     parent::__construct('orf', 'gems__openrosaforms', 'gof');
 }
 /**
  *
  * @param string $name
  */
 public function __construct($name = 'app-filter')
 {
     parent::__construct($name, 'gems__appointment_filters', 'gaf');
 }
 /**
  * Create the mail template model
  */
 public function __construct()
 {
     parent::__construct('commtemplate', 'gems__comm_templates', 'gct');
 }
 /**
  * Construct a round model
  */
 public function __construct(\Zend_Db_Adapter_Abstract $db)
 {
     parent::__construct('rounds', 'gems__rounds', 'gro', true);
     $this->db = $db;
 }
 /**
  * Create a model for the log
  */
 public function __construct()
 {
     parent::__construct('Log', 'gems__log_activity', 'gla', true);
     $this->addTable('gems__log_setup', array('gla_action' => 'gls_id_action'))->addLeftTable('gems__respondents', array('gla_respondent_id' => 'grs_id_user'))->addLeftTable('gems__staff', array('gla_by' => 'gsf_id_user'));
     $this->setKeys(array(\Gems_Model::LOG_ITEM_ID => 'gla_id'));
 }