Merge pull request #353 from eileenmcnaughton/trunk-kill-eval
[civicrm-core.git] / api / v2 / SurveyRespondant.php
CommitLineData
6a488035
TO
1<?php
2// $Id$
3
4/*
5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright Tech To The People (c) 2010 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
11 | |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
20 | |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
28*/
29
30/**
31 * File for the CiviCRM APIv2 Petition Signatures functions
32 *
33 * @package CiviCRM_APIv2
34 * @subpackage API_Contribute
35 */
36
37/**
38 * Include utility functions
39 */
40require_once 'api/v2/utils.php';
41require_once 'CRM/Utils/Rule.php';
42require_once 'CRM/Campaign/BAO/Petition.php';
43
44/**
45 * Get the list of signatories
46 *
47 * @param array $params (reference ) input parameters
48 *
49 * @return array (reference ) contribution_id of created or updated record
50 * @static void
51 * @access public
52 */
53function &civicrm_survey_respondant_get(&$params) {
54 _civicrm_initialize();
55
56 if (empty($params)) {
57 return civicrm_create_error(ts('No input parameters present'));
58 }
59
60 if (!is_array($params)) {
61 return civicrm_create_error(ts('Input parameters is not an array'));
62 }
63
64 if (!array_key_exists('survey_id', $params)) {
65 return (civicrm_create_error('survey_id mandatory'));
66 }
67
68 if (array_key_exists('status_id', $params)) {
69 $status_id = $params['status_id'];
70 }
71 else {
72 $status_id = NULL;
73 }
74
75 $petition = new CRM_Campaign_BAO_Petition();
76 $signatures = $petition->getPetitionSignature($params['survey_id'], $status_id);
77 return ($signatures);
78}
79
80function &civicrm_survey_respondant_count(&$params) {
81 _civicrm_initialize();
82 $petition = new CRM_Campaign_BAO_Petition();
83 if (array_key_exists('groupby', $params) && $params['groupby'] == 'country') {
84 $signaturesCount = $petition->getPetitionSignatureTotalbyCountry($params['survey_id']);
85 }
86 else {
87 $signaturesCount = $petition->getPetitionSignatureTotal($params['survey_id']);
88 }
89 return ($signaturesCount);
90}
91