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,354 @@
<?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$
*
*/
/**
* This class contains the funtions for Friend
*
*/
class CRM_Friend_BAO_Friend extends CRM_Friend_DAO_Friend {
/**
*/
public function __construct() {
parent::__construct();
}
/**
* Takes an associative array and creates a friend object.
*
* the function extract all the params it needs to initialize the create a
* friend object. the params array could contain additional unused name/value
* pairs
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
*
* @return int
*/
public static function add(&$params) {
return CRM_Contact_BAO_Contact::createProfileContact($params, CRM_Core_DAO::$_nullArray);
}
/**
* Given the list of params in the params array, fetch the object
* and store the values in the values array
*
* @param array $params
* Input parameters to find object.
* @param array $values
* Output values of the object.
*
* @return array
* values
*/
public static function retrieve(&$params, &$values) {
$friend = new CRM_Friend_DAO_Friend();
$friend->copyValues($params);
$friend->find(TRUE);
CRM_Core_DAO::storeValues($friend, $values);
return $values;
}
/**
* Takes an associative array and creates a friend object.
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
*
* @return void
*/
public static function create(&$params) {
$transaction = new CRM_Core_Transaction();
$mailParams = array();
//create contact corresponding to each friend
foreach ($params['friend'] as $key => $details) {
if ($details["first_name"]) {
$contactParams[$key] = array(
'first_name' => $details["first_name"],
'last_name' => $details["last_name"],
'contact_source' => ts('Tell a Friend') . ": {$params['title']}",
'email-Primary' => $details["email"],
);
$displayName = $details["first_name"] . " " . $details["last_name"];
$mailParams['email'][$displayName] = $details["email"];
}
}
$frndParams = array();
$frndParams['entity_id'] = $params['entity_id'];
$frndParams['entity_table'] = $params['entity_table'];
self::getValues($frndParams);
$activityTypeId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', 'Tell a Friend', 'value', 'name');
//create activity
$activityParams = array(
'source_contact_id' => $params['source_contact_id'],
'source_record_id' => NULL,
'activity_type_id' => $activityTypeId,
'title' => $params['title'],
'activity_date_time' => date("YmdHis"),
'subject' => ts('Tell a Friend') . ": {$params['title']}",
'details' => $params['suggested_message'],
'status_id' => 2,
'is_test' => $params['is_test'],
'campaign_id' => CRM_Utils_Array::value('campaign_id', $params),
);
//activity creation
$activity = CRM_Activity_BAO_Activity::create($activityParams);
$activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
$targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
//friend contacts creation
foreach ($contactParams as $key => $value) {
//create contact only if it does not exits in db
$value['email'] = $value['email-Primary'];
$contactID = CRM_Contact_BAO_Contact::getFirstDuplicateContact($value, 'Individual', 'Supervised', array(), FALSE);
if (!$contactID) {
$contactID = self::add($value);
}
// attempt to save activity targets
$targetParams = array(
'activity_id' => $activity->id,
'contact_id' => $contactID,
'record_type_id' => $targetID,
);
// See if it already exists
$activityContact = new CRM_Activity_DAO_ActivityContact();
$activityContact->activity_id = $activity->id;
$activityContact->contact_id = $contactID;
$activityContact->find(TRUE);
if (empty($activityContact->id)) {
CRM_Activity_BAO_ActivityContact::create($targetParams);
}
}
$transaction->commit();
//process sending of mails
$mailParams['title'] = CRM_Utils_Array::value('title', $params);
$mailParams['general_link'] = CRM_Utils_Array::value('general_link', $frndParams);
$mailParams['message'] = CRM_Utils_Array::value('suggested_message', $params);
// get domain
$domainDetails = CRM_Core_BAO_Domain::getNameAndEmail();
list($username, $mailParams['domain']) = explode('@', $domainDetails[1]);
$default = array();
$findProperties = array('id' => $params['entity_id']);
if ($params['entity_table'] == 'civicrm_contribution_page') {
$returnProperties = array('receipt_from_email', 'is_email_receipt');
CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_ContributionPage',
$findProperties,
$default,
$returnProperties
);
//if is_email_receipt is set then take receipt_from_email
//as from_email
if (!empty($default['is_email_receipt']) && !empty($default['receipt_from_email'])) {
$mailParams['email_from'] = $default['receipt_from_email'];
}
$urlPath = 'civicrm/contribute/transact';
$mailParams['module'] = 'contribute';
}
elseif ($params['entity_table'] == 'civicrm_event') {
$returnProperties = array('confirm_from_email', 'is_email_confirm');
CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event',
$findProperties,
$default,
$returnProperties
);
$mailParams['email_from'] = $domainDetails['1'];
//if is_email_confirm is set then take confirm_from_email
//as from_email
if (!empty($default['is_email_confirm']) && !empty($default['confirm_from_email'])) {
$mailParams['email_from'] = $default['confirm_from_email'];
}
$urlPath = 'civicrm/event/info';
$mailParams['module'] = 'event';
}
elseif ($params['entity_table'] == 'civicrm_pcp') {
$mailParams['email_from'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Email', $params['source_contact_id'],
'email', 'contact_id'
);
$urlPath = 'civicrm/pcp/info';
$mailParams['module'] = 'contribute';
}
$mailParams['page_url'] = CRM_Utils_System::url($urlPath, "reset=1&id={$params['entity_id']}", TRUE, NULL, FALSE, TRUE);
//send mail
self::sendMail($params['source_contact_id'], $mailParams);
}
/**
* Build the form object.
*
* @param CRM_Core_Form $form
* Form object.
*
* @return void
*/
public static function buildFriendForm($form) {
$form->addElement('checkbox', 'tf_is_active', ts('Tell a Friend enabled?'), NULL, array('onclick' => "friendBlock(this)"));
// name
$form->add('text', 'tf_title', ts('Title'), CRM_Core_DAO::getAttribute('CRM_Friend_DAO_Friend', 'title'), TRUE);
// intro-text and thank-you text
$form->add('wysiwyg', 'intro', ts('Introduction'), CRM_Core_DAO::getAttribute('CRM_Friend_DAO_Friend', 'intro') + array('class' => 'collapsed'));
$form->add('textarea', 'suggested_message', ts('Suggested Message'),
CRM_Core_DAO::getAttribute('CRM_Friend_DAO_Friend', 'suggested_message'), FALSE
);
$form->add('text', 'general_link', ts('Info Page Link'), CRM_Core_DAO::getAttribute('CRM_Friend_DAO_Friend', 'general_link'));
$form->add('text', 'tf_thankyou_title', ts('Thank-you Title'), CRM_Core_DAO::getAttribute('CRM_Friend_DAO_Friend', 'thankyou_title'), TRUE);
$form->add('wysiwyg', 'tf_thankyou_text', ts('Thank-you Message'), CRM_Core_DAO::getAttribute('CRM_Friend_DAO_Friend', 'thankyou_text') + array('class' => 'collapsed'));
if ($form->_friendId) {
// CRM-14200 the i18n dialogs need this for translation
$form->assign('friendId', $form->_friendId);
}
}
/**
* The function sets the deafult values of the form.
*
* @param array $defaults
* (reference) the default values.
*
* @return booelan
* whether anything was found
*/
public static function getValues(&$defaults) {
if (empty($defaults)) {
return NULL;
}
$friend = new CRM_Friend_BAO_Friend();
$friend->copyValues($defaults);
$found = $friend->find(TRUE);
CRM_Core_DAO::storeValues($friend, $defaults);
return $found;
}
/**
* Process that send tell a friend e-mails
*
* @param int $contactID
* @param array $values
*
* @return void
*/
public static function sendMail($contactID, &$values) {
list($fromName, $email) = CRM_Contact_BAO_Contact::getContactDetails($contactID);
// if no $fromName (only email collected from originating contact) - list returns single space
if (trim($fromName) == '') {
$fromName = $email;
}
// use contact email, CRM-4963
if (empty($values['email_from'])) {
$values['email_from'] = $email;
}
foreach ($values['email'] as $displayName => $emailTo) {
if ($emailTo) {
// FIXME: factor the below out of the foreach loop
CRM_Core_BAO_MessageTemplate::sendTemplate(
array(
'groupName' => 'msg_tpl_workflow_friend',
'valueName' => 'friend',
'contactId' => $contactID,
'tplParams' => array(
$values['module'] => $values['module'],
'senderContactName' => $fromName,
'title' => $values['title'],
'generalLink' => $values['general_link'],
'pageURL' => $values['page_url'],
'senderMessage' => $values['message'],
),
'from' => "$fromName (via {$values['domain']}) <{$values['email_from']}>",
'toName' => $displayName,
'toEmail' => $emailTo,
'replyTo' => $email,
)
);
}
}
}
/**
* Takes an associative array and creates a tell a friend object.
*
* the function extract all the params it needs to initialize the create/edit a
* friend object. the params array could contain additional unused name/value
* pairs
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
*
* @return CRM_Friend_BAO_Friend
*/
public static function addTellAFriend(&$params) {
$friendDAO = new CRM_Friend_DAO_Friend();
$friendDAO->copyValues($params);
$friendDAO->is_active = CRM_Utils_Array::value('is_active', $params, FALSE);
$friendDAO->save();
return $friendDAO;
}
}

