private function setItems()
{
// init header labels
$lblSessionId = \SpoonFilter::ucfirst(BL::lbl('SessionId'));
$lblSentOn = \SpoonFilter::ucfirst(BL::lbl('SentOn'));
$this->columnHeaders = array($lblSessionId, $lblSentOn);
// fetch query and parameters
list($query, $parameters) = $this->buildQuery();
// get the data
$records = (array) $this->get('database')->getRecords($query, $parameters);
$data = array();
// reformat data
foreach ($records as $row) {
// first row of a submission
if (!isset($data[$row['data_id']])) {
$data[$row['data_id']][$lblSessionId] = $row['session_id'];
$data[$row['data_id']][$lblSentOn] = \SpoonDate::getDate('Y-m-d H:i:s', $row['sent_on'], BL::getWorkingLanguage());
}
// value is serialized
$value = unserialize($row['value']);
// flatten arrays
if (is_array($value)) {
$value = implode(', ', $value);
}
// group submissions
$data[$row['data_id']][$row['label']] = \SpoonFilter::htmlentitiesDecode($value, null, ENT_QUOTES);
// add into headers if not yet added
if (!in_array($row['label'], $this->columnHeaders)) {
$this->columnHeaders[] = $row['label'];
}
}
// reorder data so they are in the correct column
foreach ($data as $id => $row) {
foreach ($this->columnHeaders as $header) {
// submission has this field so add it
if (isset($row[$header])) {
$this->rows[$id][] = $row[$header];
} else {
// submission does not have this field so add a placeholder
$this->rows[$id][] = '';
}
}
}
// remove the keys
$this->rows = array_values($this->rows);
}