Source of file ExactOnlineConnection.php
Size: 4,323 Bytes - Last Modified: 2021-12-24T06:50:46+00:00
/var/www/docs.ssmods.com/process/src/src/dataobjects/ExactOnlineConnection.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 | <?php namespace Hestec\ExactOnline; use SilverStripe\ORM\DataObject; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\LiteralField; use SilverStripe\Control\Director; use SilverStripe\ORM\FieldType\DBField; class ExactOnlineConnection extends DataObject { //private static $singular_name = 'Customer'; //private static $plural_name = 'Customers'; private static $table_name = 'ExactOnlineConnection'; private static $db = array( 'OauthCode' => 'Text', 'AccessToken' => 'Text', 'RefreshToken' => 'Text', 'TokenExpires' => 'Varchar(20)' ); private static $summary_fields = array( 'getConnectionTitle' ); public function getConnectionTitle(){ if (strlen($this->AccessToken) > 100 && strlen($this->RefreshToken) > 100){ return DBField::create_field('HTMLText', 'Exact Online <span style="color: green;font-weight: bold;">'._t("ExactOnlineConnection.CONNECTED", "CONNECTED").'</span>, '._t("ExactOnlineConnection.CLICK_HERE_TO_DISCONNECT", "click here to disconnect.")); }else{ return DBField::create_field('HTMLText', 'Exact Online <span style="color: red;font-weight: bold;">'._t("ExactOnlineConnection.NOT_CONNECTED", "NOT CONNECTED").'</span>, '._t("ExactOnlineConnection.CLICK_HERE_TO_CONNECT", "click here to connect.")); } } // Run on dev buld function requireDefaultRecords() { parent::requireDefaultRecords(); if (ExactOnlineConnection::get()->count() == 0){ $connection = new ExactOnlineConnection(); $connection->write(); } } function fieldLabels($includerelations = true) { $labels = parent::fieldLabels($includerelations); $labels['getConnectionTitle'] = ''; return $labels; } public function getCMSFields() { $infoheader = "<p><strong>"._t("ExactOnlineConnection.INSTRUCTIONS", "Instructions").":</strong></p>"; $infostep_1 = "<li>"._t("ExactOnlineConnection.INFOSTEP_1", "Click the CONNECT button.")."</li>"; $infostep_2 = "<li>"._t("ExactOnlineConnection.INFOSTEP_2", "You will be redirected to the Exact Online login screen.")." *</li>"; $infostep_3 = "<li>"._t("ExactOnlineConnection.INFOSTEP_3", "Login with your Exact Online credentials.")." *</li>"; $infostep_4 = "<li>"._t("ExactOnlineConnection.INFOSTEP_4", "When the connection is made, you will be redirected back to the CMS.")."</li>"; $infostep_5 = "<li>"._t("ExactOnlineConnection.INFOSTEP_5", "The status in the CMS will display CONNECTED.")."</li>"; $infostep_6 = "<p>* "._t("ExactOnlineConnection.INFOSTEP_6", "note: when you are already logged in in Exact Online with the same browser, step 2 en 3 are skipped.")."</p>"; $infotext = $infoheader."<ol>".$infostep_1.$infostep_2.$infostep_3.$infostep_4.$infostep_5."</ol>".$infostep_6; $IntroField = LiteralField::create('IntroField', $infotext); //$ClientIdField = TextField::create('ClientId', 'ClientId'); //$ClientSecretField = TextField::create('ClientSecret', 'ClientSecret'); //$WebhookSecretField = TextField::create('WebhookSecret', 'WebhookSecret'); if (strlen($this->AccessToken) < 100 || strlen($this->RefreshToken) < 100) { $ConnectButtonField = LiteralField::create('ConnectButtonField', '<a href="' . Director::absoluteBaseURL() . 'ExactController/Connect" class="btn btn-primary font-icon-save">'._t("ExactOnlineConnection.CONNECT", "CONNECT").'</a>'); }else{ $ConnectButtonField = LiteralField::create('ConnectButtonField', '<a href="' . Director::absoluteBaseURL() . 'ExactController/Disconnect" class="btn btn-primary font-icon-logout">'._t("ExactOnlineConnection.DISCONNECT", "DISCONNECT").'</a>'); } return new FieldList( $IntroField, $ConnectButtonField ); } static function getAuthCode() { $output = ExactOnlineConnection::get()->first(); return $output->OauthCode; } public function canDelete($member = null) { return false; } public function canEdit($member = null) { return false; } public function canView($member = null) { return true; } } |