original_string: protected function replaceCreateView(\Gems_Tracker_Survey $survey, \MUtil_Model_ModelAbstract $answerModel)
      {
          $viewName = $this->getViewName($survey);
          $responseDb = $this->project->getResponseDatabase();
          $fieldSql   = '';
  
          foreach ($answerModel->getItemsOrdered() as $name) {
              if (true === $answerModel->get($name, 'survey_question') && // It should be a question
                      !in_array($name, array('submitdate', 'startdate', 'datestamp')) && // Leave out meta info
                      !$answerModel->is($name, 'type', \MUtil_Model::TYPE_NOVALUE)) {         // Only real answers
                  $fieldSql .= ',MAX(IF(gdr_answer_id = ' . $responseDb->quote($name) . ', gdr_response, NULL)) AS ' . $responseDb->quoteIdentifier($name);
              }
          }
  
          if ($fieldSql > '') {
              $dbConfig = $this->db->getConfig();
              $tokenTable = $this->db->quoteIdentifier($dbConfig['dbname'] . '.gems__tokens');
              $createViewSql = 'CREATE OR REPLACE VIEW ' . $responseDb->quoteIdentifier($viewName) . ' AS SELECT gdr_id_token';
              $createViewSql .= $fieldSql;
              $createViewSql .= "FROM gemsdata__responses join " . $tokenTable .
                      " on (gto_id_token=gdr_id_token and gto_id_survey=" . $survey->getSurveyId() .
                      ") GROUP BY gdr_id_token;";
              try {
                  $responseDb->query($createViewSql)->execute();
              } catch (Exception $exc) {
                  $responseConfig = $responseDb->getConfig();
                  $dbUser = $this->db->quoteIdentifier($responseConfig['username']) . '@' .
                          $this->db->quoteIdentifier($responseConfig['host']);
                  $statement = "GRANT SELECT ON  " . $tokenTable . " TO " . $dbUser;
  
                  $batch = $this->getBatch();
                  $batch->addMessage(sprintf(
                          $this->_("View creation failed for survey %s with message: '%s'"),
                          $survey->getName(),
                          $exc->getMessage()
                          ));
                  $batch->addMessage(sprintf($this->_("View creation statement: %s"), $createViewSql));
                  $batch->addMessage(sprintf($this->_("Try adding rights using this statement: %s"), $statement));
              }
          }
      }
code: protected function replaceCreateView(\Gems_Tracker_Survey $survey, \MUtil_Model_ModelAbstract $answerModel)
      {
          $viewName = $this->getViewName($survey);
          $responseDb = $this->project->getResponseDatabase();
          $fieldSql   = '';
  
          foreach ($answerModel->getItemsOrdered() as $name) {
              if (true === $answerModel->get($name, 'survey_question') && // It should be a question
                      !in_array($name, array('submitdate', 'startdate', 'datestamp')) && // Leave out meta info
                      !$answerModel->is($name, 'type', \MUtil_Model::TYPE_NOVALUE)) {         // Only real answers
                  $fieldSql .= ',MAX(IF(gdr_answer_id = ' . $responseDb->quote($name) . ', gdr_response, NULL)) AS ' . $responseDb->quoteIdentifier($name);
              }
          }
  
          if ($fieldSql > '') {
              $dbConfig = $this->db->getConfig();
              $tokenTable = $this->db->quoteIdentifier($dbConfig['dbname'] . '.gems__tokens');
              $createViewSql = 'CREATE OR REPLACE VIEW ' . $responseDb->quoteIdentifier($viewName) . ' AS SELECT gdr_id_token';
              $createViewSql .= $fieldSql;
              $createViewSql .= "FROM gemsdata__responses join " . $tokenTable .
                      " on (gto_id_token=gdr_id_token and gto_id_survey=" . $survey->getSurveyId() .
                      ") GROUP BY gdr_id_token;";
              try {
                  $responseDb->query($createViewSql)->execute();
              } catch (Exception $exc) {
                  $responseConfig = $responseDb->getConfig();
                  $dbUser = $this->db->quoteIdentifier($responseConfig['username']) . '@' .
                          $this->db->quoteIdentifier($responseConfig['host']);
                  $statement = "GRANT SELECT ON  " . $tokenTable . " TO " . $dbUser;
  
                  $batch = $this->getBatch();
                  $batch->addMessage(sprintf(
                          $this->_("View creation failed for survey %s with message: '%s'"),
                          $survey->getName(),
                          $exc->getMessage()
                          ));
                  $batch->addMessage(sprintf($this->_("View creation statement: %s"), $createViewSql));
                  $batch->addMessage(sprintf($this->_("Try adding rights using this statement: %s"), $statement));
              }
          }
      }
code_tokens: protected function replaceCreateView ( \ Gems_Tracker_Survey $ survey , \ MUtil_Model_ModelAbstract $ answerModel ) { $ viewName = $ this -> getViewName ( $ survey ) ; $ responseDb = $ this -> project -> getResponseDatabase ( ) ; $ fieldSql = '' ; foreach ( $ answerModel -> getItemsOrdered ( ) as $ name ) { if ( true === $ answerModel -> get ( $ name , 'survey_question' ) && // It should be a question ! in_array ( $ name , array ( 'submitdate' , 'startdate' , 'datestamp' ) ) && // Leave out meta info ! $ answerModel -> is ( $ name , 'type' , \ MUtil_Model :: TYPE_NOVALUE ) ) { // Only real answers $ fieldSql .= ',MAX(IF(gdr_answer_id = ' . $ responseDb -> quote ( $ name ) . ', gdr_response, NULL)) AS ' . $ responseDb -> quoteIdentifier ( $ name ) ; } } if ( $ fieldSql > '' ) { $ dbConfig = $ this -> db -> getConfig ( ) ; $ tokenTable = $ this -> db -> quoteIdentifier ( $ dbConfig [ 'dbname' ] . '.gems__tokens' ) ; $ createViewSql = 'CREATE OR REPLACE VIEW ' . $ responseDb -> quoteIdentifier ( $ viewName ) . ' AS SELECT gdr_id_token' ; $ createViewSql .= $ fieldSql ; $ createViewSql .= "FROM gemsdata__responses join " . $ tokenTable . " on (gto_id_token=gdr_id_token and gto_id_survey=" . $ survey -> getSurveyId ( ) . ") GROUP BY gdr_id_token;" ; try { $ responseDb -> query ( $ createViewSql ) -> execute ( ) ; } catch ( Exception $ exc ) { $ responseConfig = $ responseDb -> getConfig ( ) ; $ dbUser = $ this -> db -> quoteIdentifier ( $ responseConfig [ 'username' ] ) . '@' . $ this -> db -> quoteIdentifier ( $ responseConfig [ 'host' ] ) ; $ statement = "GRANT SELECT ON  " . $ tokenTable . " TO " . $ dbUser ; $ batch = $ this -> getBatch ( ) ; $ batch -> addMessage ( sprintf ( $ this -> _ ( "View creation failed for survey %s with message: '%s'" ) , $ survey -> getName ( ) , $ exc -> getMessage ( ) ) ) ; $ batch -> addMessage ( sprintf ( $ this -> _ ( "View creation statement: %s" ) , $ createViewSql ) ) ; $ batch -> addMessage ( sprintf ( $ this -> _ ( "Try adding rights using this statement: %s" ) , $ statement ) ) ; } } }
docstring: Handles creating or replacing the view for this survey
  
  @param \Gems_Tracker_Survey       $viewName
  @param \MUtil_Model_ModelAbstract $answerModel
docstring_tokens: Handles creating or replacing the view for this survey