diff --git a/src/widgets/Ads.php b/src/widgets/Ads.php
new file mode 100644
index 00000000..b22a573f
--- /dev/null
+++ b/src/widgets/Ads.php
@@ -0,0 +1,157 @@
+ true];
+
+ return $rules;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public static function maxColspan(): ?int
+ {
+ return 1;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public static function isDeletable(): bool
+ {
+ return false;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public static function isLive(): bool
+ {
+ return false;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function minColspan()
+ {
+ return 1;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function getSettingsHtml(): ?string
+ {
+ return Craft::$app->getView()->renderTemplate(
+ 'translations/_components/widgets/AcclaroAds/settings',
+ [ 'widget' => $this ]
+ );
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function getBodyHtml(): ?string
+ {
+ $view = Craft::$app->getView();
+
+ $ads = $this->_getAds();
+
+ return $view->renderTemplate(
+ 'translations/_components/widgets/AcclaroAds/body',
+ ['ads' => $ads]
+ );
+ }
+
+ public static function doesUserHaveWidget(string $type): bool
+ {
+ return WidgetRecord::find()
+ ->where([
+ 'userId' => Craft::$app->getUser()->getIdentity()->id,
+ 'type' => $type,
+ ])
+ ->exists();
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public static function isSelectable(): bool
+ {
+ // Create widget if user visits dashboard for first time.
+ if (!static::doesUserHaveWidget(static::class)) {
+ $widgetRepository = Translations::$plugin->widgetRepository;
+ $adsWidget = $widgetRepository->createWidget(static::class);
+
+ $widgetRepository->saveWidget($adsWidget);
+ }
+ return (static::allowMultipleInstances() || !static::doesUserHaveWidget(static::class));
+ }
+
+ /**
+ * Returns the recent ads to be show in dahboard widget from contants file
+ *
+ * @return array
+ */
+ private function _getAds(): array
+ {
+ return Constants::ADS_CONTENT["dashboard"];
+ }
+
+ /**
+ * Returns whether the widget can be selected more than once.
+ *
+ * @return bool Whether the widget can be selected more than once
+ */
+ protected static function allowMultipleInstances(): bool
+ {
+ return false;
+ }
+}
diff --git a/src/widgets/BaseWidget.php b/src/widgets/BaseWidget.php
new file mode 100644
index 00000000..5ba01ee6
--- /dev/null
+++ b/src/widgets/BaseWidget.php
@@ -0,0 +1,36 @@
+Coverage information for target site entries.";
+ }
+
/**
* @inheritdoc
*/
diff --git a/src/widgets/NewAndModifiedEntries.php b/src/widgets/NewAndModifiedEntries.php
index 1835c5b0..6ce77e4d 100644
--- a/src/widgets/NewAndModifiedEntries.php
+++ b/src/widgets/NewAndModifiedEntries.php
@@ -11,7 +11,6 @@
namespace acclaro\translations\widgets;
use Craft;
-use craft\base\Widget;
use craft\helpers\Json;
use acclaro\translations\records\WidgetRecord;
use acclaro\translations\assetbundles\NewAndModifiedAssets;
@@ -21,7 +20,7 @@
* @package Translations
* @since 1.0.2
*/
-class NewAndModifiedEntries extends Widget
+class NewAndModifiedEntries extends BaseWidget
{
/**
* @inheritdoc
diff --git a/src/widgets/News.php b/src/widgets/News.php
index 4ce467f5..825e5ae7 100644
--- a/src/widgets/News.php
+++ b/src/widgets/News.php
@@ -11,7 +11,6 @@
namespace acclaro\translations\widgets;
use Craft;
-use craft\base\Widget;
use acclaro\translations\Constants;
use acclaro\translations\Translations;
use acclaro\translations\records\WidgetRecord;
@@ -21,7 +20,7 @@
* @package Translations
* @since 1.0.2
*/
-class News extends Widget
+class News extends BaseWidget
{
/**
* @inheritdoc
@@ -61,6 +60,16 @@ public function minColspan()
return 1;
}
+ /**
+ * @inheritdoc
+ */
+ public function getSubtitle(): ?string
+ {
+ return "
";
+ }
+
/**
* @inheritdoc
*/
diff --git a/src/widgets/RecentOrders.php b/src/widgets/RecentOrders.php
index d69fef8d..f1dfe763 100644
--- a/src/widgets/RecentOrders.php
+++ b/src/widgets/RecentOrders.php
@@ -11,7 +11,6 @@
namespace acclaro\translations\widgets;
use Craft;
-use craft\base\Widget;
use acclaro\translations\Translations;
use acclaro\translations\elements\Order;
use acclaro\translations\records\WidgetRecord;
@@ -21,7 +20,7 @@
* @package Translations
* @since 1.0.2
*/
-class RecentOrders extends Widget
+class RecentOrders extends BaseWidget
{
/**
* @inheritdoc
diff --git a/src/widgets/Translators.php b/src/widgets/Translators.php
index e9dc5b09..a3ae63d0 100644
--- a/src/widgets/Translators.php
+++ b/src/widgets/Translators.php
@@ -11,7 +11,6 @@
namespace acclaro\translations\widgets;
use Craft;
-use craft\base\Widget;
use acclaro\translations\records\WidgetRecord;
use acclaro\translations\services\repository\TranslatorRepository;
@@ -20,8 +19,9 @@
* @package Translations
* @since 1.0.2
*/
-class Translators extends Widget
+class Translators extends BaseWidget
{
+ public $limit = 5;
/**
* @inheritdoc
*/
@@ -56,6 +56,17 @@ public function minColspan()
return 1;
}
+ /**
+ * @inheritdoc
+ */
+ public function getSettingsHtml(): ?string
+ {
+ return Craft::$app->getView()->renderTemplate(
+ 'translations/_components/widgets/Translators/settings',
+ [ 'widget' => $this ]
+ );
+ }
+
/**
* @inheritdoc
*/