diff --git a/CRM/Dataprocessor/BAO/DataProcessorField.php b/CRM/Dataprocessor/BAO/DataProcessorField.php new file mode 100644 index 0000000000000000000000000000000000000000..872479069c4276c50143897d0c48a01c0bb2270a --- /dev/null +++ b/CRM/Dataprocessor/BAO/DataProcessorField.php @@ -0,0 +1,31 @@ +<?php +use CRM_Dataprocessor_ExtensionUtil as E; + +class CRM_Dataprocessor_BAO_DataProcessorField extends CRM_Dataprocessor_DAO_DataProcessorField { + + public static function checkName($title, $data_processor_id, $id=null,$name=null) { + if (!$name) { + $name = preg_replace('@[^a-z0-9_]+@','_',strtolower($title)); + } + + $name = preg_replace('@[^a-z0-9_]+@','_',strtolower($name)); + $name_part = $name; + + $sql = "SELECT COUNT(*) FROM `civicrm_data_processor_field` WHERE `name` = %1 AND `data_processor_id` = %2"; + $sqlParams[1] = array($name, 'String'); + $sqlParams[2] = array($data_processor_id, 'String'); + if (isset($id)) { + $sql .= " AND `id` != %3"; + $sqlParams[3] = array($id, 'Integer'); + } + + $i = 1; + while(CRM_Core_DAO::singleValueQuery($sql, $sqlParams) > 0) { + $i++; + $name = $name_part .'_'.$i; + $sqlParams[1] = array($name, 'String'); + } + return $name; + } + +} diff --git a/CRM/Dataprocessor/BAO/Field.php b/CRM/Dataprocessor/BAO/Field.php deleted file mode 100644 index 1253658206d8e8c61917242149953e3cf2941002..0000000000000000000000000000000000000000 --- a/CRM/Dataprocessor/BAO/Field.php +++ /dev/null @@ -1,190 +0,0 @@ -<?php -/** - * @author Jaap Jansma <jaap.jansma@civicoop.org> - * @license AGPL-3.0 - */ - -class CRM_Dataprocessor_BAO_Field extends CRM_Dataprocessor_DAO_Field { - - /** - * Function to get values - * - * @return array $result found rows with data - * @access public - * @static - */ - public static function getValues($params) { - $factory = dataprocessor_get_factory(); - $types = $factory->getDataSources(); - - $result = array(); - $field = new CRM_Dataprocessor_DAO_Field(); - if (!empty($params)) { - $fields = self::fields(); - foreach ($params as $key => $value) { - if (isset($fields[$key])) { - $field->$key = $value; - } - } - } - $field->orderBy("weight ASC"); - $field->find(); - while ($field->fetch()) { - $row = array(); - self::storeValues($field, $row); - - if (isset($types[$row['type']])) { - $row['type_name'] = $types[$row['type']]; - } else { - $row['type_name'] = ''; - } - if (!empty($row['configuration'])) { - $row['configuration'] = json_decode($row['configuration'], true); - } else { - $row['configuration'] = array(); - } - if (!empty($row['join_configuration'])) { - $row['join_configuration'] = json_decode($row['join_configuration'], true); - } else { - $row['join_configuration'] = array(); - } - - $result[$row['id']] = $row; - } - return $result; - } - - /** - * Function to add or update a DataProcessor - * - * @param array $params - * @return array $result - * @access public - * @throws Exception when params is empty - * @static - */ - public static function add($params) { - $result = array(); - if (empty($params)) { - throw new Exception('Params can not be empty when adding or updating a data processor field'); - } - - if (!isset($params['weight'])) { - $params['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Dataprocessor_DAO_Field', array('data_processor_id' => $params['data_processor_id'])); - } - - if (!empty($params['id'])) { - CRM_Utils_Hook::pre('edit', 'DataProcessorField', $params['id'], $params); - } - else { - CRM_Utils_Hook::pre('create', 'DataProcessorField', NULL, $params); - } - - $field = new CRM_Dataprocessor_DAO_Field(); - $fields = self::fields(); - foreach ($params as $key => $value) { - if (isset($fields[$key])) { - $field->$key = $value; - } - } - if (isset($field->configuration) && is_array($field->configuration)) { - $field->configuration = json_encode($field->configuration); - } - - $field->save(); - $id = $field->id; - $field = new CRM_Dataprocessor_BAO_Field(); - $field->id = $id; - $field->find(true); - CRM_Dataprocessor_BAO_DataProcessor::updateAndChekStatus($field->data_processor_id); - self::storeValues($field, $result); - - if (!empty($params['id'])) { - CRM_Utils_Hook::post('edit', 'DataProcessorField', $field->id, $field); - } - else { - CRM_Utils_Hook::post('create', 'DataProcessorField', $field->id, $field); - } - - return $result; - } - - /** - * Public function to generate name from title - * - * @param $label - * @return string - * @access public - * @static - */ - public static function buildNameFromTitle($title) { - return preg_replace('@[^a-z0-9_]+@','_', strtolower($title)); - } - - /** - * Returns whether the name is valid or not - * - * @param string $name - * @param int $data_procssor_id, - * @param int $id optional - * @return bool - * @static - */ - public static function isNameValid($name, $data_procssor_id, $id=null) { - $sql = "SELECT COUNT(*) FROM `civicrm_data_processor_field` WHERE `name` = %1 AND `data_processor_id` = %2"; - $params[1] = array($name, 'String'); - $params[2] = array($data_procssor_id, 'Integer'); - if ($id) { - $sql .= " AND `id` != %3"; - $params[3] = array($id, 'Integer'); - } - $count = CRM_Core_DAO::singleValueQuery($sql, $params); - return ($count > 0) ? false : true; - } - - /** - * Function to delete a Data Processor Field with id - * - * @param int $id - * @throws Exception when $id is empty - * @access public - * @static - */ - public static function deleteWithId($id) { - if (empty($id)) { - throw new Exception('id can not be empty when attempting to delete a data processor field'); - } - - CRM_Utils_Hook::pre('delete', 'DataProcessorField', $id, CRM_Core_DAO::$_nullArray); - - $field = new CRM_Dataprocessor_DAO_Field(); - $field->id = $id; - $field->delete(); - - CRM_Utils_Hook::post('delete', 'DataProcessorField', $id, CRM_Core_DAO::$_nullArray); - - return; - } - - /** - * Function to delete a Data Processor Field with id - * - * @param int $id - * @throws Exception when $id is empty - * @access public - * @static - */ - public static function deleteWithDataProcessorId($id) { - if (empty($id)) { - throw new Exception('id can not be empty when attempting to delete a data processor field'); - } - - $field = new CRM_Dataprocessor_DAO_Field(); - $field->data_processor_id = $id; - $field->find(FALSE); - while ($field->fetch()) { - self::deleteWithId($field->id); - } - } - -} \ No newline at end of file diff --git a/CRM/Dataprocessor/DAO/DataProcessorField.php b/CRM/Dataprocessor/DAO/DataProcessorField.php new file mode 100644 index 0000000000000000000000000000000000000000..1818c0fbdb693e29a7431cbba0b95d2912de305b --- /dev/null +++ b/CRM/Dataprocessor/DAO/DataProcessorField.php @@ -0,0 +1,252 @@ +<?php + +/** + * @package CRM + * @copyright CiviCRM LLC (c) 2004-2019 + * + * Generated from /buildkit/build/search/sites/default/files/civicrm/ext/dataprocessor/xml/schema/CRM/Dataprocessor/DataProcessorField.xml + * DO NOT EDIT. Generated by CRM_Core_CodeGen + * (GenCodeChecksum:31241877b684b9293303c171b4a4dcbb) + */ + +/** + * Database access object for the DataProcessorField entity. + */ +class CRM_Dataprocessor_DAO_DataProcessorField extends CRM_Core_DAO { + + /** + * Static instance to hold the table name. + * + * @var string + */ + static $_tableName = 'civicrm_data_processor_field'; + + /** + * Should CiviCRM log any modifications to this table in the civicrm_log table. + * + * @var bool + */ + static $_log = FALSE; + + /** + * Unique DataProcessorField ID + * + * @var int unsigned + */ + public $id; + + /** + * FK to Data Processor + * + * @var int unsigned + */ + public $data_processor_id; + + /** + * @var int + */ + public $weight; + + /** + * @var string + */ + public $name; + + /** + * @var string + */ + public $title; + + /** + * @var string + */ + public $type; + + /** + * @var text + */ + public $configuration; + + /** + * Class constructor. + */ + public function __construct() { + $this->__table = 'civicrm_data_processor_field'; + parent::__construct(); + } + + /** + * Returns foreign keys and entity references. + * + * @return array + * [CRM_Core_Reference_Interface] + */ + public static function getReferenceColumns() { + if (!isset(Civi::$statics[__CLASS__]['links'])) { + Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__); + Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'data_processor_id', 'civicrm_data_processor', 'id'); + CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']); + } + return Civi::$statics[__CLASS__]['links']; + } + + /** + * Returns all the column names of this table + * + * @return array + */ + public static function &fields() { + if (!isset(Civi::$statics[__CLASS__]['fields'])) { + Civi::$statics[__CLASS__]['fields'] = [ + 'id' => [ + 'name' => 'id', + 'type' => CRM_Utils_Type::T_INT, + 'description' => CRM_Dataprocessor_ExtensionUtil::ts('Unique DataProcessorField ID'), + 'required' => TRUE, + 'table_name' => 'civicrm_data_processor_field', + 'entity' => 'DataProcessorField', + 'bao' => 'CRM_Dataprocessor_DAO_DataProcessorField', + 'localizable' => 0, + ], + 'data_processor_id' => [ + 'name' => 'data_processor_id', + 'type' => CRM_Utils_Type::T_INT, + 'title' => CRM_Dataprocessor_ExtensionUtil::ts('Data Processor ID'), + 'description' => CRM_Dataprocessor_ExtensionUtil::ts('FK to Data Processor'), + 'required' => TRUE, + 'table_name' => 'civicrm_data_processor_field', + 'entity' => 'DataProcessorField', + 'bao' => 'CRM_Dataprocessor_DAO_DataProcessorField', + 'localizable' => 0, + ], + 'weight' => [ + 'name' => 'weight', + 'type' => CRM_Utils_Type::T_INT, + 'title' => CRM_Dataprocessor_ExtensionUtil::ts('Weight'), + 'required' => FALSE, + 'table_name' => 'civicrm_data_processor_field', + 'entity' => 'DataProcessorField', + 'bao' => 'CRM_Dataprocessor_DAO_DataProcessorField', + 'localizable' => 0, + ], + 'name' => [ + 'name' => 'name', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => CRM_Dataprocessor_ExtensionUtil::ts('Name'), + 'required' => FALSE, + 'maxlength' => 255, + 'size' => CRM_Utils_Type::HUGE, + 'table_name' => 'civicrm_data_processor_field', + 'entity' => 'DataProcessorField', + 'bao' => 'CRM_Dataprocessor_DAO_DataProcessorField', + 'localizable' => 0, + ], + 'title' => [ + 'name' => 'title', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => CRM_Dataprocessor_ExtensionUtil::ts('Title'), + 'required' => TRUE, + 'maxlength' => 255, + 'size' => CRM_Utils_Type::HUGE, + 'table_name' => 'civicrm_data_processor_field', + 'entity' => 'DataProcessorField', + 'bao' => 'CRM_Dataprocessor_DAO_DataProcessorField', + 'localizable' => 0, + ], + 'type' => [ + 'name' => 'type', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => CRM_Dataprocessor_ExtensionUtil::ts('Type'), + 'required' => TRUE, + 'maxlength' => 255, + 'size' => CRM_Utils_Type::HUGE, + 'table_name' => 'civicrm_data_processor_field', + 'entity' => 'DataProcessorField', + 'bao' => 'CRM_Dataprocessor_DAO_DataProcessorField', + 'localizable' => 0, + ], + 'configuration' => [ + 'name' => 'configuration', + 'type' => CRM_Utils_Type::T_TEXT, + 'title' => CRM_Dataprocessor_ExtensionUtil::ts('Configuration'), + 'required' => FALSE, + 'table_name' => 'civicrm_data_processor_field', + 'entity' => 'DataProcessorField', + 'bao' => 'CRM_Dataprocessor_DAO_DataProcessorField', + 'localizable' => 0, + 'serialize' => self::SERIALIZE_JSON, + ], + ]; + CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); + } + return Civi::$statics[__CLASS__]['fields']; + } + + /** + * Return a mapping from field-name to the corresponding key (as used in fields()). + * + * @return array + * Array(string $name => string $uniqueName). + */ + public static function &fieldKeys() { + if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) { + Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields())); + } + return Civi::$statics[__CLASS__]['fieldKeys']; + } + + /** + * Returns the names of this table + * + * @return string + */ + public static function getTableName() { + return self::$_tableName; + } + + /** + * Returns if this table needs to be logged + * + * @return bool + */ + public function getLog() { + return self::$_log; + } + + /** + * Returns the list of fields that can be imported + * + * @param bool $prefix + * + * @return array + */ + public static function &import($prefix = FALSE) { + $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'data_processor_field', $prefix, []); + return $r; + } + + /** + * Returns the list of fields that can be exported + * + * @param bool $prefix + * + * @return array + */ + public static function &export($prefix = FALSE) { + $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'data_processor_field', $prefix, []); + return $r; + } + + /** + * Returns the list of indices + * + * @param bool $localize + * + * @return array + */ + public static function indices($localize = TRUE) { + $indices = []; + return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices; + } + +} diff --git a/CRM/Dataprocessor/DAO/Field.php b/CRM/Dataprocessor/DAO/Field.php deleted file mode 100644 index c9fcb770deaa45dfa128095fe963780a518f0dea..0000000000000000000000000000000000000000 --- a/CRM/Dataprocessor/DAO/Field.php +++ /dev/null @@ -1,103 +0,0 @@ -<?php - -use CRM_Dataprocessor_ExtensionUtil as E; - -/** - * @author Jaap Jansma (CiviCooP) <jaap.jansma@civicoop.org> - * @license http://www.gnu.org/licenses/agpl-3.0.html - */ -class CRM_Dataprocessor_DAO_Field extends CRM_Core_DAO { - /** - * static instance to hold the field values - * - * @var array - * @static - */ - static $_fields = null; - static $_export = null; - /** - * empty definition for virtual function - */ - static function getTableName() { - return 'civicrm_data_processor_field'; - } - /** - * returns all the column names of this table - * - * @access public - * @return array - */ - public static function &fields() { - if (!(self::$_fields)) { - self::$_fields = array( - 'id' => array( - 'name' => 'id', - 'title' => E::ts('ID'), - 'type' => CRM_Utils_Type::T_INT, - 'required' => true - ) , - 'weight' => array( - 'name' => 'weight', - 'title' => E::ts('Weight'), - 'type' => CRM_Utils_Type::T_INT, - 'required' => true - ) , - 'data_processor_id' => array( - 'name' => 'data_processor_id', - 'title' => E::ts('Data Processor ID'), - 'type' => CRM_Utils_Type::T_INT, - 'required' => true, - 'FKApiName' => 'DataProcessor', - ), - 'type' => array( - 'name' => 'type', - 'title' => E::ts('Type'), - 'type' => CRM_Utils_Type::T_STRING, - 'maxlength' => 80, - 'required' => true, - ), - 'name' => array( - 'name' => 'name', - 'title' => E::ts('Name'), - 'type' => CRM_Utils_Type::T_STRING, - 'maxlength' => 128, - 'required' => true - ), - 'title' => array( - 'name' => 'title', - 'title' => E::ts('Title'), - 'type' => CRM_Utils_Type::T_STRING, - 'maxlength' => 128, - 'required' => true - ), - 'configuration' => array( - 'name' => 'configuration', - 'title' => E::ts('Configuration'), - 'type' => CRM_Utils_Type::T_TEXT, - ), - ); - } - return self::$_fields; - } - /** - * Returns an array containing, for each field, the array key used for that - * field in self::$_fields. - * - * @access public - * @return array - */ - public static function &fieldKeys() { - if (!(self::$_fieldKeys)) { - self::$_fieldKeys = array( - 'id' => 'id', - 'weight' => 'weight', - 'data_processor_id' => 'data_processor_id', - 'type' => 'type', - 'name' => 'name', - 'title' => 'title', - 'configuration' => 'configuration', - ); - } - return self::$_fieldKeys; - } -} \ No newline at end of file diff --git a/CRM/Dataprocessor/Form/DataProcessor.php b/CRM/Dataprocessor/Form/DataProcessor.php index abe5155f21f07630df68328bdece550f9ae2c2df..a9dcc6d5492bf67e07e9866d7ef8dc72e87afdf3 100644 --- a/CRM/Dataprocessor/Form/DataProcessor.php +++ b/CRM/Dataprocessor/Form/DataProcessor.php @@ -83,11 +83,12 @@ class CRM_Dataprocessor_Form_DataProcessor extends CRM_Core_Form { } protected function addFields() { - $fields = CRM_Dataprocessor_BAO_Field::getValues(array('data_processor_id' => $this->dataProcessorId)); + $fields = civicrm_api3('DataProcessorField', 'get', array('data_processor_id' => $this->dataProcessorId, 'options' => array('limit' => 0))); + $fields = $fields['values']; foreach($fields as $idx => $field) { $fields[$idx]['configuration_link'] = ''; } - CRM_Utils_Weight::addOrder($fields, 'CRM_Dataprocessor_DAO_Field', 'id', $this->currentUrl, 'data_processor_id='.$this->dataProcessorId); + CRM_Utils_Weight::addOrder($fields, 'CRM_Dataprocessor_DAO_DataProcessorField', 'id', $this->currentUrl, 'data_processor_id='.$this->dataProcessorId); $this->assign('fields', $fields); } diff --git a/CRM/Dataprocessor/Form/Field.php b/CRM/Dataprocessor/Form/Field.php index 09a873aa845bddda0d6b32131eeb658ba568878c..4ba7316cd970c338edf5899a6afb14a62be3d6dd 100644 --- a/CRM/Dataprocessor/Form/Field.php +++ b/CRM/Dataprocessor/Form/Field.php @@ -13,6 +13,8 @@ class CRM_Dataprocessor_Form_Field extends CRM_Core_Form { private $id; + private $field; + /** * Function to perform processing before displaying form (overrides parent function) * @@ -27,8 +29,8 @@ class CRM_Dataprocessor_Form_Field extends CRM_Core_Form { $this->assign('id', $this->id); if ($this->id) { - $field = CRM_Dataprocessor_BAO_Field::getValues(array('id' => $this->id)); - $this->assign('field', $field[$this->id]); + $this->field = civicrm_api3('DataProcessorField', 'getsingle', array('id' => $this->id)); + $this->assign('field', $this->field); } $title = E::ts('Data Processor Field'); @@ -77,15 +79,16 @@ class CRM_Dataprocessor_Form_Field extends CRM_Core_Form { $defaults['data_processor_id'] = $this->dataProcessorId; $defaults['id'] = $this->id; - $field = CRM_Dataprocessor_BAO_Field::getValues(array('id' => $this->id)); - if (isset($field[$this->id]['type'])) { - $defaults['type'] = $field[$this->id]['type']; - } - if (isset($field[$this->id]['title'])) { - $defaults['title'] = $field[$this->id]['title']; - } - if (isset($field[$this->id]['name'])) { - $defaults['name'] = $field[$this->id]['name']; + if ($this->field) { + if (isset($this->field['type'])) { + $defaults['type'] = $this->field['type']; + } + if (isset($this->field['title'])) { + $defaults['title'] = $this->field['title']; + } + if (isset($this->field['name'])) { + $defaults['name'] = $this->field['name']; + } } return $defaults; } @@ -94,7 +97,7 @@ class CRM_Dataprocessor_Form_Field extends CRM_Core_Form { $session = CRM_Core_Session::singleton(); $redirectUrl = $session->readUserContext(); if ($this->_action == CRM_Core_Action::DELETE) { - CRM_Dataprocessor_BAO_Field::deleteWithId($this->id); + civicrm_api3('DataProcessorField', 'delete', array('id' => $this->id)); $session->setStatus(E::ts('Field removed'), E::ts('Removed'), 'success'); CRM_Utils_System::redirect($redirectUrl); } @@ -102,61 +105,18 @@ class CRM_Dataprocessor_Form_Field extends CRM_Core_Form { $values = $this->exportValues(); if (!empty($values['name'])) { $params['name'] = $values['name']; - } else { - $params['name'] = CRM_Dataprocessor_BAO_Field::buildNameFromTitle($values['title']); } $params['title'] = $values['title']; $params['type'] = $values['type']; - if ($this->dataProcessorId) { - $params['data_processor_id'] = $this->dataProcessorId; - } + $params['data_processor_id'] = $this->dataProcessorId; if ($this->id) { $params['id'] = $this->id; } - $result = CRM_Dataprocessor_BAO_Field::add($params); + civicrm_api3('DataProcessorField', 'create', $params); CRM_Utils_System::redirect($redirectUrl); parent::postProcess(); } - /** - * Function to add validation rules (overrides parent function) - * - * @access public - */ - function addRules() { - if ($this->_action != CRM_Core_Action::DELETE) { - $this->addFormRule(array( - 'CRM_Dataprocessor_Form_Field', - 'validateName' - )); - } - } - - /** - * Function to validate if rule label already exists - * - * @param array $fields - * @return array|bool - * @access static - */ - static function validateName($fields) { - /* - * if id not empty, edit mode. Check if changed before check if exists - */ - $id = false; - if (!empty($fields['id'])) { - $id = $fields['id']; - } - if (empty($fields['name'])) { - $fields['name'] = CRM_Dataprocessor_BAO_Field::buildNameFromTitle($fields['title']); - } - if (!CRM_Dataprocessor_BAO_Field::isNameValid($fields['name'], $fields['data_processor_id'], $id)) { - $errors['name'] = E::ts('There is already a field with this name'); - return $errors; - } - return TRUE; - } - } \ No newline at end of file diff --git a/api/v3/DataProcessorField.php b/api/v3/DataProcessorField.php new file mode 100644 index 0000000000000000000000000000000000000000..b26057b3e0052aa1d9aec3c4937fa3166abb01fb --- /dev/null +++ b/api/v3/DataProcessorField.php @@ -0,0 +1,123 @@ +<?php +use CRM_Dataprocessor_ExtensionUtil as E; + +/** + * DataProcessorField.create 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/CRMDOC/API+Architecture+Standards + */ +function _civicrm_api3_data_processor_field_create_spec(&$spec) { + $fields = CRM_Dataprocessor_DAO_DataProcessorField::fields(); + foreach($fields as $fieldname => $field) { + $spec[$fieldname] = $field; + if ($fieldname != 'id' && isset($field['required']) && $field['required']) { + $spec[$fieldname]['api.required'] = true; + } + } +} + +/** + * DataProcessorField.create API + * + * @param array $params + * @return array API result descriptor + * @throws API_Exception + */ +function civicrm_api3_data_processor_field_create($params) { + if (!isset($params['weight']) && !isset($params['id'])) { + $params['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Dataprocessor_DAO_DataProcessorField', array('data_processor_id' => $params['data_processor_id'])); + } + $id = null; + if (isset($params['id'])) { + $id = $params['id']; + } + $params['name'] = CRM_Dataprocessor_BAO_DataProcessorField::checkName($params['title'], $params['data_processor_id'], $id, $params['name']); + return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); +} + +/** + * DataProcessorField.delete API + * + * @param array $params + * @return array API result descriptor + * @throws API_Exception + */ +function civicrm_api3_data_processor_field_delete($params) { + return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params); +} + +/** + * DataProcessorField.get 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/CRMDOC/API+Architecture+Standards + */ +function civicrm_api3_data_processor_field_get_spec(&$spec) { + $fields = CRM_Dataprocessor_DAO_DataProcessorField::fields(); + foreach($fields as $fieldname => $field) { + $spec[$fieldname] = $field; + } +} + +/** + * DataProcessorField.get API + * + * @param array $params + * @return array API result descriptor + * @throws API_Exception + */ +function civicrm_api3_data_processor_field_get($params) { + if (!isset($params['options']) || !isset($params['options']['sort'])) { + $params['options']['sort'] = 'weight ASC'; + } + $return = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); + foreach($return['values'] as $id => $value) { + if (isset($value['configuration'])) { + $return['values'][$id]['configuration'] = json_decode($value['configuration'], TRUE); + } + } + return $return; +} + +/** + * DataProcessorField.check_name API specification + * + * @param $params + */ +function _civicrm_api3_data_processor_field_check_name_spec($params) { + $params['id'] = array( + 'name' => 'id', + 'title' => E::ts('ID'), + ); + $params['title'] = array( + 'name' => 'title', + 'title' => E::ts('Title'), + 'api.required' => true, + ); + $params['data_processor_id'] = array( + 'name' => 'data_processor_id', + 'title' => E::ts('Data Processor Id'), + 'api.required' => true, + ); + $params['name'] = array( + 'name' => 'name', + 'title' => E::ts('Name'), + ); +} + +/** + * DataProcessorField.check_name API + * + * @param $params + */ +function civicrm_api3_data_processor_field_check_name($params) { + $name = CRM_Dataprocessor_BAO_DataProcessorField::checkName($params['title'], $params['data_processor_id'], $params['id'], $params['name']); + return array( + 'name' => $name, + ); +} diff --git a/api/v3/DataProcessorField/Create.php b/api/v3/DataProcessorField/Create.php deleted file mode 100644 index 48d851fe6124c33509bff0cff00cabf8c8f0975e..0000000000000000000000000000000000000000 --- a/api/v3/DataProcessorField/Create.php +++ /dev/null @@ -1,66 +0,0 @@ -<?php - -use CRM_Dataprocessor_ExtensionUtil as E; - -/** - * DataProcessorField.Create 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_data_processor_field_create_spec(&$spec) { - $spec['id'] = array( - 'title' => E::ts('ID'), - 'type' => CRM_Utils_Type::T_INT, - 'api.required' => false - ); - $spec['weight'] = array( - 'title' => E::ts('Weight'), - 'type' => CRM_Utils_Type::T_INT, - 'api.required' => false - ); - $spec['data_processor_id'] = array( - 'title' => E::ts('Data Processor ID'), - 'type' => CRM_Utils_Type::T_INT, - 'api.required' => true, - ); - $spec['type'] = array( - 'title' => E::ts('Type'), - 'type' => CRM_Utils_Type::T_STRING, - 'api.required' => true - ); - $spec['name'] = array( - 'title' => E::ts('Name'), - 'type' => CRM_Utils_Type::T_STRING, - 'api.required' => true - ); - $spec['title'] = array( - 'title' => E::ts('Title'), - 'type' => CRM_Utils_Type::T_STRING, - 'api.required' => true - ); - $spec['configuration'] = array( - 'title' => E::ts('Configuration'), - 'type' => CRM_Utils_Type::T_TEXT, - 'api.required' => false, - ); -} - -/** - * DataProcessorField.Create API - * - * @param array $params - * @return array API result descriptor - * @see civicrm_api3_create_success - * @see civicrm_api3_create_error - * - * - */ -function civicrm_api3_data_processor_field_create($params) { - $returnValue = CRM_Dataprocessor_BAO_Field::add($params); - $returnValues[$returnValue['id']] = $returnValue; - return civicrm_api3_create_success($returnValues, $params, 'DataProcessorField', 'Create'); -} - diff --git a/api/v3/DataProcessorField/Delete.php b/api/v3/DataProcessorField/Delete.php deleted file mode 100644 index 3b014fa1b9c3b7b8b3ac5e9e3e216d1a00c5df27..0000000000000000000000000000000000000000 --- a/api/v3/DataProcessorField/Delete.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php - -use CRM_Dataprocessor_ExtensionUtil as E; - -/** - * DataProcessorField.Delete 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/CRMDOC/API+Architecture+Standards - */ -function _civicrm_api3_data_processor_field_Delete_spec(&$spec) { - $spec['id'] = array( - 'title' => E::ts('ID'), - 'type' => CRM_Utils_Type::T_INT, - 'api.required' => true - ); -} - -/** - * DataProcessorField.Delete 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_data_processor_field_Delete($params) { - if (!array_key_exists('id', $params) || empty($params['id'])) { - throw new API_Exception('Parameter id is mandatory and can not be empty in ' . __METHOD__, 0010); - } else { - return civicrm_api3_create_success(CRM_Dataprocessor_BAO_DataProcessorField::deleteWithId($params['id']), $params, 'DataProcessorField', 'Delete'); - } -} - diff --git a/api/v3/DataProcessorField/Get.php b/api/v3/DataProcessorField/Get.php deleted file mode 100644 index dca751587053ccce90a5b2bd79180dcec785d555..0000000000000000000000000000000000000000 --- a/api/v3/DataProcessorField/Get.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php -/** - * DataProcessorField.Get 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_data_processor_field_get($params) { - $returnValues = CRM_Dataprocessor_BAO_Field::getValues($params); - return civicrm_api3_create_success($returnValues, $params, 'DataProcessorField', 'Get'); -} - -/** - * DataProcessorField.Get 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_data_processor_field_get_spec(&$spec) { - $fields = CRM_Dataprocessor_BAO_Field::fields(); - foreach($fields as $fieldname => $field) { - $spec[$fieldname] = $field; - } -} - diff --git a/dataprocessor.civix.php b/dataprocessor.civix.php index 991bfade3f8e161cdcc06c2798f96d8f26d94f07..415bce1b6813b7584a9c312a8836f92d473a395a 100644 --- a/dataprocessor.civix.php +++ b/dataprocessor.civix.php @@ -263,16 +263,17 @@ function _dataprocessor_civix_find_files($dir, $pattern) { */ function _dataprocessor_civix_civicrm_managed(&$entities) { $mgdFiles = _dataprocessor_civix_find_files(__DIR__, '*.mgd.php'); + sort($mgdFiles); foreach ($mgdFiles as $file) { $es = include $file; foreach ($es as $e) { if (empty($e['module'])) { $e['module'] = E::LONG_NAME; } - $entities[] = $e; if (empty($e['params']['version'])) { $e['params']['version'] = '3'; } + $entities[] = $e; } } } @@ -456,5 +457,11 @@ function _dataprocessor_civix_civicrm_alterSettingsFolders(&$metaDataFolders = N function _dataprocessor_civix_civicrm_entityTypes(&$entityTypes) { $entityTypes = array_merge($entityTypes, array ( + 'CRM_Dataprocessor_DAO_DataProcessorField' => + array ( + 'name' => 'DataProcessorField', + 'class' => 'CRM_Dataprocessor_DAO_DataProcessorField', + 'table' => 'civicrm_data_processor_field', + ), )); } diff --git a/sql/alter.sql b/sql/alter.sql new file mode 100644 index 0000000000000000000000000000000000000000..e46fa163ac8397b483e11343ae6e0bd01386dc7e --- /dev/null +++ b/sql/alter.sql @@ -0,0 +1,4 @@ +ALTER TABLE `civicrm_data_processor_field` +CHANGE `name` `name` VARCHAR(255) NOT NULL, +CHANGE `type` `type` VARCHAR(255) NOT NULL, +CHANGE `title` `title` VARCHAR(255) NOT NULL; \ No newline at end of file diff --git a/sql/auto_install.sql b/sql/auto_install.sql new file mode 100644 index 0000000000000000000000000000000000000000..18635bb0c02aeb4d9130cbc31c498dcfca45f3fa --- /dev/null +++ b/sql/auto_install.sql @@ -0,0 +1,96 @@ +-- +--------------------------------------------------------------------+ +-- | CiviCRM version 5 | +-- +--------------------------------------------------------------------+ +-- | Copyright CiviCRM LLC (c) 2004-2019 | +-- +--------------------------------------------------------------------+ +-- | This file is a part of CiviCRM. | +-- | | +-- | CiviCRM is free software; you can copy, modify, and distribute it | +-- | under the terms of the GNU Affero General Public License | +-- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | +-- | | +-- | CiviCRM is distributed in the hope that it will be useful, but | +-- | WITHOUT ANY WARRANTY; without even the implied warranty of | +-- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | +-- | See the GNU Affero General Public License for more details. | +-- | | +-- | You should have received a copy of the GNU Affero General Public | +-- | License and the CiviCRM Licensing Exception along | +-- | with this program; if not, contact CiviCRM LLC | +-- | at info[AT]civicrm[DOT]org. If you have questions about the | +-- | GNU Affero General Public License or the licensing of CiviCRM, | +-- | see the CiviCRM license FAQ at http://civicrm.org/licensing | +-- +--------------------------------------------------------------------+ +-- +-- Generated from schema.tpl +-- DO NOT EDIT. Generated by CRM_Core_CodeGen +-- + + +-- +--------------------------------------------------------------------+ +-- | CiviCRM version 5 | +-- +--------------------------------------------------------------------+ +-- | Copyright CiviCRM LLC (c) 2004-2019 | +-- +--------------------------------------------------------------------+ +-- | This file is a part of CiviCRM. | +-- | | +-- | CiviCRM is free software; you can copy, modify, and distribute it | +-- | under the terms of the GNU Affero General Public License | +-- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | +-- | | +-- | CiviCRM is distributed in the hope that it will be useful, but | +-- | WITHOUT ANY WARRANTY; without even the implied warranty of | +-- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | +-- | See the GNU Affero General Public License for more details. | +-- | | +-- | You should have received a copy of the GNU Affero General Public | +-- | License and the CiviCRM Licensing Exception along | +-- | with this program; if not, contact CiviCRM LLC | +-- | at info[AT]civicrm[DOT]org. If you have questions about the | +-- | GNU Affero General Public License or the licensing of CiviCRM, | +-- | see the CiviCRM license FAQ at http://civicrm.org/licensing | +-- +--------------------------------------------------------------------+ +-- +-- Generated from drop.tpl +-- DO NOT EDIT. Generated by CRM_Core_CodeGen +-- +-- /******************************************************* +-- * +-- * Clean up the exisiting tables +-- * +-- *******************************************************/ + +SET FOREIGN_KEY_CHECKS=0; + +DROP TABLE IF EXISTS `civicrm_data_processor_field`; + +SET FOREIGN_KEY_CHECKS=1; +-- /******************************************************* +-- * +-- * Create new tables +-- * +-- *******************************************************/ + +-- /******************************************************* +-- * +-- * civicrm_data_processor_field +-- * +-- *******************************************************/ +CREATE TABLE `civicrm_data_processor_field` ( + + + `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique DataProcessorField ID', + `data_processor_id` int unsigned NOT NULL COMMENT 'FK to Data Processor', + `weight` int NULL , + `name` varchar(255) NULL , + `title` varchar(255) NOT NULL , + `type` varchar(255) NOT NULL , + `configuration` text NULL +, + PRIMARY KEY (`id`) + + +, CONSTRAINT FK_civicrm_data_processor_field_data_processor_id FOREIGN KEY (`data_processor_id`) REFERENCES `civicrm_data_processor`(`id`) ON DELETE CASCADE +) ; + + diff --git a/sql/auto_uninstall.sql b/sql/auto_uninstall.sql new file mode 100644 index 0000000000000000000000000000000000000000..ef24e55f9769b35e4907f1908d572d73747b7637 --- /dev/null +++ b/sql/auto_uninstall.sql @@ -0,0 +1,38 @@ +-- +--------------------------------------------------------------------+ +-- | CiviCRM version 5 | +-- +--------------------------------------------------------------------+ +-- | Copyright CiviCRM LLC (c) 2004-2019 | +-- +--------------------------------------------------------------------+ +-- | This file is a part of CiviCRM. | +-- | | +-- | CiviCRM is free software; you can copy, modify, and distribute it | +-- | under the terms of the GNU Affero General Public License | +-- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | +-- | | +-- | CiviCRM is distributed in the hope that it will be useful, but | +-- | WITHOUT ANY WARRANTY; without even the implied warranty of | +-- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | +-- | See the GNU Affero General Public License for more details. | +-- | | +-- | You should have received a copy of the GNU Affero General Public | +-- | License and the CiviCRM Licensing Exception along | +-- | with this program; if not, contact CiviCRM LLC | +-- | at info[AT]civicrm[DOT]org. If you have questions about the | +-- | GNU Affero General Public License or the licensing of CiviCRM, | +-- | see the CiviCRM license FAQ at http://civicrm.org/licensing | +-- +--------------------------------------------------------------------+ +-- +-- Generated from drop.tpl +-- DO NOT EDIT. Generated by CRM_Core_CodeGen +-- +-- /******************************************************* +-- * +-- * Clean up the exisiting tables +-- * +-- *******************************************************/ + +SET FOREIGN_KEY_CHECKS=0; + +DROP TABLE IF EXISTS `civicrm_data_processor_field`; + +SET FOREIGN_KEY_CHECKS=1; diff --git a/sql/create_civicrm_data_processor.sql b/sql/create_civicrm_data_processor.sql index 9206836af57b2e9c68f52868d68c813ee4c4c303..1bafe6ea324f1bdb3785101393ddca5f5b14a89c 100644 --- a/sql/create_civicrm_data_processor.sql +++ b/sql/create_civicrm_data_processor.sql @@ -37,17 +37,6 @@ CREATE TABLE IF NOT EXISTS `civicrm_data_processor_filter` ( PRIMARY KEY (`id`) ) ENGINE = InnoDB; -CREATE TABLE IF NOT EXISTS `civicrm_data_processor_field` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, - `weight` INT UNSIGNED NOT NULL DEFAULT 0, - `data_processor_id` INT UNSIGNED NOT NULL, - `name` VARCHAR(128) NOT NULL, - `type` VARCHAR(128) NOT NULL, - `title` VARCHAR(128) NOT NULL, - `configuration` TEXT NULL, - PRIMARY KEY (`id`) -) ENGINE = InnoDB; - CREATE TABLE IF NOT EXISTS `civicrm_data_processor_output` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `data_processor_id` INT UNSIGNED NOT NULL, diff --git a/sql/uninstall.sql b/sql/uninstall.sql index ef832e7a17f9b54dad564dc37f3f37349d064464..7fad9d6a9e220056fb55ae4806443e1c26d7881d 100644 --- a/sql/uninstall.sql +++ b/sql/uninstall.sql @@ -1,4 +1,3 @@ DROP TABLE IF EXISTS `civicrm_data_processor_output`; -DROP TABLE IF EXISTS `civicrm_data_processor_field`; DROP TABLE IF EXISTS `civicrm_data_processor_source`; DROP TABLE IF EXISTS `civicrm_data_processor`; \ No newline at end of file diff --git a/templates/CRM/Dataprocessor/Form/DataProcessorBlocks/Fields.tpl b/templates/CRM/Dataprocessor/Form/DataProcessorBlocks/Fields.tpl index e671101c7d22532d38e3671a66bc3e2210fc9cee..3f39af1c4e4013343132f0eceaca4482cbe08524 100644 --- a/templates/CRM/Dataprocessor/Form/DataProcessorBlocks/Fields.tpl +++ b/templates/CRM/Dataprocessor/Form/DataProcessorBlocks/Fields.tpl @@ -8,18 +8,12 @@ <th></th> <th></th> <th></th> - <th></th> </tr> {foreach from=$fields item=field} <tr> <td>{$field.title}</td> <td>{$field.name}</td> - <td>{$field.weight}</td> - <td> - {if $field.configuration_link} - <a href="{$source.configuration_link}">{ts}Configure Field{/ts}</a> - {/if} - </td> + <td>{if ($field.weight && !is_numeric($field.weight))}{$field.weight}{/if}</td> <td> <a href="{crmURL p="civicrm/dataprocessor/form/field" q="reset=1&action=update&data_processor_id=`$field.data_processor_id`&id=`$field.id`"}">{ts}Edit{/ts}</a> </td> diff --git a/templates/CRM/Dataprocessor/Form/Field.tpl b/templates/CRM/Dataprocessor/Form/Field.tpl index 711b32c77977fbeda6f5e991cc37bc804b876c9f..a5e57d7d900edc4b399f6cfe5b4f5217a992b7ba 100644 --- a/templates/CRM/Dataprocessor/Form/Field.tpl +++ b/templates/CRM/Dataprocessor/Form/Field.tpl @@ -21,15 +21,48 @@ </div> <div class="crm-section"> <div class="label">{$form.title.label}</div> - <div class="content">{$form.title.html}</div> + <div class="content"> + {$form.title.html} + <span class=""> + {ts}System name:{/ts} + <span id="systemName" style="font-style: italic;">{if ($field)}{$field.name}{/if}</span> + <a href="javascript:void(0);" onclick="jQuery('#nameSection').removeClass('hiddenElement'); jQuery(this).parent().addClass('hiddenElement'); return false;"> + {ts}Change{/ts} + </a> + </span> + </div> <div class="clear"></div> </div> - <div class="crm-section"> + <div id="nameSection" class="crm-section hiddenElement"> <div class="label">{$form.name.label}</div> <div class="content">{$form.name.html}</div> <div class="clear"></div> </div> </div> + + <script type="text/javascript"> + {literal} + CRM.$(function($) { + var id = {/literal}{if ($field)}{$field.id}{else}false{/if}{literal}; + var data_processor_id = {/literal}{$data_processor_id}{literal}; + + $('#title').on('blur', function() { + var title = $('#title').val(); + if ($('#nameSection').hasClass('hiddenElement') && !id) { + CRM.api3('DataProcessorField', 'check_name', { + 'title': title, + 'data_processor_id': data_processor_id + }).done(function (result) { + $('#systemName').html(result.name); + $('#name').val(result.name); + }); + } + }); + + $('#type').change(); + }); + {/literal} + </script> {/if} <div class="crm-submit-buttons"> diff --git a/xml/schema/CRM/Dataprocessor/DataProcessorField.entityType.php b/xml/schema/CRM/Dataprocessor/DataProcessorField.entityType.php new file mode 100644 index 0000000000000000000000000000000000000000..70a38a4adfe42f18e8a766130cc8c7f8cc285cf5 --- /dev/null +++ b/xml/schema/CRM/Dataprocessor/DataProcessorField.entityType.php @@ -0,0 +1,11 @@ +<?php +// This file declares a new entity type. For more details, see "hook_civicrm_entityTypes" at: +// http://wiki.civicrm.org/confluence/display/CRMDOC/Hook+Reference +return array ( + 0 => + array ( + 'name' => 'DataProcessorField', + 'class' => 'CRM_Dataprocessor_DAO_DataProcessorField', + 'table' => 'civicrm_data_processor_field', + ), +); diff --git a/xml/schema/CRM/Dataprocessor/DataProcessorField.xml b/xml/schema/CRM/Dataprocessor/DataProcessorField.xml new file mode 100644 index 0000000000000000000000000000000000000000..c9a2880f6aa36a4f83bbff0b19bb6bc13939c7b3 --- /dev/null +++ b/xml/schema/CRM/Dataprocessor/DataProcessorField.xml @@ -0,0 +1,70 @@ +<?xml version="1.0" encoding="iso-8859-1" ?> + +<table> + <base>CRM/Dataprocessor</base> + <class>DataProcessorField</class> + <name>civicrm_data_processor_field</name> + <log>false</log> + + <field> + <name>id</name> + <type>int unsigned</type> + <required>true</required> + <comment>Unique DataProcessorField ID</comment> + </field> + <primaryKey> + <name>id</name> + <autoincrement>true</autoincrement> + </primaryKey> + + <field> + <name>data_processor_id</name> + <title>Data Processor ID</title> + <type>int unsigned</type> + <required>true</required> + <comment>FK to Data Processor</comment> + </field> + <field> + <name>weight</name> + <title>Weight</title> + <type>int</type> + <required>false</required> + <length>255</length> + </field> + <field> + <name>name</name> + <title>Name</title> + <type>varchar</type> + <required>false</required> + <length>255</length> + </field> + <field> + <name>title</name> + <title>Title</title> + <type>varchar</type> + <required>true</required> + <length>255</length> + </field> + <field> + <name>type</name> + <title>Type</title> + <type>varchar</type> + <required>true</required> + <length>255</length> + </field> + <field> + <name>configuration</name> + <title>Configuration</title> + <type>text</type> + <required>false</required> + <length>255</length> + <serialize>JSON</serialize> + </field> + <foreignKey> + <name>data_processor_id</name> + <table>civicrm_data_processor</table> + <key>id</key> + <onDelete>CASCADE</onDelete> + </foreignKey> + +</table>