First commit

This commit is contained in:
Theodotos Andreou 2018-01-14 13:10:16 +00:00
commit c6e2478c40
13918 changed files with 2303184 additions and 0 deletions

View file

@ -0,0 +1,164 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| 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 |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*
*/
/**
* This class contains the functions that are called using AJAX (jQuery)
*/
class CRM_Custom_Page_AJAX {
/**
* This function uses the deprecated v1 datatable api and needs updating. See CRM-16353.
* @deprecated
*/
public static function getOptionList() {
$params = $_REQUEST;
$sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
$offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
$rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
$params['page'] = ($offset / $rowCount) + 1;
$params['rp'] = $rowCount;
$options = CRM_Core_BAO_CustomOption::getOptionListSelector($params);
$iFilteredTotal = $iTotal = $params['total'];
$selectorElements = array(
'label',
'value',
'is_default',
'is_active',
'links',
'class',
);
CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($options, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
/**
* Fix Ordering of options
*
*/
public static function fixOrdering() {
$params = $_REQUEST;
$queryParams = array(
1 => array($params['start'], 'Integer'),
2 => array($params['end'], 'Integer'),
3 => array($params['gid'], 'Integer'),
);
$dao = "SELECT id FROM civicrm_option_value WHERE weight = %1 AND option_group_id = %3";
$startid = CRM_Core_DAO::singleValueQuery($dao, $queryParams);
$dao2 = "SELECT id FROM civicrm_option_value WHERE weight = %2 AND option_group_id = %3";
$endid = CRM_Core_DAO::singleValueQuery($dao2, $queryParams);
$query = "UPDATE civicrm_option_value SET weight = %2 WHERE id = $startid";
CRM_Core_DAO::executeQuery($query, $queryParams);
// increment or decrement the rest by one
if ($params['start'] < $params['end']) {
$updateRows = "UPDATE civicrm_option_value
SET weight = weight - 1
WHERE weight > %1 AND weight < %2 AND option_group_id = %3
OR id = $endid";
}
else {
$updateRows = "UPDATE civicrm_option_value
SET weight = weight + 1
WHERE weight < %1 AND weight > %2 AND option_group_id = %3
OR id = $endid";
}
CRM_Core_DAO::executeQuery($updateRows, $queryParams);
CRM_Utils_JSON::output(TRUE);
}
/**
* Get list of Multi Record Fields.
*
*/
public static function getMultiRecordFieldList() {
$params = CRM_Core_Page_AJAX::defaultSortAndPagerParams(0, 10);
$params['cid'] = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
$params['cgid'] = CRM_Utils_Type::escape($_GET['cgid'], 'Integer');
$contactType = CRM_Contact_BAO_Contact::getContactType($params['cid']);
$obj = new CRM_Profile_Page_MultipleRecordFieldsListing();
$obj->_pageViewType = 'customDataView';
$obj->_contactId = $params['cid'];
$obj->_customGroupId = $params['cgid'];
$obj->_contactType = $contactType;
$obj->_DTparams['offset'] = ($params['page'] - 1) * $params['rp'];
$obj->_DTparams['rowCount'] = $params['rp'];
if (!empty($params['sortBy'])) {
$obj->_DTparams['sort'] = $params['sortBy'];
}
list($fields, $attributes) = $obj->browse();
// format params and add class attributes
$fieldList = array();
foreach ($fields as $id => $value) {
$field = array();
foreach ($value as $fieldId => &$fieldName) {
if (!empty($attributes[$fieldId][$id]['class'])) {
$fieldName = array('data' => $fieldName, 'cellClass' => $attributes[$fieldId][$id]['class']);
}
if (is_numeric($fieldId)) {
$fName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $fieldId, 'column_name');
CRM_Utils_Array::crmReplaceKey($value, $fieldId, $fName);
}
}
$field = $value;
array_push($fieldList, $field);
}
$totalRecords = !empty($obj->_total) ? $obj->_total : 0;
$multiRecordFields = array();
$multiRecordFields['data'] = $fieldList;
$multiRecordFields['recordsTotal'] = $totalRecords;
$multiRecordFields['recordsFiltered'] = $totalRecords;
if (!empty($_GET['is_unit_test'])) {
return $multiRecordFields;
}
CRM_Utils_JSON::output($multiRecordFields);
}
}

View file

@ -0,0 +1,316 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| 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 |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* Create a page for displaying Custom Fields.
*
* Heart of this class is the run method which checks
* for action type and then displays the appropriate
* page.
*
*/
class CRM_Custom_Page_Field extends CRM_Core_Page {
public $useLivePageJS = TRUE;
/**
* The group id of the field.
*
* @var int
*/
protected $_gid;
/**
* The action links that we need to display for the browse screen.
*
* @var array
*/
private static $_actionLinks;
/**
* Get the action links for this page.
*
* @return array
* array of action links that we need to display for the browse screen
*/
public static function &actionLinks() {
if (!isset(self::$_actionLinks)) {
self::$_actionLinks = array(
CRM_Core_Action::UPDATE => array(
'name' => ts('Edit Field'),
'url' => 'civicrm/admin/custom/group/field/update',
'qs' => 'action=update&reset=1&gid=%%gid%%&id=%%id%%',
'title' => ts('Edit Custom Field'),
),
CRM_Core_Action::BROWSE => array(
'name' => ts('Edit Multiple Choice Options'),
'url' => 'civicrm/admin/custom/group/field/option',
'qs' => 'reset=1&action=browse&gid=%%gid%%&fid=%%id%%',
'title' => ts('List Custom Options'),
),
CRM_Core_Action::PREVIEW => array(
'name' => ts('Preview Field Display'),
'url' => 'civicrm/admin/custom/group/field',
'qs' => 'action=preview&reset=1&gid=%%gid%%&id=%%id%%',
'title' => ts('Preview Custom Field'),
),
CRM_Core_Action::DISABLE => array(
'name' => ts('Disable'),
'ref' => 'crm-enable-disable',
'title' => ts('Disable Custom Field'),
),
CRM_Core_Action::ENABLE => array(
'name' => ts('Enable'),
'ref' => 'crm-enable-disable',
'title' => ts('Enable Custom Field'),
),
CRM_Core_Action::EXPORT => array(
'name' => ts('Move'),
'url' => 'civicrm/admin/custom/group/field/move',
'class' => 'small-popup',
'qs' => 'reset=1&fid=%%id%%',
'title' => ts('Move Custom Field'),
),
CRM_Core_Action::DELETE => array(
'name' => ts('Delete'),
'url' => 'civicrm/admin/custom/group/field',
'qs' => 'action=delete&reset=1&gid=%%gid%%&id=%%id%%',
'title' => ts('Delete Custom Field'),
),
);
}
return self::$_actionLinks;
}
/**
* Browse all custom group fields.
*
* @return void
*/
public function browse() {
$resourceManager = CRM_Core_Resources::singleton();
if (!empty($_GET['new']) && $resourceManager->ajaxPopupsEnabled) {
$resourceManager->addScriptFile('civicrm', 'js/crm.addNew.js', 999, 'html-header');
}
$customField = array();
$customFieldBAO = new CRM_Core_BAO_CustomField();
// fkey is gid
$customFieldBAO->custom_group_id = $this->_gid;
$customFieldBAO->orderBy('weight, label');
$customFieldBAO->find();
while ($customFieldBAO->fetch()) {
$customField[$customFieldBAO->id] = array();
CRM_Core_DAO::storeValues($customFieldBAO, $customField[$customFieldBAO->id]);
$action = array_sum(array_keys(self::actionLinks()));
if ($customFieldBAO->is_active) {
$action -= CRM_Core_Action::ENABLE;
}
else {
$action -= CRM_Core_Action::DISABLE;
}
switch ($customFieldBAO->data_type) {
case "String":
case "Int":
case "Float":
case "Money":
// if Multi Select field is selected in custom field
if ($customFieldBAO->html_type == 'Text') {
$action -= CRM_Core_Action::BROWSE;
}
break;
case "ContactReference":
case "Memo":
case "Date":
case "Boolean":
case "StateProvince":
case "Country":
case "File":
case "Link":
$action -= CRM_Core_Action::BROWSE;
break;
}
$customFieldDataType = CRM_Core_BAO_CustomField::dataType();
$customField[$customFieldBAO->id]['data_type'] = $customFieldDataType[$customField[$customFieldBAO->id]['data_type']];
$customField[$customFieldBAO->id]['order'] = $customField[$customFieldBAO->id]['weight'];
$customField[$customFieldBAO->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action,
array(
'id' => $customFieldBAO->id,
'gid' => $this->_gid,
),
ts('more'),
FALSE,
'customField.row.actions',
'CustomField',
$customFieldBAO->id
);
}
$returnURL = CRM_Utils_System::url('civicrm/admin/custom/group/field', "reset=1&action=browse&gid={$this->_gid}");
$filter = "custom_group_id = {$this->_gid}";
CRM_Utils_Weight::addOrder($customField, 'CRM_Core_DAO_CustomField',
'id', $returnURL, $filter
);
$this->assign('customField', $customField);
}
/**
* Edit custom data.
*
* editing would involved modifying existing fields + adding data to new fields.
*
* @param string $action
* The action to be invoked.
*
* @return void
*/
public function edit($action) {
// create a simple controller for editing custom dataCRM/Custom/Page/Field.php
$controller = new CRM_Core_Controller_Simple('CRM_Custom_Form_Field', ts('Custom Field'), $action);
// set the userContext stack
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field', 'reset=1&action=browse&gid=' . $this->_gid));
$controller->set('gid', $this->_gid);
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
}
/**
* Run the page.
*
* This method is called after the page is created. It checks for the
* type of action and executes that action.
*
* @return void
*/
public function run() {
$id = CRM_Utils_Request::retrieve('id', 'Positive',
$this, FALSE, 0
);
if ($id) {
$values = civicrm_api3('custom_field', 'getsingle', array('id' => $id));
$this->_gid = $values['custom_group_id'];
}
// get the group id
else {
$this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive',
$this
);
}
if ($isReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_reserved', 'id')) {
CRM_Core_Error::fatal("You cannot add or edit fields in a reserved custom field-set.");
}
$action = CRM_Utils_Request::retrieve('action', 'String',
// default to 'browse'
$this, FALSE, 'browse'
);
if ($action & CRM_Core_Action::DELETE) {
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field', 'reset=1&action=browse&gid=' . $this->_gid));
$controller = new CRM_Core_Controller_Simple('CRM_Custom_Form_DeleteField', "Delete Custom Field", '');
$id = CRM_Utils_Request::retrieve('id', 'Positive',
$this, FALSE, 0
);
$controller->set('id', $id);
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
$fieldValues = array('custom_group_id' => $this->_gid);
$wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_CustomField', $id, $fieldValues);
}
if ($this->_gid) {
$groupTitle = CRM_Core_BAO_CustomGroup::getTitle($this->_gid);
$this->assign('gid', $this->_gid);
$this->assign('groupTitle', $groupTitle);
if ($action & CRM_Core_Action::BROWSE) {
CRM_Utils_System::setTitle(ts('%1 - Custom Fields', array(1 => $groupTitle)));
}
}
// assign vars to templates
$this->assign('action', $action);
// what action to take ?
if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
// no browse for edit/update/view
$this->edit($action);
}
elseif ($action & CRM_Core_Action::PREVIEW) {
$this->preview($id);
}
else {
$this->browse();
}
// Call the parents run method
return parent::run();
}
/**
* Preview custom field.
*
* @param int $id
* Custom field id.
*
* @return void
*/
public function preview($id) {
$controller = new CRM_Core_Controller_Simple('CRM_Custom_Form_Preview', ts('Preview Custom Data'), CRM_Core_Action::PREVIEW);
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field', 'reset=1&action=browse&gid=' . $this->_gid));
$controller->set('fieldId', $id);
$controller->set('groupId', $this->_gid);
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
}
}

