mirror of
https://codeberg.org/artfulrobot/contactcats.git
synced 2025-06-27 04:37:17 +02:00
update tests, fix stuff, implement bespoke save, create actions for contactcategory
This commit is contained in:
parent
78e5b83c1d
commit
2ae781f6e3
6 changed files with 273 additions and 29 deletions
46
Civi/Api4/Action/ContactCategory/Save.php
Normal file
46
Civi/Api4/Action/ContactCategory/Save.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
namespace Civi\Api4\Action\ContactCategory;
|
||||
|
||||
use Civi\Api4\Generic\Result;
|
||||
use CRM_Contactcats_ExtensionUtil as E;
|
||||
use CRM_Core_DAO;
|
||||
|
||||
/**
|
||||
* Create ContactCategory action
|
||||
*
|
||||
* This entity's ID is a unique primary key that references
|
||||
* contact_id. Here we overwrite the validateValues which normally
|
||||
*
|
||||
* @see \Civi\Api4\Generic\AbstractAction
|
||||
*
|
||||
*/
|
||||
class Save extends \Civi\Api4\Generic\DAOSaveAction {
|
||||
|
||||
/**
|
||||
* Allow creating records with ids.
|
||||
*
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function _run(Result $result) {
|
||||
$ids = [];
|
||||
foreach (array_column($this->records, 'id') as $id) {
|
||||
if ($id) {
|
||||
$ids[] = (int) $id;
|
||||
}
|
||||
}
|
||||
if ($ids) {
|
||||
$idsList = implode(",", array_filter($ids));
|
||||
$preExisting = array_column(CRM_Core_DAO::executeQuery(
|
||||
"SELECT id FROM civicrm_contact_category WHERE id IN ($idsList)"
|
||||
)->fetchAll(), 'id');
|
||||
// Any where we were given an ID that doesn't exist are important.
|
||||
foreach (array_diff($ids, $preExisting) as $unknownID) {
|
||||
CRM_Core_DAO::executeQuery("INSERT INTO civicrm_contact_category (id) VALUES ($unknownID)");
|
||||
}
|
||||
}
|
||||
|
||||
// Now let it proceed as normal.
|
||||
parent::_run($result);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue