Esempio n. 1
0
 /**
  * Attempts to retrieve the API entity name from any calling class.
  *
  * @param string|object $classNameOrObject
  *
  * @return string
  * @throws CRM_Core_Exception
  */
 static function getEntityName($classNameOrObject)
 {
     require_once 'api/api.php';
     $className = is_string($classNameOrObject) ? $classNameOrObject : get_class($classNameOrObject);
     // First try the obvious replacements
     $daoName = str_replace(array('_BAO_', '_Form_', '_Page_'), '_DAO_', $className);
     $shortName = CRM_Core_DAO_AllCoreTables::getBriefName($daoName);
     // If that didn't work, try a different pattern
     if (!$shortName) {
         list(, $parent, , $child) = explode('_', $className);
         $daoName = "CRM_{$parent}_DAO_{$child}";
         $shortName = CRM_Core_DAO_AllCoreTables::getBriefName($daoName);
     }
     // If that didn't work, try a different pattern
     if (!$shortName) {
         $daoName = "CRM_{$parent}_DAO_{$parent}";
         $shortName = CRM_Core_DAO_AllCoreTables::getBriefName($daoName);
     }
     // If that didn't work, try a different pattern
     if (!$shortName) {
         $daoName = "CRM_Core_DAO_{$child}";
         $shortName = CRM_Core_DAO_AllCoreTables::getBriefName($daoName);
     }
     if (!$shortName) {
         throw new CRM_Core_Exception('Could not find api name for supplied class');
     }
     return _civicrm_api_get_entity_name_from_camel($shortName);
 }
Esempio n. 2
0
 /**
  * Get all DAO classes.
  */
 public function getAllDAO()
 {
     $classList = CRM_Core_DAO_AllCoreTables::getClasses();
     $return = array();
     foreach ($classList as $class) {
         $return[] = array($class);
     }
     return $return;
 }
 /**
  * Get all DAO classes.
  */
 public function getAllDAO()
 {
     $this->setUp();
     // Ugh. Need full bootstrap to enumerate classes.
     $classList = CRM_Core_DAO_AllCoreTables::getClasses();
     $return = array();
     foreach ($classList as $class) {
         $return[] = array($class);
     }
     return $return;
 }
Esempio n. 4
0
    /**
     * Create a query to find references to a particular record
     *
     * @param CRM_Core_DAO $targetDao the instance for which we want references
     * @return CRM_Core_DAO a query-handle (like the result of CRM_Core_DAO::executeQuery)
     */
    public function findReferences($targetDao)
    {
        $refColumn = $this->getReferenceKey();
        $targetColumn = $this->getTargetKey();
        $params = array(1 => array($targetDao->{$targetColumn}, 'String'), 2 => array($targetDao::getTableName(), 'String'));
        $sql = <<<EOS
SELECT id
FROM {$this->getReferenceTable()}
WHERE {$refColumn} = %1
AND {$this->getTypeColumn()} = %2
EOS;
        $daoName = CRM_Core_DAO_AllCoreTables::getClassForTable($this->getReferenceTable());
        $result = CRM_Core_DAO::executeQuery($sql, $params, TRUE, $daoName);
        return $result;
    }
Esempio n. 5
0
 private static function init($fresh = FALSE)
 {
     static $init = FALSE;
     if ($init && !$fresh) {
         return;
     }
     $entityTypes = array('CRM_Core_DAO_AddressFormat' => array('name' => 'AddressFormat', 'class' => 'CRM_Core_DAO_AddressFormat', 'table' => 'civicrm_address_format'), 'CRM_Core_DAO_Extension' => array('name' => 'Extension', 'class' => 'CRM_Core_DAO_Extension', 'table' => 'civicrm_extension'), 'CRM_Core_DAO_File' => array('name' => 'File', 'class' => 'CRM_Core_DAO_File', 'table' => 'civicrm_file'), 'CRM_Core_DAO_LocationType' => array('name' => 'LocationType', 'class' => 'CRM_Core_DAO_LocationType', 'table' => 'civicrm_location_type'), 'CRM_Core_DAO_MailSettings' => array('name' => 'MailSettings', 'class' => 'CRM_Core_DAO_MailSettings', 'table' => 'civicrm_mail_settings'), 'CRM_Core_DAO_Managed' => array('name' => 'Managed', 'class' => 'CRM_Core_DAO_Managed', 'table' => 'civicrm_managed'), 'CRM_Core_DAO_Mapping' => array('name' => 'Mapping', 'class' => 'CRM_Core_DAO_Mapping', 'table' => 'civicrm_mapping'), 'CRM_Core_DAO_OptionGroup' => array('name' => 'OptionGroup', 'class' => 'CRM_Core_DAO_OptionGroup', 'table' => 'civicrm_option_group'), 'CRM_Core_DAO_PreferencesDate' => array('name' => 'PreferencesDate', 'class' => 'CRM_Core_DAO_PreferencesDate', 'table' => 'civicrm_preferences_date'), 'CRM_Core_DAO_Worldregion' => array('name' => 'Worldregion', 'class' => 'CRM_Core_DAO_Worldregion', 'table' => 'civicrm_worldregion'), 'CRM_Core_DAO_Component' => array('name' => 'Component', 'class' => 'CRM_Core_DAO_Component', 'table' => 'civicrm_component'), 'CRM_Core_DAO_Persistent' => array('name' => 'Persistent', 'class' => 'CRM_Core_DAO_Persistent', 'table' => 'civicrm_persistent'), 'CRM_Core_DAO_PrevNextCache' => array('name' => 'PrevNextCache', 'class' => 'CRM_Core_DAO_PrevNextCache', 'table' => 'civicrm_prevnext_cache'), 'CRM_Core_DAO_ActionMapping' => array('name' => 'ActionMapping', 'class' => 'CRM_Core_DAO_ActionMapping', 'table' => 'civicrm_action_mapping'), 'CRM_ACL_DAO_ACL' => array('name' => 'ACL', 'class' => 'CRM_ACL_DAO_ACL', 'table' => 'civicrm_acl'), 'CRM_ACL_DAO_EntityRole' => array('name' => 'EntityRole', 'class' => 'CRM_ACL_DAO_EntityRole', 'table' => 'civicrm_acl_entity_role'), 'CRM_Contact_DAO_Contact' => array('name' => 'Contact', 'class' => 'CRM_Contact_DAO_Contact', 'table' => 'civicrm_contact'), 'CRM_Contact_DAO_ACLContactCache' => array('name' => 'ACLContactCache', 'class' => 'CRM_Contact_DAO_ACLContactCache', 'table' => 'civicrm_acl_contact_cache'), 'CRM_Contact_DAO_RelationshipType' => array('name' => 'RelationshipType', 'class' => 'CRM_Contact_DAO_RelationshipType', 'table' => 'civicrm_relationship_type'), 'CRM_Contact_DAO_SavedSearch' => array('name' => 'SavedSearch', 'class' => 'CRM_Contact_DAO_SavedSearch', 'table' => 'civicrm_saved_search'), 'CRM_Contact_DAO_ContactType' => array('name' => 'ContactType', 'class' => 'CRM_Contact_DAO_ContactType', 'table' => 'civicrm_contact_type'), 'CRM_Batch_DAO_Batch' => array('name' => 'Batch', 'class' => 'CRM_Batch_DAO_Batch', 'table' => 'civicrm_batch'), 'CRM_Batch_DAO_EntityBatch' => array('name' => 'EntityBatch', 'class' => 'CRM_Batch_DAO_EntityBatch', 'table' => 'civicrm_entity_batch'), 'CRM_Mailing_DAO_Component' => array('name' => 'Component', 'class' => 'CRM_Mailing_DAO_Component', 'table' => 'civicrm_mailing_component'), 'CRM_Mailing_DAO_BounceType' => array('name' => 'BounceType', 'class' => 'CRM_Mailing_DAO_BounceType', 'table' => 'civicrm_mailing_bounce_type'), 'CRM_Mailing_DAO_BouncePattern' => array('name' => 'BouncePattern', 'class' => 'CRM_Mailing_DAO_BouncePattern', 'table' => 'civicrm_mailing_bounce_pattern'), 'CRM_Contribute_DAO_Premium' => array('name' => 'Premium', 'class' => 'CRM_Contribute_DAO_Premium', 'table' => 'civicrm_premiums'), 'CRM_Financial_DAO_Currency' => array('name' => 'Currency', 'class' => 'CRM_Financial_DAO_Currency', 'table' => 'civicrm_currency'), 'CRM_Financial_DAO_FinancialAccount' => array('name' => 'FinancialAccount', 'class' => 'CRM_Financial_DAO_FinancialAccount', 'table' => 'civicrm_financial_account'), 'CRM_Financial_DAO_PaymentProcessorType' => array('name' => 'PaymentProcessorType', 'class' => 'CRM_Financial_DAO_PaymentProcessorType', 'table' => 'civicrm_payment_processor_type'), 'CRM_Financial_DAO_FinancialType' => array('name' => 'FinancialType', 'class' => 'CRM_Financial_DAO_FinancialType', 'table' => 'civicrm_financial_type'), 'CRM_Financial_DAO_EntityFinancialAccount' => array('name' => 'EntityFinancialAccount', 'class' => 'CRM_Financial_DAO_EntityFinancialAccount', 'table' => 'civicrm_entity_financial_account'), 'CRM_Financial_DAO_FinancialItem' => array('name' => 'FinancialItem', 'class' => 'CRM_Financial_DAO_FinancialItem', 'table' => 'civicrm_financial_item'), 'CRM_SMS_DAO_Provider' => array('name' => 'Provider', 'class' => 'CRM_SMS_DAO_Provider', 'table' => 'civicrm_sms_provider'), 'CRM_Member_DAO_MembershipStatus' => array('name' => 'MembershipStatus', 'class' => 'CRM_Member_DAO_MembershipStatus', 'table' => 'civicrm_membership_status'), 'CRM_Campaign_DAO_Campaign' => array('name' => 'Campaign', 'class' => 'CRM_Campaign_DAO_Campaign', 'table' => 'civicrm_campaign'), 'CRM_Campaign_DAO_CampaignGroup' => array('name' => 'CampaignGroup', 'class' => 'CRM_Campaign_DAO_CampaignGroup', 'table' => 'civicrm_campaign_group'), 'CRM_Campaign_DAO_Survey' => array('name' => 'Survey', 'class' => 'CRM_Campaign_DAO_Survey', 'table' => 'civicrm_survey'), 'CRM_Event_DAO_ParticipantStatusType' => array('name' => 'ParticipantStatusType', 'class' => 'CRM_Event_DAO_ParticipantStatusType', 'table' => 'civicrm_participant_status_type'), 'CRM_Event_Cart_DAO_Cart' => array('name' => 'Cart', 'class' => 'CRM_Event_Cart_DAO_Cart', 'table' => 'civicrm_event_carts'), 'CRM_Dedupe_DAO_RuleGroup' => array('name' => 'RuleGroup', 'class' => 'CRM_Dedupe_DAO_RuleGroup', 'table' => 'civicrm_dedupe_rule_group'), 'CRM_Dedupe_DAO_Rule' => array('name' => 'Rule', 'class' => 'CRM_Dedupe_DAO_Rule', 'table' => 'civicrm_dedupe_rule'), 'CRM_Dedupe_DAO_Exception' => array('name' => 'Exception', 'class' => 'CRM_Dedupe_DAO_Exception', 'table' => 'civicrm_dedupe_exception'), 'CRM_Case_DAO_Case' => array('name' => 'Case', 'class' => 'CRM_Case_DAO_Case', 'table' => 'civicrm_case'), 'CRM_Case_DAO_CaseContact' => array('name' => 'CaseContact', 'class' => 'CRM_Case_DAO_CaseContact', 'table' => 'civicrm_case_contact'), 'CRM_Grant_DAO_Grant' => array('name' => 'Grant', 'class' => 'CRM_Grant_DAO_Grant', 'table' => 'civicrm_grant'), 'CRM_Friend_DAO_Friend' => array('name' => 'Friend', 'class' => 'CRM_Friend_DAO_Friend', 'table' => 'civicrm_tell_friend'), 'CRM_Pledge_DAO_PledgeBlock' => array('name' => 'PledgeBlock', 'class' => 'CRM_Pledge_DAO_PledgeBlock', 'table' => 'civicrm_pledge_block'), 'CRM_Queue_DAO_QueueItem' => array('name' => 'QueueItem', 'class' => 'CRM_Queue_DAO_QueueItem', 'table' => 'civicrm_queue_item'), 'CRM_PCP_DAO_PCP' => array('name' => 'PCP', 'class' => 'CRM_PCP_DAO_PCP', 'table' => 'civicrm_pcp'), 'CRM_Core_DAO_Cache' => array('name' => 'Cache', 'class' => 'CRM_Core_DAO_Cache', 'table' => 'civicrm_cache'), 'CRM_Core_DAO_Country' => array('name' => 'Country', 'class' => 'CRM_Core_DAO_Country', 'table' => 'civicrm_country'), 'CRM_Core_DAO_CustomGroup' => array('name' => 'CustomGroup', 'class' => 'CRM_Core_DAO_CustomGroup', 'table' => 'civicrm_custom_group'), 'CRM_Core_DAO_CustomField' => array('name' => 'CustomField', 'class' => 'CRM_Core_DAO_CustomField', 'table' => 'civicrm_custom_field'), 'CRM_Core_DAO_Domain' => array('name' => 'Domain', 'class' => 'CRM_Core_DAO_Domain', 'table' => 'civicrm_domain'), 'CRM_Core_DAO_Email' => array('name' => 'Email', 'class' => 'CRM_Core_DAO_Email', 'table' => 'civicrm_email'), 'CRM_Core_DAO_EntityFile' => array('name' => 'EntityFile', 'class' => 'CRM_Core_DAO_EntityFile', 'table' => 'civicrm_entity_file'), 'CRM_Core_DAO_IM' => array('name' => 'IM', 'class' => 'CRM_Core_DAO_IM', 'table' => 'civicrm_im'), 'CRM_Core_DAO_Job' => array('name' => 'Job', 'class' => 'CRM_Core_DAO_Job', 'table' => 'civicrm_job'), 'CRM_Core_DAO_JobLog' => array('name' => 'JobLog', 'class' => 'CRM_Core_DAO_JobLog', 'table' => 'civicrm_job_log'), 'CRM_Core_DAO_Log' => array('name' => 'Log', 'class' => 'CRM_Core_DAO_Log', 'table' => 'civicrm_log'), 'CRM_Core_DAO_MappingField' => array('name' => 'MappingField', 'class' => 'CRM_Core_DAO_MappingField', 'table' => 'civicrm_mapping_field'), 'CRM_Core_DAO_Menu' => array('name' => 'Menu', 'class' => 'CRM_Core_DAO_Menu', 'table' => 'civicrm_menu'), 'CRM_Core_DAO_Navigation' => array('name' => 'Navigation', 'class' => 'CRM_Core_DAO_Navigation', 'table' => 'civicrm_navigation'), 'CRM_Core_DAO_Note' => array('name' => 'Note', 'class' => 'CRM_Core_DAO_Note', 'table' => 'civicrm_note'), 'CRM_Core_DAO_OptionValue' => array('name' => 'OptionValue', 'class' => 'CRM_Core_DAO_OptionValue', 'table' => 'civicrm_option_value'), 'CRM_Core_DAO_Phone' => array('name' => 'Phone', 'class' => 'CRM_Core_DAO_Phone', 'table' => 'civicrm_phone'), 'CRM_Core_DAO_StateProvince' => array('name' => 'StateProvince', 'class' => 'CRM_Core_DAO_StateProvince', 'table' => 'civicrm_state_province'), 'CRM_Core_DAO_Tag' => array('name' => 'Tag', 'class' => 'CRM_Core_DAO_Tag', 'table' => 'civicrm_tag'), 'CRM_Core_DAO_UFMatch' => array('name' => 'UFMatch', 'class' => 'CRM_Core_DAO_UFMatch', 'table' => 'civicrm_uf_match'), 'CRM_Core_DAO_Timezone' => array('name' => 'Timezone', 'class' => 'CRM_Core_DAO_Timezone', 'table' => 'civicrm_timezone'), 'CRM_Core_DAO_OpenID' => array('name' => 'OpenID', 'class' => 'CRM_Core_DAO_OpenID', 'table' => 'civicrm_openid'), 'CRM_Core_DAO_Website' => array('name' => 'Website', 'class' => 'CRM_Core_DAO_Website', 'table' => 'civicrm_website'), 'CRM_Core_DAO_Setting' => array('name' => 'Setting', 'class' => 'CRM_Core_DAO_Setting', 'table' => 'civicrm_setting'), 'CRM_Core_DAO_PrintLabel' => array('name' => 'PrintLabel', 'class' => 'CRM_Core_DAO_PrintLabel', 'table' => 'civicrm_print_label'), 'CRM_Core_DAO_WordReplacement' => array('name' => 'WordReplacement', 'class' => 'CRM_Core_DAO_WordReplacement', 'table' => 'civicrm_word_replacement'), 'CRM_ACL_DAO_Cache' => array('name' => 'Cache', 'class' => 'CRM_ACL_DAO_Cache', 'table' => 'civicrm_acl_cache'), 'CRM_Contact_DAO_Group' => array('name' => 'Group', 'class' => 'CRM_Contact_DAO_Group', 'table' => 'civicrm_group'), 'CRM_Contact_DAO_SubscriptionHistory' => array('name' => 'SubscriptionHistory', 'class' => 'CRM_Contact_DAO_SubscriptionHistory', 'table' => 'civicrm_subscription_history'), 'CRM_Contact_DAO_GroupContactCache' => array('name' => 'GroupContactCache', 'class' => 'CRM_Contact_DAO_GroupContactCache', 'table' => 'civicrm_group_contact_cache'), 'CRM_Contact_DAO_GroupNesting' => array('name' => 'GroupNesting', 'class' => 'CRM_Contact_DAO_GroupNesting', 'table' => 'civicrm_group_nesting'), 'CRM_Contact_DAO_GroupOrganization' => array('name' => 'GroupOrganization', 'class' => 'CRM_Contact_DAO_GroupOrganization', 'table' => 'civicrm_group_organization'), 'CRM_Contact_DAO_Relationship' => array('name' => 'Relationship', 'class' => 'CRM_Contact_DAO_Relationship', 'table' => 'civicrm_relationship'), 'CRM_Mailing_Event_DAO_Subscribe' => array('name' => 'Subscribe', 'class' => 'CRM_Mailing_Event_DAO_Subscribe', 'table' => 'civicrm_mailing_event_subscribe'), 'CRM_Mailing_Event_DAO_Confirm' => array('name' => 'Confirm', 'class' => 'CRM_Mailing_Event_DAO_Confirm', 'table' => 'civicrm_mailing_event_confirm'), 'CRM_Contribute_DAO_ContributionPage' => array('name' => 'ContributionPage', 'class' => 'CRM_Contribute_DAO_ContributionPage', 'table' => 'civicrm_contribution_page'), 'CRM_Contribute_DAO_Product' => array('name' => 'Product', 'class' => 'CRM_Contribute_DAO_Product', 'table' => 'civicrm_product'), 'CRM_Contribute_DAO_PremiumsProduct' => array('name' => 'PremiumsProduct', 'class' => 'CRM_Contribute_DAO_PremiumsProduct', 'table' => 'civicrm_premiums_product'), 'CRM_Contribute_DAO_Widget' => array('name' => 'Widget', 'class' => 'CRM_Contribute_DAO_Widget', 'table' => 'civicrm_contribution_widget'), 'CRM_Financial_DAO_PaymentProcessor' => array('name' => 'PaymentProcessor', 'class' => 'CRM_Financial_DAO_PaymentProcessor', 'table' => 'civicrm_payment_processor'), 'CRM_Member_DAO_MembershipType' => array('name' => 'MembershipType', 'class' => 'CRM_Member_DAO_MembershipType', 'table' => 'civicrm_membership_type'), 'CRM_Member_DAO_MembershipBlock' => array('name' => 'MembershipBlock', 'class' => 'CRM_Member_DAO_MembershipBlock', 'table' => 'civicrm_membership_block'), 'CRM_Activity_DAO_Activity' => array('name' => 'Activity', 'class' => 'CRM_Activity_DAO_Activity', 'table' => 'civicrm_activity'), 'CRM_Activity_DAO_ActivityContact' => array('name' => 'ActivityContact', 'class' => 'CRM_Activity_DAO_ActivityContact', 'table' => 'civicrm_activity_contact'), 'CRM_Case_DAO_CaseActivity' => array('name' => 'CaseActivity', 'class' => 'CRM_Case_DAO_CaseActivity', 'table' => 'civicrm_case_activity'), 'CRM_Pledge_DAO_Pledge' => array('name' => 'Pledge', 'class' => 'CRM_Pledge_DAO_Pledge', 'table' => 'civicrm_pledge'), 'CRM_Report_DAO_ReportInstance' => array('name' => 'ReportInstance', 'class' => 'CRM_Report_DAO_ReportInstance', 'table' => 'civicrm_report_instance'), 'CRM_Price_DAO_PriceSet' => array('name' => 'PriceSet', 'class' => 'CRM_Price_DAO_PriceSet', 'table' => 'civicrm_price_set'), 'CRM_Price_DAO_PriceSetEntity' => array('name' => 'PriceSetEntity', 'class' => 'CRM_Price_DAO_PriceSetEntity', 'table' => 'civicrm_price_set_entity'), 'CRM_Core_DAO_County' => array('name' => 'County', 'class' => 'CRM_Core_DAO_County', 'table' => 'civicrm_county'), 'CRM_Core_DAO_Dashboard' => array('name' => 'Dashboard', 'class' => 'CRM_Core_DAO_Dashboard', 'table' => 'civicrm_dashboard'), 'CRM_Core_DAO_Discount' => array('name' => 'Discount', 'class' => 'CRM_Core_DAO_Discount', 'table' => 'civicrm_discount'), 'CRM_Core_DAO_EntityTag' => array('name' => 'EntityTag', 'class' => 'CRM_Core_DAO_EntityTag', 'table' => 'civicrm_entity_tag'), 'CRM_Core_DAO_MessageTemplate' => array('name' => 'MessageTemplate', 'class' => 'CRM_Core_DAO_MessageTemplate', 'table' => 'civicrm_msg_template'), 'CRM_Core_DAO_UFGroup' => array('name' => 'UFGroup', 'class' => 'CRM_Core_DAO_UFGroup', 'table' => 'civicrm_uf_group'), 'CRM_Core_DAO_UFField' => array('name' => 'UFField', 'class' => 'CRM_Core_DAO_UFField', 'table' => 'civicrm_uf_field'), 'CRM_Core_DAO_UFJoin' => array('name' => 'UFJoin', 'class' => 'CRM_Core_DAO_UFJoin', 'table' => 'civicrm_uf_join'), 'CRM_Core_DAO_ActionSchedule' => array('name' => 'ActionSchedule', 'class' => 'CRM_Core_DAO_ActionSchedule', 'table' => 'civicrm_action_schedule'), 'CRM_Core_DAO_ActionLog' => array('name' => 'ActionLog', 'class' => 'CRM_Core_DAO_ActionLog', 'table' => 'civicrm_action_log'), 'CRM_Contact_DAO_DashboardContact' => array('name' => 'DashboardContact', 'class' => 'CRM_Contact_DAO_DashboardContact', 'table' => 'civicrm_dashboard_contact'), 'CRM_Mailing_DAO_Mailing' => array('name' => 'Mailing', 'class' => 'CRM_Mailing_DAO_Mailing', 'table' => 'civicrm_mailing'), 'CRM_Mailing_DAO_MailingGroup' => array('name' => 'MailingGroup', 'class' => 'CRM_Mailing_DAO_MailingGroup', 'table' => 'civicrm_mailing_group'), 'CRM_Mailing_DAO_TrackableURL' => array('name' => 'TrackableURL', 'class' => 'CRM_Mailing_DAO_TrackableURL', 'table' => 'civicrm_mailing_trackable_url'), 'CRM_Mailing_DAO_MailingJob' => array('name' => 'MailingJob', 'class' => 'CRM_Mailing_DAO_MailingJob', 'table' => 'civicrm_mailing_job'), 'CRM_Mailing_DAO_Recipients' => array('name' => 'Recipients', 'class' => 'CRM_Mailing_DAO_Recipients', 'table' => 'civicrm_mailing_recipients'), 'CRM_Mailing_DAO_Spool' => array('name' => 'Spool', 'class' => 'CRM_Mailing_DAO_Spool', 'table' => 'civicrm_mailing_spool'), 'CRM_Mailing_Event_DAO_Queue' => array('name' => 'Queue', 'class' => 'CRM_Mailing_Event_DAO_Queue', 'table' => 'civicrm_mailing_event_queue'), 'CRM_Mailing_Event_DAO_Bounce' => array('name' => 'Bounce', 'class' => 'CRM_Mailing_Event_DAO_Bounce', 'table' => 'civicrm_mailing_event_bounce'), 'CRM_Mailing_Event_DAO_Delivered' => array('name' => 'Delivered', 'class' => 'CRM_Mailing_Event_DAO_Delivered', 'table' => 'civicrm_mailing_event_delivered'), 'CRM_Mailing_Event_DAO_Forward' => array('name' => 'Forward', 'class' => 'CRM_Mailing_Event_DAO_Forward', 'table' => 'civicrm_mailing_event_forward'), 'CRM_Mailing_Event_DAO_Opened' => array('name' => 'Opened', 'class' => 'CRM_Mailing_Event_DAO_Opened', 'table' => 'civicrm_mailing_event_opened'), 'CRM_Mailing_Event_DAO_Reply' => array('name' => 'Reply', 'class' => 'CRM_Mailing_Event_DAO_Reply', 'table' => 'civicrm_mailing_event_reply'), 'CRM_Mailing_Event_DAO_TrackableURLOpen' => array('name' => 'TrackableURLOpen', 'class' => 'CRM_Mailing_Event_DAO_TrackableURLOpen', 'table' => 'civicrm_mailing_event_trackable_url_open'), 'CRM_Mailing_Event_DAO_Unsubscribe' => array('name' => 'Unsubscribe', 'class' => 'CRM_Mailing_Event_DAO_Unsubscribe', 'table' => 'civicrm_mailing_event_unsubscribe'), 'CRM_Contribute_DAO_ContributionRecur' => array('name' => 'ContributionRecur', 'class' => 'CRM_Contribute_DAO_ContributionRecur', 'table' => 'civicrm_contribution_recur'), 'CRM_Financial_DAO_FinancialTrxn' => array('name' => 'FinancialTrxn', 'class' => 'CRM_Financial_DAO_FinancialTrxn', 'table' => 'civicrm_financial_trxn'), 'CRM_Member_DAO_Membership' => array('name' => 'Membership', 'class' => 'CRM_Member_DAO_Membership', 'table' => 'civicrm_membership'), 'CRM_Member_DAO_MembershipLog' => array('name' => 'MembershipLog', 'class' => 'CRM_Member_DAO_MembershipLog', 'table' => 'civicrm_membership_log'), 'CRM_Price_DAO_PriceField' => array('name' => 'PriceField', 'class' => 'CRM_Price_DAO_PriceField', 'table' => 'civicrm_price_field'), 'CRM_Price_DAO_PriceFieldValue' => array('name' => 'PriceFieldValue', 'class' => 'CRM_Price_DAO_PriceFieldValue', 'table' => 'civicrm_price_field_value'), 'CRM_Price_DAO_LineItem' => array('name' => 'LineItem', 'class' => 'CRM_Price_DAO_LineItem', 'table' => 'civicrm_line_item'), 'CRM_PCP_DAO_PCPBlock' => array('name' => 'PCPBlock', 'class' => 'CRM_PCP_DAO_PCPBlock', 'table' => 'civicrm_pcp_block'), 'CRM_Core_DAO_Address' => array('name' => 'Address', 'class' => 'CRM_Core_DAO_Address', 'table' => 'civicrm_address'), 'CRM_Core_DAO_LocBlock' => array('name' => 'LocBlock', 'class' => 'CRM_Core_DAO_LocBlock', 'table' => 'civicrm_loc_block'), 'CRM_Contact_DAO_GroupContact' => array('name' => 'GroupContact', 'class' => 'CRM_Contact_DAO_GroupContact', 'table' => 'civicrm_group_contact'), 'CRM_Contribute_DAO_Contribution' => array('name' => 'Contribution', 'class' => 'CRM_Contribute_DAO_Contribution', 'table' => 'civicrm_contribution'), 'CRM_Contribute_DAO_ContributionProduct' => array('name' => 'ContributionProduct', 'class' => 'CRM_Contribute_DAO_ContributionProduct', 'table' => 'civicrm_contribution_product'), 'CRM_Contribute_DAO_ContributionSoft' => array('name' => 'ContributionSoft', 'class' => 'CRM_Contribute_DAO_ContributionSoft', 'table' => 'civicrm_contribution_soft'), 'CRM_Financial_DAO_EntityFinancialTrxn' => array('name' => 'EntityFinancialTrxn', 'class' => 'CRM_Financial_DAO_EntityFinancialTrxn', 'table' => 'civicrm_entity_financial_trxn'), 'CRM_Member_DAO_MembershipPayment' => array('name' => 'MembershipPayment', 'class' => 'CRM_Member_DAO_MembershipPayment', 'table' => 'civicrm_membership_payment'), 'CRM_Event_DAO_Event' => array('name' => 'Event', 'class' => 'CRM_Event_DAO_Event', 'table' => 'civicrm_event'), 'CRM_Event_DAO_Participant' => array('name' => 'Participant', 'class' => 'CRM_Event_DAO_Participant', 'table' => 'civicrm_participant'), 'CRM_Event_DAO_ParticipantPayment' => array('name' => 'ParticipantPayment', 'class' => 'CRM_Event_DAO_ParticipantPayment', 'table' => 'civicrm_participant_payment'), 'CRM_Event_Cart_DAO_EventInCart' => array('name' => 'EventInCart', 'class' => 'CRM_Event_Cart_DAO_EventInCart', 'table' => 'civicrm_events_in_carts'), 'CRM_Pledge_DAO_PledgePayment' => array('name' => 'PledgePayment', 'class' => 'CRM_Pledge_DAO_PledgePayment', 'table' => 'civicrm_pledge_payment'));
     CRM_Utils_Hook::entityTypes($entityTypes);
     self::$tables = array();
     self::$daoToClass = array();
     foreach ($entityTypes as $entityType) {
         self::registerEntityType($entityType['name'], $entityType['class'], $entityType['table']);
     }
     $init = TRUE;
 }
Esempio n. 6
0
 public static function init($fresh = FALSE)
 {
     static $init = FALSE;
     if ($init && !$fresh) {
         return;
     }
     Civi::$statics[__CLASS__] = array();
     $file = preg_replace('/\\.php$/', '.data.php', __FILE__);
     $entityTypes = (require $file);
     CRM_Utils_Hook::entityTypes($entityTypes);
     self::$entityTypes = array();
     self::$tables = array();
     self::$daoToClass = array();
     foreach ($entityTypes as $entityType) {
         self::registerEntityType($entityType['name'], $entityType['class'], $entityType['table'], isset($entityType['fields_callback']) ? $entityType['fields_callback'] : NULL, isset($entityType['links_callback']) ? $entityType['links_callback'] : NULL);
     }
     $init = TRUE;
 }
Esempio n. 7
0
File: Api.php Progetto: kidaa30/yes
 /**
  * Attempts to retrieve the API entity name from any calling class.
  * FIXME: This is a bit hackish but the naming convention for forms is not very strict
  *
  * @param string|object $classNameOrObject
  *
  * @return string
  * @throws CRM_Core_Exception
  */
 public static function getEntityName($classNameOrObject)
 {
     require_once 'api/api.php';
     $className = is_string($classNameOrObject) ? $classNameOrObject : get_class($classNameOrObject);
     // First try the obvious replacements
     $daoName = str_replace(array('_BAO_', '_Form_', '_Page_'), '_DAO_', $className);
     $entityName = CRM_Core_DAO_AllCoreTables::getBriefName($daoName);
     // If that didn't work, try a different pattern
     if (!$entityName) {
         list(, $parent, , $child) = explode('_', $className);
         $daoName = "CRM_{$parent}_DAO_{$child}";
         $entityName = CRM_Core_DAO_AllCoreTables::getBriefName($daoName);
     }
     // If that didn't work, try a different pattern
     if (!$entityName) {
         $daoName = "CRM_{$parent}_DAO_{$parent}";
         $entityName = CRM_Core_DAO_AllCoreTables::getBriefName($daoName);
     }
     // If that didn't work, try a different pattern
     if (!$entityName) {
         $daoName = "CRM_Core_DAO_{$child}";
         $entityName = CRM_Core_DAO_AllCoreTables::getBriefName($daoName);
     }
     // If that didn't work, try using just the trailing name
     if (!$entityName) {
         $entityName = CRM_Core_DAO_AllCoreTables::getFullName($child) ? $child : NULL;
     }
     // If that didn't work, try using just the leading name
     if (!$entityName) {
         $entityName = CRM_Core_DAO_AllCoreTables::getFullName($parent) ? $parent : NULL;
     }
     if (!$entityName) {
         throw new CRM_Core_Exception('Could not find api name for supplied class');
     }
     return $entityName;
 }
 /**
  * Returns the list of fields that can be exported
  *
  * @param bool $prefix
  *
  * @return array
  */
 static function &export($prefix = false)
 {
     $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'participant_payment', $prefix, array());
     return $r;
 }
