当前位置: 首页>>代码示例>>PHP>>正文


PHP _civicrm_api_get_entity_name_from_camel函数代码示例

本文整理汇总了PHP中_civicrm_api_get_entity_name_from_camel函数的典型用法代码示例。如果您正苦于以下问题:PHP _civicrm_api_get_entity_name_from_camel函数的具体用法?PHP _civicrm_api_get_entity_name_from_camel怎么用?PHP _civicrm_api_get_entity_name_from_camel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了_civicrm_api_get_entity_name_from_camel函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getEntityName

 /**
  * 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);
 }
开发者ID:prashantgajare,项目名称:civicrm-core,代码行数:36,代码来源:Api.php

示例2: civicrm_api3_generic_getList

/**
 * Generic api wrapper used for quicksearch and autocomplete.
 *
 * @param array $apiRequest
 *
 * @return mixed
 */
function civicrm_api3_generic_getList($apiRequest)
{
    $entity = _civicrm_api_get_entity_name_from_camel($apiRequest['entity']);
    $request = $apiRequest['params'];
    $meta = civicrm_api3_generic_getfields(array('action' => 'get') + $apiRequest, FALSE);
    // Hey api, would you like to provide default values?
    $fnName = "_civicrm_api3_{$entity}_getlist_defaults";
    $defaults = function_exists($fnName) ? $fnName($request) : array();
    _civicrm_api3_generic_getList_defaults($entity, $request, $defaults, $meta['values']);
    // Hey api, would you like to format the search params?
    $fnName = "_civicrm_api3_{$entity}_getlist_params";
    $fnName = function_exists($fnName) ? $fnName : '_civicrm_api3_generic_getlist_params';
    $fnName($request);
    $request['params']['check_permissions'] = !empty($apiRequest['params']['check_permissions']);
    $result = civicrm_api3($entity, 'get', $request['params']);
    // Hey api, would you like to format the output?
    $fnName = "_civicrm_api3_{$entity}_getlist_output";
    $fnName = function_exists($fnName) ? $fnName : '_civicrm_api3_generic_getlist_output';
    $values = $fnName($result, $request, $entity, $meta['values']);
    _civicrm_api3_generic_getlist_postprocess($result, $request, $values);
    $output = array('page_num' => $request['page_num']);
    // Limit is set for searching but not fetching by id
    if (!empty($request['params']['options']['limit'])) {
        // If we have an extra result then this is not the last page
        $last = $request['params']['options']['limit'] - 1;
        $output['more_results'] = isset($values[$last]);
        unset($values[$last]);
    }
    return civicrm_api3_create_success($values, $request['params'], $entity, 'getlist', CRM_Core_DAO::$_nullObject, $output);
}
开发者ID:nielosz,项目名称:civicrm-core,代码行数:37,代码来源:Getlist.php

示例3: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // load Civi to get access to civicrm_api_get_function_name
     $civicrm_api3 = $this->getContainer()->get('civicrm_api3');
     if (!$civicrm_api3 || !$civicrm_api3->local) {
         $output->writeln("<error>Require access to local CiviCRM source tree. Configure civicrm_api3_conf_path.</error>");
         return;
     }
     $ctx = array();
     $ctx['type'] = 'module';
     $ctx['basedir'] = rtrim(getcwd(), '/');
     $basedir = new Path($ctx['basedir']);
     $info = new Info($basedir->string('info.xml'));
     $info->load($ctx);
     $attrs = $info->get()->attributes();
     if ($attrs['type'] != 'module') {
         $output->writeln('<error>Wrong extension type: ' . $attrs['type'] . '</error>');
         return;
     }
     if (!preg_match('/^[A-Za-z0-9]+$/', $input->getArgument('<EntityName>'))) {
         throw new Exception("Entity name must be alphanumeric camel-case");
     }
     $ctx['entityNameCamel'] = ucfirst($input->getArgument('<EntityName>'));
     $ctx['tableName'] = 'civicrm_' . strtolower($input->getArgument('<EntityName>'));
     if (function_exists('civicrm_api_get_function_name')) {
         $ctx['apiFunctionPrefix'] = strtolower(civicrm_api_get_function_name($ctx['entityNameCamel'], '', self::API_VERSION));
     } elseif (function_exists('_civicrm_api_get_entity_name_from_camel')) {
         $ctx['apiFunctionPrefix'] = 'civicrm_api' . self::API_VERSION . '_' . _civicrm_api_get_entity_name_from_camel($ctx['entityNameCamel']) . '_' . $ctx['actionNameCamel'];
     } else {
         throw new Exception("Failed to determine proper API function name. Perhaps the API internals have changed?");
     }
     $ctx['apiFile'] = $basedir->string('api', 'v3', $ctx['entityNameCamel'] . '.php');
     $ctx['daoClassName'] = strtr($ctx['namespace'], '/', '_') . '_DAO_' . $input->getArgument('<EntityName>');
     $ctx['daoClassFile'] = $basedir->string(strtr($ctx['daoClassName'], '_', '/') . '.php');
     $ctx['baoClassName'] = strtr($ctx['namespace'], '/', '_') . '_BAO_' . $input->getArgument('<EntityName>');
     $ctx['baoClassFile'] = $basedir->string(strtr($ctx['baoClassName'], '_', '/') . '.php');
     $ctx['schemaFile'] = $basedir->string('xml', 'schema', $ctx['namespace'], $input->getArgument('<EntityName>') . '.xml');
     $ctx['entityTypeFile'] = $basedir->string('xml', 'schema', $ctx['namespace'], $input->getArgument('<EntityName>') . '.entityType.php');
     $ext = new Collection();
     $ext->builders['dirs'] = new Dirs(array(dirname($ctx['apiFile']), dirname($ctx['daoClassFile']), dirname($ctx['baoClassFile']), dirname($ctx['schemaFile'])));
     $ext->builders['dirs']->save($ctx, $output);
     $ext->builders['api.php'] = new Template('CRMCivixBundle:Code:entity-api.php.php', $ctx['apiFile'], FALSE, $this->getContainer()->get('templating'));
     $ext->builders['bao.php'] = new Template('CRMCivixBundle:Code:entity-bao.php.php', $ctx['baoClassFile'], FALSE, $this->getContainer()->get('templating'));
     $ext->builders['entity.xml'] = new Template('CRMCivixBundle:Code:entity-schema.xml.php', $ctx['schemaFile'], FALSE, $this->getContainer()->get('templating'));
     if (!file_exists($ctx['entityTypeFile'])) {
         $mgdEntities = array(array('name' => $ctx['entityNameCamel'], 'class' => $ctx['daoClassName'], 'table' => $ctx['tableName']));
         $header = "// This file declares a new entity type. For more details, see \"hook_civicrm_entityTypes\" at:\n" . "// http://wiki.civicrm.org/confluence/display/CRMDOC/Hook+Reference";
         $ext->builders['entityType.php'] = new PhpData($ctx['entityTypeFile'], $header);
         $ext->builders['entityType.php']->set($mgdEntities);
     }
     $ext->init($ctx);
     $ext->save($ctx, $output);
 }
