本文整理汇总了PHP中SpoonFilter::isOdd方法的典型用法代码示例。如果您正苦于以下问题:PHP SpoonFilter::isOdd方法的具体用法?PHP SpoonFilter::isOdd怎么用?PHP SpoonFilter::isOdd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SpoonFilter
的用法示例。
在下文中一共展示了SpoonFilter::isOdd方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseBody
/**
* 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;
//.........这里部分代码省略.........
示例2: testIsOdd
public function testIsOdd()
{
$this->assertFalse(SpoonFilter::isOdd(0));
$this->assertTrue(SpoonFilter::isOdd(1));
$this->assertFalse(SpoonFilter::isOdd(10901920));
$this->assertTrue(SpoonFilter::isOdd(-1337));
}
示例3: parseBody
/**
* 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) {
//.........这里部分代码省略.........