Esempio n. 9
0
/**
 * Having a DAO object find the entity name
 * @param object $bao DAO being passed in
 * @return string
 */
function _civicrm_api_get_entity_name_from_dao($bao)
{
    $daoName = str_replace("BAO", "DAO", get_class($bao));
    return _civicrm_api_get_entity_name_from_camel(CRM_Core_DAO_AllCoreTables::getBriefName($daoName));
}
Esempio n. 10
0
 /**
  * Returns the list of fields that can be exported
  *
  * @param bool $prefix
  *
  * @return array
  */
 static function &export($prefix = false)
 {
     $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'financial_type', $prefix, array());
     return $r;
 }
Esempio n. 11
0
 /**
  * Returns the list of fields that can be exported
  *
  * @param bool $prefix
  *
  * @return array
  */
 static function &export($prefix = false)
 {
     $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'word_replacement', $prefix, array());
     return $r;
 }
Esempio n. 12
0
/**
 * API to determine if a record is in-use.
 *
 * @param array $apiRequest
 *   Api request as an array.
 *
 * @throws API_Exception
 * @return array
 *   API result (int 0 or 1)
 */
function civicrm_api3_generic_getrefcount($apiRequest)
{
    $entityToClassMap = CRM_Core_DAO_AllCoreTables::daoToClass();
    if (!isset($entityToClassMap[$apiRequest['entity']])) {
        throw new API_Exception("The entity '{$apiRequest['entity']}' is unknown or unsupported by 'getrefcount'. Consider implementing this API.", 'getrefcount_unsupported');
    }
    $daoClass = $entityToClassMap[$apiRequest['entity']];
    /* @var $dao CRM_Core_DAO */
    $dao = new $daoClass();
    $dao->id = $apiRequest['params']['id'];
    if ($dao->find(TRUE)) {
        return civicrm_api3_create_success($dao->getReferenceCounts());
    } else {
        return civicrm_api3_create_success(array());
    }
}
Esempio n. 13
0
 protected function tearDown()
 {
     CRM_Utils_Hook::singleton()->reset();
     CRM_Core_DAO_AllCoreTables::init(1);
     parent::tearDown();
 }