开发者ID:twomice,项目名称:civix,代码行数:53,代码来源:AddEntityCommand.php

示例4: flushConstant

 /**
  * Flush constant.
  *
  * Wrapper for Pseudoconstant methods. We use this so the calling function
  * doesn't need to know which class the Pseudoconstant is on
  * (some are on the Contribute_Pseudoconsant Class etc
  *
  *
  * @param $constant
  *
  * @return array
  *   array reference of all relevant constant
  */
 public static function flushConstant($constant)
 {
     $class = self::findConstantClass($constant);
     if ($class) {
         $class::flush(lcfirst($constant));
         //@todo the rule is api functions should only be called from within the api - we
         // should move this function to a Core class
         $name = _civicrm_api_get_entity_name_from_camel($constant);
         CRM_Core_OptionGroup::flush($name);
         return TRUE;
     }
 }
开发者ID:FundingWorks,项目名称:civicrm-core,代码行数:25,代码来源:PseudoConstant.php

示例5: civicrm_api3_generic_getList

/**
 * Generic api wrapper used for quicksearch and autocomplete
 *
 * @param $apiRequest array
 * @return mixed
 */
function civicrm_api3_generic_getList($apiRequest)
{
    $entity = _civicrm_api_get_entity_name_from_camel($apiRequest['entity']);
    $request = $apiRequest['params'];
    _civicrm_api3_generic_getList_defaults($entity, $request);
    // Hey api, would you like to format the search params?
    $fnName = "_civicrm_api3_{$entity}_getlist_params";
    $fnName = function_exists($fnName) ? $fnName : '_civicrm_api3_generic_getlist_params';
    $fnName($request);
    $result = civicrm_api3($entity, 'get', $request['params']);
    // Hey api, would you like to format the output?
    $fnName = "_civicrm_api3_{$entity}_getlist_output";
    $fnName = function_exists($fnName) ? $fnName : '_civicrm_api3_generic_getlist_output';
    $values = $fnName($result, $request);
    $output = array('more_results' => isset($values[10]), 'page_num' => $request['page_num']);
    unset($values[10]);
    return civicrm_api3_create_success($values, $request['params'], $entity, 'getlist', CRM_Core_DAO::$_nullObject, $output);
}
开发者ID:archcidburnziso,项目名称:civicrm-core,代码行数:24,代码来源:Getlist.php

