Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display public title and description on profiles and unsubscribe/subs… #18645

Merged
merged 1 commit into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions CRM/Contact/BAO/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -1030,14 +1030,16 @@ public static function getGroupList(&$params) {
* @param string $parents
* @param string $spacer
* @param bool $titleOnly
* @param bool $public
*
* @return array
*/
public static function getGroupsHierarchy(
$groupIDs,
$parents = NULL,
$spacer = '<span class="child-indent"></span>',
$titleOnly = FALSE
$titleOnly = FALSE,
$public = FALSE
) {
if (empty($groupIDs)) {
return [];
Expand All @@ -1055,7 +1057,7 @@ public static function getGroupsHierarchy(
$groups = [];
$args = [1 => [$groupIdString, 'String']];
$query = "
SELECT id, title, description, visibility, parents, saved_search_id
SELECT id, title, frontend_title, description, frontend_description, visibility, parents, saved_search_id
FROM civicrm_group
WHERE id IN $groupIdString
";
Expand All @@ -1076,22 +1078,32 @@ public static function getGroupsHierarchy(
$roots = [];
$tree = [];
while ($dao->fetch()) {
$title = $dao->title;
$description = $dao->description;
if ($public) {
if (!empty($dao->frontend_title)) {
$title = $dao->frontend_title;
}
if (!empty($dao->frontend_description)) {
$description = $dao->frontend_description;
}
}
if ($dao->parents) {
$parentArray = explode(',', $dao->parents);
$parent = self::filterActiveGroups($parentArray);
$tree[$parent][] = [
'id' => $dao->id,
'title' => empty($dao->saved_search_id) ? $dao->title : '* ' . $dao->title,
'title' => empty($dao->saved_search_id) ? $title : '* ' . $title,
'visibility' => $dao->visibility,
'description' => $dao->description,
'description' => $description,
];
}
else {
$roots[] = [
'id' => $dao->id,
'title' => empty($dao->saved_search_id) ? $dao->title : '* ' . $dao->title,
'title' => empty($dao->saved_search_id) ? $title : '* ' . $title,
'visibility' => $dao->visibility,
'description' => $dao->description,
'description' => $description,
];
}
}
Expand Down
8 changes: 6 additions & 2 deletions CRM/Contact/BAO/GroupContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ public static function getGroupList($contactId = 0, $visibility = FALSE) {
*
* @param bool $includeSmartGroups
* Include or Exclude Smart Group(s)
* @param bool $public
* Are we returning groups for use on a public page.
*
* @return array|int
* the relevant data object values for the contact or the total count when $count is TRUE
Expand All @@ -317,7 +319,8 @@ public static function getContactGroup(
$onlyPublicGroups = FALSE,
$excludeHidden = TRUE,
$groupId = NULL,
$includeSmartGroups = FALSE
$includeSmartGroups = FALSE,
$public = FALSE
) {
if ($count) {
$select = 'SELECT count(DISTINCT civicrm_group_contact.id)';
Expand All @@ -326,6 +329,7 @@ public static function getContactGroup(
$select = 'SELECT
civicrm_group_contact.id as civicrm_group_contact_id,
civicrm_group.title as group_title,
civicrm_group.frontend_title as group_public_title,
civicrm_group.visibility as visibility,
civicrm_group_contact.status as status,
civicrm_group.id as group_id,
Expand Down Expand Up @@ -393,7 +397,7 @@ public static function getContactGroup(
$id = $dao->civicrm_group_contact_id;
$values[$id]['id'] = $id;
$values[$id]['group_id'] = $dao->group_id;
$values[$id]['title'] = $dao->group_title;
$values[$id]['title'] = ($public && !empty($group->group_public_title) ? $group->group_public_title : $dao->group_title);
$values[$id]['visibility'] = $dao->visibility;
$values[$id]['is_hidden'] = $dao->is_hidden;
switch ($dao->status) {
Expand Down
10 changes: 6 additions & 4 deletions CRM/Contact/Form/Edit/TagsAndGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ class CRM_Contact_Form_Edit_TagsAndGroups {
* If used for building tag block.
* @param string $fieldName
* This is used in batch profile(i.e to build multiple blocks).
*
* @param string $groupElementType
*
* The html type of the element we are adding e.g. checkbox, select
* @param bool $public
* Is this being used in a public form e.g. Profile.
*/
public static function buildQuickForm(
&$form,
Expand All @@ -54,7 +55,8 @@ public static function buildQuickForm(
$groupName = 'Group(s)',
$tagName = 'Tag(s)',
$fieldName = NULL,
$groupElementType = 'checkbox'
$groupElementType = 'checkbox',
$public = FALSE
) {
if (!isset($form->_tagGroup)) {
$form->_tagGroup = [];
Expand Down Expand Up @@ -88,7 +90,7 @@ public static function buildQuickForm(
}

if ($groupID || !empty($group)) {
$groups = CRM_Contact_BAO_Group::getGroupsHierarchy($ids, NULL, '- ');
$groups = CRM_Contact_BAO_Group::getGroupsHierarchy($ids, NULL, '- ', FALSE, $public);

$attributes['skiplabel'] = TRUE;
$elements = [];
Expand Down
8 changes: 4 additions & 4 deletions CRM/Contact/Page/View/UserDashBoard/GroupContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,31 @@ public function browse() {
NULL,
NULL, TRUE, TRUE,
$this->_onlyPublicGroups,
NULL, NULL, TRUE
NULL, NULL, TRUE, TRUE
);

$in = CRM_Contact_BAO_GroupContact::getContactGroup(
$this->_contactId,
'Added',
NULL, FALSE, TRUE,
$this->_onlyPublicGroups,
NULL, NULL, TRUE
NULL, NULL, TRUE, TRUE
);

$pending = CRM_Contact_BAO_GroupContact::getContactGroup(
$this->_contactId,
'Pending',
NULL, FALSE, TRUE,
$this->_onlyPublicGroups,
NULL, NULL, TRUE
NULL, NULL, TRUE, TRUE
);

$out = CRM_Contact_BAO_GroupContact::getContactGroup(
$this->_contactId,
'Removed',
NULL, FALSE, TRUE,
$this->_onlyPublicGroups,
NULL, NULL, TRUE
NULL, NULL, TRUE, TRUE
);

$this->assign('groupCount', $count);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/BAO/UFGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -2026,7 +2026,7 @@ public static function buildProfile(
CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId,
CRM_Contact_Form_Edit_TagsAndGroups::GROUP,
TRUE, $required,
$title, NULL, $name
$title, NULL, $name, 'checkbox', TRUE
);
}
elseif ($fieldName === 'tag') {
Expand Down
2 changes: 2 additions & 0 deletions CRM/Group/Form/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ protected function setEntityFields() {
'required' => TRUE,
],
'description' => ['name' => 'description'],
'frontend_title' => ['name' => 'frontend_title'],
'frontend_description' => ['name' => 'frontend_description'],
];
}

Expand Down
8 changes: 5 additions & 3 deletions CRM/Mailing/Event/BAO/Unsubscribe.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ public static function &unsub_from_mailing($job_id, $queue_id, $hash, $return =
$do = CRM_Core_DAO::executeQuery("
SELECT grp.id as group_id,
grp.title as title,
grp.frontend_title as frontend_title,
grp.frontend_description as frontend_description,
grp.description as description
FROM civicrm_group grp
LEFT JOIN civicrm_group_contact gc
Expand All @@ -250,15 +252,15 @@ public static function &unsub_from_mailing($job_id, $queue_id, $hash, $return =
$returnGroups = [];
while ($do->fetch()) {
$returnGroups[$do->group_id] = [
'title' => $do->title,
'description' => $do->description,
'title' => !empty($do->frontend_title) ? $do->frontend_title : $do->title,
'description' => !empty($do->frontend_description) ? $do->frontend_description : $do->description,
];
}
return $returnGroups;
}
else {
while ($do->fetch()) {
$groups[$do->group_id] = $do->title;
$groups[$do->group_id] = !empty($do->frontend_title) ? $do->frontend_title : $do->title;
}
}
$transaction = new CRM_Core_Transaction();
Expand Down
12 changes: 6 additions & 6 deletions CRM/Mailing/Form/Subscribe.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ public function preProcess() {

// make sure requested qroup is accessible and exists
$query = "
SELECT title, description
SELECT title, frontend_title, description, frontend_description
FROM civicrm_group
WHERE id={$this->_groupID}
AND visibility != 'User and User Admin Only'
AND $groupTypeCondition";

$dao = CRM_Core_DAO::executeQuery($query);
if ($dao->fetch()) {
$this->assign('groupName', $dao->title);
CRM_Utils_System::setTitle(ts('Subscribe to Mailing List - %1', [1 => $dao->title]));
$this->assign('groupName', !empty($dao->frontend_title) ? $dao->frontend_title : $dao->title);
CRM_Utils_System::setTitle(ts('Subscribe to Mailing List - %1', [1 => !empty($dao->frontend_title) ? $dao->frontend_title : $dao->title]));
}
else {
CRM_Core_Error::statusBounce("The specified group is not configured for this action OR The group doesn't exist.");
Expand Down Expand Up @@ -77,7 +77,7 @@ public function buildQuickForm() {
$groupTypeCondition = CRM_Contact_BAO_Group::groupTypeCondition('Mailing');

$query = "
SELECT id, title, description
SELECT id, title, frontend_title, description, frontend_description
FROM civicrm_group
WHERE ( saved_search_id = 0
OR saved_search_id IS NULL )
Expand All @@ -89,8 +89,8 @@ public function buildQuickForm() {
while ($dao->fetch()) {
$row = [];
$row['id'] = $dao->id;
$row['title'] = $dao->title;
$row['description'] = $dao->description;
$row['title'] = $dao->frontend_title ?? $dao->title;
$row['description'] = $dao->frontend_description ?? $dao->description;
$row['checkbox'] = CRM_Core_Form::CB_PREFIX . $row['id'];
$this->addElement('checkbox',
$row['checkbox'],
Expand Down
45 changes: 29 additions & 16 deletions templates/CRM/Group/Form/Edit.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,25 @@
</td>
</tr>

{if $group.created_by}
<tr class="crm-group-form-block-created">
<td class="label">{ts}Created By{/ts}</td>
<td>{$group.created_by}</td>
</tr>
{/if}

{if $group.modified_by}
<tr class="crm-group-form-block-modified">
<td class="label">{ts}Modified By{/ts}</td>
<td>{$group.modified_by}</td>
</tr>
{/if}

<tr class="crm-group-form-block-description">
<td class="label">{$form.description.label}</td>
<td>{$form.description.html}<br />
<span class="description">{ts}Group description is displayed when groups are listed in Profiles and Mailing List Subscribe forms.{/ts}</span>
<td>{$form.description.html}</td>
</tr>

<tr><td colspan="2">If either of the following fields are filled out they will be used instead of the title or description field in profiles and Mailing List Subscription/unsubscribe forms</td></tr>

<tr class="crm-group-form-block-frontend-title">
<td class="label">{$form.frontend_title.label} {if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_group' field='frontend_title' id=$group.id}{/if}</td>
<td>{$form.frontend_title.html|crmAddClass:huge}
{if $group.saved_search_id}&nbsp;({ts}Smart Group{/ts}){/if}
</td>
</tr>

<tr class="crm-group-form-block-frontend-description">
<td class="label">{$form.frontend_description.label} {if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_group' field='frontend_description' id=$group.id}{/if}</td>
<td>{$form.frontend_description.html}</td>
</tr>

{if $form.group_type}
<tr class="crm-group-form-block-group_type">
<td class="label">{$form.group_type.label}</td>
Expand All @@ -71,6 +69,21 @@
<td>{$form.is_active.html}</td>
</tr>

{if $group.created_by}
<tr class="crm-group-form-block-created">
<td class="label">{ts}Created By{/ts}</td>
<td>{$group.created_by}</td>
</tr>
{/if}

{if $group.modified_by}
<tr class="crm-group-form-block-modified">
<td class="label">{ts}Modified By{/ts}</td>
<td>{$group.modified_by}</td>
</tr>
{/if}


<tr>
<td colspan=2>{include file="CRM/Custom/Form/CustomData.tpl"}</td>
</tr>
Expand Down