Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
v2.5.19
Browse files Browse the repository at this point in the history
  • Loading branch information
kjmartens committed Apr 23, 2019
1 parent 8de147a commit 892e7bc
Show file tree
Hide file tree
Showing 4 changed files with 268 additions and 52 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Solspace Freeform Changelog

## 2.5.19 - 2019-04-23
### Added
- Added Insightly CRM Lead integration for Freeform Pro edition.

### Changed
- Updated Hidden fields to be in their original field position (instead of first in form) when viewing submissions in the CP.
- Updated Date field picker and format getters to be public.

### Fixed
- Fixed a bug where Form Color setting for forms was only visible in Pro edition.
- Fixed a bug where using `DD/MM/YYYY` formatting and Min/Max date setting on Date fields would result in an error upon submit when validating.
- Fixed a bug where the Resend Notifications feature errored when email notifications extended layouts.
- Fixed a bug where permanently deleting fields could cause an error if assigned to an integration field list.

## 2.5.18 - 2019-04-18
### Added
- Added Active Campaign mailing list API integration (Pro edition).
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "solspace/craft3-freeform-pro",
"description": "Adds API integrations, reCAPTCHA, conditional rules logic, premium field types, advanced exporting and widgets to Freeform.",
"version": "2.5.18",
"version": "2.5.19",
"type": "craft-plugin",
"authors": [
{
Expand Down
104 changes: 53 additions & 51 deletions src/Fields/DatetimeField.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ public function getConstraints(): array
'minDate' => $this->getGeneratedMinDate($this->getDateFormat()),
]
),
$this->getFormat(),
$this->getGeneratedMinDate()
);
$constraints[] = new MaxDateConstraint(
Expand All @@ -293,6 +294,7 @@ public function getConstraints(): array
'maxDate' => $this->getGeneratedMaxDate($this->getDateFormat()),
]
),
$this->getFormat(),
$this->getGeneratedMaxDate()
);

Expand All @@ -302,53 +304,7 @@ public function getConstraints(): array
/**
* @return string
*/
protected function getInputHtml(): string
{
$attributes = $this->getCustomAttributes();
$this->addInputClass('form-date-time-field');

if ($this->isUseDatepicker()) {
$this->addInputClass('form-datepicker');
$this->addInputAttribute('autocomplete', 'off');
}

$hasTime = \in_array($this->getDateTimeType(), [self::DATETIME_TYPE_BOTH, self::DATETIME_TYPE_TIME], true);
$hasDate = \in_array($this->getDateTimeType(), [self::DATETIME_TYPE_BOTH, self::DATETIME_TYPE_DATE], true);

$this->addInputAttribute('class', $attributes->getClass() . ' ' . $this->getInputClassString());

$locale = \Craft::$app->locale->id;
$freeformPath = \Yii::getAlias('@freeform');
if (!file_exists($freeformPath . "/Resources/js/lib/flatpickr/i10n/$locale.js")) {
$locale = '';
}

return '<input '
. $this->getInputAttributesString()
. $this->getAttributeString('name', $this->getHandle())
. $this->getAttributeString('type', $this->getType())
. $this->getAttributeString('id', $this->getIdAttribute())
. $this->getAttributeString('data-datepicker-format', $this->getDatepickerFormat())
. $this->getAttributeString('data-datepicker-enabletime', $hasTime ?: '')
. $this->getAttributeString('data-datepicker-enabledate', $hasDate ?: '')
. $this->getAttributeString('data-datepicker-clock_24h', $this->isClock24h() ?: '')
. $this->getAttributeString('data-datepicker-locale', $locale)
. $this->getAttributeString('data-datepicker-min-date', $this->getGeneratedMinDate($this->getFormat()))
. $this->getAttributeString('data-datepicker-max-date', $this->getGeneratedMaxDate($this->getFormat()))
. $this->getAttributeString(
'placeholder',
$this->translate($attributes->getPlaceholder() ?: $this->getPlaceholder())
)
. $this->getAttributeString('value', $this->getValue(), false)
. $this->getRequiredAttribute()
. $attributes->getInputAttributesAsString()
. '/>';
}

