/** * takes an associative array and creates a contribution object * * the function extract all the params it needs to initialize the create a * contribution object. the params array could contain additional unused name/value * pairs * * @param array $params (reference ) an assoc array of name/value pairs * @param array $ids the array that holds all the db ids * * @return object CRM_Contribute_BAO_Contribution object * @access public * @static */ function add(&$params, &$ids) { require_once 'CRM/Utils/Hook.php'; $duplicates = array(); if (CRM_Contribute_BAO_Contribution::checkDuplicate($params, $duplicates)) { $error =& CRM_Core_Error::singleton(); $d = implode(', ', $duplicates); $error->push(CRM_CORE_ERROR_DUPLICATE_CONTRIBUTION, 'Fatal', array($d), "Found matching contribution(s): {$d}"); return $error; } if (CRM_Utils_Array::value('contribution', $ids)) { CRM_Utils_Hook::pre('edit', 'Contribution', $ids['contribution'], $params); } else { CRM_Utils_Hook::pre('create', 'Contribution', null, $params); } $contribution =& new CRM_Contribute_BAO_Contribution(); $contribution->copyValues($params); $contribution->domain_id = CRM_Utils_Array::value('domain', $ids, CRM_Core_Config::domainID()); $contribution->id = CRM_Utils_Array::value('contribution', $ids); require_once 'CRM/Utils/Rule.php'; if (!CRM_Utils_Rule::currencyCode($contribution->currency)) { require_once 'CRM/Core/Config.php'; $config =& CRM_Core_Config::singleton(); $contribution->currency = $config->defaultCurrency; } $result = $contribution->save(); if (CRM_Utils_Array::value('contribution', $ids)) { CRM_Utils_Hook::post('edit', 'Contribution', $contribution->id, $contribution); } else { CRM_Utils_Hook::post('create', 'Contribution', $contribution->id, $contribution); } return $result; }
/** * 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; }
/** * takes an associative array and adds email * * @param array $params (reference ) an assoc array of name/value pairs * * @return object CRM_Core_BAO_Email object on success, null otherwise * @access public * @static */ static function add(&$params) { $email = new CRM_Core_DAO_Email(); $email->copyValues($params); // CRM-11006 move calls to pre hook from create function to add function if (!empty($params['id'])) { CRM_Utils_Hook::pre('edit', 'Email', $params['id'], $email); } else { CRM_Utils_Hook::pre('create', 'Email', NULL, $e); } // lower case email field to optimize queries $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower'; $email->email = $strtolower($email->email); // since we're setting bulkmail for 1 of this contact's emails, first reset all their emails to is_bulkmail false // (only 1 email address can have is_bulkmail = true) if ($email->is_bulkmail != 'null' && $params['contact_id'] && !self::isMultipleBulkMail()) { $sql = "\nUPDATE civicrm_email\nSET is_bulkmail = 0\nWHERE contact_id = {$params['contact_id']}\n"; CRM_Core_DAO::executeQuery($sql); } // handle if email is on hold self::holdEmail($email); $email->save(); // CRM-11006 move calls to pre hook from create function to add function if (!empty($params['id'])) { CRM_Utils_Hook::post('edit', 'Email', $email->id, $email); } else { CRM_Utils_Hook::post('create', 'Email', $email->id, $email); } return $email; }
/** * 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; }
/** * Takes an associative array and adds email. * * @param array $params * (reference ) an assoc array of name/value pairs. * * @return object * CRM_Core_BAO_Email object on success, null otherwise */ public static function add(&$params) { $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, 'Email', CRM_Utils_Array::value('id', $params), $params); $email = new CRM_Core_DAO_Email(); $email->copyValues($params); // lower case email field to optimize queries $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower'; $email->email = $strtolower($email->email); /* * since we're setting bulkmail for 1 of this contact's emails, first reset all their other emails to is_bulkmail false * We shouldn't not set the current email to false even though we * are about to reset it to avoid contaminating the changelog if logging is enabled * (only 1 email address can have is_bulkmail = true) */ if ($email->is_bulkmail != 'null' && $params['contact_id'] && !self::isMultipleBulkMail()) { $sql = "\nUPDATE civicrm_email\nSET is_bulkmail = 0\nWHERE contact_id = {$params['contact_id']}\n"; if ($hook == 'edit') { $sql .= " AND id <> {$params['id']}"; } CRM_Core_DAO::executeQuery($sql); } // handle if email is on hold self::holdEmail($email); $email->save(); if ($email->is_primary) { // update the UF user email if that has changed CRM_Core_BAO_UFMatch::updateUFName($email->contact_id); } CRM_Utils_Hook::post($hook, 'Email', $email->id, $email); return $email; }
/** * Takes an associative array and creates a contribution object. * * the function extract all the params it needs to initialize the create a * contribution object. the params array could contain additional unused name/value * pairs * * @param array $params * (reference ) an assoc array of name/value pairs. * * @return CRM_Contribute_BAO_Contribution * @todo move hook calls / extended logic to create - requires changing calls to call create not add */ public static function add(&$params) { if (!empty($params['id'])) { CRM_Utils_Hook::pre('edit', 'ContributionRecur', $params['id'], $params); } else { CRM_Utils_Hook::pre('create', 'ContributionRecur', NULL, $params); } // make sure we're not creating a new recurring contribution with the same transaction ID // or invoice ID as an existing recurring contribution $duplicates = array(); if (self::checkDuplicate($params, $duplicates)) { $error = CRM_Core_Error::singleton(); $d = implode(', ', $duplicates); $error->push(CRM_Core_Error::DUPLICATE_CONTRIBUTION, 'Fatal', array($d), "Found matching recurring contribution(s): {$d}"); return $error; } $recurring = new CRM_Contribute_BAO_ContributionRecur(); $recurring->copyValues($params); $recurring->id = CRM_Utils_Array::value('id', $params); // set currency for CRM-1496 if (empty($params['id']) && !isset($recurring->currency)) { $config = CRM_Core_Config::singleton(); $recurring->currency = $config->defaultCurrency; } $result = $recurring->save(); if (!empty($params['id'])) { CRM_Utils_Hook::post('edit', 'ContributionRecur', $recurring->id, $recurring); } else { CRM_Utils_Hook::post('create', 'ContributionRecur', $recurring->id, $recurring); } if (!empty($params['custom']) && is_array($params['custom'])) { CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contribution_recur', $recurring->id); } return $result; }
/** * Add Dashboard. * * @param array $params * Values. * * * @return object */ public static function create($params) { $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, 'Dashboard', CRM_Utils_Array::value('id', $params), $params); $dao = self::addDashlet($params); CRM_Utils_Hook::post($hook, 'Dashboard', $dao->id, $dao); return $dao; }
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; }
/** * Takes an associative array and adds im. * * @param array $params * (reference ) an assoc array of name/value pairs. * * @return object * CRM_Core_BAO_IM object on success, null otherwise */ public static function add(&$params) { $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, 'IM', CRM_Utils_Array::value('id', $params), $params); $im = new CRM_Core_DAO_IM(); $im->copyValues($params); $im->save(); CRM_Utils_Hook::post($hook, 'IM', $im->id, $im); return $im; }
/** * @param array $params (reference ) an assoc array of name/value pairs * * @return object CRM_Core_BAO_SEPASddFile object on success, null otherwise * @access public * @static */ static function add(&$params) { $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, 'SepaSddFile', CRM_Utils_Array::value('id', $params), $params); $dao = new CRM_Sepa_DAO_SEPASddFile(); $dao->copyValues($params); $dao->save(); CRM_Utils_Hook::post($hook, 'SepaSddFile', $dao->id, $dao); return $dao; }
/** * Add the Message Templates. * * @param array $params * Reference array contains the values submitted by the form. * * * @return object */ public static function add(&$params) { $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, 'MessageTemplate', CRM_Utils_Array::value('id', $params), $params); $messageTemplates = new CRM_Core_DAO_MessageTemplate(); $messageTemplates->copyValues($params); $messageTemplates->save(); CRM_Utils_Hook::post($hook, 'MessageTemplate', $messageTemplates->id, $messageTemplates); return $messageTemplates; }
/** * function to add the membership Blocks * * @param array $params reference array contains the values submitted by the form * * @access public * @static * * @return object */ static function create(&$params) { $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, 'MembershipBlock', CRM_Utils_Array::value('id', $params), $params); $dao = new CRM_Member_DAO_MembershipBlock(); $dao->copyValues($params); $dao->id = CRM_Utils_Array::value('id', $params); CRM_Utils_Hook::post($hook, 'MembershipBlock', $dao->id, $dao); return $dao; }
/** * Takes an associative array and adds OpenID. * * @param array $params * (reference ) an assoc array of name/value pairs. * * @return object * CRM_Core_BAO_OpenID object on success, null otherwise */ public static function add(&$params) { $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, 'OpenID', CRM_Utils_Array::value('id', $params), $params); $openId = new CRM_Core_DAO_OpenID(); $openId->copyValues($params); $openId->save(); CRM_Utils_Hook::post($hook, 'OpenID', $openId->id, $openId); return $openId; }
/** * @param array $params (reference ) an assoc array of name/value pairs * * @return object CRM_Banking_BAO_BankAccount object on success, null otherwise * @access public * @static */ static function add(&$params) { $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, 'BankAccountReference', CRM_Utils_Array::value('id', $params), $params); $dao = new CRM_Banking_DAO_BankAccountReference(); $dao->copyValues($params); $dao->save(); CRM_Utils_Hook::post($hook, 'BankAccountReference', $dao->id, $dao); return $dao; }
/** * Takes an associative array and adds im. * * @param array $params * (reference ) an assoc array of name/value pairs. * * @return object * CRM_Core_BAO_Website object on success, null otherwise */ public static function add(&$params) { $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, 'Website', CRM_Utils_Array::value('id', $params), $params); $website = new CRM_Core_DAO_Website(); $website->copyValues($params); $website->save(); CRM_Utils_Hook::post($hook, 'Website', $website->id, $website); return $website; }
/** * Creates a new entry in the database. * * @param array $params (reference) an assoc array of name/value pairs * * @return object CRM_Upgrade_Snapshot_V4p2_Price_DAO_LineItem object * @access public * @static */ static function create(&$params) { //create mode only as we don't support editing line items CRM_Utils_Hook::pre('create', 'LineItem', $params['entity_id'], $params); $lineItemBAO = new CRM_Upgrade_Snapshot_V4p2_Price_BAO_LineItem(); $lineItemBAO->copyValues($params); $return = $lineItemBAO->save(); CRM_Utils_Hook::post('create', 'LineItem', $params['entity_id'], $params); return $return; }
/** * Create a new Appraisal based on array-data * * @param array $params key-value pairs * @return CRM_Appraisals_DAO_Appraisal|NULL */ public static function create(&$params) { $className = 'CRM_Appraisals_DAO_Appraisal'; $entityName = 'Appraisal'; $hook = empty($params['id']) ? 'create' : 'edit'; if ($hook === 'create') { if (empty($params['appraisal_cycle_id'])) { throw new Exception("Please specify 'appraisal_cycle_id' value to create Appraisal."); } $appraisalCycle = civicrm_api3('AppraisalCycle', 'getsingle', array('sequential' => 1, 'id' => (int) $params['appraisal_cycle_id'])); if (!empty($appraisalCycle['is_error']) && (int) $appraisalCycle['is_error']) { throw new Exception("Cannot find Appraisal Cycle with 'id' = " . (int) $params['appraisal_cycle_id'] . '.'); } if (empty($params['self_appraisal_due'])) { $params['self_appraisal_due'] = $appraisalCycle['cycle_self_appraisal_due']; } if (empty($params['manager_appraisal_due'])) { $params['manager_appraisal_due'] = $appraisalCycle['cycle_manager_appraisal_due']; } if (empty($params['grade_due'])) { $params['grade_due'] = $appraisalCycle['cycle_grade_due']; } if (empty($params['status_id'])) { $params['status_id'] = 1; } } else { $instance = new $className(); $instance->id = (int) $params['id']; if (!$instance->find()) { throw new Exception("Cannot find Appraisal with 'id' = " . (int) $params['id'] . '.'); } $instance->fetch(); $dueChanged = false; if (!empty($params['self_appraisal_due']) && $params['self_appraisal_due'] != $instance->self_appraisal_due) { $dueChanged = true; } if (!empty($params['manager_appraisal_due']) && $params['manager_appraisal_due'] != $instance->manager_appraisal_due) { $dueChanged = true; } if (!empty($params['grade_due']) && $params['grade_due'] != $instance->grade_due) { $dueChanged = true; } if ($dueChanged) { $instance->due_changed = 1; $instance->save(); } } CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params); $instance = new $className(); $instance->copyValues($params); $instance->save(); CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance); ////TODO: trigger on post: CRM_Tasksassignments_Reminder::sendReminder((int)$instance->id); return $instance; }
/** * Create a new MyEmmaFieldMap based on array-data * * @param array $params key-value pairs * @return CRM_Myemma_DAO_MyEmmaAccount|NULL */ public static function create($params) { $entityName = 'MyEmmaFieldMap'; $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params); $instance = new CRM_Myemma_DAO_MyEmmaFieldMap(); $instance->copyValues($params); $instance->save(); CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance); return $instance; }
public static function create($params) { $entityName = 'PayScale'; $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params); $instance = new self(); $instance->copyValues($params); $instance->save(); CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance); return $instance; }
/** * @param array $params (reference ) an assoc array of name/value pairs * * @return object CRM_Banking_BAO_BankTransaction object on success, null otherwise * @access public * @static */ static function add(&$params) { $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, 'BankTransaction', CRM_Utils_Array::value('id', $params), $params); // TODO: convert the arrays (suggestions, data_parsed) back into JSON $dao = new CRM_Banking_DAO_BankTransaction(); $dao->copyValues($params); $dao->save(); CRM_Utils_Hook::post($hook, 'BankTransaction', $dao->id, $dao); return $dao; }
public static function create($params) { $className = 'CRM_Appraisals_DAO_AppraisalCriteria'; $entityName = 'AppraisalCriteria'; $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params); $instance = new $className(); $instance->copyValues($params); $instance->save(); CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance); return $instance; }
/** * takes an associative array and adds phone * * @param array $params (reference ) an assoc array of name/value pairs * * @return object CRM_Core_BAO_Phone object on success, null otherwise * @access public * @static */ static function add(&$params) { // Ensure mysql phone function exists CRM_Core_DAO::checkSqlFunctionsExist(); $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, 'Phone', CRM_Utils_Array::value('id', $params), $params); $phone = new CRM_Core_DAO_Phone(); $phone->copyValues($params); $phone->save(); CRM_Utils_Hook::post($hook, 'Phone', $phone->id, $phone); return $phone; }
static function create($params) { $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, 'UFMatch', CRM_Utils_Array::value('id', $params), $params); if (empty($params['domain_id'])) { $params['domain_id'] = CRM_Core_Config::domainID(); } $dao = new CRM_Core_DAO_UFMatch(); $dao->copyValues($params); $dao->save(); CRM_Utils_Hook::post($hook, 'UFMatch', $dao->id, $dao); return $dao; }
/** * Create a new BatchSettings based on array-data * * @param array $params key-value pairs * * @return CRM_Civigiftaid_DAO_BatchSettings|NULL */ public static function create($params) { static::addDefaults($params); static::preProcessParams($params); $entityName = 'BatchSettings'; $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params); $instance = new static(); $instance->copyValues($params); $instance->save(); CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance); return $instance; }
/** * Add the membership log record. * * @param array $params * Values to use in create. * * @return CRM_CiviDiscount_DAO_Track */ public static function create($params) { $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, 'DiscountTrack', CRM_Utils_Array::value('id', $params), $params); $dao = new CRM_CiviDiscount_DAO_Track(); $dao->copyValues($params); $dao->save(); if ($hook == 'create') { CRM_CiviDiscount_BAO_Item::incrementUsage($dao->item_id); } CRM_Utils_Hook::post($hook, 'DiscountTrack', $dao->id, $dao); return $dao; }
/** * Create a new MyEmmaAccount based on array-data * * @param array $params key-value pairs * @return CRM_Myemma_DAO_MyEmmaAccount|NULL */ public static function create($params) { $entityName = 'MyEmmaAccount'; $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params); $instance = new CRM_Myemma_DAO_MyEmmaAccount(); $instance->copyValues($params); $instance->save(); $id = $instance->id; self::createCustomField('myemma', $instance->name, $id); self::createCustomField('myemma_group', $instance->name, $id); CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance); return $instance; }
/** * takes an associative array and creates a membership object * * the function extract all the params it needs to initialize the create a * membership object. the params array could contain additional unused name/value * pairs * * @param array $params (reference ) an assoc array of name/value pairs * @param array $ids the array that holds all the db ids * * @return object CRM_Member_BAO_Membership object * @access public * @static */ static function &add(&$params, &$ids) { require_once 'CRM/Utils/Hook.php'; if (CRM_Utils_Array::value('membership', $ids)) { CRM_Utils_Hook::pre('edit', 'Membership', $ids['membership'], $params); } else { CRM_Utils_Hook::pre('create', 'Membership', null, $params); } // converting dates to mysql format if (isset($params['join_date'])) { $params['join_date'] = CRM_Utils_Date::isoToMysql($params['join_date']); } if (isset($params['start_date'])) { $params['start_date'] = CRM_Utils_Date::isoToMysql($params['start_date']); } if (isset($params['end_date'])) { $params['end_date'] = CRM_Utils_Date::isoToMysql($params['end_date']); } if (CRM_Utils_Array::value('reminder_date', $params)) { $params['reminder_date'] = CRM_Utils_Date::isoToMysql($params['reminder_date']); } else { $params['reminder_date'] = 'null'; } if (!CRM_Utils_Array::value('is_override', $params)) { $params['is_override'] = 'null'; } $membership =& new CRM_Member_BAO_Membership(); $membership->copyValues($params); $membership->id = CRM_Utils_Array::value('membership', $ids); $membership->save(); $membership->free(); $session =& CRM_Core_Session::singleton(); //get the log start date. //it is set during renewal of membership. $logStartDate = CRM_Utils_array::value('log_start_date', $params); $logStartDate = $logStartDate ? CRM_Utils_Date::isoToMysql($logStartDate) : $membership->start_date; $membershipLog = array('membership_id' => $membership->id, 'status_id' => $membership->status_id, 'start_date' => $logStartDate, 'end_date' => $membership->end_date, 'renewal_reminder_date' => $membership->reminder_date, 'modified_id' => CRM_Utils_Array::value('userId', $ids), 'modified_date' => date('Ymd')); require_once 'CRM/Member/BAO/MembershipLog.php'; CRM_Member_BAO_MembershipLog::add($membershipLog, CRM_Core_DAO::$_nullArray); // reset the group contact cache for this group require_once 'CRM/Contact/BAO/GroupContactCache.php'; CRM_Contact_BAO_GroupContactCache::remove(); if (CRM_Utils_Array::value('membership', $ids)) { CRM_Utils_Hook::post('edit', 'Membership', $membership->id, $membership); } else { CRM_Utils_Hook::post('create', 'Membership', $membership->id, $membership); } return $membership; }
/** * @param array $params (reference ) an assoc array of name/value pairs * * @return object CRM_Core_BAO_SEPAMandate object on success, null otherwise * @access public * @static (I do apologize, I don't want to) */ static function add(&$params) { // handle 'normal' creation process inlcuding hooks $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, 'SepaMandate', CRM_Utils_Array::value('id', $params), $params); // set default date to today if (!array_key_exists("date", $params)) { $params["date"] = date("YmdHis"); } if (empty($params['id'])) { CRM_Utils_SepaCustomisationHooks::create_mandate($params); if (empty($params['reference'])) { // If no mandate reference was supplied by the caller nor the customisation hook, create a nice default one. $creditor = civicrm_api3('SepaCreditor', 'getsingle', array('id' => $params['creditor_id'], 'return' => 'mandate_prefix')); $dao = new CRM_Core_DAO(); $database = $dao->database(); $next_id = CRM_Core_DAO::singleValueQuery("SELECT auto_increment FROM information_schema.tables WHERE table_schema='{$database}' and table_name='civicrm_sdd_mandate';"); $params['reference'] = $creditor['mandate_prefix'] . '-' . $params['creditor_id'] . '-' . $params['type'] . '-' . date("Y") . '-' . $next_id; } } // validate IBAN / BIC if (!empty($params['iban'])) { $params['iban'] = strtoupper($params['iban']); // create uppercase string $params['iban'] = str_replace(' ', '', $params['iban']); // strip spaces $iban_error = CRM_Sepa_Logic_Verification::verifyIBAN($params['iban']); if ($iban_error) { throw new CRM_Exception($iban_error . ':' . $params['iban']); } } if (!empty($params['bic'])) { $bic_error = CRM_Sepa_Logic_Verification::verifyBIC($params['bic']); if ($bic_error) { throw new CRM_Exception($bic_error . ':' . $params['bic']); } } // create the DAO object $dao = new CRM_Sepa_DAO_SEPAMandate(); $dao->copyValues($params); if (self::is_active(CRM_Utils_Array::value('status', $params))) { if ($dao->validation_date == NULL) { $dao->validation_date = date("YmdHis"); } } $dao->save(); CRM_Utils_Hook::post($hook, 'SepaMandate', $dao->id, $dao); return $dao; }
/** * takes an associative array and creates a participant object * * the function extract all the params it needs to initialize the create a * participant object. the params array could contain additional unused name/value * pairs * * @param array $params (reference ) an assoc array of name/value pairs * @param array $ids the array that holds all the db ids * * @return object CRM_Event_BAO_Participant object * @access public * @static */ static function &add(&$params) { require_once 'CRM/Utils/Hook.php'; if (CRM_Utils_Array::value('id', $params)) { CRM_Utils_Hook::pre('edit', 'Participant', $params['id'], $params); } else { CRM_Utils_Hook::pre('create', 'Participant', null, $params); } // converting dates to mysql format if (CRM_Utils_Array::value('register_date', $params)) { $params['register_date'] = CRM_Utils_Date::isoToMysql($params['register_date']); } if (CRM_Utils_Array::value('participant_fee_amount', $params)) { $params['participant_fee_amount'] = CRM_Utils_Rule::cleanMoney($params['participant_fee_amount']); } if (CRM_Utils_Array::value('participant_fee_amount', $params)) { $params['fee_amount'] = CRM_Utils_Rule::cleanMoney($params['fee_amount']); } $participantBAO = new CRM_Event_BAO_Participant(); if (CRM_Utils_Array::value('id', $params)) { $participantBAO->id = CRM_Utils_Array::value('id', $params); $participantBAO->find(true); $participantBAO->register_date = CRM_Utils_Date::isoToMysql($participantBAO->register_date); } $participantBAO->copyValues($params); //CRM-6910 //1. If currency present, it should be valid one. //2. We should have currency when amount is not null. require_once 'CRM/Utils/Rule.php'; $currency = $participantBAO->fee_currency; if ($currency || !CRM_Utils_System::isNull($participantBAO->fee_amount)) { if (!CRM_Utils_Rule::currencyCode($currency)) { $config = CRM_Core_Config::singleton(); $currency = $config->defaultCurrency; } } $participantBAO->fee_currency = $currency; $participantBAO->save(); $session =& CRM_Core_Session::singleton(); // reset the group contact cache for this group require_once 'CRM/Contact/BAO/GroupContactCache.php'; CRM_Contact_BAO_GroupContactCache::remove(); if (CRM_Utils_Array::value('id', $params)) { CRM_Utils_Hook::post('edit', 'Participant', $participantBAO->id, $participantBAO); } else { CRM_Utils_Hook::post('create', 'Participant', $participantBAO->id, $participantBAO); } return $participantBAO; }
public static function create($params) { $entityName = 'HoursLocation'; $hook = empty($params['id']) ? 'create' : 'edit'; /*if (!empty($params['id'])) { $existing = civicrm_api3('HRHoursLocation', 'getsingle', array('id' => $params['id'])); $params = array_merge($existing, $params); }*/ CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params); $instance = new self(); $instance->copyValues($params); $instance->save(); CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance); return $instance; }