<commit_before><?php

/**
 * CiviCRM Caldera Forms Relationship Processor Class.
 *
 * @since 0.2
 */
class CiviCRM_Caldera_Forms_Relationship_Processor {

	/**
     * Plugin reference.
     *
     * @since 0.4.4
     */
    public $plugin;

	/**
	 * The processor key.
	 *
	 * @since 0.2
	 * @access public
	 * @var str $key_name The processor key
	 */
	public $key_name = 'civicrm_relationship';

	/**
	 * Initialises this object.
	 *
	 * @since 0.2
	 */
	public function __construct( $plugin ) {
		$this->plugin = $plugin;
		// register this processor
		add_filter( 'caldera_forms_get_form_processors', [ $this, 'register_processor' ] );

	}

	/**
	 * Adds this processor to Caldera Forms.
	 *
	 * @since 0.2
	 *
	 * @uses 'caldera_forms_get_form_processors' filter
	 *
	 * @param array $processors The existing processors
	 * @return array $processors The modified processors
	 */
	public function register_processor( $processors ) {

		$processors[$this->key_name] = [
			'name' => __( 'CiviCRM Relationship', 'caldera-forms-civicrm' ),
			'description' => __( 'Add CiviCRM relationship to contacts', 'caldera-forms-civicrm' ),
			'author' => '<NAME>',
			'template' => CF_CIVICRM_INTEGRATION_PATH . 'processors/relationship/relationship_config.php',
			'pre_processor' => [ $this, 'pre_processor' ],
		];

		return $processors;

	}

	/**
	 * Form processor callback.
	 *
	 * @since 0.2
	 *
	 * @param array $config Processor configuration
	 * @param array $form Form configuration
	 */
	public function pre_processor( $config, $form ) {

		// cfc transient object
		$transient = $this->plugin->transient->get();
		$this->contact_link = 'cid_' . $config['contact_link'];

		$relationship = civicrm_api3( 'Relationship', 'get', [
			'sequential' => 1,
			'contact_id_a' => $transient->contacts->{'cid_'.$config['contact_a']},
			'contact_id_b' => $transient->contacts->{'cid_'.$config['contact_b']},
			'relationship_type_id' => $config['relationship_type'],
		] );

		if ( $relationship['count'] ) {
			return;
		} else {
			try {
				$create_relationship = civicrm_api3( 'Relationship', 'create', [
					'sequential' => 1,
					'contact_id_a' => $transient->contacts->{'cid_'.$config['contact_a']},
					'contact_id_b' => $transient->contacts->{'cid_'.$config['contact_b']},
					'relationship_type_id' => $config['relationship_type'],
				] );
			} catch ( CiviCRM_API3_Exception $e ) {<commit_msg>remove contact_link<commit_after><?php

/**
 * CiviCRM Caldera Forms Relationship Processor Class.
 *
 * @since 0.2
 */
class CiviCRM_Caldera_Forms_Relationship_Processor {

	/**
     * Plugin reference.
     *
     * @since 0.4.4
     */
    public $plugin;

	/**
	 * The processor key.
	 *
	 * @since 0.2
	 * @access public
	 * @var str $key_name The processor key
	 */
	public $key_name = 'civicrm_relationship';

	/**
	 * Initialises this object.
	 *
	 * @since 0.2
	 */
	public function __construct( $plugin ) {
		$this->plugin = $plugin;
		// register this processor
		add_filter( 'caldera_forms_get_form_processors', [ $this, 'register_processor' ] );

	}

	/**
	 * Adds this processor to Caldera Forms.
	 *
	 * @since 0.2
	 *
	 * @uses 'caldera_forms_get_form_processors' filter
	 *
	 * @param array $processors The existing processors
	 * @return array $processors The modified processors
	 */
	public function register_processor( $processors ) {

		$processors[$this->key_name] = [
			'name' => __( 'CiviCRM Relationship', 'caldera-forms-civicrm' ),
			'description' => __( 'Add CiviCRM relationship to contacts', 'caldera-forms-civicrm' ),
			'author' => '<NAME>',
			'template' => CF_CIVICRM_INTEGRATION_PATH . 'processors/relationship/relationship_config.php',
			'pre_processor' => [ $this, 'pre_processor' ],
		];

		return $processors;

	}

	/**
	 * Form processor callback.
	 *
	 * @since 0.2
	 *
	 * @param array $config Processor configuration
	 * @param array $form Form configuration
	 */
	public function pre_processor( $config, $form ) {

		// cfc transient object
		$transient = $this->plugin->transient->get();

		$relationship = civicrm_api3( 'Relationship', 'get', [
			'sequential' => 1,
			'contact_id_a' => $transient->contacts->{'cid_'.$config['contact_a']},
			'contact_id_b' => $transient->contacts->{'cid_'.$config['contact_b']},
			'relationship_type_id' => $config['relationship_type'],
		] );

		if ( $relationship['count'] ) {
			return;
		} else {
			try {
				$create_relationship = civicrm_api3( 'Relationship', 'create', [
					'sequential' => 1,
					'contact_id_a' => $transient->contacts->{'cid_'.$config['contact_a']},
					'contact_id_b' => $transient->contacts->{'cid_'.$config['contact_b']},
					'relationship_type_id' => $config['relationship_type'],
				] );
			} catch ( CiviCRM_API3_Exception $e ) {
{'fraction_non_alphanumeric': 0.16162253047498948, 'fraction_numerical': 0.007566204287515763, 'mean_word_length': 3.7072205736894164, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '824361', 'n_tokens_mistral': 1836, 'n_tokens_neox': 1623, 'n_words': 318}