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


PHP CRM_Core_DAO::getDatabaseConnection方法代码示例

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


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

示例1: __construct

 public function __construct($tableName = NULL, $createSql = NULL, $createTable = FALSE)
 {
     $dao = new CRM_Core_DAO();
     $db = $dao->getDatabaseConnection();
     if ($createTable) {
         if (!$createSql) {
             CRM_Core_Error::fatal('Either an existing table name or an SQL query to build one are required');
         }
         // FIXME: we should regen this table's name if it exists rather than drop it
         if (!$tableName) {
             $tableName = 'civicrm_import_job_' . md5(uniqid(rand(), TRUE));
         }
         $db->query("DROP TABLE IF EXISTS {$tableName}");
         $db->query("CREATE TABLE {$tableName} ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci {$createSql}");
     }
     if (!$tableName) {
         CRM_Core_Error::fatal('Import Table is required.');
     }
     $this->_tableName = $tableName;
     //initialize the properties.
     $properties = array('mapperKeys', 'mapperRelated', 'mapperLocTypes', 'mapperPhoneTypes', 'mapperImProviders', 'mapperWebsiteTypes', 'mapperRelatedContactType', 'mapperRelatedContactDetails', 'mapperRelatedContactLocType', 'mapperRelatedContactPhoneType', 'mapperRelatedContactImProvider', 'mapperRelatedContactWebsiteType');
     foreach ($properties as $property) {
         $this->{"_{$property}"} = array();
     }
 }
开发者ID:hguru,项目名称:224Civi,代码行数:25,代码来源:ImportJob.php

示例2: __construct

 public function __construct($tableName = null, $createSql = null, $createTable = false)
 {
     $dao = new CRM_Core_DAO();
     $db = $dao->getDatabaseConnection();
     if ($createTable) {
         if (!$createSql) {
             CRM_Core_Error::fatal('Either an existing table name or an SQL query to build one are required');
         }
         // FIXME: we should regen this table's name if it exists rather than drop it
         if (!$tableName) {
             $tableName = 'civicrm_import_job_' . md5(uniqid(rand(), true));
         }
         $db->query("DROP TABLE IF EXISTS {$tableName}");
         $db->query("CREATE TABLE {$tableName} ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci {$createSql}");
     }
     if (!$tableName) {
         CRM_Core_Error::fatal('Import Table is required.');
     }
     $this->_tableName = $tableName;
     $this->_mapperKeys = array();
     $this->_mapperLocTypes = array();
     $this->_mapperPhoneTypes = array();
     $this->_mapperImProviders = array();
     $this->_mapperRelated = array();
     $this->_mapperRelatedContactType = array();
     $this->_mapperRelatedContactDetails = array();
     $this->_mapperRelatedContactLocType = array();
     $this->_mapperRelatedContactPhoneType = array();
     $this->_mapperRelatedContactImProvider = array();
 }
开发者ID:bhirsch,项目名称:voipdev,代码行数:30,代码来源:ImportJob.php

示例3: testToCsv

 /**
  * Test the to csv function.
  *
  * @param string $fileName
  *
  * @dataProvider getCsvFiles
  */
 public function testToCsv($fileName)
 {
     $dataSource = new CRM_Import_DataSource_Csv();
     $params = array('uploadFile' => array('name' => __DIR__ . '/' . $fileName), 'skipColumnHeader' => TRUE);
     // Get the PEAR::DB object
     $dao = new CRM_Core_DAO();
     $db = $dao->getDatabaseConnection();
     $form = new CRM_Contact_Import_Form_DataSource();
     $form->controller = new CRM_Contact_Import_Controller();
     $dataSource->postProcess($params, $db, $form);
     $tableName = $form->get('importTableName');
     $this->assertEquals(4, CRM_Core_DAO::singleValueQuery("SELECT LENGTH(last_name) FROM {$tableName}"), $fileName . ' failed on last_name');
     $this->assertEquals(21, CRM_Core_DAO::singleValueQuery("SELECT LENGTH(email) FROM {$tableName}"), $fileName . ' failed on email');
     CRM_Core_DAO::executeQuery("DROP TABLE {$tableName}");
 }
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:22,代码来源:CsvTest.php

