本文整理汇总了PHP中AppBundle\Entity\User::getDimensionsExpanded方法的典型用法代码示例。如果您正苦于以下问题:PHP User::getDimensionsExpanded方法的具体用法?PHP User::getDimensionsExpanded怎么用?PHP User::getDimensionsExpanded使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppBundle\Entity\User
的用法示例。
在下文中一共展示了User::getDimensionsExpanded方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAnswerStats
public function getAnswerStats(Answer $answer)
{
$results = array();
foreach (User::getDimensionsExpanded() as $curField => $curDimension) {
$stats = $this->em->getManager()->createQuery('SELECT
ans.dimensionValue, ans.percentage
FROM AppBundle\\Entity\\AnswerStat ans
INDEX BY ans.dimensionValue
WHERE ans.answer = :answer AND ans.dimension = :curField')->setParameter('answer', $answer)->setParameter('curField', $curField)->useQueryCache(true)->useResultCache(true)->getResult();
foreach ($curDimension as $curValue) {
if ($curValue == 'UNKNOWN') {
continue;
}
if (!isset($stats[$curValue])) {
continue;
}
$percentage = $stats[$curValue]['percentage'];
if ($percentage <= 0) {
continue;
}
$results[$curField][$curValue] = $stats[$curValue];
$results[$curField][$curValue]['percentage'] = $percentage;
}
}
return $results;
}
示例2: getSectionStats
public function getSectionStats(Section $section = null, User $user = null)
{
// Section -> question -> selectedAnswer -> dimensions percentage
// /
// Section -> question -> selectedAnswer -> total percentage
$results = array();
$generalPopulationStats = $this->em->getManager()->createQuery('SELECT
a.id,
(SELECT COUNT(uaa.id) FROM AppBundle\\Entity\\UserAnswer uaa JOIN uaa.user u WHERE uaa.answer = a) as votes,
(SELECT COUNT(uaaa.id) FROM AppBundle\\Entity\\UserAnswer uaaa JOIN uaaa.answer aa JOIN uaaa.user uu WHERE aa.question = a.question) as sumVotes
FROM AppBundle\\Entity\\Answer a
INDEX BY a.id
JOIN a.question qs
JOIN a.userAnswers uas
WHERE uas.user = :user' . (isset($section) ? ' AND qs.section = :section' : ''))->useQueryCache(true)->useResultCache(true)->setParameter('user', $user);
if (isset($section)) {
$generalPopulationStats->setParameter('section', $section);
}
$generalPopulationStats = $generalPopulationStats->getResult();
foreach ($generalPopulationStats as &$curStat) {
$curStat['percentage'] = $curStat['votes'] / $curStat['sumVotes'];
}
foreach (User::getDimensionsExpanded() as $curField => $curDimension) {
foreach ($curDimension as $curValue) {
if ($curValue == 'UNKNOWN') {
continue;
}
if ($curValue == 'RETIRED') {
continue;
}
$tstats = $this->em->getManager()->createQuery('SELECT
a.id,
(SELECT COUNT(uaab.id) FROM AppBundle\\Entity\\UserAnswer uaab WHERE uaab.answer = a) as votes,
(SELECT COUNT(uaa.id) FROM AppBundle\\Entity\\UserAnswer uaa JOIN uaa.user u WHERE uaa.answer = a AND u.' . $curField . ' = :' . $curField . ') as dimVotes,
(SELECT COUNT(uaaa.id) FROM AppBundle\\Entity\\UserAnswer uaaa JOIN uaaa.answer aa JOIN uaaa.user uu WHERE aa.question = a.question AND uu.' . $curField . ' = :' . $curField . ') as sumVotes
FROM AppBundle\\Entity\\Answer a
INDEX BY a.id
JOIN a.question qs
JOIN a.userAnswers uas
WHERE uas.user = :user' . (isset($section) ? ' AND qs.section = :section' : ''))->useQueryCache(true)->useResultCache(true)->setParameter('user', $user);
if (isset($section)) {
$tstats->setParameter('section', $section);
}
$tstats = $tstats->setParameter($curField, $curValue)->getResult();
foreach ($tstats as &$curStat) {
if ($curStat['sumVotes'] > 0) {
$curStat['percentage'] = $curStat['dimVotes'] / $curStat['votes'];
// Percentage of e.g. men who answered this compared to everyone who answered this
$tstatPercentage = $curStat['dimVotes'] / $curStat['sumVotes'];
// Percentage of e.g. men who answered this compared to all men (on any answer)
if ($tstatPercentage > $generalPopulationStats[$curStat['id']]['percentage']) {
$curStat['weight'] = $tstatPercentage * 100 - $generalPopulationStats[$curStat['id']]['percentage'] * 100;
} else {
$curStat['weight'] = 0;
}
} else {
$curStat['percentage'] = 0;
$curStat['weight'] = 0;
}
}
// Find the weighted mean
$sum = 0;
$weightSum = 0;
foreach ($tstats as $curStat) {
$sum = $sum + $curStat['weight'] * $curStat['percentage'];
$weightSum = $weightSum + $curStat['weight'];
}
//$percentage = $sum/$weightSum;
$percentage = $sum / $weightSum;
$percentage = round($percentage * 100, 1);
if ($percentage <= 0) {
continue;
}
$results[$curField][$curValue] = array();
$results[$curField][$curValue]['percentage'] = $percentage;
}
uasort($results[$curField], function ($a, $b) {
if ($a['percentage'] == $b['percentage']) {
return 0;
}
return $a['percentage'] < $b['percentage'] ? 1 : -1;
});
}
return $results;
}
示例3: finalResultChangeAction
/**
* @Route("/final_results_change", name="final_results_change")
*/
public function finalResultChangeAction(Request $request)
{
$user = $this->container->get('doctrine')->getManager()->getRepository('AppBundle\\Entity\\User')->findOneBy(array('sessionId' => $request->getSession()->getId()));
$dimensions = User::getDimensionsExpanded();
$form = $this->createForm(new UserType($request->get('dimension'), $dimensions[$request->get('dimension')]), $user);
if ('POST' == $request->getMethod()) {
$form->handleRequest($request);
if ($form->isValid()) {
$this->container->get('doctrine')->getManager()->persist($form->getData());
$this->container->get('doctrine')->getManager()->flush($form->getData());
} else {
return new Response($form->getErrorsAsString(), 400);
}
}
return new Response('', 204);
}
示例4: isValidProfileDimension
private function isValidProfileDimension($dimensionId)
{
$dimension = $this->dimensionIds[$dimensionId];
$profileDimensions = User::getDimensionsExpanded();
if (in_array($dimension, array_keys($profileDimensions))) {
return true;
} else {
return false;
}
}