Skip to content

Commit

Permalink
prepare for marketplace
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiez committed Jun 18, 2021
1 parent fe6837c commit 592467a
Show file tree
Hide file tree
Showing 15 changed files with 281 additions and 139 deletions.
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"php": "7.3"
}
},
"description": "Send SMS via Sms77",
"description": "Concrete5 package for SMS and text-to-speech calls via Sms77",
"homepage": "https://github.com/sms77io/concrete5",
"keywords": [
"cms",
Expand All @@ -30,7 +30,6 @@
"require": {
"concrete5/core": ">=8.5.2",
"php": "7.3",
"sms77/api": "^2.4",
"ext-json": "*"
},
"support": {
Expand All @@ -41,5 +40,5 @@
"source": "https://github.com/sms77io/concrete5"
},
"type": "concrete5-package",
"version": "2.0.0"
"version": "2.1.0"
}
75 changes: 6 additions & 69 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 9 additions & 17 deletions controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
use Sms77\Concrete5\Options;
use Sms77\Concrete5\Routes;

class Controller extends Package {
public const MIN_PHP_VERSION = '7.3.0';
final class Controller extends Package {
private $MIN_PHP_VERSION = '7.3.0';

protected $appVersionRequired = '8.5.2';
protected $pkgAutoloaderRegistries = [
'src' => '\Sms77\Concrete5',
];
protected $pkgHandle = 'sms77';
protected $pkgVersion = '2.0.0';

Expand All @@ -27,13 +30,11 @@ public function getPackageName(): string {
}

private function commonTasks(PackageEntity $pkg): void {
if (version_compare(PHP_VERSION, self::MIN_PHP_VERSION, '<')) {
throw new Exception(sprintf("PHP %s or greater needed to use this package.",
self::MIN_PHP_VERSION));
if (version_compare(PHP_VERSION, $this->MIN_PHP_VERSION, '<')) {
throw new Exception(sprintf('PHP %s or greater needed to use this package.',
$this->MIN_PHP_VERSION));
}

$this->on_start();

$this->installContentFile('install.xml');

$this->getConfig();
Expand Down Expand Up @@ -75,13 +76,4 @@ public function uninstall(): void {
->where('configNamespace = :namespace')
->setParameters([':namespace' => $this->pkgHandle])->execute();
}

/** Initialize the autoloader when the system boots up. */
public function on_start(): void {
$file = $this->getPackagePath() . '/vendor/autoload.php';

if (file_exists($file)) {
require_once $file;
}
}
}
}
6 changes: 3 additions & 3 deletions controllers/single_page/dashboard/sms77.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Sms77\Concrete5\Options;
use Sms77\Concrete5\Routes;

class Sms77 extends AbstractSinglePageDashboardController {
final class Sms77 extends AbstractSinglePageDashboardController {
public function submit(): void {
$msg = '';

Expand All @@ -22,7 +22,7 @@ public function submit(): void {
$msg = t('Settings updated!');
}

$to = Routes::getAbsoluteURL(Routes::DASHBOARD);
$to = Routes::getAbsoluteURL(Routes::$DASHBOARD);
if ('' !== $msg) $to .= "?message=$msg";

$this->redirect($to);
Expand All @@ -35,4 +35,4 @@ public function view(): void {
$this->set($group, $this->config[$group]);
}
}
}
}
12 changes: 6 additions & 6 deletions controllers/single_page/dashboard/sms77/bulk_sms.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

use Concrete\Core\Page\Page;
use Concrete\Core\User\UserInfoRepository;
use Sms77\Api\Params\SmsParams;
use Sms77\Concrete5\AbstractMessageController;
use Sms77\Concrete5\SmsParams;

class BulkSms extends AbstractMessageController {
final class BulkSms extends AbstractMessageController {
public function __construct(Page $c, UserInfoRepository $repo) {
parent::__construct($c, $repo, 'sms');
}

protected function onSubmit(array $recipients): void {
$this->encode($this->client->smsJson((new SmsParams)
protected function onSubmit(array $recipients) {
$this->setMessage($this->encode($this->client->sms((new SmsParams)
->setDebug((bool)$this->config['debug'])
->setFlash((bool)$this->config['flash'])
->setForeignId($this->config['foreign_id'])
Expand All @@ -23,6 +23,6 @@ protected function onSubmit(array $recipients): void {
->setNoReload((bool)$this->config['no_reload'])
->setPerformanceTracking((bool)$this->config['performance_tracking'])
->setText($this->getText())
->setTo(implode(',', $recipients))));
->setTo(implode(',', $recipients)))));
}
}
}
13 changes: 6 additions & 7 deletions controllers/single_page/dashboard/sms77/bulk_voice.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,24 @@

use Concrete\Core\Page\Page;
use Concrete\Core\User\UserInfoRepository;
use Sms77\Api\Params\VoiceParams;
use Sms77\Concrete5\AbstractMessageController;
use Sms77\Concrete5\VoiceParams;

class BulkVoice extends AbstractMessageController {
final class BulkVoice extends AbstractMessageController {
public function __construct(Page $c, UserInfoRepository $repo) {
parent::__construct($c, $repo, 'voice');
}

protected function onSubmit(array $recipients): void {
protected function onSubmit(array $recipients) {
$params = (new VoiceParams)
->setFrom($this->config['from'])
->setText($this->getText())
->setXml((bool)$this->post('xml', false));

foreach ($recipients as $to) {
$msg[] = $this->encode($this->client->voiceJson($params->setTo($to)));
$msg[] = $this->encode($this->client->voice($params->setTo($to)));
}

$this->set('message',
isset($msg) ? implode(PHP_EOL, $msg) : t('Nothing has been sent.'));
$this->setMessage($msg);
}
}
}
24 changes: 12 additions & 12 deletions install.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?xml version="1.0"?>
<concrete5-cif version="1.0">
<?xml version='1.0'?>
<concrete5-cif version='1.0'>
<attributekeys>
<attributekey
category="user"
handle="phone"
indexed="1"
name="Phone Number"
package="sms77"
profile-editable="1"
register-editable="1"
searchable="1"
type="telephone"
category='user'
handle='phone'
indexed='1'
name='Phone Number'
package='sms77'
profile-editable='1'
register-editable='1'
searchable='1'
type='telephone'
/>
</attributekeys>
</concrete5-cif>
</concrete5-cif>
30 changes: 19 additions & 11 deletions src/AbstractMessageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@

defined('C5_EXECUTE') or die('Access Denied.');

use Concrete\Core\Http\Client\Client;
use Concrete\Core\Page\Page;
use Concrete\Core\User\Group\Group;
use Concrete\Core\User\Group\GroupList;
use Concrete\Core\User\UserInfo;
use Concrete\Core\User\UserInfoRepository;
use Sms77\Api\Client;

abstract class AbstractMessageController extends AbstractSinglePageDashboardController {
public const ALL_GROUPS_ID = -2; // ID used to send to all groups
public static $ALL_GROUPS_ID = -2; // ID used to send to all groups

/** @var UserInfoRepository $repository */
protected $repo;

/** @var Client|null $client */
/** @var ApiClient|null $client */
protected $client;

/** @var string $apiKey */
Expand Down Expand Up @@ -84,15 +84,15 @@ public function on_start(): void {
/** @return void */
public function view(): void {
if (!$this->client) {
$this->set('dashboardLink', Routes::getAbsoluteURL(Routes::DASHBOARD));
$this->set('dashboardLink', Routes::getAbsoluteURL(Routes::$DASHBOARD));
}

$this->set('group', $this->post('group', self::ALL_GROUPS_ID));
$this->set('group', $this->post('group', self::$ALL_GROUPS_ID));
$this->setGroups();
}

private function setGroups(): void {
$groups = [self::ALL_GROUPS_ID => t('All Groups')];
$groups = [self::$ALL_GROUPS_ID => t('All Groups')];

foreach ((new GroupList)->getResults() as $group) {
/** @var Group $group */
Expand All @@ -105,7 +105,7 @@ private function setGroups(): void {
/** @return UserInfo[] */
private function getGroupMembers(): ?array {
$groupId = (int)$this->post('filter_group');
if ($groupId === self::ALL_GROUPS_ID) { // groupID is set to "All"
if ($groupId === self::$ALL_GROUPS_ID) { // groupID is set to "All"
return $this->repo->all(true); // return all active users
}

Expand All @@ -122,9 +122,17 @@ private function getGroupMembers(): ?array {
private function initClient(): void {
if ('' === $this->apiKey) {
$this->error->add(t('An API key is needed for sending.'));
return;
}
else {
$this->client = new Client($this->apiKey, 'concrete5');
}

/** @var Client $client */
$client = $this->app->make('http/client');
$this->client = new ApiClient($client, $this->apiKey);
}

protected function setMessage($msg) {
$this->set('message', isset($msg)
? is_array($msg) ? implode(PHP_EOL, $msg) : $msg
: t('Nothing has been sent.'));
}
}
}
Loading

0 comments on commit 592467a

Please sign in to comment.