/** * Write the CSV rows for the current step. * * @access public * @since 8.5.1 */ public function writeRows() { $results = $this->getData(); $rows = ''; if (!empty($results)) { // Go through each entry... foreach ($results as $entry) { $fieldCount = count($this->fields); $row = ''; // ...and go through each cell the user wants to export, and match it with the cell in the entry... for ($i = 0; $i < $fieldCount; $i++) { // ...then find out if it's a breakout cell and process it properly... switch ($this->fields[$i]['type']) { case 1: // Export a standard breakout; just list them all in the order requested... $row .= $this->exportBreakoutCell($this->fields[$i], $entry->id); break; case 2: // Process category table and list all categories in a single cell... $terms = array(); $results = $this->getTerms($entry->id, 'category'); foreach ($results as $term) { $terms[] = $term->name; } $row .= $this->escapeAndQuote(implode(',', $terms)) . ','; break; case 3: $count = $this->getTermCount('category'); $terms = array(); // Process the category table by breaking them out in separate cells, // Prepare an empty frame of the category cells... for ($j = 0; $j < $count + 1; $j++) { // Make an array filled with empty cells $terms[$j] = '"",'; } // Now start filling in the empty cells with data... $row = $this->getTerms($entry->id, 'category'); $j = 0; foreach ($row as $result) { $terms[$j] = $this->escapeAndQuote($result->name) . ','; $j++; } $row .= implode('', $terms); break; case 4: // Export breakout data from the serialized option cell. $row .= $this->exportBreakoutOptionsCell($this->fields[$i], $entry); break; case 5: $data = ''; $meta = cnMeta::get('entry', $entry->id, $this->fields[$i]['field'], TRUE); if (!empty($meta)) { $data = cnFormatting::maybeJSONencode($meta); } $row .= $this->escapeAndQuote($data) . ','; break; case 6: $terms = array(); $parent = $this->fields[$i]['child_of']; $results = $this->getTerms($entry->id, 'category'); foreach ($results as $term) { $terms[] = $parent . ':' . $term->term_id; if (cnTerm::isAncestorOf($parent, $term->term_id, 'category')) { $terms[] = $term->name; } } $row .= $this->escapeAndQuote(implode(',', $terms)) . ','; break; default: // If no breakout type is defined, only display the cell data... $row .= $this->escapeAndQuote($entry->{$this->fields[$i]['field']}) . ','; break; } } // Trim the trailing comma and space, then add newline. $rows .= rtrim($row, ',') . "\r\n"; } // Now write the data... $this->write($rows); return $rows; } return FALSE; }