View file

@ -0,0 +1,336 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| 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 |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* Create a page for displaying Custom Sets.
*
* Heart of this class is the run method which checks
* for action type and then displays the appropriate
* page.
*
*/
class CRM_Custom_Page_Group extends CRM_Core_Page {
/**
* The action links that we need to display for the browse screen
*
* @var array
*/
private static $_actionLinks;
/**
* Get the action links for this page.
*
*
* @return array
* array of action links that we need to display for the browse screen
*/
public static function &actionLinks() {
// check if variable _actionsLinks is populated
if (!isset(self::$_actionLinks)) {
self::$_actionLinks = array(
CRM_Core_Action::BROWSE => array(
'name' => ts('View and Edit Custom Fields'),
'url' => 'civicrm/admin/custom/group/field',
'qs' => 'reset=1&action=browse&gid=%%id%%',
'title' => ts('View and Edit Custom Fields'),
),
CRM_Core_Action::PREVIEW => array(
'name' => ts('Preview'),
'url' => 'civicrm/admin/custom/group',
'qs' => 'action=preview&reset=1&id=%%id%%',
'title' => ts('Preview Custom Data Set'),
),
CRM_Core_Action::UPDATE => array(
'name' => ts('Settings'),
'url' => 'civicrm/admin/custom/group',
'qs' => 'action=update&reset=1&id=%%id%%',
'title' => ts('Edit Custom Set'),
),
CRM_Core_Action::DISABLE => array(
'name' => ts('Disable'),
'ref' => 'crm-enable-disable',
'title' => ts('Disable Custom Set'),
),
CRM_Core_Action::ENABLE => array(
'name' => ts('Enable'),
'ref' => 'crm-enable-disable',
'title' => ts('Enable Custom Set'),
),
CRM_Core_Action::DELETE => array(
'name' => ts('Delete'),
'url' => 'civicrm/admin/custom/group',
'qs' => 'action=delete&reset=1&id=%%id%%',
'title' => ts('Delete Custom Set'),
),
);
}
return self::$_actionLinks;
}
/**
* Run the page.
*
* This method is called after the page is created. It checks for the
* type of action and executes that action.
* Finally it calls the parent's run method.
*
* @return void
*/
public function run() {
// get the requested action
$action = CRM_Utils_Request::retrieve('action', 'String',
// default to 'browse'
$this, FALSE, 'browse'
);
if ($action & CRM_Core_Action::DELETE) {
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/', 'action=browse'));
$controller = new CRM_Core_Controller_Simple('CRM_Custom_Form_DeleteGroup', "Delete Cutom Set", NULL);
$id = CRM_Utils_Request::retrieve('id', 'Positive',
$this, FALSE, 0
);
$controller->set('id', $id);
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
}
// assign vars to templates
$this->assign('action', $action);
$id = CRM_Utils_Request::retrieve('id', 'Positive',
$this, FALSE, 0
);
// what action to take ?
if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
$this->edit($id, $action);
}
elseif ($action & CRM_Core_Action::PREVIEW) {
$this->preview($id);
}
else {
// finally browse the custom groups
$this->browse();
}
// parent run
return parent::run();
}
/**
* Edit custom group.
*
* @param int $id
* Custom group id.
* @param string $action
* The action to be invoked.
*
* @return void
*/
public function edit($id, $action) {
// create a simple controller for editing custom data
$controller = new CRM_Core_Controller_Simple('CRM_Custom_Form_Group', ts('Custom Set'), $action);
// set the userContext stack
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/', 'action=browse'));
$controller->set('id', $id);
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
}
/**
* Preview custom group.
*
* @param int $id
* Custom group id.
*
* @return void
*/
public function preview($id) {
$controller = new CRM_Core_Controller_Simple('CRM_Custom_Form_Preview', ts('Preview Custom Data'), NULL);
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/custom/group', 'action=browse'));
$controller->set('groupId', $id);
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
}
/**
* Browse all custom data groups.
*
* @param string $action
* The action to be invoked.
*
* @return void
*/
public function browse($action = NULL) {
// get all custom groups sorted by weight
$customGroup = array();
$dao = new CRM_Core_DAO_CustomGroup();
$dao->is_reserved = FALSE;
$dao->orderBy('weight, title');
$dao->find();
$customGroupExtends = CRM_Core_SelectValues::customGroupExtends();
$customGroupStyle = CRM_Core_SelectValues::customGroupStyle();
while ($dao->fetch()) {
$id = $dao->id;
$customGroup[$id] = array();
CRM_Core_DAO::storeValues($dao, $customGroup[$id]);
// form all action links
$action = array_sum(array_keys(self::actionLinks()));
// update enable/disable links depending on custom_group properties.
if ($dao->is_active) {
$action -= CRM_Core_Action::ENABLE;
}
else {
$action -= CRM_Core_Action::DISABLE;
}
$customGroup[$id]['order'] = $customGroup[$id]['weight'];
$customGroup[$id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action,
array('id' => $id),
ts('more'),
FALSE,
'customGroup.row.actions',
'CustomGroup',
$id
);
if (!empty($customGroup[$id]['style'])) {
$customGroup[$id]['style_display'] = $customGroupStyle[$customGroup[$id]['style']];
}
$customGroup[$id]['extends_display'] = $customGroupExtends[$customGroup[$id]['extends']];
}
//fix for Displaying subTypes
$subTypes = array();
$subTypes['Activity'] = CRM_Core_PseudoConstant::activityType(FALSE, TRUE, FALSE, 'label', TRUE);
$subTypes['Contribution'] = CRM_Contribute_PseudoConstant::financialType();
$subTypes['Membership'] = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE);
$subTypes['Event'] = CRM_Core_OptionGroup::values('event_type');
$subTypes['Grant'] = CRM_Core_OptionGroup::values('grant_type');
$subTypes['Campaign'] = CRM_Campaign_PseudoConstant::campaignType();
$subTypes['Participant'] = array();
$subTypes['ParticipantRole'] = CRM_Core_OptionGroup::values('participant_role');;
$subTypes['ParticipantEventName'] = CRM_Event_PseudoConstant::event();
$subTypes['ParticipantEventType'] = CRM_Core_OptionGroup::values('event_type');
$subTypes['Individual'] = CRM_Contact_BAO_ContactType::subTypePairs('Individual', FALSE, NULL);
$subTypes['Household'] = CRM_Contact_BAO_ContactType::subTypePairs('Household', FALSE, NULL);
$subTypes['Organization'] = CRM_Contact_BAO_ContactType::subTypePairs('Organization', FALSE, NULL);
$relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Individual');
$relTypeOrg = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Organization');
$relTypeHou = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Household');
$allRelationshipType = array();
$allRelationshipType = array_merge($relTypeInd, $relTypeOrg);
$allRelationshipType = array_merge($allRelationshipType, $relTypeHou);
//adding subtype specific relationships CRM-5256
$relSubType = CRM_Contact_BAO_ContactType::subTypeInfo();
foreach ($relSubType as $subType => $val) {
$subTypeRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $val['parent'],
FALSE, 'label', TRUE, $subType
);
$allRelationshipType = array_merge($allRelationshipType, $subTypeRelationshipTypes);
}
$subTypes['Relationship'] = $allRelationshipType;
$cSubTypes = CRM_Core_Component::contactSubTypes();
$contactSubTypes = array();
foreach ($cSubTypes as $key => $value) {
$contactSubTypes[$key] = $key;
}
$subTypes['Contact'] = $contactSubTypes;
CRM_Core_BAO_CustomGroup::getExtendedObjectTypes($subTypes);
foreach ($customGroup as $key => $values) {
$subValue = CRM_Utils_Array::value('extends_entity_column_value', $customGroup[$key]);
$subName = CRM_Utils_Array::value('extends_entity_column_id', $customGroup[$key]);
$type = CRM_Utils_Array::value('extends', $customGroup[$key]);
if ($subValue) {
$subValue = explode(CRM_Core_DAO::VALUE_SEPARATOR,
substr($subValue, 1, -1)
);
$colValue = NULL;
foreach ($subValue as $sub) {
if ($sub) {
if ($type == 'Participant') {
if ($subName == 1) {
$colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantRole'][$sub] : $subTypes['ParticipantRole'][$sub];
}
elseif ($subName == 2) {
$colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantEventName'][$sub] : $subTypes['ParticipantEventName'][$sub];
}
elseif ($subName == 3) {
$colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantEventType'][$sub] : $subTypes['ParticipantEventType'][$sub];
}
}
elseif ($type == 'Relationship') {
$colValue = $colValue ? $colValue . ', ' . $subTypes[$type][$sub . '_a_b'] : $subTypes[$type][$sub . '_a_b'];
if (isset($subTypes[$type][$sub . '_b_a'])) {
$colValue = $colValue ? $colValue . ', ' . $subTypes[$type][$sub . '_b_a'] : $subTypes[$type][$sub . '_b_a'];
}
}
else {
$colValue = $colValue ? ($colValue . (isset($subTypes[$type][$sub]) ? ', ' . $subTypes[$type][$sub] : '')) : (isset($subTypes[$type][$sub]) ? $subTypes[$type][$sub] : '');
}
}
}
$customGroup[$key]["extends_entity_column_value"] = $colValue;
}
else {
if (is_array(CRM_Utils_Array::value($type, $subTypes))) {
$customGroup[$key]["extends_entity_column_value"] = ts("Any");
}
}
}
$returnURL = CRM_Utils_System::url('civicrm/admin/custom/group', "reset=1&action=browse");
CRM_Utils_Weight::addOrder($customGroup, 'CRM_Core_DAO_CustomGroup',
'id', $returnURL
);
$this->assign('rows', $customGroup);
}
}

