self::init($fresh);
}
+ /**
+ * (Quasi-Private) Do not call externally. For use by DAOs.
+ *
+ * @param string $dao
+ * Ex: 'CRM_Core_DAO_Address'.
+ * @param string $labelName
+ * Ex: 'address'.
+ * @param bool $prefix
+ * @param array $foreignDAOs
+ * @return array
+ */
+ public static function getExports($dao, $labelName, $prefix, $foreignDAOs) {
+ // Bug-level compatibility -- or sane behavior?
+ $cacheKey = $dao . ':export';
+ // $cacheKey = $dao . ':' . ($prefix ? 'export-prefix' : 'export');
+
+ if (!isset(Civi::$statics[__CLASS__][$cacheKey])) {
+ $exports = array();
+ $fields = $dao::fields();
+
+ foreach($fields as $name => $field) {
+ if (CRM_Utils_Array::value('export', $field)) {
+ if ($prefix) {
+ $exports[$labelName] = & $fields[$name];
+ } else {
+ $exports[$name] = & $fields[$name];
+ }
+ }
+ }
+
+ foreach ($foreignDAOs as $foreignDAO) {
+ $exports = array_merge($exports, $foreignDAO::export(TRUE));
+ }
+
+ Civi::$statics[__CLASS__][$cacheKey] = $exports;
+ }
+ return Civi::$statics[__CLASS__][$cacheKey];
+ }
+
+ /**
+ * (Quasi-Private) Do not call externally. For use by DAOs.
+ *
+ * @param string $dao
+ * Ex: 'CRM_Core_DAO_Address'.
+ * @param string $labelName
+ * Ex: 'address'.
+ * @param bool $prefix
+ * @param array $foreignDAOs
+ * @return array
+ */
+ public static function getImports($dao, $labelName, $prefix, $foreignDAOs) {
+ // Bug-level compatibility -- or sane behavior?
+ $cacheKey = $dao . ':import';
+ // $cacheKey = $dao . ':' . ($prefix ? 'import-prefix' : 'import');
+
+ if (!isset(Civi::$statics[__CLASS__][$cacheKey])) {
+ $imports = array();
+ $fields = $dao::fields();
+
+ foreach($fields as $name => $field) {
+ if (CRM_Utils_Array::value('import', $field)) {
+ if ($prefix) {
+ $imports[$labelName] = & $fields[$name];
+ } else {
+ $imports[$name] = & $fields[$name];
+ }
+ }
+ }
+
+ foreach ($foreignDAOs as $foreignDAO) {
+ $imports = array_merge($imports, $foreignDAO::import(TRUE));
+ }
+
+ Civi::$statics[__CLASS__][$cacheKey] = $imports;
+ }
+ return Civi::$statics[__CLASS__][$cacheKey];
+ }
+
}
*/
static $_links = null;
- /**
- * static instance to hold the values that can
- * be imported
- *
- * @var array
- */
- static $_import = null;
-
- /**
- * static instance to hold the values that can
- * be exported
- *
- * @var array
- */
- static $_export = null;
-
/**
* static value to see if we should log any modifications to
* this table in the civicrm_log table
* @return array
*/
static function &import( $prefix = false ) {ldelim}
- if ( ! ( self::$_import ) ) {ldelim}
- self::$_import = array ( );
- $fields = self::fields( );
- foreach ( $fields as $name => $field ) {ldelim}
- if ( CRM_Utils_Array::value( 'import', $field ) ) {ldelim}
- if ( $prefix ) {ldelim}
- self::$_import['{$table.labelName}'] =& $fields[$name];
- {rdelim} else {ldelim}
- self::$_import[$name] =& $fields[$name];
- {rdelim}
- {rdelim}
- {rdelim}
- {if $table.foreignKey}
- {foreach from=$table.foreignKey item=foreign}
- {if $foreign.import}
- self::$_import = array_merge( self::$_import,
- {$foreign.className}::import( true ) );
- {/if}
- {/foreach}
- {/if}
- {rdelim}
- return self::$_import;
+ $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, '{$table.labelName}', $prefix, array(
+ {if $table.foreignKey}{foreach from=$table.foreignKey item=foreign}
+ {if $foreign.import}'{$foreign.className}',{/if}
+ {/foreach}{/if}
+ ));
+ return $r;
{rdelim}
/**
* @return array
*/
static function &export( $prefix = false ) {ldelim}
- if ( ! ( self::$_export ) ) {ldelim}
- self::$_export = array ( );
- $fields = self::fields( );
- foreach ( $fields as $name => $field ) {ldelim}
- if ( CRM_Utils_Array::value( 'export', $field ) ) {ldelim}
- if ( $prefix ) {ldelim}
- self::$_export['{$table.labelName}'] =& $fields[$name];
- {rdelim} else {ldelim}
- self::$_export[$name] =& $fields[$name];
- {rdelim}
- {rdelim}
- {rdelim}
- {if $table.foreignKey}
- {foreach from=$table.foreignKey item=foreign}
- {if $foreign.export}
- self::$_export = array_merge( self::$_export,
- {$foreign.className}::export( true ) );
- {/if}
- {/foreach}
- {/if}
- {rdelim}
- return self::$_export;
+ $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, '{$table.labelName}', $prefix, array(
+ {if $table.foreignKey}{foreach from=$table.foreignKey item=foreign}
+ {if $foreign.export}'{$foreign.className}',{/if}
+ {/foreach}{/if}
+ ));
+ return $r;
{rdelim}
{rdelim}