本文整理汇总了PHP中Notification::getCountByTypeAndUser方法的典型用法代码示例。如果您正苦于以下问题:PHP Notification::getCountByTypeAndUser方法的具体用法?PHP Notification::getCountByTypeAndUser怎么用?PHP Notification::getCountByTypeAndUser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Notification
的用法示例。
在下文中一共展示了Notification::getCountByTypeAndUser方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testRun
/**
* Test if background export job generated csv file,
* check if content of this csv file is correct, and
* finally check if user got notification message that
* his downloads are completed.
*/
public function testRun()
{
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$numberOfUserNotifications = Notification::getCountByTypeAndUser('ExportProcessCompleted', Yii::app()->user->userModel);
$account = new Account();
$account->owner = $super;
$account->name = 'Test Account';
$account->officePhone = '1234567890';
$this->assertTrue($account->save());
$account = new Account();
$account->owner = $super;
$account->name = 'Test Account 2';
$account->officePhone = '1234567899';
$this->assertTrue($account->save());
$account = new Account(false);
$searchForm = new AccountsSearchForm($account);
$dataProvider = ExportTestHelper::makeRedBeanDataProvider($searchForm, 'Account', 0, Yii::app()->user->userModel->id);
$totalItems = $dataProvider->getTotalItemCount();
$this->assertEquals(2, $totalItems);
$exportItem = new ExportItem();
$exportItem->isCompleted = 0;
$exportItem->exportFileType = 'csv';
$exportItem->exportFileName = 'test';
$exportItem->modelClassName = 'Account';
$exportItem->serializedData = serialize($dataProvider);
$this->assertTrue($exportItem->save());
$id = $exportItem->id;
$exportItem->forget();
unset($exportItem);
$job = new ExportJob();
$this->assertTrue($job->run());
$exportItem = ExportItem::getById($id);
$fileModel = $exportItem->exportFileModel;
$this->assertEquals(1, $exportItem->isCompleted);
$this->assertEquals('csv', $exportItem->exportFileType);
$this->assertEquals('test', $exportItem->exportFileName);
$this->assertTrue($fileModel instanceof ExportFileModel);
// Get csv string via regular csv export process(directly, not in background)
// We suppose that csv generated thisway is corrected, this function itself
// is tested in another test.
$data = array();
$rows = $dataProvider->getData();
$modelToExportAdapter = new ModelToExportAdapter($rows[0]);
$headerData = $modelToExportAdapter->getHeaderData();
foreach ($rows as $model) {
$modelToExportAdapter = new ModelToExportAdapter($model);
$data[] = $modelToExportAdapter->getData();
}
$output = ExportItemToCsvFileUtil::export($data, $headerData, 'test.csv', false);
$this->assertEquals($output, $fileModel->fileContent->content);
// Check if user got notification message, and if its type is ExportProcessCompleted
$this->assertEquals($numberOfUserNotifications + 1, Notification::getCountByTypeAndUser('ExportProcessCompleted', Yii::app()->user->userModel));
}
示例2: testRunCaseFive
/**
* Check if only new messages are pulled from dropdown
* Also check case if message will be matched with user/contact/account primary email
*
* @depends testRunCaseFour
*/
public function testRunCaseFive()
{
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$user = User::getByUsername('steve');
Yii::app()->imap->connect();
ContactTestHelper::createContactByNameForOwner('contact', $user);
$contacts = Contact::getByName('contact contactson');
$contacts[0]->primaryEmail->emailAddress = Yii::app()->params['emailTestAccounts']['testEmailAddress'];
$this->assertTrue($contacts[0]->save());
AccountTestHelper::createAccountByNameForOwner('account', $user);
$accounts = Account::getByName('account');
$accounts[0]->primaryEmail->emailAddress = Yii::app()->params['emailTestAccounts']['testEmailAddress'];
$this->assertTrue($accounts[0]->save());
$john = User::getByUsername('john');
$john->primaryEmail->emailAddress = Yii::app()->params['emailTestAccounts']['testEmailAddress'];
$this->assertTrue($john->save());
EmailMessage::deleteAll();
Yii::app()->imap->deleteMessages(true);
// Check if there are no emails in dropbox
$job = new EmailArchivingJob();
$this->assertTrue($job->run());
$this->assertEquals(0, EmailMessage::getCount());
$imapStats = Yii::app()->imap->getMessageBoxStatsDetailed();
$this->assertEquals(0, $imapStats->Nmsgs);
//Now user send email to another user, and to dropbox
$pathToFiles = Yii::getPathOfAlias('application.modules.emailMessages.tests.unit.files');
Yii::app()->emailHelper->sendRawEmail("Email from Steve 3", $user->primaryEmail->emailAddress, array(Yii::app()->params['emailTestAccounts']['testEmailAddress']), 'Email from Steve', '<strong>Email</strong> from Steve', null, array(Yii::app()->imap->imapUsername), null, self::$userMailer);
sleep(30);
$job = new EmailArchivingJob();
$this->assertTrue($job->run());
$imapStats = Yii::app()->imap->getMessageBoxStatsDetailed();
$this->assertEquals(0, $imapStats->Nmsgs);
$this->assertEquals(2, EmailMessage::getCount());
$emailMessages = EmailMessage::getAll();
$emailMessage = $emailMessages[1];
$this->assertEquals('Email from Steve 3', $emailMessage->subject);
$this->assertEquals('Email from Steve', trim($emailMessage->content->textContent));
$this->assertEquals('<!-- zurmo css inline --><strong>Email</strong> from Steve', preg_replace("/\r|\n/", "", $emailMessage->content->htmlContent));
$this->assertEquals($user->primaryEmail->emailAddress, $emailMessage->sender->fromAddress);
$this->assertEquals(1, count($emailMessage->recipients));
$recipient = $emailMessage->recipients[0];
$this->assertCount(3, $recipient->personsOrAccounts);
$this->assertEquals($recipient->toAddress, Yii::app()->params['emailTestAccounts']['testEmailAddress']);
$this->assertEquals(EmailMessageRecipient::TYPE_TO, $recipient->type);
$this->assertEquals(EmailFolder::TYPE_ARCHIVED, $emailMessage->folder->type);
$job = new EmailArchivingJob();
$this->assertTrue($job->run());
$imapStats = Yii::app()->imap->getMessageBoxStatsDetailed();
$this->assertEquals(0, $imapStats->Nmsgs);
$this->assertEquals(2, EmailMessage::getCount());
$this->assertEquals(1, Notification::getCountByTypeAndUser('EmailMessageArchivingEmailAddressNotMatching', $user));
}
示例3: testExportReportWithMultiplePagesOfData
/**
* @depends testExportByModelIds
*/
public function testExportReportWithMultiplePagesOfData()
{
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$numberOfUserNotifications = Notification::getCountByTypeAndUser('ExportProcessCompleted', Yii::app()->user->userModel);
$report = new Report();
$report->setType(Report::TYPE_ROWS_AND_COLUMNS);
$report->setModuleClassName('AccountsModule');
$report->setFiltersStructure('');
$displayAttribute = new DisplayAttributeForReportForm('AccountsModule', 'Account', Report::TYPE_ROWS_AND_COLUMNS);
$displayAttribute->setModelAliasUsingTableAliasName('model1');
$displayAttribute->attributeIndexOrDerivedType = 'name';
$report->addDisplayAttribute($displayAttribute);
$dataProvider = new RowsAndColumnsReportDataProvider($report);
$exportItem = new ExportItem();
$exportItem->isCompleted = 0;
$exportItem->exportFileType = 'csv';
$exportItem->exportFileName = 'rowAndColumnsTest2';
$exportItem->modelClassName = 'SavedReport';
$exportItem->serializedData = ExportUtil::getSerializedDataForExport($dataProvider);
$this->assertTrue($exportItem->save());
$id = $exportItem->id;
$exportItem->forget();
unset($exportItem);
//Delete queued jobs from test exportItems created above
Yii::app()->jobQueue->deleteAll();
ExportModule::$asynchronousPageSize = 2;
$job = new ExportJob();
$this->assertEquals(0, count(Yii::app()->jobQueue->getAll()));
$this->assertTrue($job->run());
$this->assertEquals(0, count(Yii::app()->jobQueue->getAll()));
$exportItem = ExportItem::getById($id);
$fileModel = $exportItem->exportFileModel;
$this->assertEquals(1, $exportItem->isCompleted);
$this->assertEquals(0, $exportItem->processOffset);
$this->assertEquals('csv', $exportItem->exportFileType);
$this->assertEquals('rowAndColumnsTest2', $exportItem->exportFileName);
$this->assertTrue($fileModel instanceof ExportFileModel);
$accounts = Account::getAll();
$headerData = array('Name');
$data = array();
foreach ($accounts as $account) {
$data[] = array($account->name);
}
$output = ExportItemToCsvFileUtil::export($data, $headerData, 'rowAndColumnsTest2.csv', false);
$this->assertEquals($output, $fileModel->fileContent->content);
// Check if user got notification message, and if its type is ExportProcessCompleted
$this->assertEquals($numberOfUserNotifications + 1, Notification::getCountByTypeAndUser('ExportProcessCompleted', Yii::app()->user->userModel));
//Matrix report should not paginate
$report = new Report();
$report->setType(Report::TYPE_MATRIX);
$report->setModuleClassName('AccountsModule');
$report->setFiltersStructure('');
$displayAttribute = new DisplayAttributeForReportForm('AccountsModule', 'Account', Report::TYPE_MATRIX);
$displayAttribute->setModelAliasUsingTableAliasName('model1');
$displayAttribute->attributeIndexOrDerivedType = 'Count';
$report->addDisplayAttribute($displayAttribute);
$groupBy = new GroupByForReportForm('AccountsModule', 'Account', Report::TYPE_MATRIX);
$groupBy->attributeIndexOrDerivedType = 'name';
$groupBy->axis = 'y';
$report->addGroupBy($groupBy);
$groupBy = new GroupByForReportForm('AccountsModule', 'Account', Report::TYPE_MATRIX);
$groupBy->attributeIndexOrDerivedType = 'officePhone';
$report->addGroupBy($groupBy);
$dataProvider = new MatrixReportDataProvider($report);
$exportItem = new ExportItem();
$exportItem->isCompleted = 0;
$exportItem->exportFileType = 'csv';
$exportItem->exportFileName = 'matrixTest1';
$exportItem->modelClassName = 'SavedReport';
$exportItem->serializedData = ExportUtil::getSerializedDataForExport($dataProvider);
$this->assertTrue($exportItem->save());
$id = $exportItem->id;
$exportItem->forget();
unset($exportItem);
//Delete queued jobs from test exportItems created above
Yii::app()->jobQueue->deleteAll();
ExportModule::$asynchronousPageSize = 2;
$job = new ExportJob();
$this->assertTrue($job->run());
$exportItem = ExportItem::getById($id);
$fileModel = $exportItem->exportFileModel;
$this->assertEquals(1, $exportItem->isCompleted);
$this->assertEquals(0, $exportItem->processOffset);
$this->assertEquals('csv', $exportItem->exportFileType);
$this->assertEquals('matrixTest1', $exportItem->exportFileName);
$this->assertTrue($fileModel instanceof ExportFileModel);
$fileContent = $fileModel->fileContent->content;
$this->assertContains('Test Account', $fileContent);
$this->assertContains('Test Account 2', $fileContent);
$this->assertContains('Test Account 3', $fileContent);
$this->assertContains('Test Account 4', $fileContent);
// Check if user got notification message, and if its type is ExportProcessCompleted
$this->assertEquals($numberOfUserNotifications + 2, Notification::getCountByTypeAndUser('ExportProcessCompleted', Yii::app()->user->userModel));
}
示例4: resolveAndGetNotifications
/**
* Resolve and get notifications
* @param array $users
* @param string $type
* @param NotificationMessage $message
* @param bool $allowDuplicates
* @return Notification
*/
protected static function resolveAndGetNotifications($users, $type, NotificationMessage $message, $allowDuplicates)
{
$notifications = array();
foreach ($users as $user) {
//todo: !!!process duplication check
if ($allowDuplicates || Notification::getCountByTypeAndUser($type, $user) == 0) {
$notification = new Notification();
$notification->owner = $user;
$notification->type = $type;
$notification->notificationMessage = $message;
if (static::resolveToSaveNotification()) {
$saved = $notification->save();
if (!$saved) {
throw new NotSupportedException();
}
}
$notifications[] = $notification;
}
}
return $notifications;
}
示例5: testGetCountByTypeAndUser
/**
* @depends testNotificationMessage
*/
public function testGetCountByTypeAndUser()
{
$super = User::getByUsername('super');
$billy = User::getByUsername('billy');
Yii::app()->user->userModel = $super;
$this->assertEquals(0, count(Notification::getAll()));
$notification = new Notification();
$notification->type = 'Simple';
$notification->owner = $super;
$this->assertTrue($notification->save());
$notification = new Notification();
$notification->type = 'Simple';
$notification->owner = $super;
$this->assertTrue($notification->save());
//There are 2 notifications
$this->assertEquals(2, count(Notification::getAll()));
//And 0 notifications unread for billy
$this->assertEquals(0, Notification::getCountByTypeAndUser('Simple', $billy));
//Now add another super notification, but not simple.
$notification = new Notification();
$notification->type = 'Simple2Test';
$notification->owner = $super;
$this->assertTrue($notification->save());
//And there are still 2 notifications for super
$this->assertEquals(2, Notification::getCountByTypeAndUser('Simple', $super));
//Add a notification for billy.
$notification = new Notification();
$notification->type = 'Simple';
$notification->owner = $billy;
$this->assertTrue($notification->save());
//And there is still 1 unread notification for billy
$this->assertEquals(1, Notification::getCountByTypeAndUser('Simple', $billy));
}
示例6: processNotification
protected static function processNotification(NotificationMessage $message, $type, $users, $allowDuplicates, $isCritical)
{
assert('is_string($type) && $type != ""');
assert('is_array($users) && count($users) > 0');
assert('is_bool($allowDuplicates)');
assert('is_bool($isCritical)');
$notifications = array();
foreach ($users as $user) {
//todo: !!!process duplication check
if ($allowDuplicates || Notification::getCountByTypeAndUser($type, $user) == 0) {
$notification = new Notification();
$notification->owner = $user;
$notification->type = $type;
$notification->notificationMessage = $message;
$saved = $notification->save();
if (!$saved) {
throw new NotSupportedException();
}
$notifications[] = $notification;
}
}
if (static::resolveShouldSendEmailIfCritical() && $isCritical) {
foreach ($notifications as $notification) {
static::sendEmail($notification);
}
}
}
示例7: resolveAndGetNotifications
/**
* Resolve and get notifications
* @param NotificationMessage $message
* @param $rules
* @throws NotSupportedException
* @return Notification
*/
protected static function resolveAndGetNotifications(NotificationMessage $message, NotificationRules $rules)
{
$notifications = array();
foreach ($rules->getUsers() as $user) {
//todo: !!!process duplication check
if ($rules->allowDuplicates() || Notification::getCountByTypeAndUser($rules->getType(), $user) == 0) {
$notification = new Notification();
$notification->owner = $user;
$notification->type = $rules->getType();
$notification->notificationMessage = $message;
$notificationSettingName = static::resolveNotificationSettingNameFromType($rules->getType());
if (static::resolveToSaveNotification() && UserNotificationUtil::isEnabledByUserAndNotificationNameAndType($user, $notificationSettingName, 'inbox')) {
$saved = $notification->save();
if (!$saved) {
throw new NotSupportedException();
}
}
$notifications[] = $notification;
}
}
return $notifications;
}
示例8: testRunCaseFive
/**
* Check if only new messages are pulled from dropdown
* Also check case if message will be matched with user primary email
*
* @depends testRunCaseFour
*/
public function testRunCaseFive()
{
if (!EmailMessageTestHelper::isSetEmailAccountsTestConfiguration()) {
$this->markTestSkipped(Zurmo::t('EmailMessagesModule', 'Test email settings are not configured in perInstanceTest.php file.'));
}
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$user = User::getByUsername('steve');
Yii::app()->imap->connect();
$john = User::getByUsername('john');
$john->primaryEmail->emailAddress = Yii::app()->params['emailTestAccounts']['testEmailAddress'];
$this->assertTrue($john->save());
$messages = EmailMessage::getAll();
foreach ($messages as $message) {
$message->delete();
}
Yii::app()->imap->deleteMessages(true);
// Check if there are no emails in dropbox
$job = new EmailArchivingJob();
$this->assertTrue($job->run());
$this->assertEquals(0, count(EmailMessage::getAll()));
$imapStats = Yii::app()->imap->getMessageBoxStatsDetailed();
$this->assertEquals(0, $imapStats->Nmsgs);
//Now user send email to another user, and to dropbox
$pathToFiles = Yii::getPathOfAlias('application.modules.emailMessages.tests.unit.files');
Yii::app()->emailHelper->sendRawEmail("Email from Steve 3", $user->primaryEmail->emailAddress, array(Yii::app()->params['emailTestAccounts']['testEmailAddress']), 'Email from Steve', '<strong>Email</strong> from Steve', null, array(Yii::app()->imap->imapUsername), null, self::$userMailer);
sleep(30);
$job = new EmailArchivingJob();
$this->assertTrue($job->run());
$imapStats = Yii::app()->imap->getMessageBoxStatsDetailed();
$this->assertEquals(0, $imapStats->Nmsgs);
$this->assertEquals(1, count(EmailMessage::getAll()));
$emailMessages = EmailMessage::getAll();
$emailMessage = $emailMessages[0];
$this->assertEquals('Email from Steve 3', $emailMessage->subject);
$this->assertEquals('Email from Steve', trim($emailMessage->content->textContent));
$this->assertEquals('<strong>Email</strong> from Steve', trim($emailMessage->content->htmlContent));
$this->assertEquals($user->primaryEmail->emailAddress, $emailMessage->sender->fromAddress);
$this->assertEquals(1, count($emailMessage->recipients));
foreach ($emailMessage->recipients as $recipient) {
$this->assertEquals($recipient->toAddress, Yii::app()->params['emailTestAccounts']['testEmailAddress']);
$this->assertEquals(EmailMessageRecipient::TYPE_TO, $recipient->type);
}
$this->assertEquals(EmailFolder::TYPE_ARCHIVED, $emailMessage->folder->type);
$job = new EmailArchivingJob();
$this->assertTrue($job->run());
$imapStats = Yii::app()->imap->getMessageBoxStatsDetailed();
$this->assertEquals(0, $imapStats->Nmsgs);
$this->assertEquals(1, count(EmailMessage::getAll()));
$this->assertEquals(1, Notification::getCountByTypeAndUser('EmailMessageArchivingEmailAddressNotMatching', $user));
}