View file

@ -0,0 +1,284 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| 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 |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* Create a page for displaying Custom Options.
*
* Heart of this class is the run method which checks
* for action type and then displays the appropriate
* page.
*
*/
class CRM_Custom_Page_Option extends CRM_Core_Page {
public $useLivePageJS = TRUE;
/**
* The Group id of the option
*
* @var int
*/
protected $_gid;
/**
* The field id of the option
*
* @var int
*/
protected $_fid;
/**
* The action links that we need to display for the browse screen
*
* @var array
*/
private static $_actionLinks;
/**
* Get the action links for this page.
*
* @return array
* array of action links that we need to display for the browse screen
*/
public static function &actionLinks() {
if (!isset(self::$_actionLinks)) {
self::$_actionLinks = array(
CRM_Core_Action::UPDATE => array(
'name' => ts('Edit Option'),
'url' => 'civicrm/admin/custom/group/field/option',
'qs' => 'reset=1&action=update&id=%%id%%&fid=%%fid%%&gid=%%gid%%',
'title' => ts('Edit Multiple Choice Option'),
),
CRM_Core_Action::VIEW => array(
'name' => ts('View'),
'url' => 'civicrm/admin/custom/group/field/option',
'qs' => 'action=view&id=%%id%%&fid=%%fid%%',
'title' => ts('View Multiple Choice Option'),
),
CRM_Core_Action::DISABLE => array(
'name' => ts('Disable'),
'ref' => 'crm-enable-disable',
'title' => ts('Disable Mutliple Choice Option'),
),
CRM_Core_Action::ENABLE => array(
'name' => ts('Enable'),
'ref' => 'crm-enable-disable',
'title' => ts('Enable Mutliple Choice Option'),
),
CRM_Core_Action::DELETE => array(
'name' => ts('Delete'),
'url' => 'civicrm/admin/custom/group/field/option',
'qs' => 'action=delete&id=%%id%%&fid=%%fid%%',
'title' => ts('Disable Multiple Choice Option'),
),
);
}
return self::$_actionLinks;
}
/**
* Alphabetize multiple option values
*
* @return void
*/
public function alphabetize() {
$optionGroupID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField',
$this->_fid,
'option_group_id'
);
$query = "
SELECT id, label
FROM civicrm_option_value
WHERE option_group_id = %1";
$params = array(
1 => array($optionGroupID, 'Integer'),
);
$dao = CRM_Core_DAO::executeQuery($query, $params);
$optionValue = array();
while ($dao->fetch()) {
$optionValue[$dao->id] = $dao->label;
}
asort($optionValue, SORT_STRING | SORT_FLAG_CASE | SORT_NATURAL);
$i = 1;
foreach ($optionValue as $key => $_) {
$clause[] = "WHEN $key THEN $i";
$i++;
}
$when = implode(' ', $clause);
$sql = "
UPDATE civicrm_option_value
SET weight = CASE id
$when
END
WHERE option_group_id = %1";
$dao = CRM_Core_DAO::executeQuery($sql, $params);
}
/**
* Browse all custom group fields.
*
* @return void
*/
public function browse() {
// get the option group id
$optionGroupID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField',
$this->_fid,
'option_group_id'
);
$query = "
SELECT id, label
FROM civicrm_custom_field
WHERE option_group_id = %1";
$params = array(
1 => array($optionGroupID, 'Integer'),
2 => array($this->_fid, 'Integer'),
);
$dao = CRM_Core_DAO::executeQuery($query, $params);
$reusedNames = array();
if ($dao->N > 1) {
while ($dao->fetch()) {
$reusedNames[] = $dao->label;
}
$reusedNames = implode(', ', $reusedNames);
$newTitle = ts('%1 - Multiple Choice Options',
array(1 => $reusedNames)
);
CRM_Utils_System::setTitle($newTitle);
$this->assign('reusedNames', $reusedNames);
}
$this->assign('optionGroupID', $optionGroupID);
}
/**
* Edit custom Option.
*
* editing would involved modifying existing fields + adding data to new fields.
*
* @param string $action
* The action to be invoked.
*
* @return void
*/
public function edit($action) {
// create a simple controller for editing custom data
$controller = new CRM_Core_Controller_Simple('CRM_Custom_Form_Option', ts('Custom Option'), $action);
// set the userContext stack
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field/option',
"reset=1&action=browse&fid={$this->_fid}&gid={$this->_gid}"
));
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
}
/**
* Run the page.
*
* This method is called after the page is created. It checks for the
* type of action and executes that action.
*
* @return void
*/
public function run() {
// get the field id
$this->_fid = CRM_Utils_Request::retrieve('fid', 'Positive',
$this, FALSE, 0
);
$this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive',
$this, FALSE, 0
);
if ($isReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_reserved', 'id')) {
CRM_Core_Error::fatal("You cannot add or edit muliple choice options in a reserved custom field-set.");
}
//as url contain $gid so append breadcrumb dynamically.
$breadcrumb = array(
array(
'title' => ts('Custom Data Fields'),
'url' => CRM_Utils_System::url('civicrm/admin/custom/group/field', 'reset=1&gid=' . $this->_gid),
),
);
CRM_Utils_System::appendBreadCrumb($breadcrumb);
if ($this->_fid) {
$fieldTitle = CRM_Core_BAO_CustomField::getTitle($this->_fid);
$this->assign('fid', $this->_fid);
$this->assign('gid', $this->_gid);
$this->assign('fieldTitle', $fieldTitle);
CRM_Utils_System::setTitle(ts('%1 - Multiple Choice Options', array(1 => $fieldTitle)));
}
// get the requested action
$action = CRM_Utils_Request::retrieve('action', 'String',
// default to 'browse'
$this, FALSE, 'browse'
);
// assign vars to templates
$this->assign('action', $action);
$id = CRM_Utils_Request::retrieve('id', 'Positive',
$this, FALSE, 0
);
// take action in addition to default browse ?
if (($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD |
CRM_Core_Action::VIEW | CRM_Core_Action::DELETE
)
) ||
!empty($_POST)
) {
// no browse for edit/update/view
$this->edit($action);
}
elseif ($action & CRM_Core_Action::MAP) {
$this->alphabetize();
}
$this->browse();
// Call the parents run method
return parent::run();
}
}