-
-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CiviImport - Switch import_mappings to ImportTemplateField table
- Loading branch information
Showing
6 changed files
with
106 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
/* | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC. All rights reserved. | | ||
| | | ||
| This work is published under the GNU AGPLv3 license with some | | ||
| permitted exceptions and without any warranty. For full license | | ||
| and copyright information, see https://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
namespace Civi\UserJob; | ||
|
||
use Civi\Api4\ImportTemplateField; | ||
use Civi\Api4\UserJob; | ||
|
||
trait UserJobTrait { | ||
|
||
/** | ||
* User job id. | ||
* | ||
* This is the primary key of the civicrm_user_job table which is used to | ||
* track the import. | ||
* | ||
* @var int | ||
*/ | ||
protected $userJobID; | ||
|
||
/** | ||
* The user job in use. | ||
* | ||
* @var array | ||
*/ | ||
protected $userJob; | ||
|
||
/** | ||
* @return int|null | ||
*/ | ||
public function getUserJobID(): ?int { | ||
if (!$this->userJobID && is_a($this, 'CRM_Core_Form') && $this->get('user_job_id')) { | ||
$this->userJobID = $this->get('user_job_id'); | ||
} | ||
return $this->userJobID; | ||
} | ||
|
||
/** | ||
* Set user job ID. | ||
* | ||
* @param int $userJobID | ||
* | ||
* @return self | ||
*/ | ||
public function setUserJobID(int $userJobID): self { | ||
$this->userJobID = $userJobID; | ||
// This allows other forms in the flow ot use $this->get('user_job_id'). | ||
if (is_a($this, 'CRM_Core_Form')) { | ||
$this->set('user_job_id', $userJobID); | ||
} | ||
return $this; | ||
} | ||
|
||
/** | ||
* Get User Job. | ||
* | ||
* API call to retrieve the userJob row. | ||
* | ||
* @return array | ||
* | ||
* @throws \CRM_Core_Exception | ||
*/ | ||
protected function getUserJob(): array { | ||
if (empty($this->userJob)) { | ||
$this->userJob = UserJob::get() | ||
->addWhere('id', '=', $this->getUserJobID()) | ||
->addChain('template_fields', ImportTemplateField::get() | ||
->addWhere('user_job_id', '=', $this->getUserJobID()) | ||
->addOrderBy('column_number') | ||
) | ||
->execute() | ||
->single(); | ||
} | ||
return $this->userJob; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters