| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | Copyright CiviCRM LLC. All rights reserved. | |
| 5 | | | |
| 6 | | This work is published under the GNU AGPLv3 license with some | |
| 7 | | permitted exceptions and without any warranty. For full license | |
| 8 | | and copyright information, see https://civicrm.org/licensing | |
| 9 | +--------------------------------------------------------------------+ |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * |
| 14 | * @package CRM |
| 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
| 16 | */ |
| 17 | |
| 18 | /** |
| 19 | * This class defines the DataSource interface but must be subclassed to be |
| 20 | * useful. |
| 21 | */ |
| 22 | abstract class CRM_Import_DataSource { |
| 23 | |
| 24 | /** |
| 25 | * Provides information about the data source. |
| 26 | * |
| 27 | * @return array |
| 28 | * Description of this data source, including: |
| 29 | * - title: string, translated, required |
| 30 | * - permissions: array, optional |
| 31 | * |
| 32 | */ |
| 33 | abstract public function getInfo(); |
| 34 | |
| 35 | /** |
| 36 | * Set variables up before form is built. |
| 37 | * |
| 38 | * @param CRM_Core_Form $form |
| 39 | */ |
| 40 | abstract public function preProcess(&$form); |
| 41 | |
| 42 | /** |
| 43 | * This is function is called by the form object to get the DataSource's form snippet. |
| 44 | * |
| 45 | * It should add all fields necessary to get the data uploaded to the temporary table in the DB. |
| 46 | * |
| 47 | * @param CRM_Core_Form $form |
| 48 | */ |
| 49 | abstract public function buildQuickForm(&$form); |
| 50 | |
| 51 | /** |
| 52 | * Process the form submission. |
| 53 | * |
| 54 | * @param array $params |
| 55 | * @param string $db |
| 56 | * @param CRM_Core_Form $form |
| 57 | */ |
| 58 | abstract public function postProcess(&$params, &$db, &$form); |
| 59 | |
| 60 | /** |
| 61 | * Determine if the current user has access to this data source. |
| 62 | * |
| 63 | * @return bool |
| 64 | */ |
| 65 | public function checkPermission() { |
| 66 | $info = $this->getInfo(); |
| 67 | return empty($info['permissions']) || CRM_Core_Permission::check($info['permissions']); |
| 68 | } |
| 69 | |
| 70 | } |