示例4: postProcess

 /**
  * Call the DataSource's postProcess method to take over
  * and then setup some common data structures for the next step
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $this->controller->resetPage('MapField');
     if ($this->_dataSourceIsValid) {
         // Setup the params array
         $this->_params = $this->controller->exportValues($this->_name);
         $storeParams = array('onDuplicate' => 'onDuplicate', 'dedupe' => 'dedupe', 'contactType' => 'contactType', 'contactSubType' => 'subType', 'dateFormats' => 'dateFormats', 'savedMapping' => 'savedMapping');
         foreach ($storeParams as $storeName => $storeValueName) {
             ${$storeName} = $this->exportValue($storeValueName);
             $this->set($storeName, ${$storeName});
         }
         $this->set('dataSource', $this->_params['dataSource']);
         $this->set('skipColumnHeader', CRM_Utils_Array::value('skipColumnHeader', $this->_params));
         $session = CRM_Core_Session::singleton();
         $session->set('dateTypes', $dateFormats);
         // Get the PEAR::DB object
         $dao = new CRM_Core_DAO();
         $db = $dao->getDatabaseConnection();
         //hack to prevent multiple tables.
         $this->_params['import_table_name'] = $this->get('importTableName');
         if (!$this->_params['import_table_name']) {
             $this->_params['import_table_name'] = 'civicrm_import_job_' . md5(uniqid(rand(), TRUE));
         }
         $this->_dataSourceClass->postProcess($this->_params, $db, $this);
         // We should have the data in the DB now, parse it
         $importTableName = $this->get('importTableName');
         $fieldNames = $this->_prepareImportTable($db, $importTableName);
         $mapper = array();
         $parser = new CRM_Contact_Import_Parser_Contact($mapper);
         $parser->setMaxLinesToProcess(100);
         $parser->run($importTableName, $mapper, CRM_Import_Parser::MODE_MAPFIELD, $contactType, $fieldNames['pk'], $fieldNames['status'], CRM_Import_Parser::DUPLICATE_SKIP, NULL, NULL, FALSE, CRM_Contact_Import_Parser::DEFAULT_TIMEOUT, $contactSubType, $dedupe);
         // add all the necessary variables to the form
         $parser->set($this);
     } else {
         CRM_Core_Error::fatal("Invalid DataSource on form post. This shouldn't happen!");
     }
 }
开发者ID:prashantgajare,项目名称:civicrm-core,代码行数:44,代码来源:DataSource.php

示例5: preProcess

 /**
  * Set variables up before form is built.
  */
 public function preProcess()
 {
     $dataSource = $this->get('dataSource');
     $skipColumnHeader = $this->get('skipColumnHeader');
     $this->_mapperFields = $this->get('fields');
     $this->_importTableName = $this->get('importTableName');
     $this->_onDuplicate = $this->get('onDuplicate');
     $highlightedFields = array();
     $highlightedFields[] = 'email';
     $highlightedFields[] = 'external_identifier';
     //format custom field names, CRM-2676
     switch ($this->get('contactType')) {
         case CRM_Import_Parser::CONTACT_INDIVIDUAL:
             $contactType = 'Individual';
             $highlightedFields[] = 'first_name';
             $highlightedFields[] = 'last_name';
             break;
         case CRM_Import_Parser::CONTACT_HOUSEHOLD:
             $contactType = 'Household';
             $highlightedFields[] = 'household_name';
             break;
         case CRM_Import_Parser::CONTACT_ORGANIZATION:
             $contactType = 'Organization';
             $highlightedFields[] = 'organization_name';
             break;
     }
     $this->_contactType = $contactType;
     if ($this->_onDuplicate == CRM_Import_Parser::DUPLICATE_SKIP) {
         unset($this->_mapperFields['id']);
     } else {
         $highlightedFields[] = 'id';
     }
     if ($this->_onDuplicate != CRM_Import_Parser::DUPLICATE_NOCHECK) {
         //Mark Dedupe Rule Fields as required, since it's used in matching contact
         foreach (array('Individual', 'Household', 'Organization') as $cType) {
             $ruleParams = array('contact_type' => $cType, 'used' => 'Unsupervised');
             $this->_dedupeFields[$cType] = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
         }
         //Modify mapper fields title if fields are present in dedupe rule
         if (is_array($this->_dedupeFields[$contactType])) {
             foreach ($this->_dedupeFields[$contactType] as $val) {
                 if ($valTitle = CRM_Utils_Array::value($val, $this->_mapperFields)) {
                     $this->_mapperFields[$val] = $valTitle . ' (match to contact)';
                 }
             }
         }
     }
     // retrieve and highlight required custom fields
     $formattedFieldNames = $this->formatCustomFieldName($this->_mapperFields);
     self::$customFields = CRM_Core_BAO_CustomField::getFields($this->_contactType);
     foreach (self::$customFields as $key => $attr) {
         if (!empty($attr['is_required'])) {
             $highlightedFields[] = "custom_{$key}";
         }
     }
     $this->assign('highlightedFields', $highlightedFields);
     $this->_formattedFieldNames[$contactType] = $this->_mapperFields = array_merge($this->_mapperFields, $formattedFieldNames);
     $columnNames = array();
     //get original col headers from csv if present.
     if ($dataSource == 'CRM_Import_DataSource_CSV' && $skipColumnHeader) {
         $columnNames = $this->get('originalColHeader');
     } else {
         // get the field names from the temp. DB table
         $dao = new CRM_Core_DAO();
         $db = $dao->getDatabaseConnection();
         $columnsQuery = "SHOW FIELDS FROM {$this->_importTableName}\n                         WHERE Field NOT LIKE '\\_%'";
         $columnsResult = $db->query($columnsQuery);
         while ($row = $columnsResult->fetchRow(DB_FETCHMODE_ASSOC)) {
             $columnNames[] = $row['Field'];
         }
     }
     $showColNames = TRUE;
     if ($dataSource == 'CRM_Import_DataSource_CSV' && !$skipColumnHeader) {
         $showColNames = FALSE;
     }
     $this->assign('showColNames', $showColNames);
     $this->_columnCount = count($columnNames);
     $this->_columnNames = $columnNames;
     $this->assign('columnNames', $columnNames);
     //$this->_columnCount = $this->get( 'columnCount' );
     $this->assign('columnCount', $this->_columnCount);
     $this->_dataValues = $this->get('dataValues');
     $this->assign('dataValues', $this->_dataValues);
     $this->assign('rowDisplayCount', 2);
 }
开发者ID:nganivet,项目名称:civicrm-core,代码行数:88,代码来源:MapField.php

示例6: postProcess

 /**
  * Clean up the import table we used.
  *
  * @return void
  */
 public function postProcess()
 {
     $dao = new CRM_Core_DAO();
     $db = $dao->getDatabaseConnection();
     $importTableName = $this->get('importTableName');
     // do a basic sanity check here
     if (strpos($importTableName, 'civicrm_import_job_') === 0) {
         $query = "DROP TABLE IF EXISTS {$importTableName}";
         $db->query($query);
     }
 }
开发者ID:kidaa30,项目名称:yes,代码行数:16,代码来源:Summary.php

示例7: updateImportRecord

 /**
  * Update the record with PK $id in the import database table
  *
  * @param int $id
  * @param array $params
  *
  * @return void
  * @access public
  */
 public function updateImportRecord($id, &$params)
 {
     $statusFieldName = $this->_statusFieldName;
     $primaryKeyName = $this->_primaryKeyName;
     if ($statusFieldName && $primaryKeyName) {
         $dao = new CRM_Core_DAO();
         $db = $dao->getDatabaseConnection();
         $query = "UPDATE {$this->_tableName}\n                      SET    {$statusFieldName} = ?,\n                             {$statusFieldName}Msg = ?\n                      WHERE  {$primaryKeyName} = ?";
         $args = array($params[$statusFieldName], CRM_Utils_Array::value("{$statusFieldName}Msg", $params), $id);
         //print "Running query: $query<br/>With arguments: ".$params[$statusFieldName].", ".$params["${statusFieldName}Msg"].", $id<br/>";
         $db->query($query, $args);
     }
 }
开发者ID:hguru,项目名称:224Civi,代码行数:22,代码来源:Parser.php

示例8: loadCaseSampleData

 /**
  * @param $dsn
  * @param string $fileName
  * @param bool $lineMode
  */
 public static function loadCaseSampleData($fileName, $lineMode = FALSE)
 {
     $dao = new CRM_Core_DAO();
     $db = $dao->getDatabaseConnection();
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     $multiLingual = (bool) $domain->locales;
     $smarty = CRM_Core_Smarty::singleton();
     $smarty->assign('multilingual', $multiLingual);
     $smarty->assign('locales', explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales));
     if (!$lineMode) {
         $string = $smarty->fetch($fileName);
         // change \r\n to fix windows issues
         $string = str_replace("\r\n", "\n", $string);
         //get rid of comments starting with # and --
         $string = preg_replace("/^#[^\n]*\$/m", "\n", $string);
         $string = preg_replace("/^(--[^-]).*/m", "\n", $string);
         $queries = preg_split('/;$/m', $string);
         foreach ($queries as $query) {
             $query = trim($query);
             if (!empty($query)) {
                 $res =& $db->query($query);
                 if (PEAR::isError($res)) {
                     die("Cannot execute {$query}: " . $res->getMessage());
                 }
             }
         }
     } else {
         $fd = fopen($fileName, "r");
         while ($string = fgets($fd)) {
             $string = preg_replace("/^#[^\n]*\$/m", "\n", $string);
             $string = preg_replace("/^(--[^-]).*/m", "\n", $string);
             $string = trim($string);
             if (!empty($string)) {
                 $res =& $db->query($string);
                 if (PEAR::isError($res)) {
                     die("Cannot execute {$string}: " . $res->getMessage());
                 }
             }
         }
     }
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:47,代码来源:Component.php


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