From 22fd16901970326fa474db927fab3f61d20964d5 Mon Sep 17 00:00:00 2001 From: Adam Roses Wight Date: Wed, 15 May 2013 08:59:02 -0700 Subject: [PATCH] Register and use the autoloader during API calls --- api/api.php | 3 - api/class.api.php | 3 +- api/v3/ActivityType.php | 7 - api/v3/Address.php | 2 - api/v3/Campaign.php | 2 - api/v3/ContactType.php | 2 - api/v3/Contribution.php | 4 - api/v3/ContributionRecur.php | 2 - api/v3/CustomField.php | 6 - api/v3/CustomGroup.php | 1 - api/v3/Email.php | 2 - api/v3/File.php | 13 +- api/v3/Generic/Setvalue.php | 1 - api/v3/Grant.php | 2 - api/v3/Group.php | 5 - api/v3/GroupNesting.php | 2 - api/v3/GroupOrganization.php | 2 - api/v3/Job.php | 23 --- api/v3/MailingGroup.php | 17 -- api/v3/Membership.php | 8 - api/v3/MembershipPayment.php | 7 - api/v3/MembershipStatus.php | 10 - api/v3/MembershipType.php | 6 - api/v3/Note.php | 2 - api/v3/OptionGroup.php | 1 - api/v3/ParticipantPayment.php | 1 - api/v3/ParticipantStatusType.php | 1 - api/v3/PaymentProcessorType.php | 5 - api/v3/Phone.php | 5 - api/v3/PledgePayment.php | 5 - api/v3/Profile.php | 10 - api/v3/Relationship.php | 3 - api/v3/RelationshipType.php | 8 - api/v3/SurveyRespondant.php | 2 - api/v3/Tag.php | 5 - api/v3/UFField.php | 7 - api/v3/UFGroup.php | 2 - api/v3/UFJoin.php | 5 - api/v3/Website.php | 2 - api/v3/examples/ActivityGetfields.php | 287 ++++++++++++++++++++++++++ api/v3/examples/GrantGet.php | 14 +- api/v3/utils.php | 27 +-- 42 files changed, 301 insertions(+), 221 deletions(-) create mode 100644 api/v3/examples/ActivityGetfields.php diff --git a/api/api.php b/api/api.php index 44488cae28..2e27418365 100644 --- a/api/api.php +++ b/api/api.php @@ -205,7 +205,6 @@ function _civicrm_api_resolve($apiRequest) { 'api/v' . $apiRequest['version'] . '/' . $camelName . '/' . $actionCamelName . '.php', ); foreach ($stdFiles as $stdFile) { - require_once 'CRM/Utils/File.php'; if (CRM_Utils_File::isIncludable($stdFile)) { require_once $stdFile; if (function_exists($stdFunction)) { @@ -225,7 +224,6 @@ function _civicrm_api_resolve($apiRequest) { 'api/v' . $apiRequest['version'] . '/Generic/' . $actionCamelName . '.php', ); foreach ($genericFiles as $genericFile) { - require_once 'CRM/Utils/File.php'; if (CRM_Utils_File::isIncludable($genericFile)) { require_once $genericFile; if (function_exists($genericFunction)) { @@ -261,7 +259,6 @@ function _civicrm_api_loadEntity($entity, $version = 3) { $camelName = _civicrm_api_get_camel_name($entity, $version); // Check for master entity file; to match _civicrm_api_resolve(), only load the first one - require_once 'CRM/Utils/File.php'; $stdFile = 'api/v' . $version . '/' . $camelName . '.php'; if (CRM_Utils_File::isIncludable($stdFile)) { require_once $stdFile; diff --git a/api/class.api.php b/api/class.api.php index 6080a7681e..298427286b 100644 --- a/api/class.api.php +++ b/api/class.api.php @@ -92,9 +92,10 @@ class civicrm_api3 { if (isset($config) && isset($config['conf_path'])) { define('CIVICRM_SETTINGS_PATH', $config['conf_path'] . '/civicrm.settings.php'); require_once CIVICRM_SETTINGS_PATH; - require_once 'CRM/Core/Config.php'; + require_once 'CRM/Core/Classloader.php'; require_once 'api/api.php'; require_once "api/v3/utils.php"; + CRM_Core_Classloader::singleton()->register(); $this->cfg = CRM_Core_Config::singleton(); $this->init(); } diff --git a/api/v3/ActivityType.php b/api/v3/ActivityType.php index 6e0fb748d4..d8b9490639 100644 --- a/api/v3/ActivityType.php +++ b/api/v3/ActivityType.php @@ -41,11 +41,6 @@ * */ -/** - * Include common API util functions - */ -require_once 'CRM/Core/OptionGroup.php'; - /** * Function to retrieve activity types * @@ -87,7 +82,6 @@ function civicrm_api3_activity_type_create($params) { $action = 2; } - require_once 'CRM/Core/OptionValue.php'; $activityObject = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $action, $optionValueID); $activityType = array(); _civicrm_api3_object_to_array($activityObject, $activityType[$activityObject->id]); @@ -122,7 +116,6 @@ function civicrm_api3_activity_type_delete($params) { civicrm_api3_verify_mandatory($params, NULL, array('activity_type_id')); $activityTypeId = $params['activity_type_id']; - require_once 'CRM/Core/BAO/OptionValue.php'; return CRM_Core_BAO_OptionValue::del($activityTypeId); } diff --git a/api/v3/Address.php b/api/v3/Address.php index 1cad60f408..cfb839c7be 100644 --- a/api/v3/Address.php +++ b/api/v3/Address.php @@ -37,8 +37,6 @@ * @version $Id: Address.php 2011-02-16 ErikHommel $ */ -require_once 'CRM/Core/BAO/Address.php'; - /** * Add an Address for a contact * diff --git a/api/v3/Campaign.php b/api/v3/Campaign.php index 87789d730e..6f047a1a23 100644 --- a/api/v3/Campaign.php +++ b/api/v3/Campaign.php @@ -35,8 +35,6 @@ * @copyright CiviCRM LLC (c) 2004-2013 */ -require_once 'CRM/Campaign/BAO/Campaign.php'; - /** * create/update campaign * diff --git a/api/v3/ContactType.php b/api/v3/ContactType.php index 36b60fca23..f70b4116f3 100644 --- a/api/v3/ContactType.php +++ b/api/v3/ContactType.php @@ -35,7 +35,6 @@ * @copyright CiviCRM LLC (c) 2004-2013 */ -//require_once 'CRM/Campaign/BAO/ContactType.php'; require_once 'api/v3/utils.php'; /** @@ -53,7 +52,6 @@ require_once 'api/v3/utils.php'; * @access public */ function civicrm_api3_contact_type_create($params) { - require_once 'CRM/Utils/String.php'; civicrm_api3_verify_mandatory($params, _civicrm_api3_get_DAO(__FUNCTION__), array('name', 'parent_id')); if (!array_key_exists('label', $params)) { $params['label'] = $params['name']; diff --git a/api/v3/Contribution.php b/api/v3/Contribution.php index 18e0231b02..88219980cc 100644 --- a/api/v3/Contribution.php +++ b/api/v3/Contribution.php @@ -175,8 +175,6 @@ function civicrm_api3_contribution_get($params) { $smartGroupCache = CRM_Utils_Array::value('smartGroupCache', $params); $inputParams = CRM_Utils_Array::value('input_params', $options, array()); $returnProperties = CRM_Utils_Array::value('return', $options, NULL); - require_once 'CRM/Contribute/BAO/Query.php'; - require_once 'CRM/Contact/BAO/Query.php'; if (empty($returnProperties)) { $returnProperties = CRM_Contribute_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_CONTRIBUTE); } @@ -327,13 +325,11 @@ function civicrm_api3_contribution_transact($params) { $params['invoiceID'] = $params['invoice_id']; } - require_once 'CRM/Financial/BAO/PaymentProcessor.php'; $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($params['payment_processor_id'], $params['payment_processor_mode']); if (civicrm_error($paymentProcessor)) { return $paymentProcessor; } - require_once 'CRM/Core/Payment.php'; $payment = &CRM_Core_Payment::singleton($params['payment_processor_mode'], $paymentProcessor); if (civicrm_error($payment)) { return $payment; diff --git a/api/v3/ContributionRecur.php b/api/v3/ContributionRecur.php index c15af33b0e..31cfc4198f 100644 --- a/api/v3/ContributionRecur.php +++ b/api/v3/ContributionRecur.php @@ -33,8 +33,6 @@ * @copyright CiviCRM LLC (c) 2004-2013 */ -require_once 'CRM/Contribute/BAO/ContributionRecur.php'; - /** * Create or update a contribution_recur * diff --git a/api/v3/CustomField.php b/api/v3/CustomField.php index 233d1f7e84..0b65242c57 100644 --- a/api/v3/CustomField.php +++ b/api/v3/CustomField.php @@ -37,11 +37,6 @@ * @version $Id: CustomField.php 30879 2010-11-22 15:45:55Z shot $ */ -/** - * Files required for this package - */ -require_once 'CRM/Core/BAO/CustomField.php'; - /** * Most API functions take in associative arrays ( name => value pairs * as parameters. Some of the most commonly used parameters are @@ -255,7 +250,6 @@ SELECT count(*) 'Select', 'Multi-Select', 'CheckBox', 'Radio', 'AdvMulti-Select')) && !isset($errors[$fieldName]) ) { - require_once 'CRM/Core/OptionGroup.php'; $options = CRM_Core_OptionGroup::valuesByID($fieldDetails['option_group_id']); if (!is_array($value)) { $value = array($value); diff --git a/api/v3/CustomGroup.php b/api/v3/CustomGroup.php index 61b564c133..37d17fab47 100644 --- a/api/v3/CustomGroup.php +++ b/api/v3/CustomGroup.php @@ -112,7 +112,6 @@ function civicrm_api3_custom_group_delete($params) { $values->id = $params['id']; $values->find(TRUE); - require_once 'CRM/Core/BAO/CustomGroup.php'; $result = CRM_Core_BAO_CustomGroup::deleteGroup($values, TRUE); return $result ? civicrm_api3_create_success() : civicrm_api3_create_error('Error while deleting custom group'); } diff --git a/api/v3/Email.php b/api/v3/Email.php index 6de9a8a084..c6b688de35 100644 --- a/api/v3/Email.php +++ b/api/v3/Email.php @@ -37,8 +37,6 @@ * @version $Id: Email.php 2011-02-16 ErikHommel $ */ -require_once 'CRM/Core/BAO/Email.php'; - /** * Add an Email for a contact * diff --git a/api/v3/File.php b/api/v3/File.php index 54e18d902f..aec82c9bba 100644 --- a/api/v3/File.php +++ b/api/v3/File.php @@ -41,12 +41,6 @@ * */ -/** - * Files required for this package - */ -require_once 'CRM/Core/DAO/File.php'; -require_once 'CRM/Core/BAO/File.php'; - /** * Create a file * @@ -65,8 +59,6 @@ function civicrm_api3_file_create($params) { $params['upload_date'] = date("Ymd"); } - require_once 'CRM/Core/DAO/File.php'; - $fileDAO = new CRM_Core_DAO_File(); $properties = array('id', 'file_type_id', 'mime_type', 'uri', 'document', 'description', 'upload_date'); @@ -117,7 +109,6 @@ function &civicrm_api3_file_update($params) { return civicrm_api3_create_error('Required parameter missing'); } - require_once 'CRM/Core/DAO/File.php'; $fileDAO = new CRM_Core_DAO_File(); $fileDAO->id = $params['id']; if ($fileDAO->find(TRUE)) { @@ -150,14 +141,12 @@ function civicrm_api3_file_delete($params) { $check = FALSE; - require_once 'CRM/Core/DAO/EntityFile.php'; $entityFileDAO = new CRM_Core_DAO_EntityFile(); $entityFileDAO->file_id = $params['id']; if ($entityFileDAO->find()) { $check = $entityFileDAO->delete(); } - require_once 'CRM/Core/DAO/File.php'; $fileDAO = new CRM_Core_DAO_File(); $fileDAO->id = $params['id']; if ($fileDAO->find(TRUE)) { @@ -165,4 +154,4 @@ function civicrm_api3_file_delete($params) { } return $check ? NULL : civicrm_api3_create_error('Error while deleting a file.'); -} \ No newline at end of file +} diff --git a/api/v3/Generic/Setvalue.php b/api/v3/Generic/Setvalue.php index 59eeedfd35..471e700aca 100644 --- a/api/v3/Generic/Setvalue.php +++ b/api/v3/Generic/Setvalue.php @@ -39,7 +39,6 @@ function civicrm_api3_generic_setValue($apiRequest) { case 2: //string - require_once ("CRM/Utils/Rule.php"); if (!CRM_Utils_Rule::xssString($value)) { return civicrm_api3_create_error(ts('Illegal characters in input (potential scripting attack)'), array('error_code' => 'XSS')); } diff --git a/api/v3/Grant.php b/api/v3/Grant.php index 01b252e8a8..348e73b1e8 100644 --- a/api/v3/Grant.php +++ b/api/v3/Grant.php @@ -35,8 +35,6 @@ * @copyright CiviCRM LLC (c) 2004-2013 */ -require_once 'CRM/Grant/BAO/Grant.php'; - /** * create/update grant * diff --git a/api/v3/Group.php b/api/v3/Group.php index 2dc1d426d2..c37fe2f1fd 100644 --- a/api/v3/Group.php +++ b/api/v3/Group.php @@ -36,11 +36,6 @@ * @version $Id: Group.php 30171 2010-10-14 09:11:27Z mover $ */ -/** - * Include utility functions - */ -require_once 'CRM/Contact/BAO/Group.php'; - /** * create/update group * diff --git a/api/v3/GroupNesting.php b/api/v3/GroupNesting.php index 4ec6b61b02..2db1fa8c7d 100644 --- a/api/v3/GroupNesting.php +++ b/api/v3/GroupNesting.php @@ -38,8 +38,6 @@ * */ -require_once 'CRM/Contact/BAO/GroupNesting.php'; - /** * Provides group nesting record(s) given parent and/or child id. * diff --git a/api/v3/GroupOrganization.php b/api/v3/GroupOrganization.php index d5795c13dd..efb9483765 100644 --- a/api/v3/GroupOrganization.php +++ b/api/v3/GroupOrganization.php @@ -39,8 +39,6 @@ */ -require_once 'CRM/Contact/BAO/GroupOrganization.php'; - /** * This API will give list of the groups for particular contact * Particualr status can be sent in params array diff --git a/api/v3/Job.php b/api/v3/Job.php index 4cd5a444d9..101099adad 100644 --- a/api/v3/Job.php +++ b/api/v3/Job.php @@ -71,8 +71,6 @@ function _civicrm_api3_job_create_spec(&$params) { * {@schema Core/Job.xml} */ function civicrm_api3_job_create($params) { - require_once 'CRM/Utils/Rule.php'; - if (isset($params['id']) && !CRM_Utils_Rule::integer($params['id'])) { return civicrm_api3_create_error('Invalid value for job ID'); } @@ -106,7 +104,6 @@ function civicrm_api3_job_get($params) { * @access public */ function civicrm_api3_job_delete($params) { - require_once 'CRM/Utils/Rule.php'; if ($params['id'] != NULL && !CRM_Utils_Rule::integer($params['id'])) { return civicrm_api3_create_error('Invalid value for job ID'); } @@ -131,7 +128,6 @@ function civicrm_api3_job_delete($params) { * */ function civicrm_api3_job_execute($params) { - require_once 'CRM/Core/JobManager.php'; $facility = new CRM_Core_JobManager(); $facility->execute(FALSE); @@ -161,8 +157,6 @@ function _civicrm_api3_job_execute_spec(&$params) { * */ function civicrm_api3_job_geocode($params) { - - require_once 'CRM/Utils/Address/BatchUpdate.php'; $gc = new CRM_Utils_Address_BatchUpdate($params); @@ -199,13 +193,11 @@ function _civicrm_api3_job_geocode_spec(&$params) { * */ function civicrm_api3_job_send_reminder($params) { - require_once 'CRM/Core/Lock.php'; $lock = new CRM_Core_Lock('civimail.job.EmailProcessor'); if (!$lock->isAcquired()) { return civicrm_api3_create_error('Could not acquire lock, another EmailProcessor process is running'); } - require_once 'CRM/Core/BAO/ActionSchedule.php'; $result = CRM_Core_BAO_ActionSchedule::processQueue(CRM_Utils_Array::value('now', $params)); $lock->release(); @@ -366,8 +358,6 @@ function civicrm_api3_job_process_sms($params) { * Job to get mail responses from civimailing */ function civicrm_api3_job_fetch_bounces($params) { - require_once 'CRM/Utils/Mail/EmailProcessor.php'; - require_once 'CRM/Core/Lock.php'; $lock = new CRM_Core_Lock('civimail.job.EmailProcessor'); if (!$lock->isAcquired()) { return civicrm_api3_create_error('Could not acquire lock, another EmailProcessor process is running'); @@ -387,8 +377,6 @@ function civicrm_api3_job_fetch_bounces($params) { * Job to get mail and create activities */ function civicrm_api3_job_fetch_activities($params) { - require_once 'CRM/Utils/Mail/EmailProcessor.php'; - require_once 'CRM/Core/Lock.php'; $lock = new CRM_Core_Lock('civimail.job.EmailProcessor'); if (!$lock->isAcquired()) { return civicrm_api3_create_error('Could not acquire lock, another EmailProcessor process is running'); @@ -414,7 +402,6 @@ function civicrm_api3_job_fetch_activities($params) { * @access public */ function civicrm_api3_job_process_participant($params) { - require_once 'CRM/Event/BAO/ParticipantStatusType.php'; $result = CRM_Event_BAO_ParticipantStatusType::process($params); if (!$result['is_error']) { @@ -440,13 +427,11 @@ function civicrm_api3_job_process_participant($params) { * @access public */ function civicrm_api3_job_process_membership($params) { - require_once 'CRM/Core/Lock.php'; $lock = new CRM_Core_Lock('civimail.job.updateMembership'); if (!$lock->isAcquired()) { return civicrm_api3_create_error('Could not acquire lock, another EmailProcessor process is running'); } - require_once 'CRM/Member/BAO/Membership.php'; $result = CRM_Member_BAO_Membership::updateAllMembershipStatus(); $lock->release(); @@ -468,7 +453,6 @@ function civicrm_api3_job_process_membership($params) { * @access public */ function civicrm_api3_job_process_respondent($params) { - require_once 'CRM/Campaign/BAO/Survey.php'; $result = CRM_Campaign_BAO_Survey::releaseRespondent($params); if ($result['is_error'] == 0) { @@ -503,7 +487,6 @@ function civicrm_api3_job_process_batch_merge($params) { $mode = CRM_Utils_Array::value('mode', $params, 'safe'); $autoFlip = CRM_Utils_Array::value('auto_flip', $params, TRUE); - require_once 'CRM/Dedupe/Merger.php'; $result = CRM_Dedupe_Merger::batchMerge($rgid, $gid, $mode, $autoFlip); if ($result['is_error'] == 0) { @@ -526,8 +509,6 @@ function civicrm_api3_job_process_batch_merge($params) { */ function civicrm_api3_job_run_payment_cron($params) { - require_once 'CRM/Core/Payment.php'; - // live mode CRM_Core_Payment::handlePaymentMethod( 'PaymentCron', @@ -561,8 +542,6 @@ function civicrm_api3_job_run_payment_cron($params) { * @access public */ function civicrm_api3_job_cleanup( $params ) { - require_once 'CRM/Utils/Array.php'; - $session = CRM_Utils_Array::value( 'session' , $params, true ); $tempTable = CRM_Utils_Array::value( 'tempTables', $params, true ); $jobLog = CRM_Utils_Array::value( 'jobLog' , $params, true ); @@ -571,7 +550,6 @@ function civicrm_api3_job_cleanup( $params ) { $memCache = CRM_Utils_Array::value( 'memCache' , $params, false ); if ( $session || $tempTable || $prevNext ) { - require_once 'CRM/Core/BAO/Cache.php'; CRM_Core_BAO_Cache::cleanup( $session, $tempTable, $prevNext ); } @@ -609,7 +587,6 @@ function civicrm_api3_job_disable_expired_relationships($params) { * and use the cache */ function civicrm_api3_job_group_rebuild( $params ) { - require_once 'CRM/Core/Lock.php'; $lock = new CRM_Core_Lock('civimail.job.groupRebuild'); if (!$lock->isAcquired()) { return civicrm_api3_create_error('Could not acquire lock, another EmailProcessor process is running'); diff --git a/api/v3/MailingGroup.php b/api/v3/MailingGroup.php index 0c9f4ddc42..b9ac904baa 100644 --- a/api/v3/MailingGroup.php +++ b/api/v3/MailingGroup.php @@ -38,19 +38,6 @@ * */ -/** - * Files required for this package - */ - - - -require_once 'CRM/Contact/BAO/Group.php'; -require_once 'CRM/Mailing/Event/BAO/Queue.php'; -require_once 'CRM/Mailing/Event/BAO/Subscribe.php'; -require_once 'CRM/Mailing/Event/BAO/Unsubscribe.php'; -require_once 'CRM/Mailing/Event/BAO/Resubscribe.php'; -require_once 'CRM/Mailing/Event/BAO/TrackableURLOpen.php'; - /** * Handle an unsubscribe event * @deprecated @@ -101,15 +88,11 @@ function civicrm_api3_mailing_group_event_subscribe($params) { function civicrm_api3_mailing_group_getfields($params) { $dao = _civicrm_api3_get_DAO('Subscribe'); - $file = str_replace('_', '/', $dao) . ".php"; - require_once ($file); $d = new $dao(); $fields = $d->fields(); $d->free(); $dao = _civicrm_api3_get_DAO('Unsubscribe'); - $file = str_replace('_', '/', $dao) . ".php"; - require_once ($file); $d = new $dao(); $fields = $fields + $d->fields(); $d->free(); diff --git a/api/v3/Membership.php b/api/v3/Membership.php index 80414a4bcb..5b337bd723 100644 --- a/api/v3/Membership.php +++ b/api/v3/Membership.php @@ -38,13 +38,6 @@ * @version $Id: MembershipContact.php 30171 2010-10-14 09:11:27Z mover $ */ -/** - * Files required for this package - */ - -require_once 'CRM/Utils/Rule.php'; -require_once 'CRM/Utils/Array.php'; - /** * Deletes an existing contact membership * @@ -331,7 +324,6 @@ function _civicrm_api3_membership_format_params($params, &$values, $create = FAL */ function _civicrm_api3_membership_get_customv2behaviour(&$params, $contactID, $membershipTypeId, $activeOnly ){ // get the membership for the given contact ID - require_once 'CRM/Member/BAO/Membership.php'; $membershipParams = array( 'contact_id' => $contactID ); if ( $membershipTypeId ) { $membershipParams['membership_type_id'] = $membershipTypeId; diff --git a/api/v3/MembershipPayment.php b/api/v3/MembershipPayment.php index 147bb4dc72..f75e8a8cdf 100644 --- a/api/v3/MembershipPayment.php +++ b/api/v3/MembershipPayment.php @@ -37,12 +37,6 @@ * @version $Id: MembershipContributionLink.php 30171 2010-10-14 09:11:27Z mover $ */ -/** - * Include utility functions - */ - -require_once 'CRM/Member/DAO/MembershipPayment.php'; - /** * Add or update a link between contribution and membership * @@ -55,7 +49,6 @@ require_once 'CRM/Member/DAO/MembershipPayment.php'; */ function civicrm_api3_membership_payment_create($params) { - require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); diff --git a/api/v3/MembershipStatus.php b/api/v3/MembershipStatus.php index 979fe70e08..c974d59278 100644 --- a/api/v3/MembershipStatus.php +++ b/api/v3/MembershipStatus.php @@ -38,12 +38,6 @@ * */ -/** - * Files required for this package - */ - -require_once 'CRM/Member/BAO/MembershipStatus.php'; - /** * Create a Membership Status * @@ -102,7 +96,6 @@ function &civicrm_api3_membership_status_update($params) { //don't allow duplicate names. $name = CRM_Utils_Array::value('name', $params); if ($name) { - require_once 'CRM/Member/DAO/MembershipStatus.php'; $status = new CRM_Member_DAO_MembershipStatus(); $status->name = $params['name']; if ($status->find(TRUE) && $status->id != $params['id']) { @@ -110,7 +103,6 @@ function &civicrm_api3_membership_status_update($params) { } } - require_once 'CRM/Member/BAO/MembershipStatus.php'; $membershipStatusBAO = new CRM_Member_BAO_MembershipStatus(); $membershipStatusBAO->id = $params['id']; if ($membershipStatusBAO->find(TRUE)) { @@ -172,8 +164,6 @@ SELECT start_date, end_date, join_date $params = array(1 => array($membershipID, 'Integer')); $dao = &CRM_Core_DAO::executeQuery($query, $params); if ($dao->fetch()) { - require_once 'CRM/Member/BAO/MembershipStatus.php'; - // Take the is_admin column in MembershipStatus into consideration when requested if (! CRM_Utils_Array::value('ignore_admin_only', $membershipParams) ) { $result = &CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dao->start_date, $dao->end_date, $dao->join_date, 'today', TRUE); diff --git a/api/v3/MembershipType.php b/api/v3/MembershipType.php index 91ea2cc29c..30f9e5f103 100644 --- a/api/v3/MembershipType.php +++ b/api/v3/MembershipType.php @@ -38,11 +38,6 @@ * */ -/** - * Files required for this package - */ -require_once 'CRM/Member/BAO/MembershipType.php'; - /** * API to Create or update a Membership Type * @@ -61,7 +56,6 @@ function civicrm_api3_membership_type_create($params) { $ids['memberOfContact'] = CRM_Utils_Array::value('member_of_contact_id', $values); $ids['contributionType'] = CRM_Utils_Array::value('financial_type_id', $values); - require_once 'CRM/Member/BAO/MembershipType.php'; $membershipTypeBAO = CRM_Member_BAO_MembershipType::add($values, $ids); $membershipType = array(); _civicrm_api3_object_to_array($membershipTypeBAO, $membershipType[$membershipTypeBAO->id]); diff --git a/api/v3/Note.php b/api/v3/Note.php index 598d991d6a..18d3919881 100644 --- a/api/v3/Note.php +++ b/api/v3/Note.php @@ -42,8 +42,6 @@ * Files required for this package */ -require_once 'CRM/Core/BAO/Note.php'; - /** * Create Note * diff --git a/api/v3/OptionGroup.php b/api/v3/OptionGroup.php index d6b12e3667..53d954da3a 100644 --- a/api/v3/OptionGroup.php +++ b/api/v3/OptionGroup.php @@ -1,7 +1,6 @@ fields(); return civicrm_api3_create_success($fields); diff --git a/api/v3/Relationship.php b/api/v3/Relationship.php index 1b6c3cb94a..82db724c63 100644 --- a/api/v3/Relationship.php +++ b/api/v3/Relationship.php @@ -109,7 +109,6 @@ function _civicrm_api3_relationship_create_spec(&$params) { */ function civicrm_api3_relationship_delete($params) { - require_once 'CRM/Utils/Rule.php'; if (!CRM_Utils_Rule::integer($params['id'])) { return civicrm_api3_create_error('Invalid value for relationship ID'); } @@ -208,7 +207,6 @@ function _civicrm_api3_relationship_format_params($params, &$values) { foreach ($params as $key => $value) { // ignore empty values or empty arrays etc - require_once 'CRM/Utils/System.php'; if (CRM_Utils_System::isNull($value)) { continue; } @@ -216,7 +214,6 @@ function _civicrm_api3_relationship_format_params($params, &$values) { switch ($key) { case 'contact_id_a': case 'contact_id_b': - require_once 'CRM/Utils/Rule.php'; if (!CRM_Utils_Rule::integer($value)) { throw new Exception("contact_id not valid: $value"); } diff --git a/api/v3/RelationshipType.php b/api/v3/RelationshipType.php index 291415b89f..d0762420d0 100644 --- a/api/v3/RelationshipType.php +++ b/api/v3/RelationshipType.php @@ -38,11 +38,6 @@ * */ -/** - * Include common API util functions - */ -require_once 'CRM/Contact/BAO/RelationshipType.php'; - /** * Function to create relationship type * @@ -65,8 +60,6 @@ function civicrm_api3_relationship_type_create($params) { $params['label_b_a'] = $params['name_b_a']; } - require_once 'CRM/Utils/Rule.php'; - $ids = array(); if (isset($params['id']) && !CRM_Utils_Rule::integer($params['id'])) { return civicrm_api3_create_error('Invalid value for relationship type ID'); @@ -122,7 +115,6 @@ function civicrm_api3_relationship_type_get($params) { */ function civicrm_api3_relationship_type_delete($params) { - require_once 'CRM/Utils/Rule.php'; if ($params['id'] != NULL && !CRM_Utils_Rule::integer($params['id'])) { return civicrm_api3_create_error('Invalid value for relationship type ID'); } diff --git a/api/v3/SurveyRespondant.php b/api/v3/SurveyRespondant.php index e56d8eae09..851fd98754 100644 --- a/api/v3/SurveyRespondant.php +++ b/api/v3/SurveyRespondant.php @@ -38,8 +38,6 @@ * Include utility functions */ require_once 'api/v3/utils.php'; -require_once 'CRM/Utils/Rule.php'; -require_once 'CRM/Campaign/BAO/Petition.php'; /** * Get the list of signatories diff --git a/api/v3/Tag.php b/api/v3/Tag.php index 490862866b..02db94b3a8 100644 --- a/api/v3/Tag.php +++ b/api/v3/Tag.php @@ -37,11 +37,6 @@ * @version $Id: Tag.php 30486 2010-11-02 16:12:09Z shot $ */ -/** - * Include utility functions - */ -require_once 'CRM/Core/BAO/Tag.php'; - /** * Add a Tag. Tags are used to classify CRM entities (including Contacts, Groups and Actions). * diff --git a/api/v3/UFField.php b/api/v3/UFField.php index 78b7077c9e..030bd99c13 100644 --- a/api/v3/UFField.php +++ b/api/v3/UFField.php @@ -38,13 +38,6 @@ * */ -/** - * Include common API util functions - */ - -require_once 'CRM/Core/BAO/UFField.php'; -require_once 'CRM/Core/BAO/UFGroup.php'; - /** * Defines 'uf field' within a group. * diff --git a/api/v3/UFGroup.php b/api/v3/UFGroup.php index 54d2524343..80c69a131a 100644 --- a/api/v3/UFGroup.php +++ b/api/v3/UFGroup.php @@ -42,8 +42,6 @@ * Files required for this package */ -require_once 'CRM/Core/BAO/UFGroup.php'; - function _civicrm_api3_uf_group_create_spec(&$params) { $session = CRM_Core_Session::singleton(); $params['title']['api.required'] = 1; diff --git a/api/v3/UFJoin.php b/api/v3/UFJoin.php index 75fcf4085b..5b0a6ec3c1 100644 --- a/api/v3/UFJoin.php +++ b/api/v3/UFJoin.php @@ -38,11 +38,6 @@ * */ -/** - * Files required for this package - */ -require_once 'CRM/Core/BAO/UFJoin.php'; - /** * takes an associative array and creates a uf join in the database * diff --git a/api/v3/Website.php b/api/v3/Website.php index 36d5ebc422..2c07014857 100644 --- a/api/v3/Website.php +++ b/api/v3/Website.php @@ -37,8 +37,6 @@ * @version $Id: Website.php 2011-03-16 ErikHommel $ */ -require_once 'CRM/Core/BAO/Website.php'; - /** * Add an Website for a contact * diff --git a/api/v3/examples/ActivityGetfields.php b/api/v3/examples/ActivityGetfields.php new file mode 100644 index 0000000000..ea2cd37f3d --- /dev/null +++ b/api/v3/examples/ActivityGetfields.php @@ -0,0 +1,287 @@ + 3, + 'action' => 'create', +); + + $result = civicrm_api( 'activity','getfields',$params ); + + return $result; +} + +/* + * Function returns array of result expected from previous function + */ +function activity_getfields_expectedresult(){ + + $expectedResult = array( + 'is_error' => 0, + 'version' => 3, + 'count' => 28, + 'values' => array( + 'source_record_id' => array( + 'name' => 'source_record_id', + 'type' => 1, + 'title' => 'Source Record', + ), + 'activity_type_id' => array( + 'name' => 'activity_type_id', + 'type' => 1, + 'title' => 'Activity Type ID', + 'required' => true, + 'import' => true, + 'where' => 'civicrm_activity.activity_type_id', + 'headerPattern' => '/(activity.)?type(.id$)/i', + ), + 'activity_date_time' => array( + 'name' => 'activity_date_time', + 'type' => 12, + 'title' => 'Activity Date', + 'import' => true, + 'where' => 'civicrm_activity.activity_date_time', + 'headerPattern' => '/(activity.)?date(.time$)?/i', + 'export' => true, + ), + 'phone_id' => array( + 'name' => 'phone_id', + 'type' => 1, + 'title' => 'Phone (called) ID', + 'FKClassName' => 'CRM_Core_DAO_Phone', + ), + 'phone_number' => array( + 'name' => 'phone_number', + 'type' => 2, + 'title' => 'Phone (called) Number', + 'maxlength' => 64, + 'size' => 30, + ), + 'priority_id' => array( + 'name' => 'priority_id', + 'type' => 1, + 'title' => 'Priority', + 'pseudoconstant' => array( + 'name' => 'priority', + 'optionGroupName' => 'priority', + ), + 'api.aliases' => array( + '0' => 'priority', + ), + 'options' => array( + '1' => 'Urgent', + '2' => 'Normal', + '3' => 'Low', + ), + ), + 'parent_id' => array( + 'name' => 'parent_id', + 'type' => 1, + 'title' => 'Parent Activity Id', + 'FKClassName' => 'CRM_Activity_DAO_Activity', + ), + 'is_auto' => array( + 'name' => 'is_auto', + 'type' => 16, + 'title' => 'Auto', + ), + 'relationship_id' => array( + 'name' => 'relationship_id', + 'type' => 1, + 'title' => 'Relationship Id', + 'default' => 'UL', + 'FKClassName' => 'CRM_Contact_DAO_Relationship', + ), + 'is_current_revision' => array( + 'name' => 'is_current_revision', + 'type' => 16, + 'title' => 'Is this activity a current revision in versioning chain?', + 'import' => true, + 'where' => 'civicrm_activity.is_current_revision', + 'headerPattern' => '/(is.)?(current.)?(revision|version(ing)?)/i', + 'export' => true, + ), + 'original_id' => array( + 'name' => 'original_id', + 'type' => 1, + 'title' => 'Original Activity ID ', + 'FKClassName' => 'CRM_Activity_DAO_Activity', + ), + 'weight' => array( + 'name' => 'weight', + 'type' => 1, + 'title' => 'Weight', + ), + 'id' => array( + 'name' => 'id', + 'type' => 1, + 'title' => 'Activity ID', + 'required' => true, + 'import' => true, + 'where' => 'civicrm_activity.id', + 'export' => true, + 'uniqueName' => 'activity_id', + 'api.aliases' => array( + '0' => 'activity_id', + ), + ), + 'subject' => array( + 'name' => 'subject', + 'type' => 2, + 'title' => 'Subject', + 'maxlength' => 255, + 'size' => 45, + 'import' => true, + 'where' => 'civicrm_activity.subject', + 'headerPattern' => '/(activity.)?subject/i', + 'export' => true, + 'uniqueName' => 'activity_subject', + ), + 'duration' => array( + 'name' => 'duration', + 'type' => 1, + 'title' => 'Duration', + 'import' => true, + 'where' => 'civicrm_activity.duration', + 'headerPattern' => '/(activity.)?duration(s)?$/i', + 'export' => true, + 'uniqueName' => 'activity_duration', + ), + 'location' => array( + 'name' => 'location', + 'type' => 2, + 'title' => 'Location', + 'maxlength' => 255, + 'size' => 45, + 'import' => true, + 'where' => 'civicrm_activity.location', + 'headerPattern' => '/(activity.)?location$/i', + 'export' => true, + 'uniqueName' => 'activity_location', + ), + 'details' => array( + 'name' => 'details', + 'type' => 32, + 'title' => 'Details', + 'rows' => 8, + 'cols' => 60, + 'import' => true, + 'where' => 'civicrm_activity.details', + 'headerPattern' => '/(activity.)?detail(s)?$/i', + 'export' => true, + 'uniqueName' => 'activity_details', + ), + 'status_id' => array( + 'name' => 'status_id', + 'type' => 1, + 'title' => 'Activity Status Id', + 'import' => true, + 'where' => 'civicrm_activity.status_id', + 'headerPattern' => '/(activity.)?status(.label$)?/i', + 'uniqueName' => 'activity_status_id', + ), + 'is_test' => array( + 'name' => 'is_test', + 'type' => 16, + 'title' => 'Test', + 'import' => true, + 'where' => 'civicrm_activity.is_test', + 'headerPattern' => '/(is.)?test(.activity)?/i', + 'export' => true, + 'uniqueName' => 'activity_is_test', + ), + 'medium_id' => array( + 'name' => 'medium_id', + 'type' => 1, + 'title' => 'Activity Medium', + 'default' => 'UL', + 'uniqueName' => 'activity_medium_id', + ), + 'result' => array( + 'name' => 'result', + 'type' => 2, + 'title' => 'Result', + 'maxlength' => 255, + 'size' => 45, + 'uniqueName' => 'activity_result', + ), + 'is_deleted' => array( + 'name' => 'is_deleted', + 'type' => 16, + 'title' => 'Activity is in the Trash', + 'import' => true, + 'where' => 'civicrm_activity.is_deleted', + 'headerPattern' => '/(activity.)?(trash|deleted)/i', + 'export' => true, + 'uniqueName' => 'activity_is_deleted', + ), + 'campaign_id' => array( + 'name' => 'campaign_id', + 'type' => 1, + 'title' => 'Campaign ID', + 'import' => true, + 'where' => 'civicrm_activity.campaign_id', + 'export' => true, + 'FKClassName' => 'CRM_Campaign_DAO_Campaign', + 'uniqueName' => 'activity_campaign_id', + ), + 'engagement_level' => array( + 'name' => 'engagement_level', + 'type' => 1, + 'title' => 'Engagement Index', + 'import' => true, + 'where' => 'civicrm_activity.engagement_level', + 'export' => true, + 'uniqueName' => 'activity_engagement_level', + ), + 'source_contact_id' => array( + 'api.default' => 'user_contact_id', + ), + 'assignee_contact_id' => array( + 'name' => 'assignee_id', + 'title' => 'assigned to', + 'type' => 1, + 'FKClassName' => 'CRM_Activity_DAO_ActivityAssignment', + ), + 'target_contact_id' => array( + 'name' => 'target_id', + 'title' => 'Activity Target', + 'type' => 1, + 'FKClassName' => 'CRM_Activity_DAO_ActivityTarget', + ), + 'activity_status_id' => array( + 'name' => 'status_id', + 'title' => 'Status Id', + 'type' => 1, + ), + ), +); + + return $expectedResult ; +} + + +/* +* This example has been generated from the API test suite. The test that created it is called +* +* testGetFields and can be found in +* http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ActivityTest.php +* +* You can see the outcome of the API tests at +* http://tests.dev.civicrm.org/trunk/results-api_v3 +* +* To Learn about the API read +* http://book.civicrm.org/developer/current/techniques/api/ +* +* and review the wiki at +* http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs +* +* Read more about testing here +* http://wiki.civicrm.org/confluence/display/CRM/Testing +* +* API Standards documentation: +* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards +*/ \ No newline at end of file diff --git a/api/v3/examples/GrantGet.php b/api/v3/examples/GrantGet.php index 407c38dd1d..e20f62ff0a 100644 --- a/api/v3/examples/GrantGet.php +++ b/api/v3/examples/GrantGet.php @@ -6,7 +6,7 @@ function grant_get_example(){ $params = array( 'version' => 3, - 'contact_id' => 4, + 'contact_id' => 3, 'application_received_date' => 'now', 'decision_date' => 'next Monday', 'amount_total' => '500', @@ -30,13 +30,13 @@ function grant_get_expectedresult(){ 'is_error' => 0, 'version' => 3, 'count' => 1, - 'id' => 2, + 'id' => 1, 'values' => array( - '2' => array( - 'id' => '2', - 'contact_id' => '4', - 'application_received_date' => '2013-02-04', - 'decision_date' => '2013-02-11', + '1' => array( + 'id' => '1', + 'contact_id' => '3', + 'application_received_date' => '2013-05-14', + 'decision_date' => '2013-05-20', 'grant_type_id' => '1', 'amount_total' => '500.00', 'currency' => 'USD', diff --git a/api/v3/utils.php b/api/v3/utils.php index af6a11e9e9..281d6128a3 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -42,9 +42,10 @@ * Initialize CiviCRM - should be run at the start of each API function */ function _civicrm_api3_initialize() { - require_once 'CRM/Core/Config.php'; - $config = CRM_Core_Config::singleton(); - } + require_once 'CRM/Core/ClassLoader.php'; + CRM_Core_ClassLoader::singleton()->register(); + CRM_Core_Config::singleton(); +} /** * Wrapper Function for civicrm_verify_mandatory to make it simple to pass either / or fields for checking @@ -189,14 +190,6 @@ function civicrm_api3_create_success($values = 1, $params = array( } //if ( array_key_exists ('debug',$params) && is_object ($dao)) { if (is_array($params) && array_key_exists('debug', $params)) { - if (!is_object($dao)) { - $d = _civicrm_api3_get_DAO(CRM_Utils_Array::value('entity', $params)); - if (!empty($d)) { - $file = str_replace('_', '/', $d) . ".php"; - require_once ($file); - $dao = new $d(); - } - } if (is_string($action) && $action != 'getfields') { $apiFields = civicrm_api($entity, 'getfields', array('version' => 3, 'action' => $action) + $params); } @@ -259,8 +252,6 @@ function _civicrm_api3_load_DAO($entity) { if (empty($dao)) { return FALSE; } - $file = str_replace('_', '/', $dao) . ".php"; - require_once ($file); $d = new $dao(); return $d; } @@ -915,8 +906,6 @@ function _civicrm_api3_api_check_permission($entity, $action, &$params, $throw = return TRUE; } - require_once 'CRM/Core/Permission.php'; - require_once 'CRM/Core/DAO/permissions.php'; $permissions = _civicrm_api3_permissions($entity, $action, $params); @@ -1033,8 +1022,6 @@ function _civicrm_api3_basic_delete($bao_name, &$params) { * */ function _civicrm_api3_custom_data_get(&$returnArray, $entity, $entity_id, $groupID = NULL, $subType = NULL, $subName = NULL) { - require_once 'CRM/Core/BAO/CustomGroup.php'; - require_once 'CRM/Core/BAO/CustomField.php'; $groupTree = &CRM_Core_BAO_CustomGroup::getTree($entity, CRM_Core_DAO::$_nullObject, $entity_id, @@ -1166,8 +1153,6 @@ function _civicrm_api3_validate_date(&$params, &$fieldname, &$fieldInfo) { * @param array $fieldinfo array of fields from getfields function */ function _civicrm_api3_validate_constraint(&$params, &$fieldname, &$fieldInfo) { - $file = str_replace('_', '/', $fieldInfo['FKClassName']) . ".php"; - require_once ($file); $dao = new $fieldInfo['FKClassName']; $dao->id = $params[$fieldname]; $dao->selectAdd(); @@ -1212,7 +1197,6 @@ function _civicrm_api3_validate_uniquekey(&$params, &$fieldname, &$fieldInfo) { */ function _civicrm_api3_generic_replace($entity, $params) { - require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); try { if (!is_array($params['values'])) { @@ -1287,8 +1271,6 @@ function _civicrm_api_get_fields($entity, $unique = FALSE, &$params = array( if (empty($dao)) { return array(); } - $file = str_replace('_', '/', $dao) . ".php"; - require_once ($file); $d = new $dao(); $fields = $d->fields(); // replace uniqueNames by the normal names as the key @@ -1322,7 +1304,6 @@ function _civicrm_api_get_fields($entity, $unique = FALSE, &$params = array( * fields are prefixed with 'custom_' to represent api params */ function _civicrm_api_get_custom_fields($entity, &$params) { - require_once 'CRM/Core/BAO/CustomField.php'; $customfields = array(); $entity = _civicrm_api_get_camel_name($entity); if (strtolower($entity) == 'contact') { -- 2.25.1