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


PHP CRM_Core_DAO::_testEntitiesToSkip方法代码示例

本文整理汇总了PHP中CRM_Core_DAO::_testEntitiesToSkip方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_DAO::_testEntitiesToSkip方法的具体用法?PHP CRM_Core_DAO::_testEntitiesToSkip怎么用?PHP CRM_Core_DAO::_testEntitiesToSkip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Core_DAO的用法示例。


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

示例1: createTestObject

 /**
  * Creates a test object, including any required objects it needs via recursion
  * createOnly: only create in database, do not store or return the objects (useful for perf testing)
  * ONLY USE FOR TESTING
  *
  * @param string $daoName
  * @param array $params
  * @param int $numObjects
  * @param bool $createOnly
  *
  * @return object|array|NULL
  *   NULL if $createOnly. A single object if $numObjects==1. Otherwise, an array of multiple objects.
  */
 public static function createTestObject($daoName, $params = array(), $numObjects = 1, $createOnly = FALSE)
 {
     //this is a test function  also backtrace is set for the test suite it sometimes unsets itself
     // so we re-set here in case
     $config = CRM_Core_Config::singleton();
     $config->backtrace = TRUE;
     static $counter = 0;
     CRM_Core_DAO::$_testEntitiesToSkip = array('CRM_Core_DAO_Worldregion', 'CRM_Core_DAO_StateProvince', 'CRM_Core_DAO_Country', 'CRM_Core_DAO_Domain', 'CRM_Financial_DAO_FinancialType');
     // Prefer to instantiate BAO's instead of DAO's (when possible)
     // so that assignTestValue()/assignTestFK() can be overloaded.
     $baoName = str_replace('_DAO_', '_BAO_', $daoName);
     if (class_exists($baoName)) {
         $daoName = $baoName;
     }
     for ($i = 0; $i < $numObjects; ++$i) {
         ++$counter;
         /** @var CRM_Core_DAO $object */
         $object = new $daoName();
         $fields =& $object->fields();
         foreach ($fields as $fieldName => $fieldDef) {
             $dbName = $fieldDef['name'];
             $FKClassName = CRM_Utils_Array::value('FKClassName', $fieldDef);
             $required = CRM_Utils_Array::value('required', $fieldDef);
             if (CRM_Utils_Array::value($dbName, $params) !== NULL && !is_array($params[$dbName])) {
                 $object->{$dbName} = $params[$dbName];
             } elseif ($dbName != 'id') {
                 if ($FKClassName != NULL) {
                     $object->assignTestFK($fieldName, $fieldDef, $params);
                     continue;
                 } else {
                     $object->assignTestValue($fieldName, $fieldDef, $counter);
                 }
             }
         }
         $object->save();
         if (!$createOnly) {
             $objects[$i] = $object;
         } else {
             unset($object);
         }
     }
     if ($createOnly) {
         return NULL;
     } elseif ($numObjects == 1) {
         return $objects[0];
     } else {
         return $objects;
     }
 }
开发者ID:konadave,项目名称:civicrm-core,代码行数:62,代码来源:DAO.php