View file

@ -0,0 +1,337 @@
<?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
*
* Generated from xml/schema/CRM/Friend/Friend.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:0f2c6f4aab46e551d1e3ec7fdd55f0f5)
*/
require_once 'CRM/Core/DAO.php';
require_once 'CRM/Utils/Type.php';
/**
* CRM_Friend_DAO_Friend constructor.
*/
class CRM_Friend_DAO_Friend extends CRM_Core_DAO {
/**
* Static instance to hold the table name.
*
* @var string
*/
static $_tableName = 'civicrm_tell_friend';
/**
* Should CiviCRM log any modifications to this table in the civicrm_log table.
*
* @var boolean
*/
static $_log = false;
/**
* Friend ID
*
* @var int unsigned
*/
public $id;
/**
* Name of table where item being referenced is stored.
*
* @var string
*/
public $entity_table;
/**
* Foreign key to the referenced item.
*
* @var int unsigned
*/
public $entity_id;
/**
*
* @var string
*/
public $title;
/**
* Introductory message to contributor or participant displayed on the Tell a Friend form.
*
* @var text
*/
public $intro;
/**
* Suggested message to friends, provided as default on the Tell A Friend form.
*
* @var text
*/
public $suggested_message;
/**
* URL for general info about the organization - included in the email sent to friends.
*
* @var string
*/
public $general_link;
/**
* Text for Tell a Friend thank you page header and HTML title.
*
* @var string
*/
public $thankyou_title;
/**
* Thank you message displayed on success page.
*
* @var text
*/
public $thankyou_text;
/**
*
* @var boolean
*/
public $is_active;
/**
* Class constructor.
*/
function __construct() {
$this->__table = 'civicrm_tell_friend';
parent::__construct();
}
/**
* Returns foreign keys and entity references.
*
* @return array
* [CRM_Core_Reference_Interface]
*/
static function getReferenceColumns() {
if (!isset(Civi::$statics[__CLASS__]['links'])) {
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName() , 'entity_id', NULL, 'id', 'entity_table');
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
}
return Civi::$statics[__CLASS__]['links'];
}
/**
* Returns all the column names of this table
*
* @return array
*/
static function &fields() {
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
Civi::$statics[__CLASS__]['fields'] = array(
'id' => array(
'name' => 'id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Friend ID') ,
'description' => 'Friend ID',
'required' => true,
'table_name' => 'civicrm_tell_friend',
'entity' => 'Friend',
'bao' => 'CRM_Friend_BAO_Friend',
'localizable' => 0,
) ,
'entity_table' => array(
'name' => 'entity_table',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Entity Table') ,
'description' => 'Name of table where item being referenced is stored.',
'required' => true,
'maxlength' => 64,
'size' => CRM_Utils_Type::BIG,
'table_name' => 'civicrm_tell_friend',
'entity' => 'Friend',
'bao' => 'CRM_Friend_BAO_Friend',
'localizable' => 0,
) ,
'entity_id' => array(
'name' => 'entity_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Entity ID') ,
'description' => 'Foreign key to the referenced item.',
'required' => true,
'table_name' => 'civicrm_tell_friend',
'entity' => 'Friend',
'bao' => 'CRM_Friend_BAO_Friend',
'localizable' => 0,
) ,
'title' => array(
'name' => 'title',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Title') ,
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'table_name' => 'civicrm_tell_friend',
'entity' => 'Friend',
'bao' => 'CRM_Friend_BAO_Friend',
'localizable' => 1,
'html' => array(
'type' => 'Text',
) ,
) ,
'intro' => array(
'name' => 'intro',
'type' => CRM_Utils_Type::T_TEXT,
'title' => ts('Intro') ,
'description' => 'Introductory message to contributor or participant displayed on the Tell a Friend form.',
'table_name' => 'civicrm_tell_friend',
'entity' => 'Friend',
'bao' => 'CRM_Friend_BAO_Friend',
'localizable' => 1,
'html' => array(
'type' => 'Text',
) ,
) ,
'suggested_message' => array(
'name' => 'suggested_message',
'type' => CRM_Utils_Type::T_TEXT,
'title' => ts('Suggested Message') ,
'description' => 'Suggested message to friends, provided as default on the Tell A Friend form.',
'table_name' => 'civicrm_tell_friend',
'entity' => 'Friend',
'bao' => 'CRM_Friend_BAO_Friend',
'localizable' => 1,
'html' => array(
'type' => 'Text',
) ,
) ,
'general_link' => array(
'name' => 'general_link',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('General Link') ,
'description' => 'URL for general info about the organization - included in the email sent to friends.',
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'import' => true,
'where' => 'civicrm_tell_friend.general_link',
'headerPattern' => '',
'dataPattern' => '',
'export' => true,
'table_name' => 'civicrm_tell_friend',
'entity' => 'Friend',
'bao' => 'CRM_Friend_BAO_Friend',
'localizable' => 0,
'html' => array(
'type' => 'Text',
) ,
) ,
'thankyou_title' => array(
'name' => 'thankyou_title',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Thank You Title') ,
'description' => 'Text for Tell a Friend thank you page header and HTML title.',
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'table_name' => 'civicrm_tell_friend',
'entity' => 'Friend',
'bao' => 'CRM_Friend_BAO_Friend',
'localizable' => 1,
'html' => array(
'type' => 'Text',
) ,
) ,
'thankyou_text' => array(
'name' => 'thankyou_text',
'type' => CRM_Utils_Type::T_TEXT,
'title' => ts('Thank You Text') ,
'description' => 'Thank you message displayed on success page.',
'table_name' => 'civicrm_tell_friend',
'entity' => 'Friend',
'bao' => 'CRM_Friend_BAO_Friend',
'localizable' => 1,
'html' => array(
'type' => 'Text',
) ,
) ,
'is_active' => array(
'name' => 'is_active',
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => ts('Enabled?') ,
'table_name' => 'civicrm_tell_friend',
'entity' => 'Friend',
'bao' => 'CRM_Friend_BAO_Friend',
'localizable' => 0,
'html' => array(
'type' => 'CheckBox',
) ,
) ,
);
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
}
return Civi::$statics[__CLASS__]['fields'];
}
/**
* Return a mapping from field-name to the corresponding key (as used in fields()).
*
* @return array
* Array(string $name => string $uniqueName).
*/
static function &fieldKeys() {
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
}
return Civi::$statics[__CLASS__]['fieldKeys'];
}
/**
* Returns the names of this table
*
* @return string
*/
static function getTableName() {
return CRM_Core_DAO::getLocaleTableName(self::$_tableName);
}
/**
* Returns if this table needs to be logged
*
* @return boolean
*/
function getLog() {
return self::$_log;
}
/**
* Returns the list of fields that can be imported
*
* @param bool $prefix
*
* @return array
*/
static function &import($prefix = false) {
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'tell_friend', $prefix, array());
return $r;
}
/**
* Returns the list of fields that can be exported
*
* @param bool $prefix
*
* @return array
*/
static function &export($prefix = false) {
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'tell_friend', $prefix, array());
return $r;
}
/**
* Returns the list of indices
*/
public static function indices($localize = TRUE) {
$indices = array();
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
}
}

