/** * 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; }
/** * 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; }
/** * 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})"); } }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * @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; }
/** * 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; }
/** * 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_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; }
/** * 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; }
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; }
/** * 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; }
/** * @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; }
/** * @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; }
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; }
public static function create($params) { $entityName = 'HRAbsencePeriod'; $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(); foreach (array('end_date', 'start_date') as $yesReallyIWantToSaveTheDataInsteadOfSilentlyThrowingItAway) { if (isset($params[$yesReallyIWantToSaveTheDataInsteadOfSilentlyThrowingItAway])) { CRM_Core_DAO::executeQuery("UPDATE civicrm_hrabsence_period SET {$yesReallyIWantToSaveTheDataInsteadOfSilentlyThrowingItAway} = %1 WHERE id = %2", array(1 => array($params[$yesReallyIWantToSaveTheDataInsteadOfSilentlyThrowingItAway], 'String'), 2 => array($instance->id, 'Integer'))); } } 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_BankAccount object on success, null otherwise * @access public * @static */ static function add(&$params) { // default values if (empty($params['id'])) { $params['created_date'] = date('YmdHis'); $params['modified_date'] = date('YmdHis'); } else { $params['modified_date'] = date('YmdHis'); } $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, 'BankAccount', CRM_Utils_Array::value('id', $params), $params); $dao = new CRM_Banking_DAO_BankAccount(); $dao->copyValues($params); $dao->save(); CRM_Utils_Hook::post($hook, 'BankAccount', $dao->id, $dao); return $dao; }
/** * Takes an associative array and creates a contribution page object. * * @param array $params * (reference ) an assoc array of name/value pairs. * * @return CRM_Contribute_DAO_ContributionPage */ public static function &create(&$params) { $financialTypeId = NULL; if (!empty($params['id']) && !CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $params['id'], NULL, 1)) { $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $params['id'], 'financial_type_id'); } $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, 'ContributionPage', CRM_Utils_Array::value('id', $params), $params); $dao = new CRM_Contribute_DAO_ContributionPage(); $dao->copyValues($params); $dao->save(); if ($financialTypeId && !empty($params['financial_type_id']) && $financialTypeId != $params['financial_type_id']) { CRM_Price_BAO_PriceFieldValue::updateFinancialType($params['id'], 'civicrm_contribution_page', $params['financial_type_id']); } CRM_Utils_Hook::post($hook, 'ContributionPage', $dao->id, $dao); return $dao; }
public static function create($params) { $entityName = 'HRAbsenceType'; $hook = empty($params['id']) ? 'create' : 'edit'; if (!array_key_exists('name', $params) && !array_key_exists('id', $params)) { $params['name'] = CRM_Utils_String::munge($params['title']); } // If this is an existing type, we'll need to know about previously linked activity-type-ids if (!empty($params['id'])) { $existing = civicrm_api3('HRAbsenceType', 'getsingle', array('id' => $params['id'])); $params = array_merge($existing, $params); } $activityTypesResult = civicrm_api3('activity_type', 'get', array()); if (CRM_Utils_Array::value('allow_debits', $params) && empty($params['debit_activity_type_id'])) { $weight = count($activityTypesResult["values"]); $debitActivityLabel = $params['name']; $debitActivityTypeId = array_search($debitActivityLabel, $activityTypesResult["values"]); if (!$debitActivityTypeId) { $weight = $weight + 1; $paramsCreate = array('weight' => $weight, 'label' => $debitActivityLabel, 'filter' => 1, 'is_active' => 1, 'is_optgroup' => 0, 'is_default' => 0, 'grouping' => 'Timesheet'); $resultCreateActivityType = civicrm_api3('activity_type', 'create', $paramsCreate); $debitActivityTypeId = $resultCreateActivityType['values'][$resultCreateActivityType["id"]]['value']; } $params["debit_activity_type_id"] = $debitActivityTypeId; } if (CRM_Utils_Array::value('allow_credits', $params) && empty($params["credit_activity_type_id"])) { $weight = count($activityTypesResult["values"]); $creditActivityLabel = ts('%1 (Credit)', array(1 => $params["name"])); $creditActivityTypeId = array_search($creditActivityLabel, $activityTypesResult["values"]); if (!$creditActivityTypeId) { $weight = $weight + 1; $paramsCreate = array('weight' => $weight, 'label' => $creditActivityLabel, 'filter' => 1, 'is_active' => 1, 'is_optgroup' => 0, 'is_default' => 0, 'grouping' => 'Timesheet'); $resultCreateActivityType = civicrm_api3('activity_type', 'create', $paramsCreate); $creditActivityTypeId = $resultCreateActivityType['values'][$resultCreateActivityType["id"]]['value']; $params["credit_activity_type_id"] = $creditActivityTypeId; } } 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; }
/** * Create or update an action log entry. * * @param array $params * * @return array */ public static function create($params) { $actionLog = new CRM_Core_DAO_ActionLog(); $params['action_date_time'] = CRM_Utils_Array::value('action_date_time', $params, date('YmdHis')); $actionLog->copyValues($params); $edit = $actionLog->id ? TRUE : FALSE; if ($edit) { CRM_Utils_Hook::pre('edit', 'ActionLog', $actionLog->id, $actionLog); } else { CRM_Utils_Hook::pre('create', 'ActionLog', NULL, $actionLog); } $actionLog->save(); if ($edit) { CRM_Utils_Hook::post('edit', 'ActionLog', $actionLog->id, $actionLog); } else { CRM_Utils_Hook::post('create', 'ActionLog', NULL, $actionLog); } return $actionLog; }
/** * Create a new HRJobHour based on array-data * * @param array $params key-value pairs * @return CRM_HRJob_DAO_HRJobHour|NULL * */ public static function create($params) { $className = 'CRM_HRJob_DAO_HRJobHour'; $entityName = 'HRJobHour'; $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(); if ($hook == 'create') { $result = civicrm_api3('HRJobRole', 'get', array('sequential' => 1, 'job_id' => $instance->job_id, 'options' => array('limit' => 1))); if (!empty($result['values'])) { $role = CRM_Utils_Array::first($result['values']); civicrm_api3('HRJobRole', 'update', array('id' => $role['id'], 'job_id' => $role['job_id'], 'hours' => $instance->hours_amount, 'role_hours_unit' => $instance->hours_unit)); } } CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance); return $instance; }