Skip to content

Commit e92fb7b

Browse files
author
Muhammad Shahrukh
committed
DTAB-84: Add settings page
1 parent c78e453 commit e92fb7b

File tree

15 files changed

+241
-88
lines changed

15 files changed

+241
-88
lines changed

.github/workflows/phpstan.yml

+29
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,36 @@ jobs:
1212
CIVICRM_EXTENSIONS_DIR: site/web/sites/all/modules/civicrm/tools/extensions
1313
CIVICRM_SETTINGS_DIR: site/web/sites/default
1414

15+
services:
16+
mysql:
17+
image: mysql:5.7
18+
env:
19+
MYSQL_ROOT_PASSWORD: root
20+
ports:
21+
- 3306
22+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
23+
1524
steps:
25+
- name: Config mysql database as per CiviCRM requirement
26+
run: echo "SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));" | mysql -u root --password=root --host=mysql
27+
28+
- name: Install missing extension
29+
run: sudo apt update && apt install -y php-bcmath
30+
31+
- name: Config amp
32+
run: amp config:set --mysql_dsn=mysql://root:root@mysql:3306
33+
34+
- name: Build Drupal site
35+
run: civibuild create drupal-clean --civi-ver 5.75.0 --cms-ver 7.103 --web-root $GITHUB_WORKSPACE/site
36+
37+
- uses: compucorp/[email protected]
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
with:
41+
repo: compucorp/civicrm-core
42+
version: 5.75.0
43+
path: site/web/sites/all/modules/civicrm
44+
1645
- uses: actions/checkout@v2
1746
with:
1847
path: ${{ env.CIVICRM_EXTENSIONS_DIR }}/thinkific

CRM/Thinkific/.gitkeep

Whitespace-only changes.

CRM/Thinkific/Form/Settings.php

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
use CRM_Thinkific_ExtensionUtil as E;
4+
use CRM_Thinkific_SettingsManager as SettingsManager;
5+
6+
/**
7+
* Form controller class
8+
*
9+
* @see https://docs.civicrm.org/dev/en/latest/framework/quickform/
10+
*/
11+
class CRM_Thinkific_Form_Settings extends CRM_Core_Form {
12+
13+
public function buildQuickForm(): void {
14+
CRM_Utils_System::setTitle(E::ts('Thinkfic LMS Settings'));
15+
$this->add('password', SettingsManager::API_KEY, E::ts('Thinkfic Api Key'), NULL, TRUE);
16+
$this->add('text', SettingsManager::SUBDOMAIN, E::ts('Thinkfic Subdomain'), NULL, TRUE);
17+
18+
$this->addButtons([
19+
[
20+
'type' => 'submit',
21+
'name' => E::ts('Save'),
22+
'isDefault' => TRUE,
23+
],
24+
]);
25+
26+
// export form elements
27+
$this->assign('elementNames', $this->getRenderableElementNames());
28+
parent::buildQuickForm();
29+
}
30+
31+
public function postProcess(): void {
32+
$values = $this->exportValues();
33+
34+
/** @var array<string, mixed> $result */
35+
$result = civicrm_api3('setting', 'create', [
36+
SettingsManager::API_KEY => $values[SettingsManager::API_KEY],
37+
SettingsManager::SUBDOMAIN => $values[SettingsManager::SUBDOMAIN],
38+
]);
39+
40+
if ($result['is_error'] == 0) {
41+
CRM_Core_Session::singleton()->setStatus(E::ts('Connection success.'), E::ts('Thinkfic LMS Settings'), 'success');
42+
}
43+
else {
44+
CRM_Core_Session::singleton()->setStatus(
45+
E::ts('An issue has occurred connecting to the Thinkific platform. Please contact your administrator. Error code: 00'),
46+
E::ts('Thinkfic LMS Settings'),
47+
'error'
48+
);
49+
}
50+
51+
parent::postProcess();
52+
}
53+
54+
/**
55+
* Set defaults for form.
56+
*
57+
* @return array<string, mixed>
58+
*
59+
* @see CRM_Core_Form::setDefaultValues()
60+
*/
61+
public function setDefaultValues(): array {
62+
$defaults = [];
63+
$domainId = CRM_Core_Config::domainID();
64+
65+
/** @var array<string, array<int, array<string, mixed>>> $currentValues */
66+
$currentValues = civicrm_api3('setting', 'get', ['return' => [SettingsManager::API_KEY, SettingsManager::SUBDOMAIN]]);
67+
68+
if (isset($currentValues['values'][$domainId])) {
69+
foreach ($currentValues['values'][$domainId] as $name => $value) {
70+
$defaults[$name] = $value;
71+
}
72+
}
73+
return $defaults;
74+
}
75+
76+
/**
77+
* Get the fields/elements defined in this form.
78+
*
79+
* @return list<string>
80+
*/
81+
public function getRenderableElementNames(): array {
82+
// The _elements list includes some items which should not be
83+
// auto-rendered in the loop -- such as "qfKey" and "buttons". These
84+
// items don't have labels. We'll identify renderable by filtering on
85+
// the 'label'.
86+
$elementNames = [];
87+
/** @phpstan-ignore property.notFound */
88+
foreach ($this->_elements as $element) {
89+
/** @var HTML_QuickForm_element $element */
90+
$label = $element->getLabel();
91+
if (!empty($label)) {
92+
$elementNames[] = $element->getName();
93+
}
94+
}
95+
return $elementNames;
96+
}
97+
98+
}

CRM/Thinkific/SettingsManager.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
* Settings manager class to manage Thinkific settings.
14+
*/
15+
class CRM_Thinkific_SettingsManager {
16+
17+
/**
18+
* Constants for setting name
19+
*/
20+
const API_KEY = 'thinkific_api_key';
21+
const SUBDOMAIN = 'thinkific_subdomain';
22+
23+
}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## io.compuco.lmsd2lintegration
1+
## io.compuco.thinkific
22

33
This extension integrates Thinkific LMS with civicrm.
44

info.xml

+1
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@
3535
<mixin>[email protected]</mixin>
3636
<mixin>[email protected]</mixin>
3737
<mixin>[email protected]</mixin>
38+
<mixin>[email protected]</mixin>
3839
</mixins>
3940
</extension>

mixin/[email protected]

-36
This file was deleted.

mixin/[email protected]

-51
This file was deleted.

phpstan.neon

+7
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@ parameters:
66
paths:
77
- Civi
88
- CRM
9+
scanFiles:
10+
- thinkific.civix.php
11+
scanDirectories:
12+
- ../../../Civi
13+
- ../../../CRM
14+
- ../../../api
15+
- ../../../packages

settings/Thinkific.setting.php

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
use CRM_Thinkific_SettingsManager as SettingsManager;
13+
14+
/*
15+
* Settings metadata file
16+
*/
17+
return [
18+
'thinkific_api_key' => [
19+
'name' => SettingsManager::API_KEY,
20+
'title' => 'Thinkific Api Key',
21+
'type' => 'String',
22+
'html_type' => 'password',
23+
'default' => '',
24+
'is_domain' => 1,
25+
'is_contact' => 0,
26+
'description' => 'Api key from Thinkific',
27+
'html_attributes' => [],
28+
],
29+
'thinkific_subdomain' => [
30+
'name' => SettingsManager::SUBDOMAIN,
31+
'title' => 'Thinkific Subdomain',
32+
'type' => 'String',
33+
'html_type' => 'text',
34+
'default' => '',
35+
'is_domain' => 1,
36+
'is_contact' => 0,
37+
'description' => 'Subdomain for Thinkific',
38+
'html_attributes' => [],
39+
],
40+
];

templates/.gitkeep

Whitespace-only changes.
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{* HEADER *}
2+
<div class="crm-block crm-form-block">
3+
<div class="crm-submit-buttons">
4+
{include file="CRM/common/formButtons.tpl" location="top"}
5+
</div>
6+
{foreach from=$elementNames item=elementName}
7+
<div class="crm-section">
8+
<div class="label">{$form.$elementName.label}</div>
9+
<div class="content">{$form.$elementName.html}</div>
10+
<div class="clear"></div>
11+
</div>
12+
{/foreach}
13+
<div class="crm-submit-buttons">
14+
{include file="CRM/common/formButtons.tpl" location="bottom"}
15+
</div>
16+
</div>

thinkific.php

+17
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,20 @@ function thinkific_civicrm_install(): void {
3030
function thinkific_civicrm_enable(): void {
3131
_thinkific_civix_civicrm_enable();
3232
}
33+
34+
/**
35+
* Implements hook_civicrm_navigationMenu().
36+
*
37+
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_navigationMenu
38+
*/
39+
function thinkific_civicrm_navigationMenu(&$menu) {
40+
_thinkific_civix_insert_navigation_menu($menu, 'Administer/CiviEvent', array(
41+
'label' => E::ts('Thinkific LMS Settings'),
42+
'name' => 'thinkific_lms_settings',
43+
'url' => 'civicrm/admin/setting/preferences/thinkific',
44+
'permission' => 'administer CiviCRM',
45+
'operator' => 'OR',
46+
'separator' => 0,
47+
));
48+
_thinkific_civix_navigationMenu($menu);
49+
}

xml/.gitkeep

Whitespace-only changes.

xml/Menu/thinkific.xml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0"?>
2+
<menu>
3+
<item>
4+
<path>civicrm/admin/setting/preferences/thinkific</path>
5+
<page_callback>CRM_Thinkific_Form_Settings</page_callback>
6+
<title>Thinkific LMS Settings</title>
7+
<access_arguments>administer CiviCRM</access_arguments>
8+
</item>
9+
</menu>

0 commit comments

Comments
 (0)