View file

@ -0,0 +1,328 @@
<?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$
*
*/
/**
* This class generates form components for Tell A Friend Form For End User
*
*/
class CRM_Friend_Form extends CRM_Core_Form {
/**
* Constants for number of friend contacts.
*/
const NUM_OPTION = 3;
/**
* The id of the entity that we are proceessing.
*
* @var int
*/
protected $_entityId;
/**
* The table name of the entity that we are proceessing.
*
* @var string
*/
protected $_entityTable;
protected $_campaignId;
/**
* The contact ID.
*
* @var int
*/
protected $_contactID;
public function preProcess() {
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this);
$this->_entityId = CRM_Utils_Request::retrieve('eid', 'Positive', $this, TRUE);
$pcomponent = CRM_Utils_Request::retrieve('pcomponent', 'String', $this, TRUE);
if (in_array($pcomponent, array(
'contribute',
'event',
))) {
$values = array();
$params = array('id' => $this->_entityId);
CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_ContributionPage',
$params, $values, array('title', 'campaign_id', 'is_share')
);
$this->_title = CRM_Utils_Array::value('title', $values);
$this->_campaignId = CRM_Utils_Array::value('campaign_id', $values);
$this->_entityTable = 'civicrm_contribution_page';
if ($pcomponent == 'event') {
$this->_entityTable = 'civicrm_event';
$isShare = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_entityId, 'is_share');
}
else {
$isShare = CRM_Utils_Array::value('is_share', $values);
}
// Tell Form.tpl whether to include SocialNetwork.tpl for social media sharing
$this->assign('isShare', $isShare);
}
elseif ($pcomponent == 'pcp') {
$this->_pcpBlockId = CRM_Utils_Request::retrieve('blockId', 'Positive', $this, TRUE);
$values = array();
$params = array('id' => $this->_pcpBlockId);
CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCPBlock',
$params, $values, array('is_tellfriend_enabled', 'tellfriend_limit')
);
if (empty($values['is_tellfriend_enabled'])) {
CRM_Core_Error::fatal(ts('Tell Friend is disable for this Personal Campaign Page'));
}
$this->_mailLimit = $values['tellfriend_limit'];
$this->_entityTable = 'civicrm_pcp';
$sql = '
SELECT pcp.title,
contrib.campaign_id
FROM civicrm_pcp pcp
INNER JOIN civicrm_contribution_page contrib ON ( pcp.page_id = contrib.id AND pcp.page_type = "contribute" )
WHERE pcp.id = %1';
$pcp = CRM_Core_DAO::executeQuery($sql, array(1 => array($this->_entityId, 'Positive')));
while ($pcp->fetch()) {
$this->_title = $pcp->title;
$this->_campaignId = $pcp->campaign_id;
$pcp->free();
}
$this->assign('pcpTitle', $this->_title);
}
else {
CRM_Core_Error::fatal(ts('page argument missing or invalid'));
}
$this->assign('context', $pcomponent);
$session = CRM_Core_Session::singleton();
$this->_contactID = $session->get('userID');
if (!$this->_contactID) {
$this->_contactID = $session->get('transaction.userID');
}
if (!$this->_contactID) {
CRM_Core_Error::fatal(ts('Could not get the contact ID'));
}
// we do not want to display recently viewed items, so turn off
$this->assign('displayRecent', FALSE);
}
/**
* Set default values for the form.
*
*
* @return void
*/
public function setDefaultValues() {
$defaults = array();
$defaults['entity_id'] = $this->_entityId;
$defaults['entity_table'] = $this->_entityTable;
CRM_Friend_BAO_Friend::getValues($defaults);
CRM_Utils_System::setTitle(CRM_Utils_Array::value('title', $defaults));
$this->assign('title', CRM_Utils_Array::value('title', $defaults));
$this->assign('intro', CRM_Utils_Array::value('intro', $defaults));
$this->assign('message', CRM_Utils_Array::value('suggested_message', $defaults));
$this->assign('entityID', $this->_entityId);
list($fromName, $fromEmail) = CRM_Contact_BAO_Contact::getContactDetails($this->_contactID);
$defaults['from_name'] = $fromName;
$defaults['from_email'] = $fromEmail;
return $defaults;
}
/**
* Build the form object.
*
* @return void
*/
public function buildQuickForm() {
$this->applyFilter('__ALL__', 'trim');
// Details of User
$name = &$this->add('text',
'from_name',
ts('From'),
CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'first_name')
);
$name->freeze();
$email = &$this->add('text',
'from_email',
ts('Your Email'),
CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', 'email'),
TRUE
);
$email->freeze();
$this->add('wysiwyg', 'suggested_message', ts('Your Message'), CRM_Core_DAO::getAttribute('CRM_Friend_DAO_Friend', 'suggested_message'));
$friend = array();
$mailLimit = self::NUM_OPTION;
if ($this->_entityTable == 'civicrm_pcp') {
$mailLimit = $this->_mailLimit;
}
$this->assign('mailLimit', $mailLimit + 1);
for ($i = 1; $i <= $mailLimit; $i++) {
$this->add('text', "friend[$i][first_name]", ts("Friend's First Name"));
$this->add('text', "friend[$i][last_name]", ts("Friend's Last Name"));
$this->add('text', "friend[$i][email]", ts("Friend's Email"));
$this->addRule("friend[$i][email]", ts('The format of this email address is not valid.'), 'email');
}
$this->addButtons(array(
array(
'type' => 'submit',
'name' => ts('Send Your Message'),
'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
)
);
$this->addFormRule(array('CRM_Friend_Form', 'formRule'));
}
/**
* Validation.
*
* @param array $fields
*
* @return bool|array
* mixed true or array of errors
*/
public static function formRule($fields) {
$errors = array();
$valid = FALSE;
foreach ($fields['friend'] as $key => $val) {
if (trim($val['first_name']) || trim($val['last_name']) || trim($val['email'])) {
$valid = TRUE;
if (!trim($val['first_name'])) {
$errors["friend[{$key}][first_name]"] = ts('Please enter your friend\'s first name.');
}
if (!trim($val['last_name'])) {
$errors["friend[{$key}][last_name]"] = ts('Please enter your friend\'s last name.');
}
if (!trim($val['email'])) {
$errors["friend[{$key}][email]"] = ts('Please enter your friend\'s email address.');
}
}
}
if (!$valid) {
$errors['friend[1][first_name]'] = ts("Please enter at least one friend's information, or click Cancel if you don't want to send emails at this time.");
}
return empty($errors) ? TRUE : $errors;
}
/**
* Process the form submission.
*
*
* @return void
*/
public function postProcess() {
// get the submitted form values.
$formValues = $this->controller->exportValues($this->_name);
$formValues['entity_id'] = $this->_entityId;
$formValues['entity_table'] = $this->_entityTable;
$formValues['source_contact_id'] = $this->_contactID;
$formValues['is_test'] = $this->_action ? 1 : 0;
$formValues['title'] = $this->_title;
$formValues['campaign_id'] = $this->_campaignId;
CRM_Friend_BAO_Friend::create($formValues);
$this->assign('status', 'thankyou');
$defaults = array();
$defaults['entity_id'] = $this->_entityId;
$defaults['entity_table'] = $this->_entityTable;
CRM_Friend_BAO_Friend::getValues($defaults);
if ($this->_entityTable == 'civicrm_pcp') {
$defaults['thankyou_text'] = $defaults['thankyou_title'] = ts('Thank you for your support');
$defaults['thankyou_text'] = ts('Thanks for supporting this campaign by spreading the word to your friends.');
}
elseif ($this->_entityTable == 'civicrm_contribution_page') {
// If this is tell a friend after contributing, give donor link to create their own fundraising page
if ($linkText = CRM_PCP_BAO_PCP::getPcpBlockStatus($defaults['entity_id'], $defaults['entity_table'])) {
$linkTextUrl = CRM_Utils_System::url('civicrm/contribute/campaign',
"action=add&reset=1&pageId={$defaults['entity_id']}&component=contribute",
FALSE, NULL, TRUE,
TRUE
);
$this->assign('linkTextUrl', $linkTextUrl);
$this->assign('linkText', $linkText);
}
}
elseif ($this->_entityTable == 'civicrm_event') {
// If this is tell a friend after registering for an event, give donor link to create their own fundraising page
require_once 'CRM/PCP/BAO/PCP.php';
if ($linkText = CRM_PCP_BAO_PCP::getPcpBlockStatus($defaults['entity_id'], $defaults['entity_table'])) {
$linkTextUrl = CRM_Utils_System::url('civicrm/contribute/campaign',
"action=add&reset=1&pageId={$defaults['entity_id']}&component=event",
FALSE, NULL, TRUE,
TRUE);
$this->assign('linkTextUrl', $linkTextUrl);
$this->assign('linkText', $linkText);
}
}
CRM_Utils_System::setTitle($defaults['thankyou_title']);
$this->assign('thankYouText', $defaults['thankyou_text']);
}
}

