Skip to content

Commit

Permalink
refs #37300, gh-90, add new pcp page status Draft
Browse files Browse the repository at this point in the history
  • Loading branch information
jimyhuang committed Oct 13, 2023
1 parent baa374a commit 4be01ee
Show file tree
Hide file tree
Showing 16 changed files with 453 additions and 631 deletions.
21 changes: 7 additions & 14 deletions CRM/Contribute/BAO/PCP.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,31 +392,24 @@ static function deleteById($id = NULL) {
* @static
*
*/
static function setIsActive($id, $is_active) {
switch ($is_active) {
case 0:
$is_active = 3;
break;

case 1:
$is_active = 2;
break;
static function setIsActive($id, $statusId) {
$pcpStatus = CRM_Contribute_PseudoConstant::pcpStatus();
if (!in_array($statusId, array_keys($pcpStatus))) {
return;
}

CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_PCP', $id, 'status_id', $is_active);
CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_PCP', $id, 'status_id', $statusId);

require_once 'CRM/Contribute/PseudoConstant.php';
$pcpTitle = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_PCP', $id, 'title');
$pcpStatus = CRM_Contribute_PseudoConstant::pcpStatus();
$pcpStatus = $pcpStatus[$is_active];
$pcpStatus = $pcpStatus[$statusId];

CRM_Core_Session::setStatus(ts("%1 status has been updated to %2.", array(
1 => $pcpTitle,
2 => $pcpStatus,
)));

// send status change mail
$result = self::sendStatusUpdate($id, $is_active);
$result = self::sendStatusUpdate($id, $statusId);

if ($result) {
CRM_Core_Session::setStatus(ts("A notification email has been sent to the supporter."));
Expand Down
105 changes: 82 additions & 23 deletions CRM/Contribute/Form/PCP/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,36 @@ function setDefaultValues() {
* @access public
*/
public function buildQuickForm() {
$isManager = CRM_Core_Permission::check('administer CiviCRM');
$pcpValues = array();
$statusDraftId = CRM_Core_OptionGroup::getValue('pcp_status', 'Draft', 'name');
$statusApprovedId = intval(CRM_Core_OptionGroup::getValue('pcp_status', 'Approved', 'name'));
if (!empty($this->_pageId)) {
$dao = new CRM_Contribute_DAO_PCP();
$dao->id = $this->_pageId;
if ($dao->find(TRUE)) {
CRM_Core_DAO::storeValues($dao, $pcpValues);
}
$statusId = $pcpValues['status_id'];
}
else {
$statusId = $statusDraftId;
}

$contribPageId = !empty($pcpValues['contribution_page_id']) ? $pcpValues['contribution_page_id'] : $this->get('contribution_page_id');
$approvalNeeded = FALSE;
if (!empty($contribPageId)) {
$approvalNeeded = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_PCPBlock', $contribPageId, 'is_approval_needed', 'entity_id');
}

if ($this->_key) {
$this->add('hidden', 'key', $this->_key);
}
$this->add('text', 'title', ts('Title'), NULL, TRUE);
$this->add('textarea', 'intro_text', ts('Event Summary'), NULL, TRUE);
$this->add('text', 'goal_amount', ts('Your Goal'), NULL, TRUE);

$readOnly = array();
$readOnly[] = $this->add('text', 'title', ts('Title'), NULL, TRUE);
$readOnly[] = $this->add('textarea', 'intro_text', ts('Event Summary'), NULL, TRUE);
$readOnly[] = $this->add('text', 'goal_amount', ts('Your Goal'), NULL, TRUE);
$this->addRule('goal_amount', ts('Goal Amount should be a numeric value'), 'money');
$attributes = array();
if ($this->get('action') & CRM_Core_Action::ADD) {
Expand All @@ -124,28 +148,51 @@ public function buildQuickForm() {

$this->add('text', 'donate_link_text', ts('Donation Button'), $attributes);
$attrib = array('rows' => 8, 'cols' => 60);
$this->addWysiwyg('page_text', ts('Your Message'), $attrib);
// $this->add('textarea', 'page_text', ts('Your Message'), null, false );
$readOnly[] = $this->addWysiwyg('page_text', ts('Your Message'), $attrib);

$maxAttachments = 5;
CRM_Core_BAO_File::buildAttachment($this, 'civicrm_pcp', $this->_pageId, $maxAttachments, array('accept' => 'image/x-png,image/gif,image/jpeg', 'multiple' => 'multiple'));
if (CRM_Utils_Array::arrayKeyExists('attachFile[]', $this->_elementIndex)) {
$readOnly[] = $this->getElement('attachFile[]');
}
if (CRM_Utils_Array::arrayKeyExists('is_delete_attachment', $this->_elementIndex)) {
$readOnly[] = $this->getElement('is_delete_attachment');
}

$readOnly[] = $this->addElement('checkbox', 'is_thermometer', ts('Progress Bar'));
$readOnly[] = $this->addElement('checkbox', 'is_honor_roll', ts('Honor Roll'), NULL);
$isActive = $this->addElement('checkbox', 'is_active', ts('Active'));
$readOnly[] = $isActive;

$this->addElement('checkbox', 'is_thermometer', ts('Progress Bar'));
$this->addElement('checkbox', 'is_honor_roll', ts('Honor Roll'), NULL);
$this->addElement('checkbox', 'is_active', ts('Active'));

$this->addButtons(array(
array(
'type' => 'upload',
'name' => ts('Save'),
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
)
if (!in_array($statusId, array($statusApprovedId)) && !$isManager) {
$isActive->freeze();
}
if (!in_array($statusId, array($statusDraftId)) && !$isManager) {
foreach($readOnly as &$element) {
$element->freeze();
}
}

$buttons = array();
if ($statusId === $statusDraftId || $isManager) {
$buttons[] = array(
'type' => 'attach',
'name' => ts('Save and Preview'),
'isDefault' => TRUE,
);
}
if ($statusId === $statusDraftId) {
$submitText = !empty($approvalNeeded) ? ts('Submit').' ('.ts('Requires Approval').')' : ts('Submit');
$buttons[] = array(
'type' => 'upload',
'name' => $submitText,
);
}
$buttons[] = array(
'type' => 'cancel',
'name' => ts('Cancel'),
);
$this->addButtons($buttons);
$this->addFormRule(array('CRM_Contribute_Form_PCP_Campaign', 'formRule'), $this);
}

Expand Down Expand Up @@ -181,6 +228,7 @@ static function formRule($fields, $files, $self) {
*/
public function postProcess() {
$params = $this->controller->exportValues();
$buttonName = $this->controller->getButtonName();
$checkBoxes = array('is_thermometer', 'is_honor_roll', 'is_active');

foreach ($checkBoxes as $key) {
Expand All @@ -204,14 +252,25 @@ public function postProcess() {
$params['contribution_page_id'], 'is_approval_needed', 'entity_id'
);
$approvalMessage = NULL;
if ($this->get('action') & CRM_Core_Action::ADD) {
$params['status_id'] = $approval_needed ? 1 : 2;
$statusDraftId = CRM_Core_OptionGroup::getValue('pcp_status', 'Draft', 'name');
$statusWaitReviewId = intval(CRM_Core_OptionGroup::getValue('pcp_status', 'Waiting Review', 'name'));
$statusApprovedId = intval(CRM_Core_OptionGroup::getValue('pcp_status', 'Approved', 'name'));
if ($buttonName == '_qf_Campaign_upload') {
$params['status_id'] = $approval_needed ? $statusWaitReviewId : $statusApprovedId;
$approvalMessage = $approval_needed ? ts('but requires administrator review before you can begin your fundraising efforts. You will receive an email confirmation shortly which includes a link to return to your fundraising page.') : ts('and is ready to use.');
}
else {
if ($this->get('action') & CRM_Core_Action::ADD) {
$params['status_id'] = $statusDraftId;
}
else {
// do not update status when update and button is Save and Preview
unset($params['status_id']);
}
}

$params['id'] = $this->_pageId;

require_once 'CRM/Contribute/BAO/PCP.php';
$pcp = CRM_Contribute_BAO_PCP::add($params, FALSE);

// add attachments as needed
Expand Down
59 changes: 28 additions & 31 deletions CRM/Contribute/Form/PCP/PCP.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function preProcess() {
if ($this->_action & CRM_Core_Action::DELETE) {
//check permission for action.
if (!CRM_Core_Permission::checkActionPermission('CiviContribute', $this->_action)) {
return CRM_Core_Error::statusBounce(ts('You do not have permission to access this page'));
return CRM_Core_Error::statusBounce(ts('You do not have permission to access this page'));
}

$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
Expand All @@ -74,42 +74,39 @@ public function preProcess() {
$userID = $session->get('userID');

//do not allow destructive actions without permissions
$permission = FALSE;
if (!$userID) {
CRM_Utils_System::permissionDenied();
}
if (CRM_Core_Permission::check('administer CiviCRM') ||
($userID && (CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_PCP',
$this->_id,
'contact_id'
) == $userID))
) {
$permission = TRUE;
$isManager = $isOwner = FALSE;
if (CRM_Core_Permission::check('administer CiviCRM')) {
$isManager = TRUE;
}
if ($permission && $this->_id) {

require_once 'CRM/Contribute/BAO/PCP.php';
if ($userID && $this->_id && (CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_PCP', $this->_id, 'contact_id') == $userID)) {
$isOwner = TRUE;
}
if (($isOwner || $isManager) && $this->_id) {
$this->_title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_PCP', $this->_id, 'title');
switch ($this->_action) {
case CRM_Core_Action::DELETE:
case 'delete':
CRM_Contribute_BAO_PCP::deleteById($this->_id);
CRM_Core_Session::setStatus(ts("The Campaign Page '%1' has been deleted.", array(1 => $this->_title)));
break;

case CRM_Core_Action::DISABLE:
case 'disable':
CRM_Contribute_BAO_PCP::setDisable($this->_id, '0');
CRM_Core_Session::setStatus(ts("The Campaign Page '%1' has been disabled.", array(1 => $this->_title)));
break;

case CRM_Core_Action::ENABLE:
case 'enable':
CRM_Contribute_BAO_PCP::setDisable($this->_id, '1');
CRM_Core_Session::setStatus(ts("The Campaign Page '%1' has been enabled.", array(1 => $this->_title)));
break;
$statusId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_PCP', $this->_id, 'status_id');
$statusApprovedId = intval(CRM_Core_OptionGroup::getValue('pcp_status', 'Approved', 'name'));
if ($isManager && ($this->_action == CRM_Core_Action::DELETE || $this->_action == 'delete')) {
CRM_Contribute_BAO_PCP::deleteById($this->_id);
CRM_Core_Session::setStatus(ts("The Campaign Page '%1' has been deleted.", array(1 => $this->_title)));
}
elseif ($isManager || ($isOwner && $statusId == $statusApprovedId)) {
switch ($this->_action) {
case CRM_Core_Action::DISABLE:
case 'disable':
CRM_Contribute_BAO_PCP::setDisable($this->_id, '0');
CRM_Core_Session::setStatus(ts("The Campaign Page '%1' has been disabled.", array(1 => $this->_title)));
break;

case CRM_Core_Action::ENABLE:
case 'enable':
CRM_Contribute_BAO_PCP::setDisable($this->_id, '1');
CRM_Core_Session::setStatus(ts("The Campaign Page '%1' has been enabled.", array(1 => $this->_title)));
break;
}
}

if ($context) {
CRM_Utils_System::redirect($context);
}
Expand Down
19 changes: 17 additions & 2 deletions CRM/Contribute/Page/PCP.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ function &links() {
'qs' => 'action=revert&id=%%id%%',
'title' => ts('Reject Personal Campaign Page'),
),
CRM_Core_Action::PREVIEW => array(
'name' => ts('Revoke to Draft'),
'url' => 'civicrm/admin/pcp',
'qs' => 'action=preview&id=%%id%%',
'title' => ts('Revoke Personal Campaign Page to Draft status'),
),
CRM_Core_Action::DELETE => array(
'name' => ts('Delete'),
'url' => 'civicrm/admin/pcp',
Expand Down Expand Up @@ -118,15 +124,24 @@ function run() {
$this, FALSE,
'browse'
);
$statusApprovedId = intval(CRM_Core_OptionGroup::getValue('pcp_status', 'Approved', 'name'));
$statusNotApprovedId = intval(CRM_Core_OptionGroup::getValue('pcp_status', 'Not Approved', 'name'));
$statusDraftId = intval(CRM_Core_OptionGroup::getValue('pcp_status', 'Draft', 'name'));
if ($action & CRM_Core_Action::REVERT) {
$id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
CRM_Contribute_BAO_PCP::setIsActive($id, 0);
CRM_Contribute_BAO_PCP::setIsActive($id, $statusNotApprovedId);
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1'));
}
elseif ($action & CRM_Core_Action::RENEW) {
$id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
CRM_Contribute_BAO_PCP::setIsActive($id, 1);
CRM_Contribute_BAO_PCP::setIsActive($id, $statusApprovedId);
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1'));
}
elseif ($action & CRM_Core_Action::PREVIEW) {
$id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
CRM_Contribute_BAO_PCP::setIsActive($id, $statusDraftId);
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1'));
}
Expand Down
15 changes: 13 additions & 2 deletions CRM/Contribute/Page/PCPInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,24 @@ function run() {

require_once 'CRM/Contribute/BAO/PCP.php';
$link = CRM_Contribute_BAO_PCP::pcpLinks();
unset($link['all'][CRM_Core_Action::ENABLE]);
unset($link['all'][CRM_Core_Action::DELETE]);
if ($pcpInfo['status_id'] == $approvedId) {
if ($pcpInfo['is_active']) {
unset($link['all'][CRM_Core_Action::ENABLE]);
}
else {
unset($link['all'][CRM_Core_Action::DISABLE]);
}
}
else {
unset($link['all'][CRM_Core_Action::DISABLE]);
unset($link['all'][CRM_Core_Action::ENABLE]);
}
$hints = array(
CRM_Core_Action::UPDATE => ts('Change the content and appearance of your page'),
CRM_Core_Action::DETACH => ts('Send emails inviting your friends to support your campaign!'),
CRM_Core_Action::BROWSE => ts('Update your personal contact information'),
CRM_Core_Action::DISABLE => ts('De-activate the page (you can re-activate it later)'),
CRM_Core_Action::DELETE => ts('Remove the page (this cannot be undone!)'),
);
CRM_Core_DAO::commonRetrieveAll('CRM_Contribute_DAO_PCPBlock', $pcpInfo['contribution_page_id'],
'entity_id', $blockValues, array('is_tellfriend_enabled')
Expand Down
39 changes: 19 additions & 20 deletions CRM/Core/BAO/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,16 +415,13 @@ static function formatAttachment(&$formValues,
if (isset($formValues[$attachName]) && !empty($formValues[$attachName])) {
for ($i = 0; $i < $numAttachments; $i++) {
// ensure file is not empty
$contents = file_get_contents($formValues[$attachName][$i]['name']);
if ($contents) {
$fileParams = array(
'uri' => $formValues[$attachName][$i]['name'],
'type' => $formValues[$attachName][$i]['type'],
'upload_date' => date('Ymdhis'),
'location' => $formValues[$attachName][$i]['name'],
);
$params['attachFile_'.$i] = $fileParams;
}
$fileParams = array(
'uri' => $formValues[$attachName][$i]['name'],
'type' => $formValues[$attachName][$i]['type'],
'upload_date' => date('Ymdhis'),
'location' => $formValues[$attachName][$i]['name'],
);
$params['attachFile_'.$i] = $fileParams;
}
}
}
Expand All @@ -442,16 +439,18 @@ static function processAttachment(&$params,
if (isset($params["attachFile_$i"]) &&
is_array($params["attachFile_$i"])
) {
self::filePostProcess($params["attachFile_$i"]['location'],
NULL,
$entityTable,
$entityID,
NULL,
TRUE,
$params["attachFile_$i"],
"attachFile_$i",
$params["attachFile_$i"]['type']
);
if (!empty($params["attachFile_$i"]['location']) && file_exists($params["attachFile_$i"]['location'])) {
self::filePostProcess($params["attachFile_$i"]['location'],
NULL,
$entityTable,
$entityID,
NULL,
TRUE,
$params["attachFile_$i"],
"attachFile_$i",
$params["attachFile_$i"]['type']
);
}
}
}
}
Expand Down
Loading

0 comments on commit 4be01ee

Please sign in to comment.