本文整理汇总了PHP中CRM_Core_Session::singleton方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_Session::singleton方法的具体用法?PHP CRM_Core_Session::singleton怎么用?PHP CRM_Core_Session::singleton使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_Session
的用法示例。
在下文中一共展示了CRM_Core_Session::singleton方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cdntaxreceipts_civicrm_postProcess
/**
* Implementation of hook_civicrm_postProcess().
*
* Called when a form comes back for processing. Basically, we want to process
* the button we added in cdntaxreceipts_civicrm_buildForm().
*/
function cdntaxreceipts_civicrm_postProcess($formName, &$form)
{
// first check whether I really need to process this form
if (!is_a($form, 'CRM_Contribute_Form_ContributionView')) {
return;
}
$types = array('issue_tax_receipt', 'view_tax_receipt');
$action = '';
foreach ($types as $type) {
$post = '_qf_ContributionView_submit_' . $type;
if (isset($_POST[$post])) {
if ($_POST[$post] == ts('Tax Receipt', array('domain' => 'org.civicrm.cdntaxreceipts'))) {
$action = $post;
}
}
}
if (empty($action)) {
return;
}
// the tax receipt button has been pressed. redirect to the tax receipt 'view' screen, preserving context.
$contributionId = $form->get('id');
$contactId = $form->get('cid');
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/contact/view/contribution', "reset=1&id={$contributionId}&cid={$contactId}&action=view&context=contribution&selectedChild=contribute"));
$urlParams = array('reset=1', 'id=' . $contributionId, 'cid=' . $contactId);
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/cdntaxreceipts/view', implode('&', $urlParams)));
}
示例2: ping
/**
* Simple ping function to test for liveness.
*
* @param string $var
* The string to be echoed.
*
* @return string
*/
public static function ping($var = NULL)
{
$session = CRM_Core_Session::singleton();
$key = $session->get('key');
//$session->set( 'key', $var );
return self::simple(array('message' => "PONG: {$key}"));
}
示例3: showPeriodicAlerts
/**
* Display daily system status alerts (admin only).
*/
public function showPeriodicAlerts()
{
if (CRM_Core_Permission::check('administer CiviCRM')) {
$session = CRM_Core_Session::singleton();
if ($session->timer('check_' . __CLASS__, self::CHECK_TIMER)) {
// Best attempt at re-securing folders
$config = CRM_Core_Config::singleton();
$config->cleanup(0, FALSE);
$statusMessages = array();
$maxSeverity = 0;
foreach ($this->checkAll() as $message) {
if (!$message->isVisible()) {
continue;
}
if ($message->getLevel() >= 3) {
$maxSeverity = max($maxSeverity, $message->getLevel());
$statusMessage = $message->getMessage();
$statusMessages[] = $statusTitle = $message->getTitle();
}
}
if ($statusMessages) {
if (count($statusMessages) > 1) {
$statusTitle = self::toStatusLabel($maxSeverity);
$statusMessage = '<ul><li>' . implode('</li><li>', $statusMessages) . '</li></ul>';
}
$statusMessage .= '<p><a href="' . CRM_Utils_System::url('civicrm/a/#/status') . '">' . ts('View details and manage alerts') . '</a></p>';
$statusType = $maxSeverity >= 4 ? 'error' : 'alert';
CRM_Core_Session::setStatus($statusMessage, $statusTitle, $statusType);
}
}
}
}
示例4: preProcess
/**
* For pre-processing
*
* @return void
*/
public function preProcess()
{
parent::preProcess();
$this->_key = CRM_Utils_Request::retrieve('key', 'String', $this, FALSE, 0);
$session = CRM_Core_Session::singleton();
$url = CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1&action=browse');
$session->pushUserContext($url);
$this->assign('id', $this->_id);
$this->assign('key', $this->_key);
switch ($this->_action) {
case CRM_Core_Action::ADD:
case CRM_Core_Action::DELETE:
case CRM_Core_Action::ENABLE:
case CRM_Core_Action::DISABLE:
$info = CRM_Extension_System::singleton()->getMapper()->keyToInfo($this->_key);
$extInfo = CRM_Admin_Page_Extensions::createExtendedInfo($info);
$this->assign('extension', $extInfo);
break;
case CRM_Core_Action::UPDATE:
if (!CRM_Extension_System::singleton()->getBrowser()->isEnabled()) {
CRM_Core_Error::fatal(ts('The system administrator has disabled this feature.'));
}
$info = CRM_Extension_System::singleton()->getBrowser()->getExtension($this->_key);
$extInfo = CRM_Admin_Page_Extensions::createExtendedInfo($info);
$this->assign('extension', $extInfo);
break;
default:
CRM_Core_Error::fatal(ts('Unsupported action'));
}
}
示例5: preProcess
public function preProcess()
{
$this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE);
$this->_system = CRM_Utils_Request::retrieve('system', 'Boolean', $this, FALSE, TRUE);
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'update');
if (isset($action)) {
$this->assign('action', $action);
}
$session = CRM_Core_Session::singleton();
$this->_config = new CRM_Core_DAO();
if ($this->_system) {
if (CRM_Core_Permission::check('administer CiviCRM')) {
$this->_contactID = NULL;
} else {
CRM_Utils_System::fatal('You do not have permission to edit preferences');
}
$this->_config->contact_id = NULL;
} else {
if (!$this->_contactID) {
$this->_contactID = $session->get('userID');
if (!$this->_contactID) {
CRM_Utils_System::fatal('Could not retrieve contact id');
}
$this->set('cid', $this->_contactID);
}
$this->_config->contact_id = $this->_contactID;
}
$settings = Civi::settings();
foreach ($this->_varNames as $groupName => $settingNames) {
foreach ($settingNames as $settingName => $options) {
$this->_config->{$settingName} = $settings->get($settingName);
}
}
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1'));
}
示例6: run
public function run()
{
$eid = CRM_Utils_Request::retrieve('eid', 'Positive', $this, TRUE);
$fid = CRM_Utils_Request::retrieve('fid', 'Positive', $this, FALSE);
$id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
$quest = CRM_Utils_Request::retrieve('quest', 'String', $this);
$action = CRM_Utils_Request::retrieve('action', 'String', $this);
list($path, $mimeType) = CRM_Core_BAO_File::path($id, $eid, NULL, $quest);
if (!$path) {
CRM_Core_Error::statusBounce('Could not retrieve the file');
}
$buffer = file_get_contents($path);
if (!$buffer) {
CRM_Core_Error::statusBounce('The file is either empty or you do not have permission to retrieve the file');
}
if ($action & CRM_Core_Action::DELETE) {
if (CRM_Utils_Request::retrieve('confirmed', 'Boolean', CRM_Core_DAO::$_nullObject)) {
CRM_Core_BAO_File::deleteFileReferences($id, $eid, $fid);
CRM_Core_Session::setStatus(ts('The attached file has been deleted.'), ts('Complete'), 'success');
$session = CRM_Core_Session::singleton();
$toUrl = $session->popUserContext();
CRM_Utils_System::redirect($toUrl);
}
} else {
CRM_Utils_System::download(CRM_Utils_File::cleanFileName(basename($path)), $mimeType, $buffer);
}
}
示例7: postProcess
public function postProcess()
{
$values = $this->exportValues();
// check if EmailTyped matches Email address
$result = CRM_Utils_String::compareStr($this->_email, $values['email_confirm'], TRUE);
$job_id = $this->_job_id;
$queue_id = $this->_queue_id;
$hash = $this->_hash;
$confirmURL = CRM_Utils_System::url("civicrm/mailing/{$this->_type}", "reset=1&jid={$job_id}&qid={$queue_id}&h={$hash}&confirm=1");
$this->assign('confirmURL', $confirmURL);
$session = CRM_Core_Session::singleton();
$session->pushUserContext($confirmURL);
if ($result == TRUE) {
// Email address verified
if (CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_domain($job_id, $queue_id, $hash)) {
CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue_id, NULL, TRUE, $job_id);
}
$statusMsg = ts('Email: %1 has been successfully opted out', array(1 => $values['email_confirm']));
CRM_Core_Session::setStatus($statusMsg, '', 'success');
} elseif ($result == FALSE) {
// Email address not verified
$statusMsg = ts('The email address: %1 you have entered does not match the email associated with this opt out request.', array(1 => $values['email_confirm']));
CRM_Core_Session::setStatus($statusMsg, '', 'fail');
}
}
示例8: sendEmail
/**
* send the message to all the contacts and also insert a
* contact activity in each contacts record
*
* @param array $contactIds the array of contact ids to send the email
* @param string $subject the subject of the message
* @param string $message the message contents
* @param string $emailAddress use this 'to' email address instead of the default Primary address
*
* @return array (total, added, notAdded) count of emails sent
* @access public
* @static
*/
function sendEmail(&$contactIds, &$subject, &$message, $emailAddress)
{
$session =& CRM_Core_Session::singleton();
$userID = $session->get('userID');
list($fromDisplayName, $fromEmail, $fromDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($userID);
if (!$fromEmail) {
return array(count($contactIds), 0, count($contactIds));
}
if (!trim($fromDisplayName)) {
$fromDisplayName = $fromEmail;
}
$from = CRM_Utils_Mail::encodeAddressHeader($fromDisplayName, $fromEmail);
// create the meta level record first
$email =& new CRM_Core_BAO_EmailHistory();
$email->subject = $subject;
$email->message = $message;
$email->contact_id = $userID;
$email->sent_date = date('Ymd');
$email->save();
$sent = $notSent = 0;
foreach ($contactIds as $contactId) {
if (CRM_Core_BAO_EmailHistory::sendMessage($from, $contactId, $subject, $message, $emailAddress, $email->id)) {
$sent++;
} else {
$notSent++;
}
}
return array(count($contactIds), $sent, $notSent);
}
示例9: normalize_civicrm_enable
/**
* Implementation of hook_civicrm_enable
*/
function normalize_civicrm_enable()
{
// jump to the setup screen after enabling extension
$session = CRM_Core_Session::singleton();
$session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/setting/reformat'));
return _normalize_civix_civicrm_enable();
}
示例10: showPeriodicAlerts
/**
* Execute "checkAll".
*
* @param array|NULL $messages
* List of CRM_Utils_Check_Message; or NULL if the default list should be fetched.
* @param array|string|callable $filter
* Restrict messages using a callback filter.
* By default, only show warnings and errors.
* Set TRUE to show all messages.
*/
public function showPeriodicAlerts($messages = NULL, $filter = array(__CLASS__, 'severityMap'))
{
if (CRM_Core_Permission::check('administer CiviCRM') && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'securityAlert', NULL, TRUE)) {
$session = CRM_Core_Session::singleton();
if ($session->timer('check_' . __CLASS__, self::CHECK_TIMER)) {
// Best attempt at re-securing folders
$config = CRM_Core_Config::singleton();
$config->cleanup(0, FALSE);
if ($messages === NULL) {
$messages = $this->checkAll();
}
$statusMessages = array();
$statusType = 'alert';
foreach ($messages as $message) {
if ($filter === TRUE || $message->getSeverity() >= 3) {
$statusType = $message->getSeverity() >= 4 ? 'error' : $statusType;
$statusMessage = $message->getMessage();
$statusMessages[] = $statusTitle = $message->getTitle();
}
}
if (count($statusMessages)) {
if (count($statusMessages) > 1) {
$statusTitle = ts('Multiple Alerts');
$statusMessage = '<ul><li>' . implode('</li><li>', $statusMessages) . '</li></ul>';
}
// TODO: add link to status page
CRM_Core_Session::setStatus($statusMessage, $statusTitle, $statusType);
}
}
}
}
示例11: noverwrite_civicrm_buildForm
function noverwrite_civicrm_buildForm($formName, &$form)
{
$names = array("CRM_Profile_Form_Edit", "CRM_Event_Form_Registration_Register", "CRM_Contribute_Form_Contribution_Main");
if (!in_array($formName, $names)) {
return;
}
// Don't invoke if we're using CiviMobile, since CiviMobile depends on users being able
// to edit records via profiles.
$path = CRM_Utils_Array::value('HTTP_REFERER', $_SERVER);
if ($formName == 'CRM_Profile_Form_Edit' && preg_match('#civicrm/mobile#', $path)) {
return;
}
$session = CRM_Core_Session::singleton();
if (!$session->get('userID') && !array_key_exists("cs", $_GET)) {
return;
// anonymous user, nothing to bloc
}
foreach (array('first_name', 'middle_name', 'last_name') as $f) {
if (!$form->elementExists($f)) {
continue;
}
$field = $form->getElement($f);
if ($field && $field->_attributes["value"]) {
$form->freeze($f);
}
}
// if you want to bloc it at the js level only, uncomment the next line and comment out the freeze
// CRM_Core_Resources::singleton()->addScript(file_get_contents(dirname( __FILE__ ) ."/js/noverwrite.js"));
}
示例12: postProcess
function postProcess()
{
$session = CRM_Core_Session::singleton();
$params = $this->exportValues();
$result = civicrm_api3('OptionValue', 'create', array('value' => $params['hour_value'], 'id' => CRM_Utils_Array::key($params['hour_type_select'], $this->_id)));
$session->pushUserContext(CRM_Utils_System::url('civicrm/hour/editoption', "&value={$params['hour_value']}"));
}
示例13: run
/**
* 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
* @access public
*
*/
function run()
{
// get the requested action
$action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
// assign vars to templates
$this->assign('action', $action);
$id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0);
$this->_aid = CRM_Utils_Request::retrieve('aid', 'Positive', $this);
// set breadcrumb to append to 2nd layer pages
$breadCrumb = array(array('title' => ts('Manage Items'), 'url' => CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1')));
// what action to take ?
if ($action & CRM_Core_Action::DISABLE) {
require_once 'CRM/Auction/BAO/Auction.php';
CRM_Auction_BAO_Auction::setIsActive($id, 0);
} elseif ($action & CRM_Core_Action::ENABLE) {
require_once 'CRM/Auction/BAO/Auction.php';
CRM_Auction_BAO_Auction::setIsActive($id, 1);
} elseif ($action & CRM_Core_Action::DELETE) {
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1&action=browse'));
$controller = new CRM_Core_Controller_Simple('CRM_Auction_Form_Auction_Delete', 'Delete Auction', $action);
$id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0);
$controller->set('id', $id);
$controller->process();
return $controller->run();
}
// finally browse the auctions
$this->browse();
// parent run
parent::run();
}
示例14: preProcess
/**
* build all the data structures needed to build the form
*
* @return void
* @access public
*/
function preProcess()
{
$session =& CRM_Core_Session::singleton();
//this is done to unset searchRows variable assign during AddToHousehold and AddToOrganization
$this->set('searchRows', '');
$context = $this->get('context');
if ($context == 'smog' || $context == 'amtg') {
$url = CRM_Utils_System::url('civicrm/group/search', 'reset=1&force=1&context=smog&gid=');
if ($this->get('context') == 'smog') {
$session->replaceUserContext($url . $this->get('gid'));
} else {
$session->replaceUserContext($url . $this->get('amtgID'));
}
return;
}
$ssID = $this->get('ssID');
if (isset($ssID)) {
if ($this->_action == CRM_CORE_ACTION_BASIC) {
$fragment = 'search';
} else {
$fragment = 'search/advanced';
}
$url = CRM_Utils_System::url('civicrm/contact/' . $fragment, 'reset=1&force=1&ssID=' . $ssID);
$session->replaceUserContext($url);
return;
}
}
示例15: preProcess
/**
* build all the data structures needed to build the form
*
* @return void
* @access public
*/
function preProcess()
{
// reset action from the session
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'update');
$this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
$rcid = CRM_Utils_Request::retrieve('rcid', 'Positive', $this);
$rcid = $rcid ? "&id={$rcid}" : '';
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/user', "reset=1{$rcid}"));
if ($this->_contactId) {
$contact = new CRM_Contact_DAO_Contact();
$contact->id = $this->_contactId;
if (!$contact->find(TRUE)) {
CRM_Core_Error::statusBounce(ts('contact does not exist: %1', array(1 => $this->_contactId)));
}
$this->_contactType = $contact->contact_type;
// check for permissions
if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) {
CRM_Core_Error::statusBounce(ts('You do not have the necessary permission to edit this contact.'));
}
list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($this->_contactId);
CRM_Utils_System::setTitle($displayName, $contactImage . ' ' . $displayName);
} else {
CRM_Core_Error::statusBounce(ts('Could not get a contact_id and/or contact_type'));
}
}