3069 Posts in 868 Topics by 650 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2152 Views |
-
[SOLVED] Adding a "virtual" value to $summary_fields

27 March 2009 at 7:03am Last edited: 27 March 2009 8:42pm
Hi,
I was wondering if it is possible to add a virtual field to the $summary_fields of a dataobject.
The situation:
3 DataObject's: Poll, PollAwnser and PollVotes
Now in the overview page of polls i would like to list the number of votes cast for each poll.
(SELECT COUNT(PollID) FROM PollVote WHERE PollID = <ID>)Is there any way to do this in SilverStripe?
p.s. I'm using ModelAdmin to for the UI if that's off any importance.Cheers,
Geert -
Re: [SOLVED] Adding a "virtual" value to $summary_fields

27 March 2009 at 8:25am Last edited: 27 March 2009 8:26am
Yes, this should be possible. The summary field can also be the result of an object method, so for example in your Poll object:
// Cast method calls nicely
static $casting = array(
"VotesCast" => "Int"
);// Return the number of votes cast in this poll
function getVotesCast() {
$sqlQuery = new SQLQuery(
"COUNT(*)",
"PollVote",
"PollID = $this->ID"
);
return $sqlQuery->execute()->value();
}Now you should be able to add "VotesCast" to your summary fields.
-
Re: [SOLVED] Adding a "virtual" value to $summary_fields

27 March 2009 at 8:42pm
As said on IRC before, thanks for the help.
Works like a charm. -
Re: [SOLVED] Adding a "virtual" value to $summary_fields

28 March 2009 at 3:03am
or
function getVotesCount() {
return $this->PollVotes()->count();
}with Poll.php
static $has_many = array (
'PollVotes' => 'PollVote'
); -
Re: [SOLVED] Adding a "virtual" value to $summary_fields

14 January 2010 at 1:03pm
I have installed the poll module to my site. How do I display the history of all the polls and results to a single page?
| 2152 Views | ||
|
Page:
1
|
Go to Top |