示例6: _civicrm_api_get_entity_name_from_camel

 /**
  * @param int $id
  * @param $values
  * @param int $wildcard
  * @param bool $useEquals
  *
  * @param string $apiEntity
  *
  * @return array|null
  */
 public static function &fixWhereValues($id, &$values, $wildcard = 0, $useEquals = FALSE, $apiEntity = NULL)
 {
     // skip a few search variables
     static $skipWhere = NULL;
     static $likeNames = NULL;
     $result = NULL;
     // Change camelCase EntityName to lowercase with underscores
     $apiEntity = _civicrm_api_get_entity_name_from_camel($apiEntity);
     if (CRM_Utils_System::isNull($values)) {
         return $result;
     }
     if (!$skipWhere) {
         $skipWhere = array('task', 'radio_ts', 'uf_group_id', 'component_mode', 'qfKey', 'operator', 'display_relationship_type');
     }
     if (in_array($id, $skipWhere) || substr($id, 0, 4) == '_qf_' || substr($id, 0, 7) == 'hidden_') {
         return $result;
     }
     if ($apiEntity && substr($id, 0, strlen($apiEntity)) != $apiEntity && (substr($id, 0, 10) != 'financial_' && substr($id, 0, 8) != 'payment_')) {
         $id = $apiEntity . '_' . $id;
     }
     if (!$likeNames) {
         $likeNames = array('sort_name', 'email', 'note', 'display_name');
     }
     // email comes in via advanced search
     // so use wildcard always
     if ($id == 'email') {
         $wildcard = 1;
     }
     if (!$useEquals && in_array($id, $likeNames)) {
         $result = array($id, 'LIKE', $values, 0, 1);
     } elseif (is_string($values) && strpos($values, '%') !== FALSE) {
         $result = array($id, 'LIKE', $values, 0, 0);
     } elseif ($id == 'group') {
         if (is_array($values)) {
             foreach ($values as $groupIds => $val) {
                 $matches = array();
                 if (preg_match('/-(\\d+)$/', $groupIds, $matches)) {
                     if (strlen($matches[1]) > 0) {
                         $values[$matches[1]] = 1;
                         unset($values[$groupIds]);
                     }
                 }
             }
         } else {
             $groupIds = explode(',', $values);
             unset($values);
             foreach ($groupIds as $groupId) {
                 $values[$groupId] = 1;
             }
         }
         $result = array($id, 'IN', $values, 0, 0);
     } elseif ($id == 'contact_tags' || $id == 'tag') {
         if (!is_array($values)) {
             $tagIds = explode(',', $values);
             unset($values);
             foreach ($tagIds as $tagId) {
                 $values[$tagId] = 1;
             }
         }
         $result = array($id, 'IN', $values, 0, 0);
     } elseif ($id == 'contact_type') {
         $result = array($id, 'IN', $values, 0, $wildcard);
     } else {
         $result = array($id, '=', $values, 0, $wildcard);
     }
     return $result;
 }
开发者ID:vakeesan26,项目名称:civicrm-core,代码行数:77,代码来源:Query.php

示例7: civicrm_api3_generic_getfields

/**
 * Get information about fields for a given api request.
 *
 * Getfields information is used for documentation, validation, default setting
 * We first query the scheme using the $dao->fields function & then augment
 * that information by calling the _spec functions that apply to the relevant function
 * Note that we use 'unique' field names as described in the xml/schema files
 * for get requests & just field name for create. This is because some get functions
 * access multiple objects e.g. contact api accesses is_deleted from the activity
 * table & from the contact table
 *
 * @param array $apiRequest
 *   Api request as an array. Keys are.
 *   - entity: string
 *   - action: string
 *   - version: string
 *   - function: callback (mixed)
 *   - params: array, varies
 *
 * @param bool $unique
 *   Determines whether to key by unique field names (only affects get-type) actions
 *
 * @return array
 *   API success object
 */
