-
-
Save kitsunet/5956139 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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