|
|
@ -30,7 +30,49 @@ function fulcrm_collection_menu() {
|
|
|
|
return $items;
|
|
|
|
return $items;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function fulcrm_collection_to_form( $collection_data, $d = array() ) {
|
|
|
|
function fulcrm_collection_get_d_value( $d, $key ) {
|
|
|
|
|
|
|
|
$key = explode( '.', $key );
|
|
|
|
|
|
|
|
foreach ( $key as $bit ) {
|
|
|
|
|
|
|
|
if ( array_key_exists( $bit, $d ) )
|
|
|
|
|
|
|
|
$d = $d[ $bit ];
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $d;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _fulcrm_collection_set_d_value( &$d, $key, $value ) {
|
|
|
|
|
|
|
|
switch ( count( $key ) ) {
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
$d[ $key[ 0 ] ] = $value;
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
if ( !array_key_exists( $key[ 0 ], $d ) )
|
|
|
|
|
|
|
|
$d[ $key[ 0 ] ] = array();
|
|
|
|
|
|
|
|
return _fulcrm_collection_set_value( $d[ $key[ 0 ] ], array_slice( $key, 1 ), $value );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function fulcrm_collection_set_d_value( &$d, $key, $value ) {
|
|
|
|
|
|
|
|
return _fulcrm_collection_set_d_value( $d, explode( '.', $key ), $value );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function fulcrm_collection_form_values_to_d( $prefix, $values ) {
|
|
|
|
|
|
|
|
$d = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ( $values as $k => $v ) {
|
|
|
|
|
|
|
|
$bits = explode( '/fulcrm/', $k );
|
|
|
|
|
|
|
|
if ( ( count( $bits ) === 2 ) && ( $bits[ 0 ] === $prefix ) ) {
|
|
|
|
|
|
|
|
fulcrm_collection_set_d_value( $d, $bits[ 1 ], $v );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $d;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function fulcrm_collection_to_form( $prefix, $collection_data, $d = array() ) {
|
|
|
|
$form = array();
|
|
|
|
$form = array();
|
|
|
|
|
|
|
|
|
|
|
|
foreach ( $collection_data[ '_structure' ] as $set_data ) {
|
|
|
|
foreach ( $collection_data[ '_structure' ] as $set_data ) {
|
|
|
@ -46,11 +88,12 @@ function fulcrm_collection_to_form( $collection_data, $d = array() ) {
|
|
|
|
case 'text':
|
|
|
|
case 'text':
|
|
|
|
case 'email':
|
|
|
|
case 'email':
|
|
|
|
case 'tel':
|
|
|
|
case 'tel':
|
|
|
|
$fieldset[ $field_data[ 'key' ] ] = array( '#type' => 'textfield',
|
|
|
|
$fieldset[ $prefix . '/fulcrm/' . $field_data[ 'key' ] ] = array( '#type' => 'textfield',
|
|
|
|
'#title' => $field_data[ 'name' ],
|
|
|
|
'#title' => $field_data[ 'name' ],
|
|
|
|
'#description' => $field_data[ 'description' ],
|
|
|
|
'#description' => $field_data[ 'description' ],
|
|
|
|
'#required' => $field_data[ 'required' ],
|
|
|
|
'#required' => $field_data[ 'required' ],
|
|
|
|
);
|
|
|
|
'#default_value' => fulcrm_collection_get_d_value( $d, $field_data[ 'key' ] ),
|
|
|
|
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
drupal_set_message( t('Cannot handle ":type" collection structure.', array( ':type' => $field_data[ 'type' ] )), 'error' );
|
|
|
|
drupal_set_message( t('Cannot handle ":type" collection structure.', array( ':type' => $field_data[ 'type' ] )), 'error' );
|
|
|
|