View file

@ -0,0 +1,136 @@
<?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$
*
*/
/**
* This class generates form components for Tell A Friend
*
*/
class CRM_Friend_Form_Contribute extends CRM_Contribute_Form_ContributionPage {
/**
* Tell a friend id in db.
*
* @var int
*/
public $_friendId;
public function preProcess() {
parent::preProcess();
}
/**
* Set default values for the form. Note that in edit/view mode
* the default values are retrieved from the database
*
*
* @return void
*/
public function setDefaultValues() {
$defaults = array();
if (isset($this->_id)) {
$defaults['entity_table'] = 'civicrm_contribution_page';
$defaults['entity_id'] = $this->_id;
CRM_Friend_BAO_Friend::getValues($defaults);
$this->_friendId = CRM_Utils_Array::value('id', $defaults);
$defaults['tf_title'] = CRM_Utils_Array::value('title', $defaults);
$defaults['tf_is_active'] = CRM_Utils_Array::value('is_active', $defaults);
$defaults['tf_thankyou_title'] = CRM_Utils_Array::value('thankyou_title', $defaults);
$defaults['tf_thankyou_text'] = CRM_Utils_Array::value('thankyou_text', $defaults);
}
if (!$this->_friendId) {
$defaults['intro'] = ts('Help us spread the word and leverage the power of your contribution by telling your friends. Use the space below to personalize your email message - let your friends know why you support us. Then fill in the name(s) and email address(es) and click \'Send Your Message\'.');
$defaults['suggested_message'] = ts('Thought you might be interested in learning about and helping this organization. I think they do important work.');
$defaults['tf_thankyou_text'] = ts('Thanks for telling your friends about us and supporting our efforts. Together we can make a difference.');
$defaults['tf_title'] = ts('Tell a Friend');
$defaults['tf_thankyou_title'] = ts('Thanks for Spreading the Word');
}
return $defaults;
}
/**
* Build the form object.
*
* @return void
*/
public function buildQuickForm() {
if (isset($this->_id)) {
$defaults['entity_table'] = 'civicrm_contribution_page';
$defaults['entity_id'] = $this->_id;
CRM_Friend_BAO_Friend::getValues($defaults);
$this->_friendId = CRM_Utils_Array::value('id', $defaults);
}
CRM_Friend_BAO_Friend::buildFriendForm($this);
parent::buildQuickForm();
}
/**
* Process the form submission.
*
*
* @return void
*/
public function postProcess() {
// get the submitted form values.
$formValues = $this->controller->exportValues($this->_name);
$formValues['entity_table'] = 'civicrm_contribution_page';
$formValues['entity_id'] = $this->_id;
$formValues['title'] = $formValues['tf_title'];
$formValues['is_active'] = CRM_Utils_Array::value('tf_is_active', $formValues, FALSE);
$formValues['thankyou_title'] = CRM_Utils_Array::value('tf_thankyou_title', $formValues);
$formValues['thankyou_text'] = CRM_Utils_Array::value('tf_thankyou_text', $formValues);
if (($this->_action & CRM_Core_Action::UPDATE) && $this->_friendId) {
$formValues['id'] = $this->_friendId;
}
CRM_Friend_BAO_Friend::addTellAFriend($formValues);
parent::endPostProcess();
}
/**
* Return a descriptive name for the page, used in wizard header
*
* @return string
*/
public function getTitle() {
return ts('Tell a Friend');
}
}

