/** * 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 ('export' === $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; }
/** * The round description of the first round that has not been answered. * * @return string Round description or Stopped/Completed if not found. */ public function getCurrentRound() { $isStop = false; $today = new \Zend_Date(); $tokens = $this->getTokens(); $stop = $this->util->getReceptionCodeLibrary()->getStopString(); foreach ($tokens as $token) { $validUntil = $token->getValidUntil(); if (!empty($validUntil) && $validUntil->isEarlier($today)) { continue; } if ($token->isCompleted()) { continue; } $code = $token->getReceptionCode(); if (!$code->isSuccess()) { if ($code->getCode() === $stop) { $isStop = true; } continue; } return $token->getRoundDescription(); } if ($isStop) { return $this->translate->_('Track stopped'); } return $this->translate->_('Track completed'); }