Merge pull request #2967 from colemanw/select
[civicrm-core.git] / api / v3 / Pledge.php
index e77858a3f54dd655c7d734e6160d74ca4c2c5b16..52eb53e0a7c07a85a11eaf15cafe081b6f7c7098 100644 (file)
@@ -1,11 +1,10 @@
 <?php
-// $Id$
 
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -33,7 +32,7 @@
  * @package CiviCRM_APIv3
  * @subpackage API_Pledge
  *
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * @version $Id: Pledge.php
  *
  */
@@ -73,15 +72,15 @@ function civicrm_api3_pledge_create($params) {
  * @example PledgeDelete.php
  * @access public
  */
-function civicrm_api3_pledge_delete($params) {\r
-  if (CRM_Pledge_BAO_Pledge::deletePledge($params['id'])) {\r
-    return civicrm_api3_create_success(array(\r
-      'id' => $params['id']\r
-    ), $params, 'pledge', 'delete');\r
-  }\r
-  else {\r
-    return civicrm_api3_create_error('Could not delete pledge');\r
-  }\r
+function civicrm_api3_pledge_delete($params) {
+  if (CRM_Pledge_BAO_Pledge::deletePledge($params['id'])) {
+    return civicrm_api3_create_success(array(
+      'id' => $params['id']
+    ), $params, 'pledge', 'delete');
+  }
+  else {
+    return civicrm_api3_create_error('Could not delete pledge');
+  }
 }
 
 function _civicrm_api3_pledge_delete_spec(&$params) {
@@ -130,25 +129,11 @@ function _civicrm_api3_pledge_create_spec(&$params) {
  * @access public
  */
 function civicrm_api3_pledge_get($params) {
+  $mode = CRM_Contact_BAO_Query::MODE_PLEDGE;
+  $entity = 'pledge';
+
+  list($dao, $query) = _civicrm_api3_get_query_object($params, $mode, $entity);
 
-  $options = _civicrm_api3_get_options_from_params($params, TRUE, 'pledge','get');
-  if (empty($options['return'])) {
-    $options['return'] = CRM_Pledge_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_PLEDGE);
-  }
-  else {
-    $options['return']['pledge_id'] = 1;
-  }
-  $newParams = CRM_Contact_BAO_Query::convertFormValues($options['input_params']);
-  $query = new CRM_Contact_BAO_Query($newParams, $options['return'], NULL,
-    FALSE, FALSE, CRM_Contact_BAO_Query::MODE_PLEDGE
-  );
-  list($select, $from, $where) = $query->query();
-  $sql = "$select $from $where";
-  if (!empty($options['sort'])) {
-    $sql .= " ORDER BY " . $options['sort'];
-  }
-  $sql .= " LIMIT " . $options['offset'] . " , " . $options['limit'];
-  $dao = CRM_Core_DAO::executeQuery($sql);
   $pledge = array();
   while ($dao->fetch()) {
     $pledge[$dao->pledge_id] = $query->store($dao);