/** * Create or update either a Personal Campaign Page OR a PCP Block. * * @param array $params * * @return CRM_PCP_DAO_PCPBlock */ public static function create($params) { $dao = new CRM_PCP_DAO_PCPBlock(); $dao->copyValues($params); $dao->save(); return $dao; }
/** * function to add or update either a Personal Campaign Page OR a PCP Block * * @param array $params reference array contains the values submitted by the form * @param bool $pcpBlock if true, create or update PCPBlock, else PCP * @access public * @static * * @return object */ static function add(&$params, $pcpBlock = TRUE) { if ($pcpBlock) { // action is taken depending upon the mode $dao = new CRM_PCP_DAO_PCPBlock(); $dao->copyValues($params); $dao->save(); return $dao; } else { $dao = new CRM_PCP_DAO_PCP(); $dao->copyValues($params); // ensure we set status_id since it is a not null field // we should change the schema and allow this to be null if (!$dao->id && !isset($dao->status_id)) { $dao->status_id = 0; } // set currency for CRM-1496 if (!isset($dao->currency)) { $config =& CRM_Core_Config::singleton(); $dao->currency = $config->defaultCurrency; } $dao->save(); return $dao; } }
/** * File for the CiviCRM APIv3 group functions * * @package CiviCRM_APIv3 * @subpackage API_pcpteams * @copyright CiviCRM LLC (c) 2004-2014 */ function civicrm_api3_pcpteams_create($params) { // since we are allowing html input from the user // we also need to purify it, so lets clean it up // $params['pcp_title'] = $pcp['title']; // $params['pcp_contact_id'] = $pcp['contact_id']; $htmlFields = array('intro_text', 'page_text', 'title'); foreach ($htmlFields as $field) { if (!empty($params[$field])) { $params[$field] = CRM_Utils_String::purifyHTML($params[$field]); } } $entity_table = CRM_PCP_BAO_PCP::getPcpEntityTable($params['page_type']); $pcpBlock = new CRM_PCP_DAO_PCPBlock(); $pcpBlock->entity_table = $entity_table; $pcpBlock->entity_id = $params['page_id']; $pcpBlock->find(TRUE); $params['pcp_block_id'] = $pcpBlock->id; $params['goal_amount'] = CRM_Utils_Rule::cleanMoney($params['goal_amount']); // 1 -> waiting review // 2 -> active / approved (default for now) $params['status_id'] = CRM_Utils_Array::value('status_id', $params, 2); // active by default for now $params['is_active'] = CRM_Utils_Array::value('is_active', $params, 1); $pcp = CRM_Pcpteams_BAO_PCP::create($params, FALSE); //Custom Set $customFields = CRM_Core_BAO_CustomField::getFields('PCP', FALSE, FALSE, NULL, NULL, TRUE); $isCustomValueSet = FALSE; foreach ($customFields as $fieldID => $fieldValue) { list($tableName, $columnName, $cgId) = CRM_Core_BAO_CustomField::getTableColumnGroup($fieldID); if (!empty($params[$columnName]) || !empty($params["custom_{$fieldID}"])) { $isCustomValueSet = TRUE; //FIXME: to find out the custom value exists, set -1 as default now $params["custom_{$fieldID}_-1"] = !empty($params[$columnName]) ? $params[$columnName] : $params["custom_{$fieldID}"]; } } if ($isCustomValueSet) { $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $pcp->id, 'PCP'); CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_pcp', $pcp->id); } //end custom set $values = array(); @_civicrm_api3_object_to_array_unique_fields($pcp, $values[$pcp->id]); return civicrm_api3_create_success($values, $params, 'Pcpteams', 'create'); }
/** * Process the form submission. * * * @return void */ public function postProcess() { $params = $this->controller->exportValues($this->_name); $checkBoxes = array('is_thermometer', 'is_honor_roll', 'is_active', 'is_notify'); foreach ($checkBoxes as $key) { if (!isset($params[$key])) { $params[$key] = 0; } } $session = CRM_Core_Session::singleton(); $contactID = isset($this->_contactID) ? $this->_contactID : $session->get('userID'); if (!$contactID) { $contactID = $this->get('contactID'); } $params['title'] = $params['pcp_title']; $params['intro_text'] = $params['pcp_intro_text']; $params['contact_id'] = $contactID; $params['page_id'] = $this->get('component_page_id') ? $this->get('component_page_id') : $this->_contriPageId; $params['page_type'] = $this->_component; // since we are allowing html input from the user // we also need to purify it, so lets clean it up $htmlFields = array('intro_text', 'page_text', 'title'); foreach ($htmlFields as $field) { if (!empty($params[$field])) { $params[$field] = CRM_Utils_String::purifyHTML($params[$field]); } } $entity_table = CRM_PCP_BAO_PCP::getPcpEntityTable($params['page_type']); $pcpBlock = new CRM_PCP_DAO_PCPBlock(); $pcpBlock->entity_table = $entity_table; $pcpBlock->entity_id = $params['page_id']; $pcpBlock->find(TRUE); $params['pcp_block_id'] = $pcpBlock->id; $params['goal_amount'] = CRM_Utils_Rule::cleanMoney($params['goal_amount']); $approval_needed = $pcpBlock->is_approval_needed; $approvalMessage = NULL; if ($this->get('action') & CRM_Core_Action::ADD) { $params['status_id'] = $approval_needed ? 1 : 2; $approvalMessage = $approval_needed ? ts('but requires administrator review before you can begin promoting your campaign. You will receive an email confirmation shortly which includes a link to return to this page.') : ts('and is ready to use.'); } $params['id'] = $this->_pageId; $pcp = CRM_PCP_BAO_PCP::add($params, FALSE); //create page in wordpress create_wp_campaign($pcp->title, $pcp->contact_id, $pcp->id); CRM_Core_Error::debug_log_message("Calling create_wp_campaign.... Params title: {$pcp->title}, contact_id: {$pcp->contact_id}, pcp_id: {$pcp->id} "); // add attachments as needed CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_pcp', $pcp->id); $pageStatus = isset($this->_pageId) ? ts('updated') : ts('created'); $statusId = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcp->id, 'status_id'); //send notification of PCP create/update. $pcpParams = array('entity_table' => $entity_table, 'entity_id' => $pcp->page_id); $notifyParams = array(); $notifyStatus = ""; CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCPBlock', $pcpParams, $notifyParams, array('notify_email')); if ($emails = $pcpBlock->notify_email) { $this->assign('pcpTitle', $pcp->title); if ($this->_pageId) { $this->assign('mode', 'Update'); } else { $this->assign('mode', 'Add'); } $pcpStatus = CRM_Core_OptionGroup::getLabel('pcp_status', $statusId); $this->assign('pcpStatus', $pcpStatus); $this->assign('pcpId', $pcp->id); $supporterUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$pcp->contact_id}", TRUE, NULL, FALSE, FALSE); $this->assign('supporterUrl', $supporterUrl); $supporterName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $pcp->contact_id, 'display_name'); $this->assign('supporterName', $supporterName); if ($this->_component == 'contribute') { $pageUrl = CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpBlock->entity_id}", TRUE, NULL, FALSE, TRUE); $contribPageTitle = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $pcpBlock->entity_id, 'title'); } elseif ($this->_component == 'event') { $pageUrl = CRM_Utils_System::url('civicrm/event', "reset=1&id={$pcpBlock->entity_id}", TRUE, NULL, FALSE, TRUE); $contribPageTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $pcpBlock->entity_id, 'title'); } $this->assign('contribPageUrl', $pageUrl); $this->assign('contribPageTitle', $contribPageTitle); $managePCPUrl = CRM_Utils_System::url('civicrm/admin/pcp', "reset=1", TRUE, NULL, FALSE, FALSE); $this->assign('managePCPUrl', $managePCPUrl); //get the default domain email address. list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(); if (!$domainEmailAddress || $domainEmailAddress == '*****@*****.**') { $fixUrl = CRM_Utils_System::url('civicrm/admin/domain', 'action=update&reset=1'); CRM_Core_Error::fatal(ts('The site administrator needs to enter a valid \'FROM Email Address\' in <a href="%1">Administer CiviCRM » Communications » FROM Email Addresses</a>. The email address used may need to be a valid mail account with your email service provider.', array(1 => $fixUrl))); } //if more than one email present for PCP notification , //first email take it as To and other as CC and First email //address should be sent in users email receipt for //support purpose. $emailArray = explode(',', $emails); $to = $emailArray[0]; unset($emailArray[0]); $cc = implode(',', $emailArray); list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'pcp_notify', 'contactId' => $contactID, 'from' => "{$domainEmailName} <{$domainEmailAddress}>", 'toEmail' => $to, 'cc' => $cc)); if ($sent) { $notifyStatus = ts('A notification email has been sent to the site administrator.'); } } CRM_Core_BAO_File::processAttachment($params, 'civicrm_pcp', $pcp->id); // send email notification to supporter, if initial setup / add mode. if (!$this->_pageId) { CRM_PCP_BAO_PCP::sendStatusUpdate($pcp->id, $statusId, TRUE, $this->_component); if ($approvalMessage && CRM_Utils_Array::value('status_id', $params) == 1) { $notifyStatus .= ts(' You will receive a second email as soon as the review process is complete.'); } } //check if pcp created by anonymous user $anonymousPCP = 0; if (!$session->get('userID')) { $anonymousPCP = 1; } CRM_Core_Session::setStatus(ts("Your Personal Campaign Page has been %1 %2 %3", array(1 => $pageStatus, 2 => $approvalMessage, 3 => $notifyStatus)), '', 'info'); if (!$this->_pageId) { $session->pushUserContext(CRM_Utils_System::url('civicrm/pcp/info', "reset=1&id={$pcp->id}&ap={$anonymousPCP}")); } elseif ($this->_context == 'dashboard') { $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/pcp', 'reset=1')); } }
/** * Function to build the form * * @return void * @access public */ public function buildQuickForm() { // Assign the email address from a contact id lookup as in CRM_Event_BAO_Event->sendMail() $primaryContactId = $this->get('primaryContactId'); if ($primaryContactId) { list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($primaryContactId); $this->assign('email', $email); } $this->assignToTemplate(); if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) { $lineItemForTemplate = array(); foreach ($this->_lineItem as $key => $value) { if (!empty($value)) { $lineItemForTemplate[$key] = $value; } } if (!empty($lineItemForTemplate)) { $this->assign('lineItem', $lineItemForTemplate); } } $this->assign('totalAmount', $this->_totalAmount); $hookDiscount = $this->get('hookDiscount'); if ($hookDiscount) { $this->assign('hookDiscount', $hookDiscount); } $this->assign('receive_date', $this->_receiveDate); $this->assign('trxn_id', $this->_trxnId); //cosider total amount. $this->assign('isAmountzero', $this->_totalAmount <= 0 ? TRUE : FALSE); $this->assign('defaultRole', FALSE); if (CRM_Utils_Array::value('defaultRole', $this->_params[0]) == 1) { $this->assign('defaultRole', TRUE); } $defaults = array(); $fields = array(); if (!empty($this->_fields)) { foreach ($this->_fields as $name => $dontCare) { $fields[$name] = 1; } } $fields['state_province'] = $fields['country'] = $fields['email'] = 1; foreach ($fields as $name => $dontCare) { if (isset($this->_params[0][$name])) { $defaults[$name] = $this->_params[0][$name]; if (substr($name, 0, 7) == 'custom_') { $timeField = "{$name}_time"; if (isset($this->_params[0][$timeField])) { $defaults[$timeField] = $this->_params[0][$timeField]; } } elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes) && !empty($this->_params[0][$name . '_custom'])) { $defaults[$name . '_custom'] = $this->_params[0][$name . '_custom']; } } } $this->_submitValues = array_merge($this->_submitValues, $defaults); $this->setDefaults($defaults); $params['entity_id'] = $this->_eventId; $params['entity_table'] = 'civicrm_event'; $data = array(); CRM_Friend_BAO_Friend::retrieve($params, $data); if (!empty($data['is_active'])) { $friendText = $data['title']; $this->assign('friendText', $friendText); if ($this->_action & CRM_Core_Action::PREVIEW) { $url = CRM_Utils_System::url('civicrm/friend', "eid={$this->_eventId}&reset=1&action=preview&pcomponent=event"); } else { $url = CRM_Utils_System::url('civicrm/friend', "eid={$this->_eventId}&reset=1&pcomponent=event"); } $this->assign('friendURL', $url); } $this->freeze(); //lets give meaningful status message, CRM-4320. $isOnWaitlist = $isRequireApproval = FALSE; if ($this->_allowWaitlist && !$this->_allowConfirmation) { $isOnWaitlist = TRUE; } if ($this->_requireApproval && !$this->_allowConfirmation) { $isRequireApproval = TRUE; } $this->assign('isOnWaitlist', $isOnWaitlist); $this->assign('isRequireApproval', $isRequireApproval); // find pcp info $dao = new CRM_PCP_DAO_PCPBlock(); $dao->entity_table = 'civicrm_event'; $dao->entity_id = $this->_eventId; $dao->is_active = 1; $dao->find(TRUE); if ($dao->id) { $this->assign('pcpLink', CRM_Utils_System::url('civicrm/contribute/campaign', 'action=add&reset=1&pageId=' . $this->_eventId . '&component=event')); $this->assign('pcpLinkText', $dao->link_text); } // Assign Participant Count to Lineitem Table $this->assign('pricesetFieldsCount', CRM_Price_BAO_PriceSet::getPricesetCount($this->_priceSetId)); // can we blow away the session now to prevent hackery $this->controller->reset(); }
/** * Browse all events. * * @return void */ public function browse() { Civi::resources()->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header'); $this->_sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter', 'String', $this); $createdId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE, 0); if (strtolower($this->_sortByCharacter) == 'all' || !empty($_POST)) { $this->_sortByCharacter = ''; $this->set('sortByCharacter', ''); } $this->_force = $this->_searchResult = NULL; $this->search(); $params = array(); $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE); $this->_searchResult = CRM_Utils_Request::retrieve('searchResult', 'Boolean', $this); $whereClause = $this->whereClause($params, FALSE, $this->_force); $this->pagerAToZ($whereClause, $params); $params = array(); $whereClause = $this->whereClause($params, TRUE, $this->_force); // because is_template != 1 would be to simple $whereClause .= ' AND (is_template = 0 OR is_template IS NULL)'; $this->pager($whereClause, $params); list($offset, $rowCount) = $this->_pager->getOffsetAndRowCount(); // get all custom groups sorted by weight $manageEvent = array(); $query = "\n SELECT *\n FROM civicrm_event\n WHERE {$whereClause}\nORDER BY start_date desc\n LIMIT {$offset}, {$rowCount}"; $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Event_DAO_Event'); $permissions = CRM_Event_BAO_Event::checkPermission(); //get all campaigns. $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE); // get the list of active event pcps $eventPCPS = array(); $pcpDao = new CRM_PCP_DAO_PCPBlock(); $pcpDao->entity_table = 'civicrm_event'; $pcpDao->find(); while ($pcpDao->fetch()) { $eventPCPS[$pcpDao->entity_id] = $pcpDao->entity_id; } // check if we're in shopping cart mode for events $enableCart = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME, 'enable_cart'); $this->assign('eventCartEnabled', $enableCart); $mapping = CRM_Utils_Array::first(CRM_Core_BAO_ActionSchedule::getMappings(array('id' => CRM_Event_ActionMapping::EVENT_NAME_MAPPING_ID))); $eventType = CRM_Core_OptionGroup::values('event_type'); while ($dao->fetch()) { if (in_array($dao->id, $permissions[CRM_Core_Permission::VIEW])) { $manageEvent[$dao->id] = array(); $repeat = CRM_Core_BAO_RecurringEntity::getPositionAndCount($dao->id, 'civicrm_event'); $manageEvent[$dao->id]['repeat'] = ''; if ($repeat) { $manageEvent[$dao->id]['repeat'] = ts('Repeating (%1 of %2)', array(1 => $repeat[0], 2 => $repeat[1])); } CRM_Core_DAO::storeValues($dao, $manageEvent[$dao->id]); // form all action links $action = array_sum(array_keys($this->links())); if ($dao->is_active) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } if (!in_array($dao->id, $permissions[CRM_Core_Permission::DELETE])) { $action -= CRM_Core_Action::DELETE; } if (!in_array($dao->id, $permissions[CRM_Core_Permission::EDIT])) { $action -= CRM_Core_Action::UPDATE; } $manageEvent[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $dao->id), ts('more'), TRUE, 'event.manage.list', 'Event', $dao->id); $params = array('entity_id' => $dao->id, 'entity_table' => 'civicrm_event', 'is_active' => 1); $defaults['location'] = CRM_Core_BAO_Location::getValues($params, TRUE); $manageEvent[$dao->id]['friend'] = CRM_Friend_BAO_Friend::getValues($params); if (isset($defaults['location']['address'][1]['city'])) { $manageEvent[$dao->id]['city'] = $defaults['location']['address'][1]['city']; } if (isset($defaults['location']['address'][1]['state_province_id'])) { $manageEvent[$dao->id]['state_province'] = CRM_Core_PseudoConstant::stateProvince($defaults['location']['address'][1]['state_province_id']); } //show campaigns on selector. $manageEvent[$dao->id]['campaign'] = CRM_Utils_Array::value($dao->campaign_id, $allCampaigns); $manageEvent[$dao->id]['reminder'] = CRM_Core_BAO_ActionSchedule::isConfigured($dao->id, $mapping->getId()); $manageEvent[$dao->id]['is_pcp_enabled'] = CRM_Utils_Array::value($dao->id, $eventPCPS); $manageEvent[$dao->id]['event_type'] = CRM_Utils_Array::value($manageEvent[$dao->id]['event_type_id'], $eventType); $manageEvent[$dao->id]['is_repeating_event'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_RecurringEntity', $dao->id, 'parent_id', 'entity_id'); // allow hooks to set 'field' value which allows configuration pop-up to show a tab as enabled/disabled CRM_Utils_Hook::tabset('civicrm/event/manage/rows', $manageEvent, array('event_id' => $dao->id)); } } $manageEvent['tab'] = self::tabs($enableCart); $this->assign('rows', $manageEvent); $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1'); $statusTypesPending = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 0'); $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes)); $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending)); $this->assign('findParticipants', $findParticipants); }
/** * returns the list of fields that can be exported * * @access public * return array * @static */ static function &export($prefix = false) { if (!self::$_export) { self::$_export = array(); $fields = self::fields(); foreach ($fields as $name => $field) { if (CRM_Utils_Array::value('export', $field)) { if ($prefix) { self::$_export['pcp_block'] =& $fields[$name]; } else { self::$_export[$name] =& $fields[$name]; } } } } return self::$_export; }
/** * Process the form submission. * * * @return void */ public function postProcess() { // get the submitted form values. $params = $this->controller->exportValues($this->_name); // Source $params['entity_table'] = 'civicrm_event'; $params['entity_id'] = $this->_id; // Target $params['target_entity_type'] = CRM_Utils_Array::value('target_entity_type', $params, 'event'); if ($params['target_entity_type'] == 'event') { $params['target_entity_id'] = $this->_id; } else { $params['target_entity_id'] = CRM_Utils_Array::value('target_entity_id', $params, $this->_id); } $dao = new CRM_PCP_DAO_PCPBlock(); $dao->entity_table = $params['entity_table']; $dao->entity_id = $this->_id; $dao->find(TRUE); $params['id'] = $dao->id; $params['is_active'] = CRM_Utils_Array::value('pcp_active', $params, FALSE); $params['is_approval_needed'] = CRM_Utils_Array::value('is_approval_needed', $params, FALSE); $params['is_tellfriend_enabled'] = CRM_Utils_Array::value('is_tellfriend_enabled', $params, FALSE); $dao = CRM_PCP_BAO_PCP::add($params); // Update tab "disabled" css class $this->ajaxResponse['tabValid'] = !empty($params['is_active']); parent::endPostProcess(); }
/** * 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() { $session = CRM_Core_Session::singleton(); $config = CRM_Core_Config::singleton(); $permissionCheck = FALSE; $statusMessage = ''; if ($config->userFramework != 'Joomla') { $permissionCheck = CRM_Core_Permission::check('administer CiviCRM'); } //get the pcp id. $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE); $prms = array('id' => $this->_id); CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $prms, $pcpInfo); $this->_component = $pcpInfo['page_type']; if (empty($pcpInfo)) { $statusMessage = ts('The personal campaign page you requested is currently unavailable.'); CRM_Core_Error::statusBounce($statusMessage, $config->userFrameworkBaseURL); } CRM_Utils_System::setTitle($pcpInfo['title']); $this->assign('pcp', $pcpInfo); $pcpStatus = CRM_Core_OptionGroup::values("pcp_status"); $approvedId = CRM_Core_OptionGroup::getValue('pcp_status', 'Approved', 'name'); // check if PCP is created by anonymous user $anonymousPCP = CRM_Utils_Request::retrieve('ap', 'Boolean', $this); if ($anonymousPCP) { $loginURL = $config->userSystem->getLoginURL(); $anonMessage = ts('Once you\'ve received your new account welcome email, you can <a href=%1>click here</a> to login and promote your campaign page.', array(1 => $loginURL)); CRM_Core_Session::setStatus($anonMessage, ts('Success'), 'success'); } else { $statusMessage = ts('The personal campaign page you requested is currently unavailable. However you can still support the campaign by making a contribution here.'); } $pcpBlock = new CRM_PCP_DAO_PCPBlock(); $pcpBlock->entity_table = CRM_PCP_BAO_PCP::getPcpEntityTable($pcpInfo['page_type']); $pcpBlock->entity_id = $pcpInfo['page_id']; $pcpBlock->find(TRUE); // Redirect back to source page in case of error. if ($pcpInfo['page_type'] == 'contribute') { $urlBase = 'civicrm/contribute/transact'; } elseif ($pcpInfo['page_type'] == 'event') { $urlBase = 'civicrm/event/register'; } if ($pcpInfo['status_id'] != $approvedId || !$pcpInfo['is_active']) { if ($pcpInfo['contact_id'] != $session->get('userID') && !$permissionCheck) { CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url($urlBase, "reset=1&id=" . $pcpInfo['page_id'], FALSE, NULL, FALSE, TRUE)); } } else { $getStatus = CRM_PCP_BAO_PCP::getStatus($this->_id, $this->_component); if (!$getStatus) { // PCP not enabled for this contribution page. Forward everyone to source page CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url($urlBase, "reset=1&id=" . $pcpInfo['page_id'], FALSE, NULL, FALSE, TRUE)); } } $default = array(); if ($pcpBlock->target_entity_type == 'contribute') { $urlBase = 'civicrm/contribute/transact'; } elseif ($pcpBlock->target_entity_type == 'event') { $urlBase = 'civicrm/event/register'; } if ($pcpBlock->entity_table == 'civicrm_event') { $page_class = 'CRM_Event_DAO_Event'; $this->assign('pageName', CRM_Event_PseudoConstant::event($pcpInfo['page_id'])); CRM_Core_DAO::commonRetrieveAll($page_class, 'id', $pcpInfo['page_id'], $default, array('start_date', 'end_date', 'registration_start_date', 'registration_end_date')); } elseif ($pcpBlock->entity_table == 'civicrm_contribution_page') { $page_class = 'CRM_Contribute_DAO_ContributionPage'; $this->assign('pageName', CRM_Contribute_PseudoConstant::contributionPage($pcpInfo['page_id'], TRUE)); CRM_Core_DAO::commonRetrieveAll($page_class, 'id', $pcpInfo['page_id'], $default, array('start_date', 'end_date')); } $pageInfo = $default[$pcpInfo['page_id']]; if ($pcpInfo['contact_id'] == $session->get('userID')) { $owner = $pageInfo; $owner['status'] = CRM_Utils_Array::value($pcpInfo['status_id'], $pcpStatus); $this->assign('owner', $owner); $link = CRM_PCP_BAO_PCP::pcpLinks(); $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::VIEW => ts('Copy this link to share directly with your network!'), 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::ENABLE => ts('Activate the page (you can de-activate it later)'), CRM_Core_Action::DELETE => ts('Remove the page (this cannot be undone!)')); $replace = array('id' => $this->_id, 'block' => $pcpBlock->id, 'pageComponent' => $this->_component); if (!$pcpBlock->is_tellfriend_enabled || CRM_Utils_Array::value('status_id', $pcpInfo) != $approvedId) { unset($link['all'][CRM_Core_Action::DETACH]); } switch ($pcpInfo['is_active']) { case 1: unset($link['all'][CRM_Core_Action::ENABLE]); break; case 0: unset($link['all'][CRM_Core_Action::DISABLE]); break; } $this->assign('links', $link['all']); $this->assign('hints', $hints); $this->assign('replace', $replace); } $honor = CRM_PCP_BAO_PCP::honorRoll($this->_id); $entityFile = CRM_Core_BAO_File::getEntityFile('civicrm_pcp', $this->_id); if (!empty($entityFile)) { $fileInfo = reset($entityFile); $fileId = $fileInfo['fileID']; $image = '<img src="' . CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$this->_id}") . '" />'; $this->assign('image', $image); } $totalAmount = CRM_PCP_BAO_PCP::thermoMeter($this->_id); $achieved = round($totalAmount / $pcpInfo['goal_amount'] * 100, 2); if ($pcpBlock->is_active == 1) { $linkTextUrl = CRM_Utils_System::url('civicrm/contribute/campaign', "action=add&reset=1&pageId={$pcpInfo['page_id']}&component={$pcpInfo['page_type']}", TRUE, NULL, TRUE, TRUE); $this->assign('linkTextUrl', $linkTextUrl); $this->assign('linkText', $pcpBlock->link_text); } $this->assign('honor', $honor); $this->assign('total', $totalAmount ? $totalAmount : '0.0'); $this->assign('achieved', $achieved <= 100 ? $achieved : 100); if ($achieved <= 100) { $this->assign('remaining', 100 - $achieved); } // make sure that we are between contribution page start and end dates OR registration start date and end dates if they are set if ($pcpBlock->entity_table == 'civicrm_event') { $startDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('registration_start_date', $pageInfo)); $endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('registration_end_date', $pageInfo)); } else { $startDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('start_date', $pageInfo)); $endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('end_date', $pageInfo)); } $now = time(); $validDate = TRUE; if ($startDate && $startDate >= $now) { $validDate = FALSE; } if ($endDate && $endDate < $now) { $validDate = FALSE; } $this->assign('validDate', $validDate); // form parent page url if ($action == CRM_Core_Action::PREVIEW) { $parentUrl = CRM_Utils_System::url($urlBase, "id={$pcpInfo['page_id']}&reset=1&action=preview", TRUE, NULL, TRUE, TRUE); } else { $parentUrl = CRM_Utils_System::url($urlBase, "id={$pcpInfo['page_id']}&reset=1", TRUE, NULL, TRUE, TRUE); } $this->assign('parentURL', $parentUrl); if ($validDate) { $contributionText = ts('Contribute Now'); if (!empty($pcpInfo['donate_link_text'])) { $contributionText = $pcpInfo['donate_link_text']; } $this->assign('contributionText', $contributionText); // we always generate urls for the front end in joomla if ($action == CRM_Core_Action::PREVIEW) { $url = CRM_Utils_System::url($urlBase, "id=" . $pcpBlock->target_entity_id . "&pcpId={$this->_id}&reset=1&action=preview", TRUE, NULL, TRUE, TRUE); } else { $url = CRM_Utils_System::url($urlBase, "id=" . $pcpBlock->target_entity_id . "&pcpId={$this->_id}&reset=1", TRUE, NULL, TRUE, TRUE); } $this->assign('contributeURL', $url); } // we do not want to display recently viewed items, so turn off $this->assign('displayRecent', FALSE); $single = $permission = FALSE; switch ($action) { case CRM_Core_Action::BROWSE: $subForm = 'PCPAccount'; $form = "CRM_PCP_Form_{$subForm}"; $single = TRUE; break; case CRM_Core_Action::UPDATE: $subForm = 'Campaign'; $form = "CRM_PCP_Form_{$subForm}"; $single = TRUE; break; } $userID = $session->get('userID'); //make sure the user has "administer CiviCRM" permission //OR has created the PCP if (CRM_Core_Permission::check('administer CiviCRM') || $userID && CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $this->_id, 'contact_id') == $userID) { $permission = TRUE; } if ($single && $permission) { $controller = new CRM_Core_Controller_Simple($form, $subForm, $action); $controller->set('id', $this->_id); $controller->set('single', TRUE); $controller->process(); return $controller->run(); } $session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1&id=' . $this->_id)); parent::run(); }
/** * Function to process the form * * @access public * * @return void */ public function postProcess() { // get the submitted form values. $params = $this->controller->exportValues($this->_name); // Source $params['entity_table'] = 'civicrm_contribution_page'; $params['entity_id'] = $this->_id; // Target $params['target_entity_type'] = CRM_Utils_Array::value('target_entity_type', $params, 'contribute'); $params['target_entity_id'] = $this->_id; $dao = new CRM_PCP_DAO_PCPBlock(); $dao->entity_table = $params['entity_table']; $dao->entity_id = $this->_id; $dao->find(TRUE); $params['id'] = $dao->id; $params['is_active'] = CRM_Utils_Array::value('pcp_active', $params, FALSE); $params['is_approval_needed'] = CRM_Utils_Array::value('is_approval_needed', $params, FALSE); $params['is_tellfriend_enabled'] = CRM_Utils_Array::value('is_tellfriend_enabled', $params, FALSE); $dao = CRM_PCP_BAO_PCP::add($params); parent::endPostProcess(); }
/** * Process the form when submitted * * @return void * @access public */ public function postProcess() { $transaction = new CRM_Core_Transaction(); // first delete the join entries associated with this contribution page $dao = new CRM_Core_DAO_UFJoin(); $params = array('entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id); $dao->copyValues($params); $dao->delete(); //next delete the membership block fields $dao = new CRM_Member_DAO_MembershipBlock(); $dao->entity_table = 'civicrm_contribution_page'; $dao->entity_id = $this->_id; $dao->delete(); //next delete the pcp block fields $dao = new CRM_PCP_DAO_PCPBlock(); $dao->entity_table = 'civicrm_contribution_page'; $dao->entity_id = $this->_id; $dao->delete(); // need to delete premiums. CRM-4586 CRM_Contribute_BAO_Premium::deletePremium($this->_id); // price set cleanup, CRM-5527 CRM_Price_BAO_PriceSet::removeFrom('civicrm_contribution_page', $this->_id); // finally delete the contribution page $dao = new CRM_Contribute_DAO_ContributionPage(); $dao->id = $this->_id; $dao->delete(); $transaction->commit(); CRM_Core_Session::setStatus(ts("The contribution page '%1' has been deleted.", array(1 => $this->_title)), ts('Deleted'), 'success'); }
static function getPcpBlockId($eventId, $component = 'event') { if (empty($eventId)) { return null; } $entity_table = CRM_PCP_BAO_PCP::getPcpEntityTable($component); $pcpBlock = new CRM_PCP_DAO_PCPBlock(); $pcpBlock->entity_table = $entity_table; $pcpBlock->entity_id = $eventId; $pcpBlock->find(TRUE); return $pcpBlock->id; }