/**
* @return string
*/
private function getDatepickerFormat(): string
public function getDatepickerFormat(): string
{
$format = $this->getFormat();

Expand All @@ -366,7 +322,7 @@ private function getDatepickerFormat(): string
*
* @return string
*/
private function getHumanReadableFormat(): string
public function getHumanReadableFormat(): string
{
$format = $this->getFormat();

Expand All @@ -384,7 +340,7 @@ private function getHumanReadableFormat(): string
*
* @return string
*/
private function getFormat(): string
public function getFormat(): string
{
$showDate = \in_array($this->getDateTimeType(), [self::DATETIME_TYPE_BOTH, self::DATETIME_TYPE_DATE], true);
$showTime = \in_array($this->getDateTimeType(), [self::DATETIME_TYPE_BOTH, self::DATETIME_TYPE_TIME], true);
Expand All @@ -404,7 +360,7 @@ private function getFormat(): string
/**
* @return string
*/
private function getDateFormat(): string
public function getDateFormat(): string
{
$month = $this->isDateLeadingZero() ? 'm' : 'n';
$day = $this->isDateLeadingZero() ? 'd' : 'j';
Expand Down Expand Up @@ -448,7 +404,7 @@ private function getDateFormat(): string
/**
* @return string
*/
private function getTimeFormat(): string
public function getTimeFormat(): string
{
$minutes = 'i';

Expand All @@ -462,4 +418,50 @@ private function getTimeFormat(): string

return $hours . $this->getClockSeparator() . $minutes . $ampm;
}

/**
* @return string
*/
protected function getInputHtml(): string
{
$attributes = $this->getCustomAttributes();
$this->addInputClass('form-date-time-field');

if ($this->isUseDatepicker()) {
$this->addInputClass('form-datepicker');
$this->addInputAttribute('autocomplete', 'off');
}

$hasTime = \in_array($this->getDateTimeType(), [self::DATETIME_TYPE_BOTH, self::DATETIME_TYPE_TIME], true);
$hasDate = \in_array($this->getDateTimeType(), [self::DATETIME_TYPE_BOTH, self::DATETIME_TYPE_DATE], true);

$this->addInputAttribute('class', $attributes->getClass() . ' ' . $this->getInputClassString());

$locale = \Craft::$app->locale->id;
$freeformPath = \Yii::getAlias('@freeform');
if (!file_exists($freeformPath . "/Resources/js/lib/flatpickr/i10n/$locale.js")) {
$locale = '';
}

return '<input '
. $this->getInputAttributesString()
. $this->getAttributeString('name', $this->getHandle())
. $this->getAttributeString('type', $this->getType())
. $this->getAttributeString('id', $this->getIdAttribute())
. $this->getAttributeString('data-datepicker-format', $this->getDatepickerFormat())
. $this->getAttributeString('data-datepicker-enabletime', $hasTime ?: '')
. $this->getAttributeString('data-datepicker-enabledate', $hasDate ?: '')
. $this->getAttributeString('data-datepicker-clock_24h', $this->isClock24h() ?: '')
. $this->getAttributeString('data-datepicker-locale', $locale)
. $this->getAttributeString('data-datepicker-min-date', $this->getGeneratedMinDate($this->getFormat()))
. $this->getAttributeString('data-datepicker-max-date', $this->getGeneratedMaxDate($this->getFormat()))
. $this->getAttributeString(
'placeholder',
$this->translate($attributes->getPlaceholder() ?: $this->getPlaceholder())
)
. $this->getAttributeString('value', $this->getValue(), false)
. $this->getRequiredAttribute()
. $attributes->getInputAttributesAsString()
. '/>';
}
}
200 changes: 200 additions & 0 deletions src/Integrations/CRM/Insightly.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
<?php

namespace Solspace\FreeformPro\Integrations\CRM;

use GuzzleHttp\Client;
use Solspace\Freeform\Library\Exceptions\Integrations\IntegrationException;
use Solspace\Freeform\Library\Integrations\CRM\AbstractCRMIntegration;
use Solspace\Freeform\Library\Integrations\DataObjects\FieldObject;
use Solspace\Freeform\Library\Integrations\IntegrationStorageInterface;
use Solspace\Freeform\Library\Integrations\SettingBlueprint;

class Insightly extends AbstractCRMIntegration
{
const SETTING_API_KEY = 'api_key';

const TITLE = 'Insightly';
const LOG_CATEGORY = 'Insightly';

/**
* Returns a list of additional settings for this integration
* Could be used for anything, like - AccessTokens
*
* @return SettingBlueprint[]
*/
public static function getSettingBlueprints(): array
{
return [
new SettingBlueprint(
SettingBlueprint::TYPE_TEXT,
self::SETTING_API_KEY,
'API Key',
'Enter your Insightly API key here.',
true
),
];
}

/**
* Push objects to the CRM
*
* @param array $keyValueList
*
* @return bool
*/
public function pushObject(array $keyValueList): bool
{
$response = $this
->getAuthorizedClient()
->post(
$this->getEndpoint('/Leads'),
['json' => $keyValueList]
);

return $response->getStatusCode() === 200;
}

/**
* Check if it's possible to connect to the API
*
* @return bool
*/
public function checkConnection(): bool
{
$response = $this
->getAuthorizedClient()
->get($this->getEndpoint('/Leads'));

return $response->getStatusCode() === 200;
}

/**
* Fetch the custom fields from the integration
*
* @return FieldObject[]
*/
public function fetchFields(): array
{
$fieldList = [
new FieldObject('SALUTATION', 'Salutation', FieldObject::TYPE_STRING),
new FieldObject('FIRST_NAME', 'First Name', FieldObject::TYPE_STRING),
new FieldObject('LAST_NAME', 'Last Name', FieldObject::TYPE_STRING),
new FieldObject('TITLE', 'Title', FieldObject::TYPE_STRING),
new FieldObject('EMAIL', 'Email', FieldObject::TYPE_STRING),
new FieldObject('PHONE', 'Phone', FieldObject::TYPE_STRING),
new FieldObject('MOBILE', 'Mobile', FieldObject::TYPE_STRING),
new FieldObject('FAX', 'Fax', FieldObject::TYPE_STRING),
new FieldObject('WEBSITE', 'Website', FieldObject::TYPE_STRING),
new FieldObject('ORGANISATION_NAME', 'Organisation Name', FieldObject::TYPE_STRING),
new FieldObject('INDUSTRY', 'Industry', FieldObject::TYPE_STRING),
new FieldObject('EMPLOYEE_COUNT', 'Employee Count', FieldObject::TYPE_STRING),
new FieldObject('IMAGE_URL', 'Image URL', FieldObject::TYPE_STRING),
new FieldObject('ADDRESS_STREET', 'Address - Street', FieldObject::TYPE_STRING),
new FieldObject('ADDRESS_CITY', 'Address - City', FieldObject::TYPE_STRING),
new FieldObject('ADDRESS_STATE', 'Address - State', FieldObject::TYPE_STRING),
new FieldObject('ADDRESS_POSTCODE', 'Address - Postcode', FieldObject::TYPE_STRING),
new FieldObject('ADDRESS_COUNTRY', 'Address - Country', FieldObject::TYPE_STRING),
new FieldObject('LEAD_DESCRIPTION', 'Lead Description', FieldObject::TYPE_STRING),
new FieldObject('LEAD_RATING', 'Lead Rating', FieldObject::TYPE_STRING),
];

$response = $this
->getAuthorizedClient()
->get($this->getEndpoint('/CustomFields/Leads'));

$data = json_decode($response->getBody(), false);
foreach ($data as $field) {
if (!$field->EDITABLE) {
continue;
}

$type = null;

switch ($field->FIELD_TYPE) {
case 'TEXT':
case 'DROPDOWN':
case 'URL':
case 'MULTILINETEXT':
$type = FieldObject::TYPE_STRING;
break;

case 'DATE':
$type = FieldObject::TYPE_DATETIME;
break;

case 'BIT':
$type = FieldObject::TYPE_BOOLEAN;
break;

case 'NUMERIC':
$type = FieldObject::TYPE_NUMERIC;
break;
}

if (null === $type) {
continue;
}

$fieldObject = new FieldObject(
$field->FIELD_NAME,
$field->FIELD_LABEL,
$type,
false
);

$fieldList[] = $fieldObject;
}

return $fieldList;
}

/**
* Authorizes the application
* Returns the access_token
*
* @return string
* @throws IntegrationException
*/
public function fetchAccessToken(): string
{
return $this->getSetting(self::SETTING_API_KEY);
}

/**
* A method that initiates the authentication
*/
public function initiateAuthentication()
{
}

/**
* Perform anything necessary before this integration is saved
*
* @param IntegrationStorageInterface $model
*/
public function onBeforeSave(IntegrationStorageInterface $model)
{
$model->updateAccessToken($this->getSetting(self::SETTING_API_KEY));
}

/**
* @return string
*/
protected function getApiRootUrl(): string
{
return 'https://api.insightly.com/v3.0/';
}

/**
* @return Client
*/
private function getAuthorizedClient(): Client
{
$client = new Client([
'headers' => ['Content-Type' => 'application/json'],
'auth' => [$this->getAccessToken(), ''],
]);

return $client;
}
}

0 comments on commit 892e7bc

Please sign in to comment.