View file

@ -0,0 +1,148 @@
<?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$
*
*/
/**
* This class generates form components for Tell A Friend
*
*/
class CRM_Friend_Form_Event extends CRM_Event_Form_ManageEvent {
/**
* Tell a friend id in db.
*
* @var int
*/
public $_friendId;
public function preProcess() {
parent::preProcess();
}
/**
* Set default values for the form.
*
*
* @return void
*/
public function setDefaultValues() {
$defaults = array();
if (isset($this->_id)) {
$defaults['entity_table'] = 'civicrm_event';
$defaults['entity_id'] = $this->_id;
CRM_Friend_BAO_Friend::getValues($defaults);
if (!empty($defaults['id'])) {
$defaults['tf_id'] = CRM_Utils_Array::value('id', $defaults);
$this->_friendId = $defaults['tf_id'];
// lets unset the 'id' since it conflicts with eventID (or contribID)
// CRM-12667
unset($defaults['id']);
}
$defaults['tf_title'] = CRM_Utils_Array::value('title', $defaults);
$defaults['tf_is_active'] = CRM_Utils_Array::value('is_active', $defaults);
$defaults['tf_thankyou_title'] = CRM_Utils_Array::value('thankyou_title', $defaults);
$defaults['tf_thankyou_text'] = CRM_Utils_Array::value('thankyou_text', $defaults);
}
if (!$this->_friendId) {
$defaults['intro'] = ts('Help us spread the word about this event. Use the space below to personalize your email message - let your friends know why you\'re attending. Then fill in the name(s) and email address(es) and click \'Send Your Message\'.');
$defaults['suggested_message'] = ts('Thought you might be interested in checking out this event. I\'m planning on attending.');
$defaults['tf_thankyou_text'] = ts('Thanks for spreading the word about this event to your friends.');
$defaults['tf_title'] = ts('Tell a Friend');
$defaults['tf_thankyou_title'] = ts('Thanks for Spreading the Word');
}
return $defaults;
}
/**
* Build the form object.
*
* @return void
*/
public function buildQuickForm() {
if (isset($this->_id)) {
$defaults['entity_table'] = 'civicrm_event';
$defaults['entity_id'] = $this->_id;
CRM_Friend_BAO_Friend::getValues($defaults);
$this->_friendId = CRM_Utils_Array::value('id', $defaults);
}
CRM_Friend_BAO_Friend::buildFriendForm($this);
parent::buildQuickForm();
}
/**
* Process the form submission.
*
*
* @return void
*/
public function postProcess() {
// get the submitted form values.
$formValues = $this->controller->exportValues($this->_name);
// let's unset event id
unset($formValues['id']);
$formValues['entity_table'] = 'civicrm_event';
$formValues['entity_id'] = $this->_id;
$formValues['title'] = $formValues['tf_title'];
$formValues['is_active'] = CRM_Utils_Array::value('tf_is_active', $formValues, FALSE);
$formValues['thankyou_title'] = CRM_Utils_Array::value('tf_thankyou_title', $formValues);
$formValues['thankyou_text'] = CRM_Utils_Array::value('tf_thankyou_text', $formValues);
if (($this->_action & CRM_Core_Action::UPDATE) && $this->_friendId) {
$formValues['id'] = $this->_friendId;
}
CRM_Friend_BAO_Friend::addTellAFriend($formValues);
// Update tab "disabled" css class
$this->ajaxResponse['tabValid'] = !empty($formValues['tf_is_active']);
parent::endPostProcess();
}
/**
* Return a descriptive name for the page, used in wizard header
*
* @return string
*/
public function getTitle() {
return ts('Tell a Friend');
}
}