From owner-svn-src-user@FreeBSD.ORG Thu Apr 17 20:47:31 2014 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6C677D9F; Thu, 17 Apr 2014 20:47:31 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 403F7119E; Thu, 17 Apr 2014 20:47:31 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s3HKlVSv040780; Thu, 17 Apr 2014 20:47:31 GMT (envelope-from des@svn.freebsd.org) Received: (from des@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s3HKlUYY040778; Thu, 17 Apr 2014 20:47:30 GMT (envelope-from des@svn.freebsd.org) Message-Id: <201404172047.s3HKlUYY040778@svn.freebsd.org> From: Dag-Erling Smørgrav Date: Thu, 17 Apr 2014 20:47:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r264626 - user/des/fbp/lib/FBP/Schema/Result X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Apr 2014 20:47:31 -0000 Author: des Date: Thu Apr 17 20:47:30 2014 New Revision: 264626 URL: http://svnweb.freebsd.org/changeset/base/264626 Log: Add "voters" accessor to polls and questions. Modified: user/des/fbp/lib/FBP/Schema/Result/Poll.pm user/des/fbp/lib/FBP/Schema/Result/Question.pm Modified: user/des/fbp/lib/FBP/Schema/Result/Poll.pm ============================================================================== --- user/des/fbp/lib/FBP/Schema/Result/Poll.pm Thu Apr 17 20:42:03 2014 (r264625) +++ user/des/fbp/lib/FBP/Schema/Result/Poll.pm Thu Apr 17 20:47:30 2014 (r264626) @@ -233,6 +233,32 @@ sub votes_rs($) { return $self->questions->search_related_rs('votes'); } +=head2 voters + +Return persons who have voted in this poll. In list context, returns +a list of voters. In scalar context, returns a resultset. + +=cut + +sub voters($) { + my ($self) = @_; + + return wantarray() ? $self->voters_rs->all : $self->voters_rs; +} + +=head2 voters_rs + +Return persons who have voted in this poll as a resultset. + +=cut + +sub voters_rs($) { + my ($self) = @_; + + return $self->questions->search_related_rs('votes')-> + search_related_rs('voter', undef, { distinct => 1 }); +} + =head2 validate_answer Validates an answer to this poll and dies if it is not valid. Modified: user/des/fbp/lib/FBP/Schema/Result/Question.pm ============================================================================== --- user/des/fbp/lib/FBP/Schema/Result/Question.pm Thu Apr 17 20:42:03 2014 (r264625) +++ user/des/fbp/lib/FBP/Schema/Result/Question.pm Thu Apr 17 20:47:30 2014 (r264626) @@ -182,6 +182,31 @@ __PACKAGE__->has_many( # Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-04-16 20:57:55 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:I/1G7NpDuffuLD3XnoJLpw +=head2 voters + +Return persons who have responded to this question. In list context, +returns a list of voters. In scalar context, returns a resultset. + +=cut + +sub voters($) { + my ($self) = @_; + + return wantarray() ? $self->voters_rs->all : $self->voters_rs; +} + +=head2 voters_rs + +Return persons who have responded to this question as a resultset. + +=cut + +sub voters_rs($) { + my ($self) = @_; + + return $self->votes->search_related_rs('voter', undef, { distinct => 1 }); +} + =head2 validate_answer Validates an answer to this question and dies if it is not valid.