Commit a51671ab authored by jaapjansma's avatar jaapjansma

Added title column to default data retrieval criteria.

parent fafa77c3
......@@ -3,6 +3,7 @@ Version 1.6 (not yet released)
* Updated user interface for better usability.
* Added validation for minimum length.
* Added title column to default data retrieval criteria.
Version 1.5.1
=============
......
......@@ -7,10 +7,10 @@ use CRM_FormProcessor_ExtensionUtil as E;
* @license http://www.gnu.org/licenses/agpl-3.0.html
*/
class CRM_FormProcessor_BAO_FormProcessorDefaultDataInput extends CRM_FormProcessor_DAO_FormProcessorDefaultDataInput {
/**
* Function to get values
*
*
* @return array $result found rows with data
* @access public
* @static
......@@ -44,12 +44,12 @@ class CRM_FormProcessor_BAO_FormProcessorDefaultDataInput extends CRM_FormProces
$configuration->set($name, $value);
}
$type->setConfiguration($configuration);
$row['type'] = $type;
}
$row['validators'] = array_values(CRM_FormProcessor_BAO_FormProcessorValidation::getValues(array('entity_id' => $input->id, 'entity' => 'FormProcessorDefaultDataInput')));
$result[$row['id']] = $row;
} else {
//invalid input because no there is no form processor
......@@ -61,8 +61,8 @@ class CRM_FormProcessor_BAO_FormProcessorDefaultDataInput extends CRM_FormProces
/**
* Function to add or update form processor input
*
* @param array $params
*
* @param array $params
* @return array $result
* @access public
* @throws Exception when params is empty
......@@ -73,14 +73,14 @@ class CRM_FormProcessor_BAO_FormProcessorDefaultDataInput extends CRM_FormProces
if (empty($params)) {
throw new Exception('Params can not be empty when adding or updating a form processor input');
}
if (!empty($params['id'])) {
CRM_Utils_Hook::pre('edit', 'FormProcessorDefaultDataInput', $params['id'], $params);
}
else {
CRM_Utils_Hook::pre('create', 'FormProcessorDefaultDataInput', NULL, $params);
}
$input = new CRM_FormProcessor_BAO_FormProcessorDefaultDataInput();
$fields = self::fields();
foreach ($params as $key => $value) {
......@@ -93,20 +93,20 @@ class CRM_FormProcessor_BAO_FormProcessorDefaultDataInput extends CRM_FormProces
}
$input->save();
self::storeValues($input, $result);
if (!empty($params['id'])) {
CRM_Utils_Hook::post('edit', 'FormProcessorDefaultDataInput', $input->id, $input);
}
else {
CRM_Utils_Hook::post('create', 'FormProcessorDefaultDataInput', $input->id, $input);
}
return $result;
}
/**
* Function to delete a form processor input with id
*
*
* @param int $id
* @throws Exception when $id is empty
* @access public
......@@ -116,18 +116,18 @@ class CRM_FormProcessor_BAO_FormProcessorDefaultDataInput extends CRM_FormProces
if (empty($id)) {
throw new Exception('id can not be empty when attempting to delete a form processor input');
}
CRM_Utils_Hook::pre('delete', 'FormProcessorDefaultDataInput', $id, CRM_Core_DAO::$_nullArray);
$input = new CRM_FormProcessor_BAO_FormProcessorDefaultDataInput();
$input->id = $id;
if ($input->find(true)) {
CRM_FormProcessor_BAO_FormProcessorValidation::deleteWithEntityId('FormProcessorDefaultDataInput', $input->id);
$input->delete();
}
CRM_Utils_Hook::post('delete', 'FormProcessorDefaultDataInput', $id, CRM_Core_DAO::$_nullArray);
return;
}
......@@ -147,6 +147,21 @@ class CRM_FormProcessor_BAO_FormProcessorDefaultDataInput extends CRM_FormProces
}
}
/**
* Public function to generate name from title
*
* @param $title
*
* @return string
* @access public
* @static
*/
public static function buildNameFromTitle($title) {
$titleParts = explode(' ', strtolower($title));
$nameString = implode('_', $titleParts);
return substr($nameString, 0, 80);
}
/**
* Returns whether the name is valid or not
*
......@@ -171,6 +186,6 @@ class CRM_FormProcessor_BAO_FormProcessorDefaultDataInput extends CRM_FormProces
$count = CRM_Core_DAO::singleValueQuery($sql, $params);
return ($count > 0) ? FALSE : TRUE;
}
}
\ No newline at end of file
}
......@@ -43,6 +43,13 @@ class CRM_FormProcessor_DAO_FormProcessorDefaultDataInput extends CRM_Core_DAO {
'required' => true,
'FKApiName' => 'FormProcessorInstance',
),
'title' => array(
'name' => 'title',
'title' => E::ts('Title'),
'type' => CRM_Utils_Type::T_STRING,
'maxlength' => 128,
'required' => true,
) ,
'name' => array(
'name' => 'name',
'title' => E::ts('Name'),
......@@ -88,8 +95,9 @@ class CRM_FormProcessor_DAO_FormProcessorDefaultDataInput extends CRM_Core_DAO {
public static function &fieldKeys() {
if (!(self::$_fieldKeys)) {
self::$_fieldKeys = array(
'id' => 'id',
'id' => 'id',
'form_processor_instance_id' => 'form_processor_instance_id',
'title' => 'title',
'name' => 'name',
'type' => 'type',
'is_required' => 'is_required',
......@@ -123,4 +131,4 @@ class CRM_FormProcessor_DAO_FormProcessorDefaultDataInput extends CRM_Core_DAO {
}
return self::$_export;
}
}
\ No newline at end of file
}
......@@ -23,12 +23,17 @@ class CRM_FormProcessor_Upgrader extends CRM_FormProcessor_Upgrader_Base {
}
public function upgrade_1003() {
CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_form_processor_action`
CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_form_processor_action`
ADD COLUMN `delay` VARCHAR(255) NULL,
ADD COLUMN `delay_configuration` TEXT NULL");
return TRUE;
}
public function upgrade_1004() {
CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_form_processor_default_data_input` ADD COLUMN `title` VARCHAR(128) NULL AFTER `form_processor_instance_id`");
return TRUE;
}
/**
* Example: Work with entities usually not available during the install step.
*
......
<?php
use CRM_FormProcessor_ExtensionUtil as E;
/**
* FormProcessorDefaultDataInput.Converttitletoname API
*
* @param array $params
* @return array API result descriptor
* @see civicrm_api3_create_success
* @see civicrm_api3_create_error
* @throws API_Exception
*/
function civicrm_api3_form_processor_default_data_input_converttitletoname($params) {
$title = $params['title'];
$returnValues['name'] = CRM_FormProcessor_BAO_FormProcessorDefaultInput::buildNameFromTitle($title);
return $returnValues;
}
/**
* FormProcessorInput.Converttitletoname API specification (optional)
* This is used for documentation and validation.
*
* @param array $spec description of fields supported by this API call
* @return void
* @see http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
*/
function _civicrm_api3_form_processor_input_converttitletoname_spec(&$spec) {
$spec['title'] = array(
'title' => E::ts('Title'),
'type' => CRM_Utils_Type::T_STRING,
'api.required' => true
);
}
......@@ -22,6 +22,11 @@ function _civicrm_api3_form_processor_default_data_input_create_spec(&$spec) {
'api.required' => true,
'FKApiName' => 'FormProcessorInstance',
);
$spec['title'] = array(
'title' => E::ts('Title'),
'type' => CRM_Utils_Type::T_STRING,
'api.required' => true
);
$spec['name'] = array(
'title' => E::ts('Name'),
'type' => CRM_Utils_Type::T_STRING,
......
......@@ -14,7 +14,7 @@ CREATE TABLE IF NOT EXISTS `civicrm_form_processor_instance` (
`modified_user_id` INT NULL,
`permission` VARCHAR(255) NOT NULL DEFAULT '',
`status` TINYINT NULL DEFAULT 1,
`source_file` VARCHAR(255) NOT NULL DEFAULT '',
`source_file` VARCHAR(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
UNIQUE INDEX `name_UNIQUE` (`name` ASC)
) ENGINE = InnoDB;
......@@ -59,6 +59,7 @@ CREATE TABLE IF NOT EXISTS `civicrm_form_processor_action` (
CREATE TABLE IF NOT EXISTS `civicrm_form_processor_default_data_input` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`form_processor_instance_id` INT UNSIGNED NOT NULL,
`title` VARCHAR(128) NULL,
`name` VARCHAR(80) NOT NULL,
`type` VARCHAR(80) NOT NULL,
`is_required` TINYINT NULL DEFAULT 0,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment