/** * Set variables up before form is built. * * * @return void */ public function preProcess() { // current set id $this->_id = $this->get('id'); if ($this->_id && ($isReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_id, 'is_reserved', 'id'))) { CRM_Core_Error::fatal("You cannot edit the settings of a reserved custom field-set."); } // setting title for html page if ($this->_action == CRM_Core_Action::UPDATE) { $title = CRM_Core_BAO_CustomGroup::getTitle($this->_id); CRM_Utils_System::setTitle(ts('Edit %1', array(1 => $title))); } elseif ($this->_action == CRM_Core_Action::VIEW) { $title = CRM_Core_BAO_CustomGroup::getTitle($this->_id); CRM_Utils_System::setTitle(ts('Preview %1', array(1 => $title))); } else { CRM_Utils_System::setTitle(ts('New Custom Field Set')); } if (isset($this->_id)) { $params = array('id' => $this->_id); CRM_Core_BAO_CustomGroup::retrieve($params, $this->_defaults); $subExtends = CRM_Utils_Array::value('extends_entity_column_value', $this->_defaults); if (!empty($subExtends)) { $this->_subtypes = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($subExtends, 1, -1)); } } }
/** * Function to set variables up before form is built * * @param null * * @return void * @access public */ function preProcess() { require_once 'CRM/Core/BAO/CustomGroup.php'; // current group id $this->_id = $this->get('id'); // setting title for html page if ($this->_action == CRM_CORE_ACTION_UPDATE) { $title = CRM_Core_BAO_CustomGroup::getTitle($this->_id); CRM_Utils_System::setTitle(ts('Edit %1', array(1 => $title))); } else { if ($this->_action == CRM_CORE_ACTION_VIEW) { $title = CRM_Core_BAO_CustomGroup::getTitle($this->_id); CRM_Utils_System::setTitle(ts('Preview %1', array(1 => $title))); } else { CRM_Utils_System::setTitle(ts('New Custom Data Group')); } } }
/** * Function to test getTitle() */ function testGetTitle() { $customGrouptitle = 'My Custom Group'; $groupParams = array('title' => $customGrouptitle, 'name' => 'my_custom_group', 'style' => 'Tab', 'extends' => 'Individual', 'is_active' => 0); $customGroup = Custom::createGroup($groupParams); $customGroupId = $customGroup->id; require_once 'CRM/Core/BAO/CustomGroup.php'; //get the custom group title $title = CRM_Core_BAO_CustomGroup::getTitle($customGroupId); //check for object update $this->assertEquals($customGrouptitle, $title); //cleanup DB by deleting customGroup Custom::deleteGroup($customGroup); }
/** * Pre processing work done here. * * Gets session variables for table name, id of entity in table, type of entity and stores them. */ public function preProcess() { $this->_cdType = CRM_Utils_Array::value('type', $_GET); $this->assign('cdType', FALSE); $this->_multiRecordDisplay = CRM_Utils_Request::retrieve('multiRecordDisplay', 'String', $this); if ($this->_cdType || $this->_multiRecordDisplay == 'single') { if ($this->_cdType) { $this->assign('cdType', TRUE); } // NOTE : group id is not stored in session from within CRM_Custom_Form_CustomData::preProcess func // this is due to some condition inside it which restricts it from saving in session // so doing this for multi record edit action $entityId = CRM_Utils_Request::retrieve('entityID', 'Positive', $this); if (!empty($entityId)) { $subType = CRM_Contact_BAO_Contact::getContactSubType($entityId, ','); } CRM_Custom_Form_CustomData::preProcess($this, NULL, $subType, NULL, NULL, $entityId); if ($this->_multiRecordDisplay) { $this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this); $this->_tableID = $this->_entityId; $this->_contactType = CRM_Contact_BAO_Contact::getContactType($this->_tableID); $mode = CRM_Utils_Request::retrieve('mode', 'String', $this); $hasReachedMax = CRM_Core_BAO_CustomGroup::hasReachedMaxLimit($this->_groupID, $this->_tableID); if ($hasReachedMax && $mode == 'add') { CRM_Core_Error::statusBounce(ts('The maximum record limit is reached')); } $this->_copyValueId = CRM_Utils_Request::retrieve('copyValueId', 'Positive', $this); $groupTitle = CRM_Core_BAO_CustomGroup::getTitle($this->_groupID); $mode = CRM_Utils_Request::retrieve('mode', 'String', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET'); $mode = ucfirst($mode); CRM_Utils_System::setTitle(ts('%1 %2 Record', array(1 => $mode, 2 => $groupTitle))); if (!empty($_POST['hidden_custom'])) { $this->assign('postedInfo', TRUE); } } return; } $this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this, TRUE); $this->_tableID = CRM_Utils_Request::retrieve('tableId', 'Positive', $this, TRUE); $this->_contactType = CRM_Contact_BAO_Contact::getContactType($this->_tableID); $this->_contactSubType = CRM_Contact_BAO_Contact::getContactSubType($this->_tableID, ','); $this->assign('contact_type', $this->_contactType); $this->assign('contact_subtype', $this->_contactSubType); list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($this->_tableID); CRM_Utils_System::setTitle($displayName, $contactImage . ' ' . $displayName); // when custom data is included in this page if (!empty($_POST['hidden_custom'])) { for ($i = 1; $i <= $_POST['hidden_custom_group_count'][$this->_groupID]; $i++) { CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_contactSubType, $i, $this->_contactType, $this->_tableID); CRM_Custom_Form_CustomData::buildQuickForm($this); CRM_Custom_Form_CustomData::setDefaultValues($this); } } }
/** * 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() { $this->preProcess(); //set the userContext stack $doneURL = 'civicrm/contact/view'; $session = CRM_Core_Session::singleton(); $session->pushUserContext(CRM_Utils_System::url($doneURL, 'action=browse&selectedChild=custom_' . $this->_groupId), FALSE); // get permission detail view or edit // use a comtact id specific function which gives us much better granularity // CRM-12646 $editCustomData = CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT); $this->assign('editCustomData', $editCustomData); //allow to edit own customdata CRM-5518 $editOwnCustomData = FALSE; if ($session->get('userID') == $this->_contactId) { $editOwnCustomData = TRUE; } $this->assign('editOwnCustomData', $editOwnCustomData); if ($this->_action == CRM_Core_Action::BROWSE) { //Custom Groups Inline $entityType = CRM_Contact_BAO_Contact::getContactType($this->_contactId); $entitySubType = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId); $groupTree =& CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $this->_contactId, $this->_groupId, $entitySubType); $displayStyle = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_groupId, 'style'); if ($this->_multiRecordDisplay != 'single') { $id = "custom_{$this->_groupId}"; $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $groupTree[$this->_groupId]['table_name']); } if ($displayStyle === 'Tab with table' && $this->_multiRecordDisplay != 'single') { $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'contact_type'); $this->assign('displayStyle', 'tableOriented'); // here the multi custom data listing code will go $multiRecordFieldListing = TRUE; $page = new CRM_Profile_Page_MultipleRecordFieldsListing(); $page->set('contactId', $this->_contactId); $page->set('customGroupId', $this->_groupId); $page->set('action', CRM_Core_Action::BROWSE); $page->set('multiRecordFieldListing', $multiRecordFieldListing); $page->set('pageViewType', 'customDataView'); $page->set('contactType', $ctype); $page->run(); } else { $recId = NULL; if ($this->_multiRecordDisplay == 'single') { $groupTitle = CRM_Core_BAO_CustomGroup::getTitle($this->_groupId); CRM_Utils_System::setTitle(ts('View %1 Record', array(1 => $groupTitle))); $recId = $this->_recId; $this->assign('multiRecordDisplay', $this->_multiRecordDisplay); $this->assign('skipTitle', 1); } CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, $recId); } } else { $controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_CustomData', ts('Custom Data'), $this->_action); $controller->setEmbedded(TRUE); $controller->set('tableId', $this->_contactId); $controller->set('groupId', $this->_groupId); $controller->set('entityType', CRM_Contact_BAO_Contact::getContactType($this->_contactId)); $controller->set('entitySubType', CRM_Contact_BAO_Contact::getContactSubType($this->_contactId, ',')); $controller->process(); $controller->run(); } return parent::run(); }
/** * Test getTitle() */ public function testGetTitle() { $customGroupTitle = 'Custom Group'; $groupParams = array('title' => $customGroupTitle, 'name' => 'my_custom_group', 'style' => 'Tab', 'extends' => 'Individual', 'is_active' => 0); $customGroup = $this->customGroupCreate($groupParams); $customGroupId = $customGroup['id']; //get the custom group title $title = CRM_Core_BAO_CustomGroup::getTitle($customGroupId); //check for object update $this->assertEquals($customGroupTitle, $title); $this->customGroupDelete($customGroupId); }
/** * 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']; } 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', $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(); }
/** * Run the page. * * This method is called after the page is created. It checks for the * type of action and executes that action. * * @param null * * @return void * @access public */ function run() { require_once 'CRM/Core/BAO/CustomGroup.php'; // get the group id $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this); $action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'browse'); // default to '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); CRM_Utils_System::setTitle(ts('%1 - Custom Fields', array(1 => $groupTitle))); } // 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($action); // no browse for edit/update/view } else { if ($action & CRM_Core_Action::PREVIEW) { $this->preview($id); } else { require_once 'CRM/Core/BAO/CustomField.php'; require_once 'CRM/Core/BAO/UFField.php'; $this->browse(); } } // Call the parents run method parent::run(); }
/** * Function to set variables up before form is built * * @param null * * @return void * @access public */ public function preProcess() { require_once 'CRM/Core/BAO/CustomGroup.php'; // current set id $this->_id = $this->get('id'); // setting title for html page if ($this->_action == CRM_Core_Action::UPDATE) { $title = CRM_Core_BAO_CustomGroup::getTitle($this->_id); CRM_Utils_System::setTitle(ts('Edit %1', array(1 => $title))); } else { if ($this->_action == CRM_Core_Action::VIEW) { $title = CRM_Core_BAO_CustomGroup::getTitle($this->_id); CRM_Utils_System::setTitle(ts('Preview %1', array(1 => $title))); } else { CRM_Utils_System::setTitle(ts('New Custom Field Set')); } } if (isset($this->_id)) { $params = array('id' => $this->_id); CRM_Core_BAO_CustomGroup::retrieve($params, $this->_defaults); $subExtends = CRM_Utils_Array::value('extends_entity_column_value', $this->_defaults); if (!empty($subExtends)) { $this->_subtypes = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($subExtends, 1, -1)); } } }