<commit_before><?
namespace Concrete\Block\Survey;
use Loader;
use \Concrete\Core\Legacy\DatabaseItemList;

/**
 * Returns all surveys in a site.
 *
 * @package Blocks
 * @subpackage Survey
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @copyright  Copyright (c) 2003-2012 Concrete5. (http://www.concrete5.org)
 * @license    http://www.concrete5.org/license/     MIT License
 *
 */
class SurveyList extends DatabaseItemList {
	protected $itemsPerPage = 10;
	protected $autoSortColumns = array('cvName', 'question', 'numberOfResponses', 'lastResponse');
	
	function __construct() {
		$this->setQuery(
			   'select distinct btSurvey.bID, CollectionVersions.cID, btSurvey.question, CollectionVersions.cvName, (select max(timestamp) from btSurveyResults where btSurveyResults.bID = btSurvey.bID and btSurveyResults.cID = CollectionVersions.cID) as lastResponse, (select count(timestamp) from btSurveyResults where btSurveyResults.bID = btSurvey.bID and btSurveyResults.cID = CollectionVersions.cID) as numberOfResponses ' .
				'from btSurvey, CollectionVersions, CollectionVersionBlocks');	
		$this->filter(false, 'btSurvey.bID = CollectionVersionBlocks.bID');
		$this->filter(false, 'CollectionVersions.cID = CollectionVersionBlocks.cID');
		$this->filter(false, 'CollectionVersionBlocks.cvID = CollectionVersionBlocks.cvID');
		$this->filter(false, 'CollectionVersions.cvIsApproved = 1');
		$this->userPostQuery .= 'group by btSurvey.bID, CollectionVersions.cID';
	}
}
<commit_msg>Fixes survey result and optimized query<commit_after><?php
namespace Concrete\Block\Survey;

use \Concrete\Core\Legacy\DatabaseItemList;

class SurveyList extends DatabaseItemList
{
    protected $itemsPerPage = 10;
    protected $autoSortColumns = array('cvName', 'question', 'numberOfResponses', 'lastResponse');

    function __construct()
    {
        $query = 'SELECT btSurvey.bID, CollectionVersions.cID, btSurvey.question, CollectionVersions.cvName,
                        max(btSurveyResults.timestamp) AS lastResponse,
                        count(btSurveyResults.bID) AS numberOfResponses
                    FROM btSurvey
                    INNER JOIN CollectionVersionBlocks
                      ON btSurvey.bID = CollectionVersionBlocks.bID
                    INNER JOIN CollectionVersions
                      ON CollectionVersionBlocks.cID = CollectionVersions.cID
                        AND CollectionVersionBlocks.cvID = CollectionVersions.cvID
                        AND CollectionVersions.cvIsApproved = 1
                    LEFT JOIN btSurveyResults
                      ON btSurvey.bID = btSurveyResults.bID
                        AND btSurveyResults.cID = CollectionVersions.cID';

        $this->setQuery($query);
        $this->userPostQuery .= 'GROUP BY btSurvey.bID, CollectionVersions.cID,
		                            btSurvey.question, CollectionVersions.cvName';
    }
}

{'fraction_non_alphanumeric': 0.10047683923705722, 'fraction_numerical': 0.0057901907356948225, 'mean_word_length': 3.2319884726224783, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7476099', 'n_tokens_mistral': 877, 'n_tokens_neox': 830, 'n_words': 177}