Esempio n. 14
0
 static function rebuildMenuAndCaches($triggerRebuild = FALSE, $sessionReset = FALSE)
 {
     $config = CRM_Core_Config::singleton();
     $config->clearModuleList();
     // also cleanup all caches
     $config->cleanupCaches($sessionReset || CRM_Utils_Request::retrieve('sessionReset', 'Boolean', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET'));
     CRM_Core_Menu::store();
     // also reset navigation
     CRM_Core_BAO_Navigation::resetNavigation();
     // also cleanup module permissions
     $config->cleanupPermissions();
     // also rebuild word replacement cache
     CRM_Core_BAO_WordReplacement::rebuild();
     CRM_Core_BAO_Setting::updateSettingsFromMetaData();
     CRM_Core_Resources::singleton()->resetCacheCode();
     // also rebuild triggers if requested explicitly
     if ($triggerRebuild || CRM_Utils_Request::retrieve('triggerRebuild', 'Boolean', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET')) {
         CRM_Core_DAO::triggerRebuild();
     }
     CRM_Core_DAO_AllCoreTables::reinitializeCache(TRUE);
     CRM_Core_ManagedEntities::singleton(TRUE)->reconcile();
 }
Esempio n. 15
0
 /**
  * List all tables which have hard foreign keys to this table.
  *
  * For now, this returns a description of every entity_id/entity_table
  * reference.
  * TODO: filter dynamic entity references on the $tableName, based on
  * schema metadata in dynamicForeignKey which enumerates a restricted
  * set of possible entity_table's.
  *
  * @param string $tableName table referred to
  *
  * @return array structure of table and column, listing every table with a
  * foreign key reference to $tableName, and the column where the key appears.
  */
 static function getReferencesToTable($tableName)
 {
     $refsFound = array();
     foreach (CRM_Core_DAO_AllCoreTables::getClasses() as $daoClassName) {
         $links = $daoClassName::getReferenceColumns();
         $daoTableName = $daoClassName::getTableName();
         foreach ($links as $refSpec) {
             if ($refSpec->getTargetTable() === $tableName or $refSpec->isGeneric()) {
                 $refsFound[] = $refSpec;
             }
         }
     }
     return $refsFound;
 }
Esempio n. 16
0
 /**
  * Returns the list of fields that can be exported
  *
  * @param bool $prefix
  *
  * @return array
  */
 static function &export($prefix = false)
 {
     $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'recurring_entity', $prefix, array());
     return $r;
 }
 /**
  * @param $entityTable
  */
 public static function preProcess($entityTable)
 {
     self::$_entityId = (int) CRM_Utils_Request::retrieve('id', 'Positive');
     self::$_entityTable = $entityTable;
     if (self::$_entityId && $entityTable) {
         $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor(self::$_entityId, $entityTable);
         if ($checkParentExistsForThisId) {
             self::$_hasParent = TRUE;
             self::$_parentEntityId = $checkParentExistsForThisId;
             self::$_scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId($checkParentExistsForThisId, $entityTable);
         } else {
             self::$_parentEntityId = self::$_entityId;
             self::$_scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId(self::$_entityId, $entityTable);
         }
         if (property_exists(self::$_scheduleReminderDetails, 'id')) {
             self::$_scheduleReminderID = self::$_scheduleReminderDetails->id;
         }
     }
     CRM_Core_OptionValue::getValues(array('name' => $entityTable . '_repeat_exclude_dates_' . self::$_parentEntityId), $optionValue);
     $excludeOptionValues = array();
     if (!empty($optionValue)) {
         foreach ($optionValue as $key => $val) {
             $excludeOptionValues[$val['value']] = substr(CRM_Utils_Date::mysqlToIso($val['value']), 0, 10);
         }
         self::$_excludeDateInfo = $excludeOptionValues;
     }
     // Assign variables
     $entityType = CRM_Core_DAO_AllCoreTables::getBriefName(CRM_Core_DAO_AllCoreTables::getClassForTable($entityTable));
     $tpl = CRM_Core_Smarty::singleton();
     $tpl->assign('recurringEntityType', ts($entityType));
     $tpl->assign('currentEntityId', self::$_entityId);
     $tpl->assign('entityTable', self::$_entityTable);
     $tpl->assign('scheduleReminderId', self::$_scheduleReminderID);
     $tpl->assign('hasParent', self::$_hasParent);
 }
Esempio n. 18
0
 /**
  * List all tables which have hard foreign keys to this table.
  *
  * For now, this returns a description of every entity_id/entity_table
  * reference.
  * TODO: filter dynamic entity references on the $tableName, based on
  * schema metadata in dynamicForeignKey which enumerates a restricted
  * set of possible entity_table's.
  *
  * @param string $tableName
  *   Table referred to.
  *
  * @return array
  *   structure of table and column, listing every table with a
  *   foreign key reference to $tableName, and the column where the key appears.
  */
 public static function getReferencesToTable($tableName)
 {
     $refsFound = array();
     foreach (CRM_Core_DAO_AllCoreTables::getClasses() as $daoClassName) {
         $links = $daoClassName::getReferenceColumns();
         $daoTableName = $daoClassName::getTableName();
         foreach ($links as $refSpec) {
             /** @var $refSpec CRM_Core_Reference_Interface */
             if ($refSpec->matchesTargetTable($tableName)) {
                 $refsFound[] = $refSpec;
             }
         }
     }
     return $refsFound;
 }
Esempio n. 19
0
 /**
  * Joins onto an fk field
  *
  * Adds one or more joins to the query to make this field available for use in a clause.
  *
  * Enforces permissions at the api level and by appending the acl clause for that entity to the join.
  *
  * @param $fkFieldName
  * @return array|null
  *   Returns the table and field name for adding this field to a SELECT or WHERE clause
  * @throws \API_Exception
  * @throws \Civi\API\Exception\UnauthorizedException
  */
 private function addFkField($fkFieldName)
 {
     $stack = explode('.', $fkFieldName);
     if (count($stack) < 2) {
         return NULL;
     }
     $prev = 'a';
     foreach ($stack as $depth => $fieldName) {
         // Setup variables then skip the first level
         if (!$depth) {
             $fk = $fieldName;
             // We only join on core fields
             // @TODO: Custom contact ref fields could be supported too
             if (!in_array($fk, $this->entityFieldNames)) {
                 return NULL;
             }
             $fkField =& $this->apiFieldSpec[$fk];
             continue;
         }
         // More than 4 joins deep seems excessive - DOS attack?
         if ($depth > self::MAX_JOINS) {
             throw new UnauthorizedException("Maximum number of joins exceeded for api.{$this->entity}.get in parameter {$fkFieldName}");
         }
         if (!isset($fkField['FKApiName']) && !isset($fkField['FKClassName'])) {
             // Join doesn't exist - might be another param with a dot in it for some reason, we'll just ignore it.
             return NULL;
         }
         // Ensure we have permission to access the other api
         if (!$this->checkPermissionToJoin($fkField['FKApiName'], array_slice($stack, 0, $depth))) {
             throw new UnauthorizedException("Authorization failed to join onto {$fkField['FKApiName']} api in parameter {$fkFieldName}");
         }
         if (!isset($fkField['FKApiSpec'])) {
             $fkField['FKApiSpec'] = \_civicrm_api_get_fields($fkField['FKApiName']);
         }
         $fieldInfo = \CRM_Utils_Array::value($fieldName, $fkField['FKApiSpec']);
         // FIXME: What if the foreign key is not the "id" column?
         if (!$fieldInfo || !isset($fkField['FKApiSpec']['id'])) {
             // Join doesn't exist - might be another param with a dot in it for some reason, we'll just ignore it.
             return NULL;
         }
         $fkTable = \CRM_Core_DAO_AllCoreTables::getTableForClass($fkField['FKClassName']);
         $tableAlias = implode('_to_', array_slice($stack, 0, $depth)) . "_to_{$fkTable}";
         $joinClause = "LEFT JOIN {$fkTable} {$tableAlias} ON {$prev}.{$fk} = {$tableAlias}.id";
         // Add acl condition
         $joinCondition = $this->getAclClause($tableAlias, $fkField['FKClassName']);
         if ($joinCondition !== NULL) {
             $joinClause .= " AND {$joinCondition}";
         }
         $this->query->join($tableAlias, $joinClause);
         if (strpos($fieldName, 'custom_') === 0) {
             list($tableAlias, $fieldName) = $this->addCustomField($fieldInfo, $tableAlias);
         }
         // Get ready to recurse to the next level
         $fk = $fieldName;
         $fkField =& $fkField['FKApiSpec'][$fieldName];
         $prev = $tableAlias;
     }
     return array($tableAlias, $fieldName);
 }
 /**
  * Lookup the admin page at which a field's option list can be edited
  * @param $fieldSpec
  * @return string|null
  */
 static function getOptionEditUrl($fieldSpec)
 {
     // If it's an option group, that's easy
     if (!empty($fieldSpec['pseudoconstant']['optionGroupName'])) {
         return 'civicrm/admin/options/' . $fieldSpec['pseudoconstant']['optionGroupName'];
     } elseif (!empty($fieldSpec['pseudoconstant']['table'])) {
         $daoName = CRM_Core_DAO_AllCoreTables::getClassForTable($fieldSpec['pseudoconstant']['table']);
         if (!$daoName) {
             return NULL;
         }
         // We don't have good mapping so have to do a bit of guesswork from the menu
         list(, $parent, , $child) = explode('_', $daoName);
         $sql = "SELECT path FROM civicrm_menu\n        WHERE page_callback LIKE '%CRM_Admin_Page_{$child}%' OR page_callback LIKE '%CRM_{$parent}_Page_{$child}%'\n        ORDER BY page_callback\n        LIMIT 1";
         return CRM_Core_Dao::singleValueQuery($sql);
     }
     return NULL;
 }
Esempio n. 21
0
 /**
  * Handling for is_primary.
  * $params is_primary could be
  *  #  1 - find other entries with is_primary = 1 &  reset them to 0
  *  #  0 - make sure at least one entry is set to 1
  *            - if no other entry is 1 change to 1
  *            - if one other entry exists change that to 1
  *            - if more than one other entry exists change first one to 1
  *              @fixme - perhaps should choose by location_type
  *  #  empty - same as 0 as once we have checked first step
  *             we know if it should be 1 or 0
  *
  *  if $params['id'] is set $params['contact_id'] may need to be retrieved
  *
  *  @param array $params
  * @static
  */
 public static function handlePrimary(&$params, $class)
 {
     $table = CRM_Core_DAO_AllCoreTables::getTableForClass($class);
     if (!$table) {
         throw new API_Exception("Failed to locate table for class [{$class}]");
     }
     // contact_id in params might be empty or the string 'null' so cast to integer
     $contactId = (int) CRM_Utils_Array::value('contact_id', $params);
     // If id is set & we haven't been passed a contact_id, retrieve it
     if (!empty($params['id']) && !isset($params['contact_id'])) {
         $entity = new $class();
         $entity->id = $params['id'];
         $entity->find(TRUE);
         $contactId = $entity->contact_id;
     }
     // If entity is not associated with contact, concept of is_primary not relevant
     if (!$contactId) {
         return;
     }
     // if params is_primary then set all others to not be primary & exit out
     if (!empty($params['is_primary'])) {
         $sql = "UPDATE {$table} SET is_primary = 0 WHERE contact_id = %1";
         $sqlParams = array(1 => array($contactId, 'Integer'));
         // we don't want to create unecessary entries in the log_ tables so exclude the one we are working on
         if (!empty($params['id'])) {
             $sql .= " AND id <> %2";
             $sqlParams[2] = array($params['id'], 'Integer');
         }
         CRM_Core_DAO::executeQuery($sql, $sqlParams);
         return;
     }
     //Check what other emails exist for the contact
     $existingEntities = new $class();
     $existingEntities->contact_id = $contactId;
     $existingEntities->orderBy('is_primary DESC');
     if (!$existingEntities->find(TRUE) || !empty($params['id']) && $existingEntities->id == $params['id']) {
         // ie. if  no others is set to be primary then this has to be primary set to 1 so change
         $params['is_primary'] = 1;
         return;
     } else {
         /*
          * If the only existing email is the one we are editing then we must set
          * is_primary to 1
          * CRM-10451
          */
         if ($existingEntities->N == 1 && $existingEntities->id == CRM_Utils_Array::value('id', $params)) {
             $params['is_primary'] = 1;
             return;
         }
         if ($existingEntities->is_primary == 1) {
             return;
         }
         // so at this point we are only dealing with ones explicity setting is_primary to 0
         // since we have reverse sorted by email we can either set the first one to
         // primary or return if is already is
         $existingEntities->is_primary = 1;
         $existingEntities->save();
     }
 }
Esempio n. 22
0
 /**
  * Returns the list of fields that can be exported
  *
  * @param bool $prefix
  *
  * @return array
  */
 static function &export($prefix = false)
 {
     $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'mailing_event_delivered', $prefix, array());
     return $r;
 }
Esempio n. 23
0
 /**
  * Apply common settings to entityRef fields.
  *
  * @param array $field
  * @param string $table
  */
 private function setEntityRefDefaults(&$field, $table)
 {
     $field['attributes'] = $field['attributes'] ? $field['attributes'] : array();
     $field['attributes'] += array('entity' => CRM_Core_DAO_AllCoreTables::getBriefName(CRM_Core_DAO_AllCoreTables::getClassForTable($table)), 'multiple' => TRUE, 'placeholder' => ts('- select -'));
 }
Esempio n. 24
0
 /**
  * Takes an associative array and creates a custom group object.
  *
  * This function is invoked from within the web form layer and also from the api layer
  *
  * @param array $params
  *   (reference) an assoc array of name/value pairs.
  *
  * @return CRM_Core_DAO_CustomGroup
  */
 public static function create(&$params)
 {
     // create custom group dao, populate fields and then save.
     $group = new CRM_Core_DAO_CustomGroup();
     if (isset($params['title'])) {
         $group->title = $params['title'];
     }
     if (in_array($params['extends'][0], array('ParticipantRole', 'ParticipantEventName', 'ParticipantEventType'))) {
         $group->extends = 'Participant';
     } else {
         $group->extends = $params['extends'][0];
     }
     $group->extends_entity_column_id = 'null';
     if ($params['extends'][0] == 'ParticipantRole' || $params['extends'][0] == 'ParticipantEventName' || $params['extends'][0] == 'ParticipantEventType') {
         $group->extends_entity_column_id = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $params['extends'][0], 'value', 'name');
     }
     //this is format when form get submit.
     $extendsChildType = CRM_Utils_Array::value(1, $params['extends']);
     //lets allow user to pass direct child type value, CRM-6893
     if (!empty($params['extends_entity_column_value'])) {
         $extendsChildType = $params['extends_entity_column_value'];
     }
     if (!CRM_Utils_System::isNull($extendsChildType)) {
         $extendsChildType = implode(CRM_Core_DAO::VALUE_SEPARATOR, $extendsChildType);
         if (CRM_Utils_Array::value(0, $params['extends']) == 'Relationship') {
             $extendsChildType = str_replace(array('_a_b', '_b_a'), array('', ''), $extendsChildType);
         }
         if (substr($extendsChildType, 0, 1) != CRM_Core_DAO::VALUE_SEPARATOR) {
             $extendsChildType = CRM_Core_DAO::VALUE_SEPARATOR . $extendsChildType . CRM_Core_DAO::VALUE_SEPARATOR;
         }
     } else {
         $extendsChildType = 'null';
     }
     $group->extends_entity_column_value = $extendsChildType;
     if (isset($params['id'])) {
         $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'weight', 'id');
     } else {
         $oldWeight = 0;
     }
     $group->weight = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_CustomGroup', $oldWeight, CRM_Utils_Array::value('weight', $params, FALSE));
     $fields = array('style', 'collapse_display', 'collapse_adv_display', 'help_pre', 'help_post', 'is_active', 'is_multiple');
     foreach ($fields as $field) {
         if (isset($params[$field]) || $field == 'is_multiple') {
             $group->{$field} = CRM_Utils_Array::value($field, $params, FALSE);
         }
     }
     $group->max_multiple = isset($params['is_multiple']) ? isset($params['max_multiple']) && $params['max_multiple'] >= '0' ? $params['max_multiple'] : 'null' : 'null';
     $tableName = $oldTableName = NULL;
     if (isset($params['id'])) {
         $group->id = $params['id'];
         //check whether custom group was changed from single-valued to multiple-valued
         $isMultiple = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'is_multiple');
         if ((!empty($params['is_multiple']) || $isMultiple) && $params['is_multiple'] != $isMultiple) {
             $oldTableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'table_name');
         }
     } else {
         $group->created_id = CRM_Utils_Array::value('created_id', $params);
         $group->created_date = CRM_Utils_Array::value('created_date', $params);
         // we do this only once, so name never changes
         if (isset($params['name'])) {
             $group->name = CRM_Utils_String::munge($params['name'], '_', 64);
         } else {
             $group->name = CRM_Utils_String::munge($group->title, '_', 64);
         }
         if (isset($params['table_name'])) {
             $tableName = $params['table_name'];
             if (CRM_Core_DAO_AllCoreTables::isCoreTable($tableName)) {
                 // Bad idea.  Prevent group creation because it might lead to a broken configuration.
                 CRM_Core_Error::fatal(ts("Cannot create custom table because %1 is already a core table.", array('1' => $tableName)));
             }
         }
     }
     if (array_key_exists('is_reserved', $params)) {
         $group->is_reserved = $params['is_reserved'] ? 1 : 0;
     }
     $op = isset($params['id']) ? 'edit' : 'create';
     CRM_Utils_Hook::pre($op, 'CustomGroup', CRM_Utils_Array::value('id', $params), $params);
     // enclose the below in a transaction
     $transaction = new CRM_Core_Transaction();
     $group->save();
     if (!isset($params['id'])) {
         if (!isset($params['table_name'])) {
             $munged_title = strtolower(CRM_Utils_String::munge($group->title, '_', 42));
             $tableName = "civicrm_value_{$munged_title}_{$group->id}";
         }
         $group->table_name = $tableName;
         CRM_Core_DAO::setFieldValue('CRM_Core_DAO_CustomGroup', $group->id, 'table_name', $tableName);
         // now create the table associated with this group
         self::createTable($group);
     } elseif ($oldTableName) {
         CRM_Core_BAO_SchemaHandler::changeUniqueToIndex($oldTableName, CRM_Utils_Array::value('is_multiple', $params));
     }
     if (CRM_Utils_Array::value('overrideFKConstraint', $params) == 1) {
         $table = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['id'], 'table_name');
         CRM_Core_BAO_SchemaHandler::changeFKConstraint($table, self::mapTableName($params['extends'][0]));
     }
     $transaction->commit();
     // reset the cache
     CRM_Utils_System::flushCache();
     if ($tableName) {
         CRM_Utils_Hook::post('create', 'CustomGroup', $group->id, $group);
     } else {
         CRM_Utils_Hook::post('edit', 'CustomGroup', $group->id, $group);
     }
     return $group;
 }
