machour / yii2-google-gmail
适用于官方 GMail Api v1 的数据提供者、小部件和助手
dev-master
2015-10-24 00:00 UTC
Requires
- google/apiclient: 1.*
- yiisoft/yii2: ~2
Suggests
- machour/yii2-google-apiclient: Allow you to connect easily to the GMail API
This package is auto-updated.
Last update: 2024-09-16 03:14:03 UTC
README
适用于官方 GMail Api v1 的数据提供者、小部件和助手。
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一
php composer.phar require --prefer-dist machour/yii2-google-gmail "*"
或者
"machour/yii2-google-gmail": "*"
将以下内容添加到你的 composer.json
文件的 require 部分中。
用法
在网格中显示你的最新线程
控制器
public function actionIndex() { $pagination = new Pagination(); $dataProvider = new GmailThreadDataProvider([ // Service must be a Google_Service_Gmail instance // Here, machour/yii2-google-apiclient is used to get that instance 'service' => Yii::$app->gmail->getService(), 'pagination' => $pagination, ]); $pagination->totalCount = $dataProvider->getTotalCount(); return $this->render('index', [ 'dataProvider' => $dataProvider ]); }
视图文件
use machour\yii2\google\gmail\widgets\GmailGridView; use machour\yii2\google\gmail\helpers\GmailHelper as GH; use yii\bootstrap\Html; echo GmailGridView::widget([ 'dataProvider' => $dataProvider, 'columns' => [ [ 'attribute' => 'date', 'value' => function ($thread, $key, $index, $widget) { /** @var Google_Service_Gmail_Thread $thread */ return GH::getMessageHeader(GH::getThreadLastMessage($thread), 'Date'); } ], [ 'attribute' => 'sender', 'value' => function ($thread, $key, $index, $widget) { /** @var Google_Service_Gmail_Thread $thread */ return GH::getThreadLastParticipant($thread); } ], [ 'attribute' => 'subject', 'value' => function ($thread, $key, $index, $widget) { /** @var Google_Service_Gmail_Thread $thread */ $subject = GH::getThreadSubject($thread); if (!$subject) { $subject = '<i>' . Yii::t('app', 'No subject') . '</i>'; } return $subject; }, 'format' => 'html', ], [ 'attribute' => 'Number of messages', 'value' => function ($thread, $key, $index, $widget) { /** @var Google_Service_Gmail_Thread $thread */ return GH::getThreadMessagesCount($thread); } ], [ 'attribute' => 'Actions', 'value' => function ($thread, $key, $index, $widget) { /** @var Google_Service_Gmail_Thread $thread */ return Html::a('View thread', ['gmail/thread', 'id' => $thread->getId()]); }, 'format' => 'html', ] ], ]);