/** * Parses the body. * * @return void * @param array $records */ private function parseBody(array $records) { // init var $rows = array(); // columns sequence $sequence = $this->getColumnsSequence(); // loop records foreach ($records as $i => &$record) { // replace possible variables $record = $this->parseRecord($record); // parse column functions $record = $this->parseColumnFunctions($record); // reset row $row = array('attributes' => '', 'oddAttributes' => '', 'evenAttributes' => '', 'columns' => array()); // row attributes $row['attributes'] = str_replace($record['labels'], $record['values'], $this->getHtmlAttributes($this->attributes['row'])); // odd row attributes (reversed since the first $i = 0) if (!SpoonFilter::isOdd($i)) { $row['oddAttributes'] = str_replace($record['labels'], $record['values'], $this->getHtmlAttributes($this->attributes['row_odd'])); } else { $row['evenAttributes'] = str_replace($record['labels'], $record['values'], $this->getHtmlAttributes($this->attributes['row_even'])); } // define the columns $columns = array(); // loop columns foreach ($sequence as $name) { // column $column = $this->columns[$name]; // has overwrite enabled if ($column->getOverwrite()) { // fetch key $iKey = array_search('[' . $column->getName() . ']', $record['labels']); // parse the actual value $columnValue = $record['values'][$iKey]; } else { // default value $columnValue = ''; // has an url if ($column->getURL() !== null) { // open url tag $columnValue .= '<a href="' . str_replace($record['labels'], $record['values'], $column->getURL()) . '"'; // add title $columnValue .= ' title="' . str_replace($record['labels'], $record['values'], $column->getURLTitle()) . '"'; // confirm if ($column->getConfirm() && $column->getConfirmMessage() !== null) { // default confirm if ($column->getConfirmCustom() == '') { $columnValue .= ' onclick="return confirm(\'' . str_replace($record['labels'], $record['values'], $column->getConfirmMessage()) . '\');"'; } else { // replace the message $tmpValue = str_replace('%message%', $column->getConfirmMessage(), $column->getConfirmCustom()); // make vars available $tmpValue = str_replace($record['labels'], $record['values'], $tmpValue); // add id $columnValue .= ' ' . $tmpValue; } } // close start tag $columnValue .= '>'; } // has an image if ($column->getImage() !== null) { // open img tag $columnValue .= '<img src="' . str_replace($record['labels'], $record['values'], $column->getImage()) . '"'; // add title & alt $columnValue .= ' alt="' . str_replace($record['labels'], $record['values'], $column->getImageTitle()) . '"'; $columnValue .= ' title="' . str_replace($record['labels'], $record['values'], $column->getImageTitle()) . '"'; // close img tag $columnValue .= ' />'; } else { // fetch key $iKey = array_search('[' . $column->getName() . ']', $record['labels']); // parse value $columnValue .= $record['values'][$iKey]; } // has an url (close the tag) if ($column->getURL() !== null) { $columnValue .= '</a>'; } } // fetch column attributes $columnAttributes = $this->getHtmlAttributes($column->getAttributes()); // visible & iteration if (!$column->getHidden()) { // add this column $columns[] = array('attributes' => $columnAttributes, 'value' => $columnValue); // add to custom list $row['column'][$name] = $columnValue; } } // add the columns to the rows $row['columns'] = $columns; // add the row $rows[] = $row; } // assign body $this->tpl->assign('rows', $rows); // assign the number of columns $this->tpl->assign('numColumns', count($rows[0]['columns'])); }
public function testIsOdd() { $this->assertFalse(SpoonFilter::isOdd(0)); $this->assertTrue(SpoonFilter::isOdd(1)); $this->assertFalse(SpoonFilter::isOdd(10901920)); $this->assertTrue(SpoonFilter::isOdd(-1337)); }
/** * Parses the body. * * @param array $records The rows. */ private function parseBody(array $records) { // init var $rows = array(); // columns sequence $sequence = $this->getColumnsSequence(); // loop records foreach ($records as $i => &$record) { // replace possible variables $record = $this->parseRecord($record); // parse column functions $record = $this->parseColumnFunctions($record); // parse custom row functions $this->parseRowFunctions($record, $this->attributes['row']); // reset row $row = array('attributes' => '', 'columns' => array()); // row attributes $row['attributes'] = str_replace($record['labels'], $record['values'], $this->getHtmlAttributes($this->attributes['row'])); // add custom row functions if (!empty($this->rowFunctionsParsed)) { // reset attributes $row['attributes'] = str_replace($record['labels'], $record['values'], $this->getHtmlAttributes($this->rowFunctionsParsed)); // clear for the next row $this->rowFunctionsParsed = array(); } else { $row['attributes'] = str_replace($record['labels'], $record['values'], $this->getHtmlAttributes($this->attributes['row'])); } // odd row attributes (reversed since the first $i = 0) if (!SpoonFilter::isOdd($i)) { $cycleAttributes = str_replace($record['labels'], $record['values'], $this->getHtmlAttributes($this->attributes['row_odd'])); } else { $cycleAttributes = str_replace($record['labels'], $record['values'], $this->getHtmlAttributes($this->attributes['row_even'])); } // no longer overwrite default attributes with odd/even attributes. if (!empty($row['attributes'])) { $cycleData = array(); $rowData = array(); preg_match_all('/( (.*?)=\\"(.*?)\\")/', $row['attributes'], $rowData); preg_match_all('/( (.*?)=\\"(.*?)\\")/', $cycleAttributes, $cycleData); // go trough the attribute data to see if anything matches foreach ($cycleData[2] as $cycleAttribute => $cycleValue) { if (in_array($cycleValue, $rowData[2])) { $rowData[3][$cycleAttribute] .= ' ' . $cycleData[3][$cycleAttribute]; // remove the data so we can use the others to merge the arrays unset($cycleData[2][$cycleAttribute], $cycleData[3][$cycleAttribute]); } } // merge all the values, so we get everything we need $rowData[2] = array_merge($rowData[2], $cycleData[2]); $rowData[3] = array_merge($rowData[3], $cycleData[3]); // rebuild the data $row['attributes'] = $this->getHTMLAttributes(array_combine($rowData[2], $rowData[3])); } else { $row['attributes'] = $cycleAttributes; } // define the columns $columns = array(); // loop columns foreach ($sequence as $name) { // column $column = $this->columns[$name]; // has overwrite enabled if ($column->getOverwrite()) { // fetch key $iKey = array_search('[' . $column->getName() . ']', $record['labels']); // parse the actual value $columnValue = $record['values'][$iKey]; } else { // default value $columnValue = ''; // has an url if ($column->getURL() !== null) { // open url tag $columnValue .= '<a href="' . str_replace($record['labels'], $record['values'], $column->getURL()) . '"'; // add title $columnValue .= ' title="' . str_replace($record['labels'], $record['values'], $column->getURLTitle()) . '"'; // confirm if ($column->getConfirm() && $column->getConfirmMessage() !== null) { // default confirm if ($column->getConfirmCustom() == '') { $columnValue .= ' onclick="return confirm(\'' . str_replace($record['labels'], $record['values'], $column->getConfirmMessage()) . '\');"'; } else { // replace the message $tmpValue = str_replace('%message%', $column->getConfirmMessage(), $column->getConfirmCustom()); // make vars available $tmpValue = str_replace($record['labels'], $record['values'], $tmpValue); // add id $columnValue .= ' ' . $tmpValue; } } // close start tag $columnValue .= '>'; } // has an image if ($column->getImage() !== null) { // open img tag $columnValue .= '<img src="' . str_replace($record['labels'], $record['values'], $column->getImage()) . '"'; // add title & alt $columnValue .= ' alt="' . str_replace($record['labels'], $record['values'], $column->getImageTitle()) . '"'; $columnValue .= ' title="' . str_replace($record['labels'], $record['values'], $column->getImageTitle()) . '"'; // close img tag $columnValue .= ' />'; } else { // fetch key $iKey = array_search('[' . $column->getName() . ']', $record['labels']); // parse value $columnValue .= $record['values'][$iKey]; } // has an url (close the tag) if ($column->getURL() !== null) { $columnValue .= '</a>'; } } // fetch column attributes $columnAttributes = str_replace($record['labels'], $record['values'], $this->getHtmlAttributes($column->getAttributes())); // visible & iteration if (!$column->getHidden()) { // add this column $columns[] = array('attributes' => $columnAttributes, 'value' => $columnValue); // add to custom list $row['column'][$name] = $columnValue; } } // add the columns to the rows $row['columns'] = $columns; // add the row $rows[] = $row; } // assign body $this->tpl->assign('rows', $rows); // assign the number of columns $this->tpl->assign('numColumns', count($rows[0]['columns'])); }