Esempio n. 25
0
 /**
  * Determine the standard URL for viewing or editing the specified link.
  *
  * This function delegates the decision-making to (a) the hook system and
  * (b) the BAO system.
  *
  * @param array $crudLinkSpec
  *   With keys:.
  *   - action: int, CRM_Core_Action::UPDATE or CRM_Core_Action::VIEW [default: VIEW]
  *   - entity_table: string, eg "civicrm_contact"
  *   - entity_id: int
  * @return array|NULL
  *   NULL if unavailable, or an array. array has keys:
  *   - path: string
  *   - query: array
  *   - title: string
  *   - url: string
  */
 public static function createDefaultCrudLink($crudLinkSpec)
 {
     $crudLinkSpec['action'] = CRM_Utils_Array::value('action', $crudLinkSpec, CRM_Core_Action::VIEW);
     $daoClass = CRM_Core_DAO_AllCoreTables::getClassForTable($crudLinkSpec['entity_table']);
     if (!$daoClass) {
         return NULL;
     }
     $baoClass = str_replace('_DAO_', '_BAO_', $daoClass);
     if (!class_exists($baoClass)) {
         return NULL;
     }
     $bao = new $baoClass();
     $bao->id = $crudLinkSpec['entity_id'];
     if (!$bao->find(TRUE)) {
         return NULL;
     }
     $link = array();
     CRM_Utils_Hook::crudLink($crudLinkSpec, $bao, $link);
     if (empty($link) && is_callable(array($bao, 'createDefaultCrudLink'))) {
         $link = $bao->createDefaultCrudLink($crudLinkSpec);
     }
     if (!empty($link)) {
         if (!isset($link['url'])) {
             $link['url'] = self::url($link['path'], $link['query'], TRUE, NULL, FALSE);
         }
         return $link;
     }
     return NULL;
 }
