|
@@ -7,7 +7,7 @@
|
|
|
*
|
|
|
* @copyright 2008 Ouest Systemes Informatiques (OSInet)
|
|
|
* @author Frederic G. MARAND
|
|
|
- * @version $Id: qbf.module,v 1.6 2008-08-28 09:53:54 marand Exp $
|
|
|
+ * @version $Id: qbf.module,v 1.7 2008-08-28 17:06:04 marand Exp $
|
|
|
* @license CeCILL 2.0
|
|
|
* @package QBF
|
|
|
*/
|
|
@@ -90,6 +90,7 @@ function qbf_transform_form($form_id)
|
|
|
$newForm['#multistep'] = TRUE;
|
|
|
$newForm['#redirect'] = FALSE;
|
|
|
$newForm['#after_build'][] = 'qbf_after_build';
|
|
|
+ $newForm['#submit'] = array('qbf_submit' => array());
|
|
|
// dsm($newForm);
|
|
|
return $newForm;
|
|
|
}
|
|
@@ -99,16 +100,23 @@ function qbf_transform_form($form_id)
|
|
|
*
|
|
|
* QBF-specific properties are:
|
|
|
* - #qbf : array of properties
|
|
|
- * - #level: only within #qbf @see QBF_* constants
|
|
|
+ * - #level: only within #qbf
|
|
|
*
|
|
|
- * @param array &$element
|
|
|
+ * @see QBF_* constants
|
|
|
+ *
|
|
|
+ * @param string $key
|
|
|
+ * @param array $element
|
|
|
* @return void
|
|
|
*/
|
|
|
-function _qbf_transform_element($key, array $element)
|
|
|
+function _qbf_transform_element($key, $element)
|
|
|
{
|
|
|
// dsm(array('key' => $key, 'element' => $element));
|
|
|
|
|
|
- // Types without a default transformation are not transformed
|
|
|
+ /**
|
|
|
+ * List default type transformations applied to widget by FAPI.
|
|
|
+ *
|
|
|
+ * Types without a default transformation are not transformed
|
|
|
+ */
|
|
|
static $arDefaultTypeTransformations = array
|
|
|
(
|
|
|
'button' => NULL,
|
|
@@ -122,7 +130,11 @@ function _qbf_transform_element($key, array $element)
|
|
|
// 'value' => 'value',
|
|
|
);
|
|
|
|
|
|
- // Properties without a default transformation are not transformed
|
|
|
+ /**
|
|
|
+ * List default property transformations applied to widget by FAPI property.
|
|
|
+ *
|
|
|
+ * Properties without a default transformation are not transformed
|
|
|
+ */
|
|
|
static $arDefaultPropertyTransformations = array
|
|
|
(
|
|
|
// Standard properties
|
|
@@ -143,7 +155,11 @@ function _qbf_transform_element($key, array $element)
|
|
|
'#validate' => NULL,
|
|
|
);
|
|
|
|
|
|
- // Property values causing element removal
|
|
|
+ /**
|
|
|
+ * List properties causing causing element removal.
|
|
|
+ *
|
|
|
+ * The key is the property name, the value is the one causing removal.
|
|
|
+ */
|
|
|
static $arKillerProperties = array
|
|
|
(
|
|
|
'#disabled' => TRUE,
|
|
@@ -371,4 +387,63 @@ function qbf_query_mapper($arQueryMap = array(), $arDefaults = array())
|
|
|
$ret[$name] = $item;
|
|
|
}
|
|
|
return $ret;
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Load a form_values array into a form used by QBF.
|
|
|
+ *
|
|
|
+ * This is typically useful when loading saved queries using qbf_load().
|
|
|
+ * For other cases, the mechanisms built within FAPI should be used instead.
|
|
|
+ *
|
|
|
+ * @see qbf_load()
|
|
|
+ *
|
|
|
+ * @param array $form
|
|
|
+ * @param array $form_values
|
|
|
+ * @return array The modified form
|
|
|
+ */
|
|
|
+function qbf_import_values($element, $form_values)
|
|
|
+ {
|
|
|
+ foreach (element_children($element) as $childName)
|
|
|
+ {
|
|
|
+ if (!empty($form_values[$childName]))
|
|
|
+ {
|
|
|
+ $element[$childName]['#qbf']['#default_value'] = $form_values[$childName];
|
|
|
+ }
|
|
|
+ $element[$childName] = qbf_import_values($element[$childName], $form_values);
|
|
|
+ }
|
|
|
+ return $element;
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Load a saved QBF query.
|
|
|
+ *
|
|
|
+ * @see qbf_import_values()
|
|
|
+ *
|
|
|
+ * @param int $qid
|
|
|
+ * @return array A form_values array usable by qbf_import_values
|
|
|
+ */
|
|
|
+function qbf_load($qid)
|
|
|
+ {
|
|
|
+ $sq = 'SELECT qq.qid, qq.uid, qq.query '
|
|
|
+ . 'FROM {qbf_queries} qq '
|
|
|
+ . 'WHERE qq.qid = %d ';
|
|
|
+ // db_rewrite_sql does not apply here until we add more advanced support for access control
|
|
|
+ $q = db_query($sq, $qid);
|
|
|
+ $ret = db_fetch_object($q); // 0 or 1 row: we are querying on the primary key
|
|
|
+ if ($ret === FALSE)
|
|
|
+ {
|
|
|
+ $ret = NULL;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $ret->query = unserialize($ret->query);
|
|
|
+ }
|
|
|
+ return $ret;
|
|
|
+ }
|
|
|
+
|
|
|
+function qbf_submit($form_id, $form_values)
|
|
|
+ {
|
|
|
+ dsm(func_num_args());
|
|
|
+ dsm(array('QS' => $form_values));
|
|
|
+ return url('goo');
|
|
|
}
|