示例2: createTestObject

 static function createTestObject($daoName, $params = array(), $numObjects = 1, $createOnly = FALSE)
 {
     static $counter = 0;
     CRM_Core_DAO::$_testEntitiesToSkip = array('CRM_Core_DAO_Worldregion', 'CRM_Core_DAO_StateProvince', 'CRM_Core_DAO_Country', 'CRM_Core_DAO_Domain');
     for ($i = 0; $i < $numObjects; ++$i) {
         ++$counter;
         $object = new $daoName();
         $fields =& $object->fields();
         foreach ($fields as $name => $value) {
             $dbName = $value['name'];
             if ($dbName == 'contact_sub_type' && empty($params['contact_sub_type'])) {
                 //coming up with a rule to set this is too complex let's not set it
                 continue;
             }
             $FKClassName = CRM_Utils_Array::value('FKClassName', $value);
             $required = CRM_Utils_Array::value('required', $value);
             if (CRM_Utils_Array::value($dbName, $params) !== NULL && !is_array($params[$dbName])) {
                 $object->{$dbName} = $params[$dbName];
             } elseif ($dbName != 'id') {
                 if ($FKClassName != NULL) {
                     //skip the FK if it is not required
                     // if it's contact id we should create even if not required
                     // we'll have a go @ fetching first though
                     // we WILL create campaigns though for so tests with a campaign pseudoconstant will complete
                     if ($FKClassName === 'CRM_Campaign_DAO_Campaign' && $daoName != $FKClassName) {
                         $required = TRUE;
                     }
                     if (!$required && $dbName != 'contact_id') {
                         $fkDAO = new $FKClassName();
                         if ($fkDAO->find(TRUE)) {
                             $object->{$dbName} = $fkDAO->id;
                         }
                         unset($fkDAO);
                         continue;
                     }
                     if (in_array($FKClassName, CRM_Core_DAO::$_testEntitiesToSkip)) {
                         $depObject = new $FKClassName();
                         $depObject->find(TRUE);
                     } elseif ($daoName == 'CRM_Member_DAO_MembershipType' && $name == 'member_of_contact_id') {
                         // FIXME: the fields() metadata is not specific enough
                         $depObject = CRM_Core_DAO::createTestObject($FKClassName, array('contact_type' => 'Organization'));
                     } else {
                         //if it is required we need to generate the dependency object first
                         $depObject = CRM_Core_DAO::createTestObject($FKClassName, CRM_Utils_Array::value($dbName, $params, 1));
                     }
                     $object->{$dbName} = $depObject->id;
                     unset($depObject);
                     continue;
                 }
                 // Pick an option value if needed
                 if ($value['type'] !== CRM_Utils_Type::T_BOOLEAN) {
                     $options = $daoName::buildOptions($dbName, 'create');
                     if ($options) {
                         $object->{$dbName} = key($options);
                         continue;
                     }
                 }
                 switch ($value['type']) {
                     case CRM_Utils_Type::T_INT:
                     case CRM_Utils_Type::T_FLOAT:
                     case CRM_Utils_Type::T_MONEY:
                         $object->{$dbName} = $counter;
                         break;
                     case CRM_Utils_Type::T_BOOLEAN:
                         if (isset($value['default'])) {
                             $object->{$dbName} = $value['default'];
                         } elseif ($value['name'] == 'is_deleted' || $value['name'] == 'is_test') {
                             $object->{$dbName} = 0;
                         } else {
                             $object->{$dbName} = 1;
                         }
                         break;
                     case CRM_Utils_Type::T_DATE:
                     case CRM_Utils_Type::T_TIMESTAMP:
                     case CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME:
                         $object->{$dbName} = '19700101';
                         if ($dbName == 'end_date') {
                             // put this in the future
                             $object->{$dbName} = '20200101';
                         }
                         break;
                     case CRM_Utils_Type::T_TIME:
                         CRM_Core_Error::fatal('T_TIME shouldnt be used.');
                         //$object->$dbName='000000';
                         //break;
                     //$object->$dbName='000000';
                     //break;
                     case CRM_Utils_Type::T_CCNUM:
                         $object->{$dbName} = '4111 1111 1111 1111';
                         break;
                     case CRM_Utils_Type::T_URL:
                         $object->{$dbName} = 'http://www.civicrm.org';
                         break;
                     case CRM_Utils_Type::T_STRING:
                     case CRM_Utils_Type::T_BLOB:
                     case CRM_Utils_Type::T_MEDIUMBLOB:
                     case CRM_Utils_Type::T_TEXT:
                     case CRM_Utils_Type::T_LONGTEXT:
                     case CRM_Utils_Type::T_EMAIL:
                     default:
//.........这里部分代码省略.........
开发者ID:archcidburnziso,项目名称:civicrm-core,代码行数:101,代码来源:DAO.php

示例3: createTestObject

 /**
  * Creates a test object, including any required objects it needs via recursion
  * createOnly: only create in database, do not store or return the objects (useful for perf testing)
  * ONLY USE FOR TESTING
  *
  * @param $daoName
  * @param array $params
  * @param int $numObjects
  * @param bool $createOnly
  *
  * @return
  */
 static function createTestObject($daoName, $params = array(), $numObjects = 1, $createOnly = FALSE)
 {
     //this is a test function  also backtrace is set for the test suite it sometimes unsets itself
     // so we re-set here in case
     $config = CRM_Core_Config::singleton();
     $config->backtrace = TRUE;
     static $counter = 0;
     CRM_Core_DAO::$_testEntitiesToSkip = array('CRM_Core_DAO_Worldregion', 'CRM_Core_DAO_StateProvince', 'CRM_Core_DAO_Country', 'CRM_Core_DAO_Domain');
     for ($i = 0; $i < $numObjects; ++$i) {
         ++$counter;
         /** @var CRM_Core_DAO $object */
         $object = new $daoName();
         $fields =& $object->fields();
         foreach ($fields as $fieldName => $fieldDef) {
             $dbName = $fieldDef['name'];
             $FKClassName = CRM_Utils_Array::value('FKClassName', $fieldDef);
             $required = CRM_Utils_Array::value('required', $fieldDef);
             if (CRM_Utils_Array::value($dbName, $params) !== NULL && !is_array($params[$dbName])) {
                 $object->{$dbName} = $params[$dbName];
             } elseif ($dbName != 'id') {
                 if ($FKClassName != NULL) {
                     $object->assignTestFK($fieldName, $fieldDef, $params);
                     continue;
                 } else {
                     $object->assignTestValue($fieldName, $fieldDef, $counter);
                 }
             }
         }
         $object->save();
         if (!$createOnly) {
             $objects[$i] = $object;
         } else {
             unset($object);
         }
     }
     if ($createOnly) {
         return;
     } elseif ($numObjects == 1) {
         return $objects[0];
     } else {
         return $objects;
     }
 }
开发者ID:prashantgajare,项目名称:civicrm-core,代码行数:55,代码来源:DAO.php

示例4: createTestObject

 static function createTestObject($daoName, $params = array(), $numObjects = 1, $createOnly = FALSE)
 {
     static $counter = 0;
     CRM_Core_DAO::$_testEntitiesToSkip = array('CRM_Core_DAO_Worldregion', 'CRM_Core_DAO_StateProvince', 'CRM_Core_DAO_Country', 'CRM_Core_DAO_Domain');
     require_once str_replace('_', DIRECTORY_SEPARATOR, $daoName) . ".php";
     for ($i = 0; $i < $numObjects; ++$i) {
         ++$counter;
         eval('$object   = new ' . $daoName . '( );');
         $fields =& $object->fields();
         foreach ($fields as $name => $value) {
             $dbName = $value['name'];
             $FKClassName = CRM_Utils_Array::value('FKClassName', $value);
             $required = CRM_Utils_Array::value('required', $value);
             if (CRM_Utils_Array::value($dbName, $params) !== NULL && !is_array($params[$dbName])) {
                 $object->{$dbName} = $params[$dbName];
             } elseif ($dbName != 'id') {
                 if ($FKClassName != NULL) {
                     //skip the FK if it is not required
                     // if it's contact id we should create even if not required
                     if (!$required && $dbName != 'contact_id') {
                         continue;
                     }
                     if (in_array($FKClassName, CRM_Core_DAO::$_testEntitiesToSkip)) {
                         $depObject = new $FKClassName();
                         $depObject->find(true);
                     } elseif ($daoName == 'CRM_Member_DAO_MembershipType' && $name == 'member_of_contact_id') {
                         // FIXME: the fields() metadata is not specific enough
                         $depObject = CRM_Core_DAO::createTestObject($FKClassName, array('contact_type' => 'Organization'));
                     } else {
                         //if it is required we need to generate the dependency object first
                         $depObject = CRM_Core_DAO::createTestObject($FKClassName, CRM_Utils_Array::value($dbName, $params, 1));
                     }
                     $object->{$dbName} = $depObject->id;
                     unset($depObject);
                     continue;
                 }
                 $constant = CRM_Utils_Array::value('pseudoconstant', $value);
                 if (!empty($constant)) {
                     $constantOptions = array_keys(CRM_Core_PseudoConstant::getConstant($constant));
                     $object->{$dbName} = $constantOptions[0];
                     continue;
                 }
                 $enum = CRM_Utils_Array::value('enumValues', $value);
                 if (!empty($enum)) {
                     $options = explode(',', $enum);
                     $object->{$dbName} = $options[0];
                     continue;
                 }
                 switch ($value['type']) {
                     case CRM_Utils_Type::T_INT:
                     case CRM_Utils_Type::T_FLOAT:
                     case CRM_Utils_Type::T_MONEY:
                         $object->{$dbName} = $counter;
                         break;
                     case CRM_Utils_Type::T_BOOL:
                     case CRM_Utils_Type::T_BOOLEAN:
                         if (isset($value['default'])) {
                             $object->{$dbName} = $value['default'];
                         } elseif ($value['name'] == 'is_deleted' || $value['name'] == 'is_test') {
                             $object->{$dbName} = 0;
                         } else {
                             $object->{$dbName} = 1;
                         }
                         break;
                     case CRM_Utils_Type::T_DATE:
                     case CRM_Utils_Type::T_TIMESTAMP:
                         $object->{$dbName} = '19700101';
                         break;
                     case CRM_Utils_Type::T_TIME:
                         CRM_Core_Error::fatal('T_TIME shouldnt be used.');
                         //$object->$dbName='000000';
                         //break;
                     //$object->$dbName='000000';
                     //break;
                     case CRM_Utils_Type::T_CCNUM:
                         $object->{$dbName} = '4111 1111 1111 1111';
                         break;
                     case CRM_Utils_Type::T_URL:
                         $object->{$dbName} = 'http://www.civicrm.org';
                         break;
                     case CRM_Utils_Type::T_STRING:
                     case CRM_Utils_Type::T_BLOB:
                     case CRM_Utils_Type::T_MEDIUMBLOB:
                     case CRM_Utils_Type::T_TEXT:
                     case CRM_Utils_Type::T_LONGTEXT:
                     case CRM_Utils_Type::T_EMAIL:
                     default:
                         if (isset($value['enumValues'])) {
                             if (isset($value['default'])) {
                                 $object->{$dbName} = $value['default'];
                             } else {
                                 if (is_array($value['enumValues'])) {
                                     $object->{$dbName} = $value['enumValues'][0];
                                 } else {
                                     $defaultValues = explode(',', $value['enumValues']);
                                     $object->{$dbName} = $defaultValues[0];
                                 }
                             }
                         } else {
                             $object->{$dbName} = $dbName . '_' . $counter;
//.........这里部分代码省略.........
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:101,代码来源:DAO.php


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