I'm fetching data from a seperate database into a TYPO3 extbase action and render it as json via typnum. It works fine. But now I would like to have instead of a fix 'WHERE account_id = 1' a flexible variable depending on the fe_user usergroup information of the user which is currently logged in. More specific, I would like to have the 'usergroup' information of the currently logged in fe_user as variable in the SQL WHERE condition. Is this possible?
I know that with ...
/**
* User Repository
*
* @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository
* @inject
*/
protected $userRepository;
.. I can access the $userRepository and with ...
$userObject =
$this->userRepository->findByUid($GLOBALS['TSFE']->fe_user->user['usergroup']);
$this->view->assign('fe_user_usergroup_uid', $userObject);
.. I can render the usergroup into the view.
The result of the above is attaches 'TYPO3\CMS\Extbase\Domain\Model\FrontendUser:' in front of the usergroup info at the moment though. So the view result ist
TYPO3\CMS\Extbase\Domain\Model\FrontendUser:1
How should the Controller exactly look like if it is possible? As of right now it's like:
JSONController.php :
<?php
namespace Vendor\Extension\Controller;
/**
* JSONController
*/
class JSONController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
/**
* @var string
*/
protected $defaultViewObjectName = 'TYPO3\CMS\Extbase\Mvc\View\JsonView';
/**
* User Repository
*
* @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository
* @inject
*/
protected $userRepository;
/**
* action dashboard
*
* @return string
*/
public function dashboardAction() {
$link = mysql_connect( 'host', 'user', 'password' );
$db = mysql_select_db( 'database', $link );
$query = "SELECT entity_status, count(*)
FROM accounts
WHERE account_id = 1
GROUP BY entity_status
ORDER BY count(*) DESC";
$result = mysql_query( $query );
$data = array();
while ( $row = mysql_fetch_assoc( $result ) ) {
$data[] = $row;
}
return json_encode( $data );
mysql_close($link);
}
}
?>
_______________________________________________
TYPO3-english mailing list
TYPO3-english@lists.typo3.org
http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-english