00001 <?php
00002 Load::commands('generics/mail');
00003
00004
00005
00006
00007 class DigestNotificationssettingsCommand extends CommandBase {
00008
00009
00010
00011 public function get_name() {
00012 return 'digest';
00013 }
00014
00015
00016
00017
00018 public function execute() {
00019 $ret = parent::execute();
00020
00021
00022 $settings = $this->get_instance();
00023 $user = $settings->get_user();
00024 $nots = array();
00025 $dao = NotificationsSettings::create_digest_adapter($settings);
00026 $dao->find();
00027 while($dao->fetch()) {
00028 if ($settings->should_notification_be_processed($dao, NotificationsSettings::TYPE_DIGEST)) {
00029 $n = clone($dao);
00030 $nots[] = $n;
00031 $n->add_sent_as(Notifications::DELIVER_DIGEST);
00032 $cmd = CommandsFactory::create_command($n, 'update', array());
00033 $cmd->execute();
00034 }
00035 }
00036 if (count($nots)) {
00037 $cmd = new MailCommand(
00038 tr('Your %appname Notifications', 'notifications', array('%appname' => Config::get_value(Config::TITLE))),
00039 $user->email,
00040 'notifications/mail/digest',
00041 array(
00042 'notifications' => $nots,
00043 'user' => $user,
00044 'settings' => $settings
00045 )
00046 );
00047 $ret->merge($cmd->execute());
00048 }
00049 if ($ret->is_ok()) {
00050 $settings->digest_last_sent = time();
00051 $ret->merge($settings->update());
00052 }
00053
00054 return $ret;
00055 }
00056 }