Skip to content

Instantly share code, notes, and snippets.

@kitsunet
Forked from riscos/T3Flow-1
Created July 9, 2013 09:54
Show Gist options
  • Save kitsunet/5956139 to your computer and use it in GitHub Desktop.
Save kitsunet/5956139 to your computer and use it in GitHub Desktop.
# Action
/**
* Shows a list of books
*
* @return void
*/
public function booksAction() {
$genre = $this->getQueryStringVar('genre');
$this->view->assign('books', $this->bookRepository->findAll($genre));
$this->view->assign('settings', $this->settings);
}
# Gets query var
/**
* Finds a get var from the query string.
*
* @param string $queryVar The name of the query var.
* @param string $queryVarElement The name of the element in the query var.
* @return mixed $queryVarValue Returns the get var or FALSE.
*/
protected function getQueryStringVar($queryVar, $queryVarElement = '') {
$queryVarValue = FALSE;
if (is_string($queryVar) && !empty($queryVar)) {
$queryStringVars = $this->request->getArguments();
if (isset($queryStringVars[$queryVar])) {
if (is_string($queryVarElement) && !empty($queryVarElement)) {
$queryVarValue = $queryStringVars[$queryVar][$queryVarElement];
if (is_string($queryVarValue)) {
$queryVarValue = trim($queryVarValue);
}
} else {
$queryVarValue = $queryStringVars[$queryVar];
if (is_string($queryVarValue)) {
$queryVarValue = trim($queryVarValue);
}
}
}
}
return $queryVarValue;
}
# Repo method
/**
* Finds all unhidden & published books.
*
* @param mixed $genre The genre to filter by (an array), or FALSE if there is no filter genre.
* @return \TYPO3\Flow\Persistence\QueryResultInterface The query result
*/
public function findAll($genre = FALSE) {
$query = $this->createQuery();
if ($genre !== FALSE) {
$query->matching(
$query->logicalAnd(
$query->equals('hidden', 0),
$query->equals('published', 1),
$query->contains('genres', $genre)
)
);
} else {
$query->matching(
$query->logicalAnd(
$query->equals('hidden', 0),
$query->equals('published', 1)
)
);
}
$query->setOrderings(
array('title' => \TYPO3\Flow\Persistence\QueryInterface::ORDER_ASCENDING)
);
return $query->execute();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment