clean up changes for batch 18
[civicrm-core.git] / api / v3 / Participant.php
index 40b2be3f0531d1a170ef14f709ad78ebed22218b..2d4742bddede9071969218929d1cb53b3e35039c 100644 (file)
@@ -1,8 +1,7 @@
 <?php
-
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  *
  */
 
-/**
- * Files required for this package
- */
-
 /**
  * Create an Event Participant
  *
  * Required parameters : event_id AND contact_id for new creation
  *                     : participant as name/value with participantid for edit
  *
- * @param   array  $params     an associative array of name/value property values of civicrm_participant
+ * @param array $params
+ *   An associative array of name/value property values of civicrm_participant.
  *
- * @return array apiresult
- * {@getfields participant_create}
- * @access public
+ * @return array
+ *   apiresult
+ *   {@getfields participant_create}
  */
 function civicrm_api3_participant_create($params) {
   //check that event id is not an template - should be done @ BAO layer
@@ -63,13 +59,13 @@ function civicrm_api3_participant_create($params) {
     }
   }
 
-  $value = array();
+  $values = $participant = array();
   _civicrm_api3_custom_format_params($params, $values, 'Participant');
   $params = array_merge($values, $params);
 
   $participantBAO = CRM_Event_BAO_Participant::create($params);
 
-  if(empty($params['price_set_id']) && empty($params['id']) && !empty($params['fee_level'])){
+  if (empty($params['price_set_id']) && empty($params['id']) && !empty($params['fee_level'])) {
     _civicrm_api3_participant_createlineitem($params, $participantBAO);
   }
   _civicrm_api3_object_to_array($participantBAO, $participant[$participantBAO->id]);
@@ -78,16 +74,20 @@ function civicrm_api3_participant_create($params) {
 }
 
 /**
+ * @todo this should be done in the BAO not the api
  * Create a default participant line item
+ * @param array $params
+ * @param $participant
+ * @throws \CiviCRM_API3_Exception
  */
-function _civicrm_api3_participant_createlineitem(&$params, $participant){
+function _civicrm_api3_participant_createlineitem(&$params, $participant) {
   // it is possible that a fee level contains information about multiple
   // price field values.
 
   $priceFieldValueDetails = CRM_Utils_Array::explodePadded(
     $params["fee_level"]);
 
-  foreach($priceFieldValueDetails as $detail) {
+  foreach ($priceFieldValueDetails as $detail) {
     if (preg_match('/- ([0-9]+)$/', $detail, $matches)) {
       // it is possible that a price field value is payd for multiple times.
       // (FIXME: if the price field value ends in minus followed by whitespace
@@ -118,7 +118,7 @@ function _civicrm_api3_participant_createlineitem(&$params, $participant){
 
     $dao = CRM_Core_DAO::executeQuery($sql, $qParams);
     if ($dao->fetch()) {
-      $lineItemparams = array(
+      $lineItemParams = array(
         'price_field_id' => $dao->priceFieldID,
         'price_field_value_id' => $dao->priceFieldValueID,
         'entity_table' => 'civicrm_participant',
@@ -127,10 +127,9 @@ function _civicrm_api3_participant_createlineitem(&$params, $participant){
         'qty' => $qty,
         'participant_count' => 0,
         'unit_price' => $dao->amount,
-        'line_total' => $qty*$dao->amount,
-        'version' => 3,
+        'line_total' => $qty * $dao->amount,
       );
-      civicrm_api('line_item', 'create', $lineItemparams);
+      civicrm_api3('line_item', 'create', $lineItemParams);
     }
 
   }
@@ -141,7 +140,8 @@ function _civicrm_api3_participant_createlineitem(&$params, $participant){
  * Adjust Metadata for Create action
  *
  * The metadata is used for setting defaults, documentation & validation
- * @param array $params array or parameters determined by getfields
+ * @param array $params
+ *   Array or parameters determined by getfields.
  */
 function _civicrm_api3_participant_create_spec(&$params) {
   $params['status_id']['api.default'] = "1";
@@ -158,11 +158,12 @@ function _civicrm_api3_participant_create_spec(&$params) {
  * If more than one matching participant exists, return an error, unless
  * the client has requested to return the first found contact
  *
- * @param  array   $params           (reference ) input parameters
+ * @param array $params
+ *   (reference ) input parameters.
  *
- * @return array (reference )        array of properties, if error an array with an error id and error message
- * {@getfields participant_get}
- * @access public
+ * @return array
+ *   (reference )        array of properties, if error an array with an error id and error message
+ *   {@getfields participant_get}
  */
 function civicrm_api3_participant_get($params) {
   $mode = CRM_Contact_BAO_Query::MODE_EVENT;
@@ -184,7 +185,8 @@ function civicrm_api3_participant_get($params) {
  * Adjust Metadata for Get action
  *
  * The metadata is used for setting defaults, documentation & validation
- * @param array $params array or parameters determined by getfields
+ * @param array $params
+ *   Array or parameters determined by getfields.
  */
 function _civicrm_api3_participant_get_spec(&$params) {
   $params['participant_test']['api.default'] = 0;
@@ -196,12 +198,12 @@ function _civicrm_api3_participant_get_spec(&$params) {
  *
  * This API is used for deleting a contact participant
  *
- * @param  array $params Array containing  Id of the contact participant to be deleted
+ * @param array $params
+ *   Array containing Id of the contact participant to be deleted.
  *
  * {@getfields participant_delete}
  * @throws Exception
  * @return array
- * @access public
  */
 function civicrm_api3_participant_delete($params) {
 
@@ -214,4 +216,3 @@ function civicrm_api3_participant_delete($params) {
     throw new Exception('Error while deleting participant');
   }
 }
-