function civicrm_api3_generic_getfields($apiRequest, $unique = TRUE)
{
    static $results = array();
    if (CRM_Utils_Array::value('cache_clear', $apiRequest['params'])) {
        $results = array();
        // we will also clear pseudoconstants here - should potentially be moved to relevant BAO classes
        CRM_Core_PseudoConstant::flush();
        if (!empty($apiRequest['params']['fieldname'])) {
            CRM_Utils_PseudoConstant::flushConstant($apiRequest['params']['fieldname']);
        }
        if (!empty($apiRequest['params']['option_group_id'])) {
            $optionGroupName = civicrm_api('option_group', 'getvalue', array('version' => 3, 'id' => $apiRequest['params']['option_group_id'], 'return' => 'name'));
            if (is_string($optionGroupName)) {
                CRM_Utils_PseudoConstant::flushConstant(_civicrm_api_get_camel_name($optionGroupName));
            }
        }
    }
    $entity = $apiRequest['entity'];
    $lowercase_entity = _civicrm_api_get_entity_name_from_camel($entity);
    $subentity = CRM_Utils_Array::value('contact_type', $apiRequest['params']);
    $action = CRM_Utils_Array::value('action', $apiRequest['params']);
    $sequential = empty($apiRequest['params']['sequential']) ? 0 : 1;
    $apiRequest['params']['options'] = CRM_Utils_Array::value('options', $apiRequest['params'], array());
    $optionsToResolve = (array) CRM_Utils_Array::value('get_options', $apiRequest['params']['options'], array());
    if (!$action || $action == 'getvalue' || $action == 'getcount') {
        $action = 'get';
    }
    // If no options, return results from cache
    if (!$apiRequest['params']['options'] && isset($results[$entity . $subentity]) && isset($action, $results[$entity . $subentity]) && isset($action, $results[$entity . $subentity][$sequential])) {
        return $results[$entity . $subentity][$action][$sequential];
    }
    // defaults based on data model and API policy
    switch ($action) {
        case 'getfields':
            $values = _civicrm_api_get_fields($entity, FALSE, $apiRequest['params']);
            return civicrm_api3_create_success($values, $apiRequest['params'], $entity, 'getfields');
        case 'create':
        case 'update':
        case 'replace':
            $unique = FALSE;
        case 'get':
        case 'getsingle':
        case 'getcount':
        case 'getstat':
            $metadata = _civicrm_api_get_fields($apiRequest['entity'], $unique, $apiRequest['params']);
            if (empty($metadata['id'])) {
                // if id is not set we will set it eg. 'id' from 'case_id', case_id will be an alias
                if (!empty($metadata[strtolower($apiRequest['entity']) . '_id'])) {
                    $metadata['id'] = $metadata[$lowercase_entity . '_id'];
                    unset($metadata[$lowercase_entity . '_id']);
                    $metadata['id']['api.aliases'] = array($lowercase_entity . '_id');
                }
            } else {
                // really the preference would be to set the unique name in the xml
                // question is which is a less risky fix this close to a release - setting in xml for the known failure
                // (note) or setting for all api where fields is returning 'id' & we want to accept 'note_id' @ the api layer
                // nb we don't officially accept note_id anyway - rationale here is more about centralising a now-tested
                // inconsistency
                $metadata['id']['api.aliases'] = array($lowercase_entity . '_id');
            }
            break;
        case 'delete':
            $metadata = array('id' => array('title' => $entity . ' ID', 'api.required' => 1, 'api.aliases' => array($lowercase_entity . '_id'), 'type' => CRM_Utils_Type::T_INT));
            break;
            // Note: adding setvalue case here instead of in a generic spec function because
            // some APIs override the generic setvalue fn which causes the generic spec to be overlooked.
        // Note: adding setvalue case here instead of in a generic spec function because
        // some APIs override the generic setvalue fn which causes the generic spec to be overlooked.
        case 'setvalue':
            $metadata = array('field' => array('title' => 'Field name', 'api.required' => 1, 'type' => CRM_Utils_Type::T_STRING), 'id' => array('title' => $entity . ' ID', 'api.required' => 1, 'type' => CRM_Utils_Type::T_INT), 'value' => array('title' => 'Value', 'description' => "Field value to set", 'api.required' => 1));
            if (array_intersect(array('all', 'field'), $optionsToResolve)) {
                $options = civicrm_api3_generic_getfields(array('entity' => $entity, array('params' => array('action' => 'create'))));
                $metadata['field']['options'] = CRM_Utils_Array::collect('title', $options['values']);
            }
            break;
//.........这里部分代码省略.........
开发者ID:nielosz,项目名称:civicrm-core,代码行数:101,代码来源:Generic.php

示例8: testByIDAlias_get

 /**
  * Create two entities and make sure we can fetch them individually by ID (e.g. using "contact_id=>2"
  * or "group_id=>4")
  *
  * @dataProvider entities_get
  *
  * limitations include the problem with avoiding loops when creating test objects -
  * hence FKs only set by createTestObject when required. e.g parent_id on campaign is not being followed through
  * Currency - only seems to support US
  */
 public function testByIDAlias_get($entityName)
 {
     if (in_array($entityName, self::toBeSkipped_automock(TRUE))) {
         // $this->markTestIncomplete("civicrm_api3_{$Entity}_create to be implemented");
         return;
     }
     $baoString = _civicrm_api3_get_DAO($entityName);
     if (empty($baoString)) {
         $this->markTestIncomplete("Entity [{$entityName}] cannot be mocked - no known DAO");
         return;
     }
     $idFieldName = _civicrm_api_get_entity_name_from_camel($entityName) . '_id';
     // create entities
     $baoObj1 = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD'));
     $this->assertTrue(is_integer($baoObj1->id), 'check first id');
     $this->deletableTestObjects[$baoString][] = $baoObj1->id;
     $baoObj2 = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD'));
     $this->assertTrue(is_integer($baoObj2->id), 'check second id');
     $this->deletableTestObjects[$baoString][] = $baoObj2->id;
     // fetch first by ID
     $result = civicrm_api($entityName, 'get', array('version' => 3, $idFieldName => $baoObj1->id));
     $this->assertAPISuccess($result);
     $this->assertTrue(!empty($result['values'][$baoObj1->id]), 'Should find first object by id');
     $this->assertEquals($baoObj1->id, $result['values'][$baoObj1->id]['id'], 'Should find id on first object');
     $this->assertEquals(1, count($result['values']));
     // fetch second by ID
     $result = civicrm_api($entityName, 'get', array('version' => 3, $idFieldName => $baoObj2->id));
     $this->assertAPISuccess($result);
     $this->assertTrue(!empty($result['values'][$baoObj2->id]), 'Should find second object by id');
     $this->assertEquals($baoObj2->id, $result['values'][$baoObj2->id]['id'], 'Should find id on second object');
     $this->assertEquals(1, count($result['values']));
 }
开发者ID:archcidburnziso,项目名称:civicrm-core,代码行数:42,代码来源:SyntaxConformanceTest.php

示例9: _civicrm_api_get_entity_name_from_dao

/**
 * 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));
}
开发者ID:prashantgajare,项目名称:civicrm-core,代码行数:10,代码来源:api.php

示例10: _civicrm_api_get_entity_name_from_camel

 /**
  * @param int $id
  * @param $values
  * @param int $wildcard
  * @param bool $useEquals
  *
  * @param string $apiEntity
  *
  * @return array|null
  */
 public static function &fixWhereValues($id, &$values, $wildcard = 0, $useEquals = FALSE, $apiEntity = NULL)
 {
     // skip a few search variables
     static $skipWhere = NULL;
     static $likeNames = NULL;
     $result = NULL;
     // Change camelCase EntityName to lowercase with underscores
     $apiEntity = _civicrm_api_get_entity_name_from_camel($apiEntity);
     if (CRM_Utils_System::isNull($values)) {
         return $result;
     }
     if (!$skipWhere) {
         $skipWhere = array('task', 'radio_ts', 'uf_group_id', 'component_mode', 'qfKey', 'operator');
     }
     if (in_array($id, $skipWhere) || substr($id, 0, 4) == '_qf_' || substr($id, 0, 7) == 'hidden_') {
         return $result;
     }
     if ($apiEntity && substr($id, 0, strlen($apiEntity)) != $apiEntity) {
         $id = $apiEntity . '_' . $id;
     }
     if (!$likeNames) {
         $likeNames = array('relationship_target_name');
     }
     if (!$useEquals && in_array($id, $likeNames)) {
         $result = array($id, 'LIKE', $values, 0, 1);
     } elseif (is_string($values) && strpos($values, '%') !== FALSE) {
         $result = array($id, 'LIKE', $values, 0, 0);
     } elseif ($id == 'relationship_type_id') {
         $result = array($id, 'IN', $values, 0, $wildcard);
     } else {
         $result = array($id, '=', $values, 0, $wildcard);
     }
     return $result;
 }
开发者ID:Chirojeugd-Vlaanderen,项目名称:civicrm-relationship-entity,代码行数:44,代码来源:Query.php

示例11: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // load Civi to get access to civicrm_api_get_function_name
     $civicrm_api3 = $this->getContainer()->get('civicrm_api3');
     if (!$civicrm_api3 || !$civicrm_api3->local) {
         $output->writeln("<error>--copy requires access to local CiviCRM source tree. Configure civicrm_api3_conf_path.</error>");
         return;
     }
     $ctx = array();
     $ctx['type'] = 'module';
     $ctx['basedir'] = rtrim(getcwd(), '/');
     $basedir = new Path($ctx['basedir']);
     $info = new Info($basedir->string('info.xml'));
     $info->load($ctx);
     $attrs = $info->get()->attributes();
     if ($attrs['type'] != 'module') {
         $output->writeln('<error>Wrong extension type: ' . $attrs['type'] . '</error>');
         return;
     }
     if (!preg_match('/^[A-Za-z0-9]+$/', $input->getArgument('<EntityName>'))) {
         throw new Exception("Entity name must be alphanumeric camel-case");
     }
     if (!preg_match('/^[A-Za-z0-9]+$/', $input->getArgument('<ActionName>'))) {
         throw new Exception("Action name must be alphanumeric camel-case");
     }
     if ($input->getOption('schedule') && !in_array($input->getOption('schedule'), self::getSchedules())) {
         throw new Exception("Schedule must be one of: " . implode(', ', self::getSchedules()));
     }
     $ctx['entityNameCamel'] = ucfirst($input->getArgument('<EntityName>'));
     $ctx['actionNameCamel'] = ucfirst($input->getArgument('<ActionName>'));
     if (function_exists('civicrm_api_get_function_name')) {
         $ctx['apiFunction'] = strtolower(civicrm_api_get_function_name($ctx['entityNameCamel'], $ctx['actionNameCamel'], self::API_VERSION));
     } elseif (function_exists('_civicrm_api_get_entity_name_from_camel')) {
         $ctx['apiFunction'] = 'civicrm_api' . self::API_VERSION . '_' . _civicrm_api_get_entity_name_from_camel($ctx['entityNameCamel']) . '_' . $ctx['actionNameCamel'];
     } else {
         throw new Exception("Failed to determine proper API function name. Perhaps the API internals have changed?");
     }
     $ctx['apiFile'] = $basedir->string('api', 'v3', $ctx['entityNameCamel'], $ctx['actionNameCamel'] . '.php');
     $ctx['apiCronFile'] = $basedir->string('api', 'v3', $ctx['entityNameCamel'], $ctx['actionNameCamel'] . '.mgd.php');
     $dirs = new Dirs(array(dirname($ctx['apiFile'])));
     $dirs->save($ctx, $output);
     if (!file_exists($ctx['apiFile'])) {
         $output->writeln(sprintf('<info>Write %s</info>', $ctx['apiFile']));
         file_put_contents($ctx['apiFile'], $this->getContainer()->get('templating')->render('CRMCivixBundle:Code:api.php.php', $ctx));
     } else {
         $output->writeln(sprintf('<error>Skip %s: file already exists</error>', $ctx['apiFile']));
     }
     if ($input->getOption('schedule')) {
         if (!file_exists($ctx['apiCronFile'])) {
             $mgdEntities = array(array('name' => 'Cron:' . $ctx['entityNameCamel'] . '.' . $ctx['actionNameCamel'], 'entity' => 'Job', 'params' => array('version' => 3, 'name' => sprintf('Call %s.%s API', $ctx['entityNameCamel'], $ctx['actionNameCamel']), 'description' => sprintf('Call %s.%s API', $ctx['entityNameCamel'], $ctx['actionNameCamel']), 'run_frequency' => $input->getOption('schedule'), 'api_entity' => $ctx['entityNameCamel'], 'api_action' => $ctx['actionNameCamel'], 'parameters' => '')));
             $header = "// This file declares a managed database record of type \"Job\".\n" . "// The record will be automatically inserted, updated, or deleted from the\n" . "// database as appropriate. For more details, see \"hook_civicrm_managed\" at:\n" . "// http://wiki.civicrm.org/confluence/display/CRMDOC42/Hook+Reference";
             $mgdBuilder = new PhpData($ctx['apiCronFile'], $header);
             $mgdBuilder->set($mgdEntities);
             $mgdBuilder->save($ctx, $output);
         } else {
             $output->writeln(sprintf('<error>Skip %s: file already exists</error>', $ctx['apiCronFile']));
         }
     }
     $module = new Module($this->getContainer()->get('templating'));
     $module->loadInit($ctx);
     $module->save($ctx, $output);
 }
开发者ID:twomice,项目名称:civix,代码行数:62,代码来源:AddApiCommand.php

示例12: _civicrm_api3_get_DAO

/**
 * Function to return the DAO of the function or Entity
 * @param String $name  either a function of the api (civicrm_{entity}_create or the entity name
 * return the DAO name to manipulate this function
 * eg. "civicrm_api3_contact_create" or "Contact" will return "CRM_Contact_BAO_Contact"
 * @return mixed|string
 */
function _civicrm_api3_get_DAO($name)
{
    if (strpos($name, 'civicrm_api3') !== FALSE) {
        $last = strrpos($name, '_');
        // len ('civicrm_api3_') == 13
        $name = substr($name, 13, $last - 13);
    }
    $name = _civicrm_api_get_camel_name($name, 3);
    if ($name == 'Individual' || $name == 'Household' || $name == 'Organization') {
        $name = 'Contact';
    }
    // hack to deal with incorrectly named BAO/DAO - see CRM-10859
    // FIXME: DAO should be renamed CRM_Mailing_DAO_MailingRecipients
    // but am not confident mailing_recipients is tested so have not tackled.
    if ($name == 'MailingRecipients') {
        return 'CRM_Mailing_DAO_Recipients';
    }
    // FIXME: DAO should be renamed CRM_Mailing_DAO_MailingComponent
    if ($name == 'MailingComponent') {
        return 'CRM_Mailing_DAO_Component';
    }
    // FIXME: DAO should be renamed CRM_ACL_DAO_AclRole
    if ($name == 'AclRole') {
        return 'CRM_ACL_DAO_EntityRole';
    }
    // FIXME: DAO should be renamed CRM_SMS_DAO_SmsProvider
    // But this would impact SMS extensions so need to coordinate
    // Probably best approach is to migrate them to use the api and decouple them from core BAOs
    if ($name == 'SmsProvider') {
        return 'CRM_SMS_DAO_Provider';
    }
    // FIXME: DAO names should follow CamelCase convention
    if ($name == 'Im' || $name == 'Acl') {
        $name = strtoupper($name);
    }
    $dao = CRM_Core_DAO_AllCoreTables::getFullName($name);
    if ($dao || !$name) {
        return $dao;
    }
    // Really weird apis can declare their own DAO name. Not sure if this is a good idea...
    if (file_exists("api/v3/{$name}.php")) {
        include_once "api/v3/{$name}.php";
    }
    $daoFn = "_civicrm_api3_" . _civicrm_api_get_entity_name_from_camel($name) . "_DAO";
    if (function_exists($daoFn)) {
        return $daoFn();
    }
    return NULL;
}
开发者ID:ruchirapingale,项目名称:civicrm-core,代码行数:56,代码来源:utils.php

示例13: civicrm_api3_generic_getfields

/**
 * Get information about fields for a given api request. Getfields information
 * is used for documentation, validation, default setting
 * We first query the scheme using the $dao->fields function & then augment
 * that information by calling the _spec functions that apply to the relevant function
 * Note that we use 'unique' field names as described in the xml/schema files
 * for get requests & just field name for create. This is because some get functions
 * access multiple objects e.g. contact api accesses is_deleted from the activity
 * table & from the contact table
 *
 * @param array $apiRequest api request as an array. Keys are
 *  - entity: string
 *  - action: string
 *  - version: string
 *  - function: callback (mixed)
 *  - params: array, varies
 *  @return array API success object
 */
function civicrm_api3_generic_getfields($apiRequest)
{
    static $results = array();
    if (CRM_Utils_Array::value('cache_clear', $apiRequest['params'])) {
        $results = array();
    }
    $entity = _civicrm_api_get_camel_name($apiRequest['entity']);
    $lcase_entity = _civicrm_api_get_entity_name_from_camel($entity);
    $subentity = CRM_Utils_Array::value('contact_type', $apiRequest['params']);
    $action = strtolower(CRM_Utils_Array::value('action', $apiRequest['params']));
    if ($action == 'getvalue' || $action == 'getvalue' || $action == 'getcount') {
        $action = 'get';
    }
    if (empty($action)) {
        if (CRM_Utils_Array::value($entity . $subentity, $results) && CRM_Utils_Array::value('values', $results[$entity . $subentity])) {
            return $results[$entity . $subentity];
        } else {
            $values = _civicrm_api_get_fields($entity);
            $results[$entity] = civicrm_api3_create_success($values, $apiRequest['params'], $entity, 'getfields');
            return $results[$entity];
        }
    }
    // determines whether to use unique field names - seem comment block above
    $unique = TRUE;
    if (isset($results[$entity . $subentity]) && CRM_Utils_Array::value($action, $results[$entity])) {
        return $results[$entity . $subentity][$action];
    }
    // defaults based on data model and API policy
    switch ($action) {
        case 'getfields':
            $values = _civicrm_api_get_fields($entity, $apiRequest['params']);
            $results[$entity][$action] = civicrm_api3_create_success($values, $apiRequest['params'], $entity, 'getfields');
            return $results[$entity][$action];
        case 'create':
        case 'update':
        case 'replace':
            $unique = FALSE;
        case 'get':
            $metadata = _civicrm_api_get_fields($apiRequest['entity'], $unique, $apiRequest['params']);
            if (empty($metadata['id']) && !empty($metadata[$apiRequest['entity'] . '_id'])) {
                $metadata['id'] = $metadata[$lcase_entity . '_id'];
                $metadata['id']['api.aliases'] = array($lcase_entity . '_id');
                unset($metadata[$lcase_entity . '_id']);
            }
            break;
        case 'delete':
            $metadata = array('id' => array('title' => 'Unique Identifier', 'api.required' => 1, 'api.aliases' => array($lcase_entity . '_id')));
            break;
        default:
            // oddballs are on their own
            $metadata = array();
    }
    // find any supplemental information
    $hypApiRequest = array('entity' => $apiRequest['entity'], 'action' => $action, 'version' => $apiRequest['version']);
    $hypApiRequest += _civicrm_api_resolve($hypApiRequest);
    $helper = '_' . $hypApiRequest['function'] . '_spec';
    if (function_exists($helper)) {
        // alter
        $helper($metadata);
    }
    foreach ($metadata as $fieldname => $field) {
        if (array_key_exists('pseudoconstant', $field) && !CRM_Utils_Array::value('FKClassName', $field)) {
            $options = civicrm_api('constant', 'get', array('version' => 3, 'name' => $field['pseudoconstant']));
            if (is_array(CRM_Utils_Array::value('values', $options))) {
                $metadata[$fieldname]['options'] = $options['values'];
            }
        }
        if (array_key_exists('enumValues', $field)) {
            $metadata[$fieldname]['options'] = explode(',', $field['enumValues']);
        }
    }
    $results[$entity][$action] = civicrm_api3_create_success($metadata, $apiRequest['params'], NULL, 'getfields');
    return $results[$entity][$action];
}
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:92,代码来源:Generic.php

示例14: _civicrm_api_call_nested_api

 /**
  * Call any nested api calls
  *
  * TODO: We don't really need this to be a separate function.
  */
 protected function _civicrm_api_call_nested_api(&$params, &$result, $action, $entity, $version)
 {
     $entity = _civicrm_api_get_entity_name_from_camel($entity);
     //we don't need to worry about nested api in the getfields/getoptions actions, so just return immediately
     if (in_array(strtolower($action), array('getfields', 'getoptions'))) {
         return;
     }
     if (strtolower($action) == 'getsingle') {
         // I don't understand the protocol here, but we don't want
         // $result to be a recursive array
         // $result['values'][0] = $result;
         $oldResult = $result;
         $result = array('values' => array(0 => $oldResult));
     }
     foreach ($params as $field => $newparams) {
         if ((is_array($newparams) || $newparams === 1) && $field != 'api.has_parent' && substr($field, 0, 3) == 'api') {
             // 'api.participant.delete' => 1 is a valid options - handle 1 instead of an array
             if ($newparams === 1) {
                 $newparams = array('version' => $version);
             }
             // can be api_ or api.
             $separator = $field[3];
             if (!($separator == '.' || $separator == '_')) {
                 continue;
             }
             $subAPI = explode($separator, $field);
             $subaction = empty($subAPI[2]) ? $action : $subAPI[2];
             $subParams = array('debug' => \CRM_Utils_Array::value('debug', $params));
             $subEntity = $subAPI[1];
             foreach ($result['values'] as $idIndex => $parentAPIValues) {
                 if (strtolower($subEntity) != 'contact') {
                     //contact spits the dummy at activity_id so what else won't it like?
                     //set entity_id & entity table based on the parent's id & entity. e.g for something like
                     //note if the parent call is contact 'entity_table' will be set to 'contact' & 'id' to the contact id from
                     //the parent call.
                     //in this case 'contact_id' will also be set to the parent's id
                     $subParams["entity_id"] = $parentAPIValues['id'];
                     $subParams['entity_table'] = 'civicrm_' . _civicrm_api_get_entity_name_from_camel($entity);
                     $subParams[strtolower($entity) . "_id"] = $parentAPIValues['id'];
                 }
                 if (strtolower($entity) != 'contact' && \CRM_Utils_Array::value(strtolower($subEntity . "_id"), $parentAPIValues)) {
                     //e.g. if event_id is in the values returned & subentity is event then pass in event_id as 'id'
                     //don't do this for contact as it does some wierd things like returning primary email &
                     //thus limiting the ability to chain email
                     //TODO - this might need the camel treatment
                     $subParams['id'] = $parentAPIValues[$subEntity . "_id"];
                 }
                 if (\CRM_Utils_Array::value('entity_table', $result['values'][$idIndex]) == $subEntity) {
                     $subParams['id'] = $result['values'][$idIndex]['entity_id'];
                 }
                 // if we are dealing with the same entity pass 'id' through (useful for get + delete for example)
                 if (strtolower($entity) == strtolower($subEntity)) {
                     $subParams['id'] = $result['values'][$idIndex]['id'];
                 }
                 $subParams['version'] = $version;
                 if (!empty($params['check_permissions'])) {
                     $subParams['check_permissions'] = $params['check_permissions'];
                 }
                 $subParams['sequential'] = 1;
                 $subParams['api.has_parent'] = 1;
                 if (array_key_exists(0, $newparams)) {
                     $genericParams = $subParams;
                     // it is a numerically indexed array - ie. multiple creates
                     foreach ($newparams as $entityparams) {
                         $subParams = array_merge($genericParams, $entityparams);
                         _civicrm_api_replace_variables($subAPI[1], $subaction, $subParams, $result['values'][$idIndex], $separator);
                         $result['values'][$result['id']][$field][] = civicrm_api($subEntity, $subaction, $subParams);
                         if ($result['is_error'] === 1) {
                             throw new \Exception($subEntity . ' ' . $subaction . 'call failed with' . $result['error_message']);
                         }
                     }
                 } else {
                     $subParams = array_merge($subParams, $newparams);
                     _civicrm_api_replace_variables($subAPI[1], $subaction, $subParams, $result['values'][$idIndex], $separator);
                     $result['values'][$idIndex][$field] = civicrm_api($subEntity, $subaction, $subParams);
                     if (!empty($result['is_error'])) {
                         throw new \Exception($subEntity . ' ' . $subaction . 'call failed with' . $result['error_message']);
                     }
                 }
             }
         }
     }
     if (strtolower($action) == 'getsingle') {
         $result = $result['values'][0];
     }
 }
开发者ID:prashantgajare,项目名称:civicrm-core,代码行数:91,代码来源:ChainSubscriber.php

示例15: _civicrm_api3_get_DAO

/**
 * Function to return the DAO of the function or Entity
 * @param String $name  either a function of the api (civicrm_{entity}_create or the entity name
 * return the DAO name to manipulate this function
 * eg. "civicrm_api3_contact_create" or "Contact" will return "CRM_Contact_BAO_Contact"
 * @return mixed|string
 */
function _civicrm_api3_get_DAO($name)
{
    if (strpos($name, 'civicrm_api3') !== FALSE) {
        $last = strrpos($name, '_');
        // len ('civicrm_api3_') == 13
        $name = substr($name, 13, $last - 13);
    }
    $name = _civicrm_api_get_camel_name($name, 3);
    if ($name == 'Individual' || $name == 'Household' || $name == 'Organization') {
        $name = 'Contact';
    }
    //hack to deal with incorrectly named BAO/DAO - see CRM-10859 -
    // several of these have been removed but am not confident mailing_recipients is
    // tests so have not tackled.
    // correct approach for im is unclear
    if ($name == 'mailing_recipients' || $name == 'MailingRecipients') {
        return 'CRM_Mailing_BAO_Recipients';
    }
    if (strtolower($name) == 'im') {
        return 'CRM_Core_BAO_IM';
    }
    $dao = CRM_Core_DAO_AllCoreTables::getFullName($name);
    if ($dao || !$name) {
        return $dao;
    }
    // Really weird apis can declare their own DAO name. Not sure if this is a good idea...
    if (file_exists("api/v3/{$name}.php")) {
        include_once "api/v3/{$name}.php";
    }
    $daoFn = "_civicrm_api3_" . _civicrm_api_get_entity_name_from_camel($name) . "_DAO";
    if (function_exists($daoFn)) {
        return $daoFn();
    }
    return NULL;
}
开发者ID:hguru,项目名称:224Civi,代码行数:42,代码来源:utils.php


注:本文中的_civicrm_api_get_entity_name_from_camel函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。