Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/3.7 web integration #98

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions civicrm/custom/php/CRM/NYSS/BAO/Integration/Website.php
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ static function processSurvey($contactId, $action, $params)
$actParams = [
'subject' => $params->form_title,
'date' => date('Y-m-d H:i:s'),
'activity_type_id' => CRM_Core_OptionGroup::getValue('activity_type', 'Website Survey', 'name'),
'activity_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Website Survey'),
'details' => (!empty($params->detail)) ? $params->detail : '',
'target_contact_id' => $contactId,
'source_contact_id' => civicrm_api3('uf_match', 'getvalue', [
Expand Down Expand Up @@ -971,7 +971,7 @@ static function buildSurvey($data) {
'title' => "Survey: {$formTitle} [{$data->form_id}]",
'table_name' => "civicrm_value_surveydata_{$data->form_id}",
'extends' => ['0' => 'Activity'],
'extends_entity_column_value' => CRM_Core_OptionGroup::getValue('activity_type', 'Website Survey', 'name'),
'extends_entity_column_value' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Website Survey'),
'collapse_display' => 1,
'collapse_adv_display' => 1,
'style' => 'Inline',
Expand Down
45 changes: 24 additions & 21 deletions civicrm/custom/php/CRM/NYSS/BAO/Integration/WebsiteEvent.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php

use Civi\API\Exception\UnauthorizedException;
use CRM_Core_DAO;
use InvalidArgumentException;
use PhpParser\Node\Expr\Cast\Object_;

abstract class CRM_NYSS_BAO_Integration_WebsiteEvent implements CRM_NYSS_BAO_Integration_WebsiteEventInterface {
Expand Down Expand Up @@ -225,15 +223,18 @@ protected function hasEntityTag(int $contact_id, int $tag_id): bool {
* @throws \CRM_Core_Exception
*/
protected function createEntityTag(int $contact_id, int $tag_id): void {
$results = \Civi\Api4\EntityTag::create($this->getCiviPermissionCheck())
->addValue('entity_table', 'civicrm_contact')
->addValue('entity_id', $contact_id)
->addValue('tag_id', $tag_id)
->setCheckPermissions($this->getCiviPermissionCheck())
->execute();

if ((count($results) < 1) || (isset($results[0]['error_code']))) {
throw new \CRM_Core_Exception('Failed to create tag with error: ' . $results[0]['error_message']);
// only create if it doesn't already exist
if (! $this->hasEntityTag($contact_id,$tag_id)) {
$results = \Civi\Api4\EntityTag::create($this->getCiviPermissionCheck())
->addValue('entity_table', 'civicrm_contact')
->addValue('entity_id', $contact_id)
->addValue('tag_id', $tag_id)
->setCheckPermissions($this->getCiviPermissionCheck())
->execute();

if ((count($results) < 1) || (isset($results[0]['error_code']))) {
throw new \CRM_Core_Exception('Failed to create tag with error: ' . $results[0]['error_message']);
}
}
}

Expand All @@ -248,16 +249,18 @@ protected function createEntityTag(int $contact_id, int $tag_id): void {
* @throws \Civi\API\Exception\UnauthorizedException
*/
protected function deleteEntityTag(int $contact_id, int $tag_id): void {
$results = \Civi\Api4\EntityTag::delete($this->getCiviPermissionCheck())
->addWhere('entity_table', '=', 'civicrm_contact')
->addWhere('entity_id', '=', $contact_id)
->addWhere('tag_id', '=', $tag_id)
->setCheckPermissions($this->getCiviPermissionCheck())
->execute();

if (count($results) < 1) {
throw new \CRM_Core_Exception('Failed to delete entity tag');
}
if ($this->hasEntityTag($contact_id,$tag_id)) {
$results = \Civi\Api4\EntityTag::delete($this->getCiviPermissionCheck())
->addWhere('entity_table', '=', 'civicrm_contact')
->addWhere('entity_id', '=', $contact_id)
->addWhere('tag_id', '=', $tag_id)
->setCheckPermissions($this->getCiviPermissionCheck())
->execute();

if (count($results) < 1) {
throw new \CRM_Core_Exception('Failed to delete entity tag');
}
}
}

public function getEventInfo(): object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
<?php

use CRM_Core_Exception;
use CRM_NYSS_BAO_Integration_Website;
use CRM_NYSS_BAO_Integration_WebsiteEventData;
use Exception;
use InvalidArgumentException;
use stdClass;

class CRM_NYSS_BAO_Integration_WebsiteEvent_AccountEvent extends \CRM_NYSS_BAO_Integration_WebsiteEvent implements \CRM_NYSS_BAO_Integration_WebsiteEventInterface {

const ACTIVITY_TYPE = 'Account';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<?php

use Civi\API\Exception\UnauthorizedException;
use CRM_Core_Exception;
use CRM_NYSS_BAO_Integration_OpenLegislation;
use InvalidArgumentException;
use CRM_NYSS_BAO_Integration_WebsiteEvent;
use CRM_NYSS_BAO_Integration_WebsiteEventInteface;

class CRM_NYSS_BAO_Integration_WebsiteEvent_BillEvent extends CRM_NYSS_BAO_Integration_WebsiteEvent implements CRM_NYSS_BAO_Integration_WebsiteEventInterface {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<?php

use Civi\API\Exception\UnauthorizedException;
use CRM_Core_Exception;
use CRM_NYSS_BAO_Integration_WebsiteEvent;
use CRM_NYSS_BAO_Integration_WebsiteEventInteface;
use InvalidArgumentException;

class CRM_NYSS_BAO_Integration_WebsiteEvent_CommitteeEvent extends CRM_NYSS_BAO_Integration_WebsiteEvent implements CRM_NYSS_BAO_Integration_WebsiteEventInterface {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<?php

use Civi\API\Exception\UnauthorizedException;
use CRM_Core_Exception;
use NYSS_Integration\WebsiteEvent;
use NYSS_Integration\WebsiteEventInterface;
use InvalidArgumentException;

class CRM_NYSS_BAO_Integration_WebsiteEvent_IssueEvent extends CRM_NYSS_BAO_Integration_WebsiteEvent implements CRM_NYSS_BAO_Integration_WebsiteEventInterface {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

use CRM_NYSS_BAO_Integration_WebsiteEvent_PollEvent;

class CRM_NYSS_BAO_Integration_WebsiteEvent_PetitionEvent extends CRM_NYSS_BAO_Integration_WebsiteEvent_PollEvent implements CRM_NYSS_BAO_Integration_WebsiteEventInterface {

use CRM_NYSS_BAO_Integration_WebsiteEvent_FollowableEvent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
<?php

use Civi\API\Exception\UnauthorizedException;
use CRM_Core_Exception;
use CRM_NYSS_BAO_Integration_WebsiteEvent_FollowableEvent;
use CRM_NYSS_BAO_Integration_WebsiteEventData;
use InvalidArgumentException;
use CRM_NYSS_BAO_Integration_WebsiteEvent;
use CRM_NYSS_BAO_Integration_WebsiteEventInteface;

abstract class CRM_NYSS_BAO_Integration_WebsiteEvent_PollEvent extends CRM_NYSS_BAO_Integration_WebsiteEvent implements \CRM_NYSS_BAO_Integration_WebsiteEventInterface {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use InvalidArgumentException;
use PhpParser\Node\Expr\Cast\Object_;

class CRM_NYSS_BAO_Integration_WebsiteEventData {
Expand Down