/** * Creates a new entry in the database. * * @param array $params * (reference) an assoc array of name/value pairs. * * @return CRM_Price_DAO_LineItem */ public static function create(&$params) { $id = CRM_Utils_Array::value('id', $params); if ($id) { CRM_Utils_Hook::pre('edit', 'LineItem', $id, $params); $op = CRM_Core_Action::UPDATE; } else { CRM_Utils_Hook::pre('create', 'LineItem', $params['entity_id'], $params); $op = CRM_Core_Action::ADD; } // unset entity table and entity id in $params // we never update the entity table and entity id during update mode if ($id) { unset($params['entity_id'], $params['entity_table']); } if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && CRM_Utils_Array::value('check_permissions', $params)) { if (empty($params['financial_type_id'])) { throw new Exception('Mandatory key(s) missing from params array: financial_type_id'); } CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types, $op); if (!in_array($params['financial_type_id'], array_keys($types))) { throw new Exception('You do not have permission to create this line item'); } } $lineItemBAO = new CRM_Price_BAO_LineItem(); $lineItemBAO->copyValues($params); $return = $lineItemBAO->save(); if ($id) { CRM_Utils_Hook::post('edit', 'LineItem', $id, $lineItemBAO); } else { CRM_Utils_Hook::post('create', 'LineItem', $lineItemBAO->id, $lineItemBAO); } return $return; }
public function tearDown() { CRM_Utils_Hook::singleton()->reset(); parent::tearDown(); $this->callAPISuccess('system', 'flush', array()); $this->quickCleanup(array('civicrm_domain')); }
/** * */ function tearDown() { $this->_mut->stop(); $this->quickCleanup(array('civicrm_mailing', 'civicrm_mailing_job', 'civicrm_contact')); CRM_Utils_Hook::singleton()->reset(); parent::tearDown(); }
/** * Get a list of AngularJS modules which should be autoloaded. * * @return array * Each item has some combination of these keys: * - ext: string * The Civi extension which defines the Angular module. * - js: array(string $relativeFilePath) * List of JS files (relative to the extension). * - css: array(string $relativeFilePath) * List of CSS files (relative to the extension). * - partials: array(string $relativeFilePath) * A list of partial-HTML folders (relative to the extension). * This will be mapped to "~/moduleName" by crmResource. * - settings: array(string $key => mixed $value) * List of settings to preload. */ public function getModules() { if ($this->modules === NULL) { $config = \CRM_Core_Config::singleton(); $angularModules = array(); $angularModules['angularFileUpload'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-file-upload/dist/angular-file-upload.min.js')); $angularModules['crmApp'] = array('ext' => 'civicrm', 'js' => array('ang/crmApp.js')); $angularModules['crmAttachment'] = array('ext' => 'civicrm', 'js' => array('ang/crmAttachment.js'), 'css' => array('ang/crmAttachment.css'), 'partials' => array('ang/crmAttachment'), 'settings' => array('token' => \CRM_Core_Page_AJAX_Attachment::createToken())); $angularModules['crmAutosave'] = array('ext' => 'civicrm', 'js' => array('ang/crmAutosave.js')); $angularModules['crmCxn'] = array('ext' => 'civicrm', 'js' => array('ang/crmCxn.js', 'ang/crmCxn/*.js'), 'css' => array('ang/crmCxn.css'), 'partials' => array('ang/crmCxn')); //$angularModules['crmExample'] = array( // 'ext' => 'civicrm', // 'js' => array('ang/crmExample.js'), // 'partials' => array('ang/crmExample'), //); $angularModules['crmResource'] = array('ext' => 'civicrm', 'js' => array('js/angular-crmResource/all.js')); $angularModules['crmUi'] = array('ext' => 'civicrm', 'js' => array('ang/crmUi.js'), 'partials' => array('ang/crmUi'), 'settings' => array('browseUrl' => $config->userFrameworkResourceURL . 'packages/kcfinder/browse.php', 'uploadUrl' => $config->userFrameworkResourceURL . 'packages/kcfinder/upload.php')); $angularModules['crmUtil'] = array('ext' => 'civicrm', 'js' => array('ang/crmUtil.js')); // https://github.com/jwstadler/angular-jquery-dialog-service $angularModules['dialogService'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-jquery-dialog-service/dialog-service.js')); $angularModules['ngRoute'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-route/angular-route.min.js')); $angularModules['ngSanitize'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-sanitize/angular-sanitize.min.js')); $angularModules['ui.utils'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-ui-utils/ui-utils.min.js')); $angularModules['ui.sortable'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-ui-sortable/sortable.min.js')); $angularModules['unsavedChanges'] = array('ext' => 'civicrm', 'js' => array('bower_components/angular-unsavedChanges/dist/unsavedChanges.min.js')); foreach (\CRM_Core_Component::getEnabledComponents() as $component) { $angularModules = array_merge($angularModules, $component->getAngularModules()); } \CRM_Utils_Hook::angularModules($angularModules); $this->modules = $this->resolvePatterns($angularModules); } return $this->modules; }
/** * Run dashboard. * * @return void */ public function run() { // Add dashboard js and css $resources = CRM_Core_Resources::singleton(); $resources->addScriptFile('civicrm', 'js/jquery/jquery.dashboard.js', 0, 'html-header', FALSE); $resources->addStyleFile('civicrm', 'css/dashboard.css'); $resetCache = CRM_Utils_Request::retrieve('resetCache', 'Positive', CRM_Core_DAO::$_nullObject); CRM_Utils_System::setTitle(ts('CiviCRM Home')); $session = CRM_Core_Session::singleton(); $contactID = $session->get('userID'); if ($resetCache) { CRM_Core_BAO_Dashboard::resetDashletCache($contactID); } // call hook to get html from other modules // ignored but needed to prevent warnings $contentPlacement = CRM_Utils_Hook::DASHBOARD_BELOW; $html = CRM_Utils_Hook::dashboard($contactID, $contentPlacement); if (is_array($html)) { $this->assign_by_ref('hookContent', $html); $this->assign('hookContentPlacement', $contentPlacement); } $communityMessages = CRM_Core_CommunityMessages::create(); if ($communityMessages->isEnabled()) { $message = $communityMessages->pick(); if ($message) { $this->assign('communityMessages', $communityMessages->evalMarkup($message['markup'])); } } return parent::run(); }
/** * Check function. * * This function includes the IDS vendor parts and runs the * detection routines on the request array. * * @param array $args * List of path parts. * * @return bool */ public function check($args) { // lets bypass a few civicrm urls from this check $skip = array('civicrm/admin/setting/updateConfigBackend', 'civicrm/admin/messageTemplates'); CRM_Utils_Hook::idsException($skip); $this->path = implode('/', $args); if (in_array($this->path, $skip)) { return NULL; } // Add request url and user agent. $_REQUEST['IDS_request_uri'] = $_SERVER['REQUEST_URI']; if (isset($_SERVER['HTTP_USER_AGENT'])) { $_REQUEST['IDS_user_agent'] = $_SERVER['HTTP_USER_AGENT']; } $configFile = self::createConfigFile(FALSE); // init the PHPIDS and pass the REQUEST array require_once 'IDS/Init.php'; try { $init = IDS_Init::init($configFile); $ids = new IDS_Monitor($_REQUEST, $init); } catch (Exception $e) { // might be an old stale copy of Config.IDS.ini // lets try to rebuild it again and see if it works $configFile = self::createConfigFile(TRUE); $init = IDS_Init::init($configFile); $ids = new IDS_Monitor($_REQUEST, $init); } $result = $ids->run(); if (!$result->isEmpty()) { $this->react($result); } return TRUE; }
public function testHookAlterMailer() { $test = $this; $mockMailer = new CRM_Utils_FakeObject(array('send' => function ($recipients, $headers, $body) use($test) { $test->calls['send']++; $test->assertEquals(array('*****@*****.**'), $recipients); $test->assertEquals('Subject Example', $headers['Subject']); })); CRM_Utils_Hook::singleton()->setHook('civicrm_alterMailer', function (&$mailer, $driver, $params) use($test, $mockMailer) { $test->calls['civicrm_alterMailer']++; $test->assertTrue(is_string($driver) && !empty($driver)); $test->assertTrue(is_array($params)); $test->assertTrue(is_callable(array($mailer, 'send'))); $mailer = $mockMailer; }); $params = array(); $params['groupName'] = 'CRM_Core_Config_MailerTest'; $params['from'] = 'From Example <*****@*****.**>'; $params['toName'] = 'To Example'; $params['toEmail'] = '*****@*****.**'; $params['subject'] = 'Subject Example'; $params['text'] = 'Example text'; $params['html'] = '<p>Example HTML</p>'; CRM_Utils_Mail::send($params); $this->assertEquals(1, $this->calls['civicrm_alterMailer']); $this->assertEquals(1, $this->calls['send']); // once more, just to make sure the hooks are called right #times CRM_Utils_Mail::send($params); CRM_Utils_Mail::send($params); $this->assertEquals(1, $this->calls['civicrm_alterMailer']); $this->assertEquals(3, $this->calls['send']); }
public function getManagedEntities() { // Use hook_civicrm_caseTypes to build a list of OptionValues // In the long run, we may want more specialized logic for this, but // this design is fairly convenient and will allow us to replace it // without changing the hook_civicrm_caseTypes interface. $entities = array(); $caseTypes = array(); CRM_Utils_Hook::caseTypes($caseTypes); $proc = new CRM_Case_XMLProcessor(); $caseTypesGroupId = civicrm_api3('OptionGroup', 'getvalue', array('name' => 'case_type', 'return' => 'id')); if (!is_numeric($caseTypesGroupId)) { throw new CRM_Core_Exception("Found invalid ID for OptionGroup (case_type)"); } foreach ($caseTypes as $name => $caseType) { $xml = $proc->retrieve($name); if (!$xml) { throw new CRM_Core_Exception("Failed to load XML for case type (" . $name . ")"); } if (isset($caseType['module'], $caseType['name'], $caseType['file'])) { $entities[] = array('module' => $caseType['module'], 'name' => $caseType['name'], 'entity' => 'OptionValue', 'params' => array('version' => 3, 'name' => $caseType['name'], 'label' => (string) $xml->name, 'description' => (string) $xml->description, 'option_group_id' => $caseTypesGroupId, 'is_reserved' => 1)); } else { throw new CRM_Core_Exception("Invalid case type"); } } return $entities; }
/** * Add the membership Payments. * * @param array $params * Reference array contains the values submitted by the form. * * * @return object */ public static function create($params) { $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, 'MembershipPayment', CRM_Utils_Array::value('id', $params), $params); $dao = new CRM_Member_DAO_MembershipPayment(); $dao->copyValues($params); $dao->id = CRM_Utils_Array::value('id', $params); //Fixed for avoiding duplicate entry error when user goes //back and forward during payment mode is notify if (!$dao->find(TRUE)) { $dao->save(); } CRM_Utils_Hook::post($hook, 'MembershipPayment', $dao->id, $dao); // CRM-14197 we are in the process on phasing out membershipPayment in favour of storing both contribution_id & entity_id (membership_id) on the line items // table. However, at this stage we have both - there is still quite a bit of refactoring to do to set the line_iten entity_id right the first time // however, we can assume at this stage that any contribution id will have only one line item with that membership type in the line item table // OR the caller will have taken responsibility for updating the line items themselves so we will update using SQL here if (!isset($params['membership_type_id'])) { $membership_type_id = civicrm_api3('membership', 'getvalue', array('id' => $dao->membership_id, 'return' => 'membership_type_id')); } else { $membership_type_id = $params['membership_type_id']; } $sql = "UPDATE civicrm_line_item li\n LEFT JOIN civicrm_price_field_value pv ON pv.id = li.price_field_value_id\n SET entity_table = 'civicrm_membership', entity_id = %1\n WHERE pv.membership_type_id = %2\n AND contribution_id = %3"; CRM_Core_DAO::executeQuery($sql, array(1 => array($dao->membership_id, 'Integer'), 2 => array($membership_type_id, 'Integer'), 3 => array($dao->contribution_id, 'Integer'))); return $dao; }
static function initTasks() { if (!self::$_tasks) { self::$_tasks = array(1 => array('title' => ts('Add Contacts to Group'), 'class' => 'CRM_Contact_Form_Task_AddToGroup', 'result' => true), 2 => array('title' => ts('Remove Contacts from Group'), 'class' => 'CRM_Contact_Form_Task_RemoveFromGroup', 'result' => true), 3 => array('title' => ts('Tag Contacts (assign tags)'), 'class' => 'CRM_Contact_Form_Task_AddToTag', 'result' => true), 4 => array('title' => ts('Untag Contacts (remove tags)'), 'class' => 'CRM_Contact_Form_Task_RemoveFromTag', 'result' => true), 5 => array('title' => ts('Export Contacts'), 'class' => array('CRM_Export_Form_Select', 'CRM_Export_Form_Map'), 'result' => false), 6 => array('title' => ts('Send Email to Contacts'), 'class' => 'CRM_Contact_Form_Task_Email', 'result' => false), 7 => array('title' => ts('Send SMS to Contacts'), 'class' => 'CRM_Contact_Form_Task_SMS', 'result' => true), 8 => array('title' => ts('Delete Contacts'), 'class' => 'CRM_Contact_Form_Task_Delete', 'result' => false), 9 => array('title' => ts('Add Contacts to Household'), 'class' => 'CRM_Contact_Form_Task_AddToHousehold', 'result' => true), 10 => array('title' => ts('Add Contacts to Organization'), 'class' => 'CRM_Contact_Form_Task_AddToOrganization', 'result' => true), 11 => array('title' => ts('Record Activity for Contacts'), 'class' => 'CRM_Activity_Form_Activity', 'result' => true), 13 => array('title' => ts('New Smart Group'), 'class' => 'CRM_Contact_Form_Task_SaveSearch', 'result' => true), 14 => array('title' => ts('Update Smart Group'), 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update', 'result' => true), 15 => array('title' => ts('Print Contacts'), 'class' => 'CRM_Contact_Form_Task_Print', 'result' => false), 16 => array('title' => ts('Mailing Labels'), 'class' => 'CRM_Contact_Form_Task_Label', 'result' => true), 17 => array('title' => ts('Batch Update via Profile'), 'class' => array('CRM_Contact_Form_Task_PickProfile', 'CRM_Contact_Form_Task_Batch'), 'result' => true), 19 => array('title' => ts('Print PDF Letter for Contacts'), 'class' => 'CRM_Contact_Form_Task_PDF', 'result' => true), 21 => array('title' => ts('Merge Contacts'), 'class' => 'CRM_Contact_Form_Task_Merge', 'result' => true)); //CRM-4418, check for delete if (!CRM_Core_Permission::check('delete contacts')) { unset(self::$_tasks[8]); } //show map action only if map provider and key is set $config =& CRM_Core_Config::singleton(); if ($config->mapProvider && $config->mapAPIKey) { self::$_tasks[12] = array('title' => ts('Map Contacts'), 'class' => 'CRM_Contact_Form_Task_Map', 'result' => false); } if (CRM_Core_Permission::access('CiviEvent')) { self::$_tasks[18] = array('title' => ts('Add Contacts to Event'), 'class' => 'CRM_Event_Form_Participant', 'result' => true); } if (CRM_Core_Permission::access('CiviMail')) { self::$_tasks[20] = array('title' => ts('Schedule/Send a Mass Mailing'), 'class' => array('CRM_Mailing_Form_Group', 'CRM_Mailing_Form_Settings', 'CRM_Mailing_Form_Upload', 'CRM_Mailing_Form_Test', 'CRM_Mailing_Form_Schedule'), 'result' => false); } self::$_tasks += CRM_Core_Component::taskList(); require_once 'CRM/Utils/Hook.php'; CRM_Utils_Hook::searchTasks('contact', self::$_tasks); asort(self::$_tasks); } }
function tearDown() { $this->quickCleanup(array('civicrm_job', 'civicrm_action_log', 'civicrm_action_schedule')); $this->quickCleanUpFinancialEntities(); CRM_Utils_Hook::singleton()->reset(); parent::tearDown(); }
/** * Submit a payment using Advanced Integration Method * * @param array $params assoc array of input parameters for this transaction * @return array the result in a nice formatted array (or an error object) * @public */ function doDirectPayment(&$params) { // Invoke hook_civicrm_paymentProcessor // In Dummy's case, there is no translation of parameters into // the back-end's canonical set of parameters. But if a processor // does this, it needs to invoke this hook after it has done translation, // but before it actually starts talking to its proprietary back-end. $cookedParams = $params; // no translation in Dummy processor CRM_Utils_Hook::alterPaymentProcessorParams($this, $params, $cookedParams); //end of hook invokation if ($this->_mode == 'test') { $query = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE 'test\\_%'"; $p = array(); $trxn_id = strval(CRM_Core_Dao::singleValueQuery($query, $p)); $trxn_id = str_replace('test_', '', $trxn_id); $trxn_id = intval($trxn_id) + 1; $params['trxn_id'] = sprintf('test_%08d', $trxn_id); } else { $query = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE 'live_%'"; $p = array(); $trxn_id = strval(CRM_Core_Dao::singleValueQuery($query, $p)); $trxn_id = str_replace('live_', '', $trxn_id); $trxn_id = intval($trxn_id) + 1; $params['trxn_id'] = sprintf('live_%08d', $trxn_id); } $params['gross_amount'] = $params['amount']; return $params; }
function getTemplateFileName() { $profID = CRM_Utils_Request::retrieve('gid', 'String', $this); $this->_params['contact_type'] = 'Individual'; $selector = new CRM_Profile_Selector_Listings($this->_params, $this->_customFields, $profID, $this->_map, FALSE, 0); $extraWhereClause = NULL; $grpParams = array('name' => 'HRJobContract_Summary'); CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomGroup', $grpParams, $cGrp); $fdParams = array('name' => 'Final_Termination_Date', 'custom_group_id' => $cGrp['id']); CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $fdParams, $fdField); $idParams = array('name' => 'Initial_Join_Date', 'custom_group_id' => $cGrp['id']); CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $idParams, $idField); $extraWhereClause = " (({$cGrp['table_name']}.{$fdField['column_name']} >= CURDATE() OR {$cGrp['table_name']}.{$fdField['column_name']} IS NULL) AND\n ({$cGrp['table_name']}.{$idField['column_name']} IS NOT NULL AND {$cGrp['table_name']}.{$idField['column_name']} <= CURDATE()))"; $column = $columnHeaders = $selector->getColumnHeaders(); $rows = $selector->getRows(4, 0, 0, NULL, NULL, $extraWhereClause); CRM_Utils_Hook::searchColumns('profile', $columnHeaders, $rows, $this); $this->assign('aaData', json_encode($rows)); /* to bring column names in [ { "sTitle": "Engine" }, { "sTitle": "Browser" },] format*/ $colunmH = "["; foreach ($column as $k => $v) { if (!empty($v['name'])) { $name = '{"sTitle":"' . $v['name'] . '"}'; } else { $name = '{"bSortable": false}'; } $colunmH .= $name . ","; } $colunmH .= "]"; $this->assign('aaColumn', $colunmH); return 'CRM/HRProfile/Page/HRProfile.tpl'; }
/** * Load token data. * * @param TokenValueEvent $e * @throws TokenException */ public function onEvaluate(TokenValueEvent $e) { // For reasons unknown, replaceHookTokens requires a pre-computed list of // hook *categories* (aka entities aka namespaces). We'll cache // this in the TokenProcessor's context. $hookTokens = array(); \CRM_Utils_Hook::tokens($hookTokens); $categories = array_keys($hookTokens); $e->getTokenProcessor()->context['hookTokenCategories'] = $categories; $messageTokens = $e->getTokenProcessor()->getMessageTokens(); foreach ($e->getRows() as $row) { if (empty($row->context['contact'])) { $params = array(array('contact_id', '=', $row->context['contactId'], 0, 0)); list($contact, $_) = \CRM_Contact_BAO_Query::apiQuery($params); $contact = reset($contact); //CRM-4524 if (!$contact || is_a($contact, 'CRM_Core_Error')) { // FIXME: Need to differentiate errors which kill the batch vs the individual row. throw new TokenException("Failed to generate token data. Invalid contact ID: " . $row->context['contactId']); } } else { $contact = $row->context['contact']; } if (!empty($row->context['tmpTokenParams'])) { // merge activity tokens with contact array // this is pretty weird. $contact = array_merge($contact, $row->context['tmpTokenParams']); } // Note: This is a small contract change from the past; data should be missing // less randomly. //\CRM_Utils_Hook::tokenValues($contact, $row->context['contactId']); \CRM_Utils_Hook::tokenValues($contact, $row->context['contactId'], empty($row->context['mailingJob']) ? NULL : $row->context['mailingJob']->id, $messageTokens, $row->context['controller']); $row->context('contact', $contact); } }
function doDirectPayment(&$params) { $logon = $this->_paymentProcessor['user_name']; $password = $this->_paymentProcessor['password']; $url_site = $this->_paymentProcessor['url_site']; // create pjpgCustInfo object $pjpgCustInfo = new pjpgCustInfo(); $pjpgCustInfo->setEmail($params['email']); $billing = array("logon" => $logon, "password" => $password, "url_site" => $url_site, "first_name" => $params['first_name'], "last_name" => $params['last_name'], "address" => $params['street_address'], "city" => $params['city'], "province" => $params['state_province'], "postal_code" => $params['postal_code'], "country" => $params['country']); $pjpgCustInfo->setBilling($billing); // create pjpgTransaction object $my_orderid = $params['invoiceID']; $expiry_string = sprintf('%04d%02d', $params['year'], $params['month']); $txnArray = array('type' => 'purchase', 'order_id' => $my_orderid, 'amount' => sprintf('%01.2f', $params['amount']), 'pan' => $params['credit_card_number'], 'expdate' => $expiry_string, 'crypt_type' => '7', 'cust_id' => $params['contact_id']); // Allow further manipulation of params via custom hooks CRM_Utils_Hook::alterPaymentProcessorParams($this, $params, $txnArray); $pjpgTxn = new pjpgTransaction($txnArray); // set customer info (level 3 data) for the transaction $pjpgTxn->setCustInfo($pjpgCustInfo); // empty installments convert to 999 because PayJunction do not allow open end donation if ($params['installments'] == "") { $params['installments'] = "999"; } // create recurring object if ($params['is_recur'] == true && $params['installments'] > 1) { // schedule start date as today $params['dc_schedule_start'] = date("Y-m-d"); // format: YYYY-MM-DD // Recur Variables $dc_schedule_create = $params['is_recur']; $recurUnit = $params['frequency_unit']; $recurInterval = $params['frequency_interval']; $dc_schedule_start = $params['dc_schedule_start']; $startDate = date("Y/m/d", $next); // next payment in moneris required format $numRecurs = $params['installments']; $recurArray = array('dc_schedule_create' => $dc_schedule_create, 'recur_unit' => $recurUnit, 'start_date' => $startDate, 'num_recurs' => $numRecurs, 'start_now' => 'false', 'period' => $recurInterval, 'dc_schedule_start' => $dc_schedule_start, 'amount' => sprintf('%01.2f', $params['amount'])); $pjpgRecur = new pjpgRecur($recurArray); $pjpgTxn->setRecur($pjpgRecur); } // create a pjpgRequest object passing the transaction object $pjpgRequest = new pjpgRequest($pjpgTxn); $pjpgHttpPost = new pjpgHttpsPost($pjpgRequest); // get an pjpgResponse object $pjpgResponse = $pjpgHttpPost->getPJpgResponse(); if (self::isError($pjpgResponse)) { return self::error($pjpgResponse); } /* Check for application errors */ $result =& self::checkResult($pjpgResponse); if (is_a($result, 'CRM_Core_Error')) { return $result; } // Success $params['trxn_result_code'] = $pjpgResponse['dc_response_code']; $params['trxn_id'] = $pjpgResponse['dc_transaction_id']; $params['gross_amount'] = $params['amount']; return $params; }
/** * params must contain at least id=xx & {one of the fields from getfields}=value */ function civicrm_api3_generic_setValue($apiRequest) { $entity = $apiRequest['entity']; $params = $apiRequest['params']; // we can't use _spec, doesn't work with generic civicrm_api3_verify_mandatory($params, NULL, array('id', 'field', 'value')); $id = $params['id']; if (!is_numeric($id)) { return civicrm_api3_create_error(ts('Please enter a number'), array('error_code' => 'NaN', 'field' => "id")); } $field = CRM_Utils_String::munge($params['field']); $value = $params['value']; $fields = civicrm_api($entity, 'getFields', array("version" => 3, "sequential")); // getfields error, shouldn't happen. if ($fields['is_error']) { return $fields; } $fields = $fields['values']; if (!array_key_exists($field, $fields)) { return civicrm_api3_create_error("Param 'field' ({$field}) is invalid. must be an existing field", array("error_code" => "invalid_field", "fields" => array_keys($fields))); } $def = $fields[$field]; if (array_key_exists('required', $def) && empty($value)) { return civicrm_api3_create_error(ts("This can't be empty, please provide a value"), array("error_code" => "required", "field" => $field)); } switch ($def['type']) { case 1: //int if (!is_numeric($value)) { return civicrm_api3_create_error("Param '{$field}' must be a number", array('error_code' => 'NaN')); } case 2: //string require_once "CRM/Utils/Rule.php"; if (!CRM_Utils_Rule::xssString($value)) { return civicrm_api3_create_error(ts('Illegal characters in input (potential scripting attack)'), array('error_code' => 'XSS')); } if (array_key_exists('maxlength', $def)) { $value = substr($value, 0, $def['maxlength']); } break; case 16: //boolean $value = (bool) $value; break; case 4: //date //date default: return civicrm_api3_create_error("Param '{$field}' is of a type not managed yet. Join the API team and help us implement it", array('error_code' => 'NOT_IMPLEMENTED')); } if (CRM_Core_DAO::setFieldValue(_civicrm_api3_get_DAO($entity), $id, $field, $value)) { $entity = array('id' => $id, $field => $value); CRM_Utils_Hook::post('edit', $entity, $id, $entity); return civicrm_api3_create_success($entity); } else { return civicrm_api3_create_error("error assigning {$field}={$value} for {$entity} (id={$id})"); } }
public function tearDown() { CRM_Utils_Hook::singleton()->reset(); $this->quickCleanup(array('civicrm_group')); $config = CRM_Core_Config::singleton(); unset($config->userPermissionClass->permissions); parent::tearDown(); }
public function testHookCron() { $hook = $this->getMock('stdClass', array('civicrm_cron')); $hook->expects($this->once())->method('civicrm_cron')->with($this->isInstanceOf('CRM_Core_JobManager')); CRM_Utils_Hook::singleton()->setMock($hook); $jobManager = new CRM_Core_JobManager(); $jobManager->execute(FALSE); }
/** * (non-PHPdoc) * @see CiviUnitTestCase::tearDown() */ function tearDown() { CRM_Utils_Hook::singleton()->reset(); $tablesToTruncate = array('civicrm_contact'); $this->quickCleanup($tablesToTruncate); $config = CRM_Core_Config::singleton(); unset($config->userPermissionClass->permissions); }
/** * This hook is called once for every batch before the pdf template is rendered. * You should use this for performance reasons when the token can be shared between chunk items (for example a contact * address that is the same for all files) * * You can implement this hook to add/modify template tokens * e.g. in your hook implementation call $template->assign('myCustomToken', 'my custom token'); * and place a token called {$myCustomToken} in the template. * * @param object $template * * @return mixed based on op. pre-hooks return a boolean or * an error message which aborts the operation * @access public */ static function pdf_shared_token(&$template, &$chunk) { if (version_compare(CRM_Utils_System::version(), '4.5', '<')) { return CRM_Utils_Hook::singleton()->invoke(1, $template, $chunk_item, self::$null, self::$null, self::$null, 'civicrm_pdf_shared_token'); } else { return CRM_Utils_Hook::singleton()->invoke(1, $template, $chunk_item, self::$null, self::$null, self::$null, self::$null, 'civicrm_pdf_shared_token'); } }
/** * (non-PHPdoc) * @see CiviUnitTestCase::tearDown() */ public function tearDown() { CRM_Utils_Hook::singleton()->reset(); $tablesToTruncate = array('civicrm_contact', 'civicrm_group_contact', 'civicrm_group', 'civicrm_acl', 'civicrm_acl_cache', 'civicrm_acl_entity_role', 'civicrm_acl_contact_cache', 'civicrm_contribution', 'civicrm_participant', 'civicrm_uf_match'); $this->quickCleanup($tablesToTruncate); $config = CRM_Core_Config::singleton(); unset($config->userPermissionClass->permissions); }
/** * Get or build the list of search objects (via hook) * * @return array * Array of CRM_Report_BAO_Hook_Interface objects */ public function getSearchQueryObjects() { if ($this->_queryObjects === NULL) { $this->_queryObjects = array(); CRM_Utils_Hook::queryObjects($this->_queryObjects, 'Report'); } return $this->_queryObjects; }
public static function create(&$params) { $vacancy = new self(); if (!empty($params['id'])) { CRM_Core_DAO::executeQuery("DELETE FROM civicrm_hrvacancy_stage WHERE vacancy_id = {$params['id']}"); CRM_Core_DAO::executeQuery("DELETE FROM civicrm_hrvacancy_permission WHERE vacancy_id = {$params['id']}"); } $vacancyParams = CRM_HRRecruitment_BAO_HRVacancy::formatParams($params); $entityName = 'HRVacancy'; $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params); if (!empty($params['id'])) { $vacancy->find($params['id']); $vacancy->created_date = $vacancy->created_date ? CRM_Utils_Date::processDate($vacancy->created_date) : date('YmdHis'); $vacancy->created_id = $vacancy->created_id ? $vacancy->created_id : CRM_Core_Session::singleton()->get('userID'); } else { $vacancyParams['created_date'] = date('YmdHis'); $vacancyParams['created_id'] = CRM_Core_Session::singleton()->get('userID'); } $vacancy->copyValues($vacancyParams); $vacancy->save(); if (isset($params['stages']) && count($params['stages'])) { foreach ($params['stages'] as $key => $stage_id) { $dao = new CRM_HRRecruitment_DAO_HRVacancyStage(); $dao->case_status_id = $stage_id; $dao->vacancy_id = $vacancy->id; $dao->weight = $key + 1; $dao->save(); } } foreach (array('application_profile', 'evaluation_profile') as $profileName) { if (!empty($params[$profileName])) { $dao = new CRM_Core_DAO_UFJoin(); $dao->module = 'Vacancy'; $dao->entity_table = 'civicrm_hrvacancy'; $dao->entity_id = $vacancy->id; $dao->module_data = $profileName; if (!empty($params['id'])) { $dao->find(TRUE); } $dao->uf_group_id = $params[$profileName]; $dao->save(); } } if (!empty($params['permission']) && !empty($params['permission_contact_id'])) { foreach ($params['permission'] as $key => $permission) { if ($permission && $params['permission_contact_id'][$key]) { $dao = new CRM_HRRecruitment_DAO_HRVacancyPermission(); $dao->contact_id = $params['permission_contact_id'][$key]; $dao->permission = $permission; $dao->vacancy_id = $vacancy->id; $dao->save(); } } } CRM_Utils_Hook::post($hook, $entityName, $vacancy->id, $vacancy); return $vacancy; }
/** * These tasks are the core set of tasks that the user can perform * on a contact / group of contacts. * * @return array * the set of tasks for a group of contacts. */ public static function &tasks() { if (!self::$_tasks) { self::$_tasks = array(1 => array('title' => ts('Print Mailing Recipients'), 'class' => 'CRM_Mailing_Form_Task_Print', 'result' => FALSE)); CRM_Utils_Hook::searchTasks('mailing', self::$_tasks); asort(self::$_tasks); } return self::$_tasks; }
/** * Constructor and getter for the singleton instance. * * @param bool $fresh * * @return self * An instance of $config->userHookClass */ public static function singleton($fresh = FALSE) { if (self::$_singleton == NULL || $fresh) { $config = CRM_Core_Config::singleton(); $class = $config->userHookClass; self::$_singleton = new $class(); } return self::$_singleton; }
/** */ public function tearDown() { $this->_mut->stop(); // $this->quickCleanup(array('civicrm_mailing', 'civicrm_mailing_job', 'civicrm_contact')); CRM_Utils_Hook::singleton()->reset(); CRM_Mailing_BAO_MailingJob::$mailsProcessed = 0; // DGW parent::tearDown(); }
/** * These tasks are the core set of tasks that the user can perform * on a relationship / group of relationships * * @return array * the set of tasks for a group of relationships */ public static function &tasks() { if (!self::$_tasks) { self::$_tasks = array(1 => array('title' => ts('Export Relationships'), 'class' => array('CRM_Relationship_Export_Form_Select', 'CRM_Relationship_Export_Form_Map'), 'result' => FALSE)); CRM_Utils_Hook::searchTasks('relationship', self::$_tasks); asort(self::$_tasks); } return self::$_tasks; }
/** * This hook data transforms data stored in accounts_data to be formatted into a standard format. * * The called hook is expected to add a key 'civicrm_formatted' to the accountsData array * with the data using the same field names as the relevant CiviCRM api. * * @param array $accountsData data from accounts system * @param string $entity entity - eg. 'AccountContact' * @param string $plugin plugin in use * * @return mixed * Ignore value. */ public static function mapAccountsData(&$accountsData, $entity, $plugin) { $codeVersion = explode('.', CRM_Utils_System::version()); if (version_compare($codeVersion[0] . '.' . $codeVersion[1], 4.5) >= 0) { return CRM_Utils_Hook::singleton()->invoke(3, $accountsData, $entity, $plugin, CRM_Core_DAO::$_nullObject, CRM_Core_DAO::$_nullObject, CRM_Core_DAO::$_nullObject, 'civicrm_mapAccountsData'); } else { return CRM_Utils_Hook::singleton()->invoke(3, $accountsData, $entity, $plugin, CRM_Core_DAO::$_nullObject, CRM_Core_DAO::$_nullObject, 'civicrm_mapAccountsData'); } }
/** * These tasks are the core set of tasks that the user can perform * on a contact / group of contacts * * @return array the set of tasks for a group of contacts * @static * @access public */ static function &tasks() { if (!self::$_tasks) { self::$_tasks = array(2 => array('title' => ts('Print Bookings'), 'class' => 'CRM_Contribute_Form_Task_Print', 'result' => FALSE)); CRM_Utils_Hook::searchTasks('contribution', self::$_tasks); asort(self::$_tasks); } return self::$_tasks; }
/** * These tasks are the core set of tasks that the user can perform * on a voter / group of voters * * @return array the set of tasks for a group of voters. * @static * @access public */ static function &tasks() { if (!self::$_tasks) { self::$_tasks = array(1 => array('title' => ts('Record Respondents Interview'), 'class' => array('CRM_Campaign_Form_Task_Interview', 'CRM_Campaign_Form_Task_Release'), 'result' => FALSE), 2 => array('title' => ts('Reserve Respondents'), 'class' => array('CRM_Campaign_Form_Task_Reserve', 'CRM_Campaign_Form_Task_Interview', 'CRM_Campaign_Form_Task_Release'), 'result' => FALSE), 3 => array('title' => ts('Release Respondents'), 'class' => 'CRM_Campaign_Form_Task_Release', 'result' => FALSE), 4 => array('title' => ts('Print Respondents'), 'class' => 'CRM_Campaign_Form_Task_Print', 'result' => FALSE)); } CRM_Utils_Hook::searchTasks('campaign', self::$_tasks); asort(self::$_tasks); return self::$_tasks; }