Esempio n. 26
0
 /**
  * @param bool $triggerRebuild
  * @param bool $sessionReset
  *
  * @throws Exception
  */
 public static function rebuildMenuAndCaches($triggerRebuild = FALSE, $sessionReset = FALSE)
 {
     $config = CRM_Core_Config::singleton();
     $config->clearModuleList();
     // also cleanup all caches
     $config->cleanupCaches($sessionReset || CRM_Utils_Request::retrieve('sessionReset', 'Boolean', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET'));
     CRM_Core_Menu::store();
     // also reset navigation
     CRM_Core_BAO_Navigation::resetNavigation();
     // also cleanup module permissions
     $config->cleanupPermissions();
     // rebuild word replacement cache - pass false to prevent operations redundant with this fn
     CRM_Core_BAO_WordReplacement::rebuild(FALSE);
     Civi::service('settings_manager')->flush();
     // Clear js caches
     CRM_Core_Resources::singleton()->flushStrings()->resetCacheCode();
     CRM_Case_XMLRepository::singleton(TRUE);
     // also rebuild triggers if requested explicitly
     if ($triggerRebuild || CRM_Utils_Request::retrieve('triggerRebuild', 'Boolean', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET')) {
         CRM_Core_DAO::triggerRebuild();
     }
     CRM_Core_DAO_AllCoreTables::reinitializeCache(TRUE);
     CRM_Core_ManagedEntities::singleton(TRUE)->reconcile();
     //CRM-16257 update Config.IDS.ini might be an old copy
     CRM_Core_IDS::createConfigFile(TRUE);
 }
 /**
  * @param array $apiRequest
  *   Array(entity=>$,action=>$,params=>$,expectedResults=>$).
  * @param array $rules
  *   Whitelist - list of allowed API calls/patterns.
  * @param bool $expectSuccess
  *   TRUE if the call should succeed.
  *   Success implies that the 'expectedResults' are returned.
  *   Failure implies that the standard error message is returned.
  * @dataProvider restrictionCases
  */
 public function testEach($apiRequest, $rules, $expectSuccess)
 {
     \CRM_Core_DAO_AllCoreTables::init(TRUE);
     $recs = $this->getFixtures();
     \CRM_Core_DAO_AllCoreTables::registerEntityType('Widget', 'CRM_Fake_DAO_Widget', 'fake_widget');
     $widgetProvider = new \Civi\API\Provider\StaticProvider(3, 'Widget', array('id', 'widget_type', 'provider', 'title'), array(), $recs['widget']);
     \CRM_Core_DAO_AllCoreTables::registerEntityType('Sprocket', 'CRM_Fake_DAO_Sprocket', 'fake_sprocket');
     $sprocketProvider = new \Civi\API\Provider\StaticProvider(3, 'Sprocket', array('id', 'sprocket_type', 'widget_id', 'provider', 'title', 'comment'), array(), $recs['sprocket']);
     $whitelist = WhitelistRule::createAll($rules);
     $dispatcher = new EventDispatcher();
     $kernel = new Kernel($dispatcher);
     $kernel->registerApiProvider($sprocketProvider);
     $kernel->registerApiProvider($widgetProvider);
     $dispatcher->addSubscriber(new WhitelistSubscriber($whitelist));
     $dispatcher->addSubscriber(new ChainSubscriber());
     $apiRequest['params']['debug'] = 1;
     $apiRequest['params']['check_permissions'] = 'whitelist';
     $result = $kernel->run($apiRequest['entity'], $apiRequest['action'], $apiRequest['params']);
     if ($expectSuccess) {
         $this->assertAPISuccess($result);
         $this->assertTrue(is_array($apiRequest['expectedResults']));
         $this->assertTreeEquals($apiRequest['expectedResults'], $result['values']);
     } else {
         $this->assertAPIFailure($result);
         $this->assertRegExp('/The request does not match any active API authorizations./', $result['error_message']);
     }
 }
Esempio n. 28
0
/**
 * Returns fields allowable by api.
 *
 * @param $entity
 *   String Entity to query.
 * @param bool $unique
 *   Index by unique fields?.
 * @param array $params
 *
 * @return array
 */
function _civicrm_api_get_fields($entity, $unique = FALSE, &$params = array())
{
    $unsetIfEmpty = array('dataPattern', 'headerPattern', 'default', 'export', 'import');
    $dao = _civicrm_api3_get_DAO($entity);
    if (empty($dao)) {
        return array();
    }
    $d = new $dao();
    $fields = $d->fields();
    // replace uniqueNames by the normal names as the key
    if (empty($unique)) {
        foreach ($fields as $name => &$field) {
            //getting rid of unused attributes
            foreach ($unsetIfEmpty as $attr) {
                if (empty($field[$attr])) {
                    unset($field[$attr]);
                }
            }
            if ($name == $field['name']) {
                continue;
            }
            if (array_key_exists($field['name'], $fields)) {
                $field['error'] = 'name conflict';
                // it should never happen, but better safe than sorry
                continue;
            }
            $fields[$field['name']] = $field;
            $fields[$field['name']]['uniqueName'] = $name;
            unset($fields[$name]);
        }
    }
    // Translate FKClassName to the corresponding api
    foreach ($fields as $name => &$field) {
        if (!empty($field['FKClassName'])) {
            $FKApi = CRM_Core_DAO_AllCoreTables::getBriefName($field['FKClassName']);
            if ($FKApi) {
                $field['FKApiName'] = $FKApi;
            }
        }
    }
    $fields += _civicrm_api_get_custom_fields($entity, $params);
    return $fields;
}
Esempio n. 29
0
 /**
  * Returns the list of fields that can be exported
  *
  * @param bool $prefix
  *
  * @return array
  */
 static function &export($prefix = false)
 {
     $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'price_set', $prefix, array());
     return $r;
 }
 /**
  * Low-level option getter, rarely accessed directly.
  * NOTE: Rather than calling this function directly use CRM_*_BAO_*::buildOptions()
  *
  * @param String $daoName
  * @param String $fieldName
  * @param Array $params
  * - name       string  name of the option group
  * - flip       boolean results are return in id => label format if false
  *                            if true, the results are reversed
  * - grouping   boolean if true, return the value in 'grouping' column (currently unsupported for tables other than option_value)
  * - localize   boolean if true, localize the results before returning
  * - condition  string|array add condition(s) to the sql query - will be concatenated using 'AND'
  * - keyColumn  string the column to use for 'id'
  * - labelColumn string the column to use for 'label'
  * - orderColumn string the column to use for sorting, defaults to 'weight' column if one exists, else defaults to labelColumn
  * - onlyActive boolean return only the action option values
  * - fresh      boolean ignore cache entries and go back to DB
  * @param String $context: Context string
  *
  * @return Array on success, FALSE on error.
  *
  * @static
  */
 public static function get($daoName, $fieldName, $params = array(), $context = NULL)
 {
     CRM_Core_DAO::buildOptionsContext($context);
     $flip = !empty($params['flip']);
     // Merge params with defaults
     $params += array('grouping' => FALSE, 'localize' => FALSE, 'onlyActive' => $context == 'validate' || $context == 'get' ? FALSE : TRUE, 'fresh' => FALSE);
     // Custom fields are not in the schema
     if (strpos($fieldName, 'custom_') === 0 && is_numeric($fieldName[7])) {
         $customField = new CRM_Core_DAO_CustomField();
         $customField->id = (int) substr($fieldName, 7);
         $customField->find(TRUE);
         $options = FALSE;
         if (!empty($customField->option_group_id)) {
             $options = CRM_Core_OptionGroup::valuesByID($customField->option_group_id, $flip, $params['grouping'], $params['localize'], CRM_Utils_Array::value('labelColumn', $params, 'label'), $params['onlyActive'], $params['fresh']);
         } else {
             if ($customField->data_type === 'StateProvince') {
                 $options = self::stateProvince();
             } elseif ($customField->data_type === 'Country') {
                 $options = $context == 'validate' ? self::countryIsoCode() : self::country();
             } elseif ($customField->data_type === 'Boolean') {
                 $options = $context == 'validate' ? array(0, 1) : array(1 => ts('Yes'), 0 => ts('No'));
             }
             $options = $options && $flip ? array_flip($options) : $options;
         }
         if ($options !== FALSE) {
             CRM_Utils_Hook::customFieldOptions($customField->id, $options, FALSE);
         }
         $customField->free();
         return $options;
     }
     // Core field: load schema
     $dao = new $daoName();
     $fields = $dao->fields();
     $fieldKeys = $dao->fieldKeys();
     $dao->free();
     // Support "unique names" as well as sql names
     $fieldKey = $fieldName;
     if (empty($fields[$fieldKey])) {
         $fieldKey = CRM_Utils_Array::value($fieldName, $fieldKeys);
     }
     // If neither worked then this field doesn't exist. Return false.
     if (empty($fields[$fieldKey])) {
         return FALSE;
     }
     $fieldSpec = $fields[$fieldKey];
     // If the field is an enum, explode the enum definition and return the array.
     if (isset($fieldSpec['enumValues'])) {
         // use of a space after the comma is inconsistent in xml
         $enumStr = str_replace(', ', ',', $fieldSpec['enumValues']);
         $output = explode(',', $enumStr);
         return array_combine($output, $output);
     } elseif (!empty($fieldSpec['pseudoconstant'])) {
         $pseudoconstant = $fieldSpec['pseudoconstant'];
         // Merge params with schema defaults
         $params += array('condition' => CRM_Utils_Array::value('condition', $pseudoconstant, array()), 'keyColumn' => CRM_Utils_Array::value('keyColumn', $pseudoconstant), 'labelColumn' => CRM_Utils_Array::value('labelColumn', $pseudoconstant));
         // Fetch option group from option_value table
         if (!empty($pseudoconstant['optionGroupName'])) {
             if ($context == 'validate') {
                 $params['labelColumn'] = 'name';
             }
             // Call our generic fn for retrieving from the option_value table
             return CRM_Core_OptionGroup::values($pseudoconstant['optionGroupName'], $flip, $params['grouping'], $params['localize'], $params['condition'] ? ' AND ' . implode(' AND ', (array) $params['condition']) : NULL, $params['labelColumn'] ? $params['labelColumn'] : 'label', $params['onlyActive'], $params['fresh'], $params['keyColumn'] ? $params['keyColumn'] : 'value');
         }
         // Fetch options from other tables
         if (!empty($pseudoconstant['table'])) {
             // Normalize params so the serialized cache string will be consistent.
             CRM_Utils_Array::remove($params, 'flip', 'fresh');
             ksort($params);
             $cacheKey = $daoName . $fieldName . serialize($params);
             // Retrieve cached options
             if (isset(self::$cache[$cacheKey]) && empty($params['fresh'])) {
                 $output = self::$cache[$cacheKey];
             } else {
                 $daoName = CRM_Core_DAO_AllCoreTables::getClassForTable($pseudoconstant['table']);
                 if (!class_exists($daoName)) {
                     return FALSE;
                 }
                 // Get list of fields for the option table
                 $dao = new $daoName();
                 $availableFields = array_keys($dao->fieldKeys());
                 $dao->free();
                 $select = "SELECT %1 AS id, %2 AS label";
                 $from = "FROM %3";
                 $wheres = array();
                 $order = "ORDER BY %2";
                 // Use machine name instead of label in validate context
                 if ($context == 'validate') {
                     if (!empty($pseudoconstant['nameColumn'])) {
                         $params['labelColumn'] = $pseudoconstant['nameColumn'];
                     } elseif (in_array('name', $availableFields)) {
                         $params['labelColumn'] = 'name';
                     }
                 }
                 // Condition param can be passed as an sql clause string or an array of clauses
                 if (!empty($params['condition'])) {
                     $wheres[] = implode(' AND ', (array) $params['condition']);
                 }
                 // onlyActive param will automatically filter on common flags
                 if (!empty($params['onlyActive'])) {
                     foreach (array('is_active' => 1, 'is_deleted' => 0, 'is_test' => 0) as $flag => $val) {
                         if (in_array($flag, $availableFields)) {
                             $wheres[] = "{$flag} = {$val}";
                         }
                     }
                 }
                 // Filter domain specific options
                 if (in_array('domain_id', $availableFields)) {
                     $wheres[] = 'domain_id = ' . CRM_Core_Config::domainID();
                 }
                 $queryParams = array(1 => array($params['keyColumn'], 'String', CRM_Core_DAO::QUERY_FORMAT_NO_QUOTES), 2 => array($params['labelColumn'], 'String', CRM_Core_DAO::QUERY_FORMAT_NO_QUOTES), 3 => array($pseudoconstant['table'], 'String', CRM_Core_DAO::QUERY_FORMAT_NO_QUOTES));
                 // Add orderColumn param
                 if (!empty($params['orderColumn'])) {
                     $queryParams[4] = array($params['orderColumn'], 'String', CRM_Core_DAO::QUERY_FORMAT_NO_QUOTES);
                     $order = "ORDER BY %4";
                 } elseif (isset($params['orderColumn']) && $params['orderColumn'] === FALSE) {
                     $order = '';
                 } elseif (in_array('weight', $availableFields)) {
                     $order = "ORDER BY weight";
                 }
                 $output = array();
                 $query = "{$select} {$from}";
                 if ($wheres) {
                     $query .= " WHERE " . implode($wheres, ' AND ');
                 }
                 $query .= ' ' . $order;
                 $dao = CRM_Core_DAO::executeQuery($query, $queryParams);
                 while ($dao->fetch()) {
                     $output[$dao->id] = $dao->label;
                 }
                 $dao->free();
                 // Localize results
                 if (!empty($params['localize']) || $pseudoconstant['table'] == 'civicrm_country' || $pseudoconstant['table'] == 'civicrm_state_province') {
                     $I18nParams = array();
                     if ($pseudoconstant['table'] == 'civicrm_country') {
                         $I18nParams['context'] = 'country';
                     }
                     if ($pseudoconstant['table'] == 'civicrm_state_province') {
                         $I18nParams['context'] = 'province';
                     }
                     $i18n = CRM_Core_I18n::singleton();
                     $i18n->localizeArray($output, $I18nParams);
                     // Maintain sort by label
                     if ($order == "ORDER BY %2") {
                         CRM_Utils_Array::asort($output);
                     }
                 }
                 self::$cache[$cacheKey] = $output;
             }
             return $flip ? array_flip($output) : $output;
         }
     } elseif (CRM_Utils_Array::value('type', $fieldSpec) === CRM_Utils_Type::T_BOOLEAN) {
         $output = $context == 'validate' ? array(0, 1) : array(1 => ts('Yes'), 0 => ts('No'));
         return $flip ? array_flip($output) : $output;
     }
     // If we're still here, it's an error. Return FALSE.
     return FALSE;
 }