/** * Return activity content by given user. * * This output is generated by current mode. * * @param type $user * @return string */ private function getActivityContent($user) { $receive_email_activities = $user->getSetting("receive_email_activities", 'core', HSetting::Get('receive_email_activities', 'mailing')); // User never wants activity content if ($receive_email_activities == User::RECEIVE_EMAIL_NEVER) { return ""; } // We are in hourly mode and user wants receive a daily summary if ($this->mode == 'hourly' && $receive_email_activities == User::RECEIVE_EMAIL_DAILY_SUMMARY) { return ""; } // We are in daily mode and user wants receive not daily if ($this->mode == 'daily' && $receive_email_activities != User::RECEIVE_EMAIL_DAILY_SUMMARY) { return ""; } // User is online and want only receive when offline if ($this->mode == 'hourly') { $isOnline = count($user->httpSessions) > 0; if ($receive_email_activities == User::RECEIVE_EMAIL_WHEN_OFFLINE && $isOnline) { return ""; } } $lastMailDate = $user->last_activity_email; if ($lastMailDate == "" || $lastMailDate == "0000-00-00 00:00:00") { $lastMailDate = new CDbExpression('NOW() - INTERVAL 24 HOUR'); } $action = new DashboardStreamAction(null, 'console'); $action->limit = 50; $action->mode = BaseStreamAction::MODE_ACTIVITY; $action->user = $user; $action->init(); //$action->criteria->condition .= " AND 1=2"; // Limit results to last activity mail $action->criteria->condition .= " AND wall_entry.created_at > :maxDate"; $action->criteria->params[':maxDate'] = $lastMailDate; $output = ""; foreach ($action->getWallEntries() as $wallEntry) { $output .= $wallEntry->content->getUnderlyingObject()->getMailOut(); } # Save last run $user->last_activity_email = new CDbExpression('NOW()'); $user->save(); // Return Output return $output; }
private function getStreamActionIds($limit = 4) { $action = new DashboardStreamAction(Yii::app()->getController(), 'testAc'); $action->limit = $limit; $action->init(); $wallEntries = $action->getWallEntries(); $wallEntryIds = array_map(create_function('$entry', 'return $entry->id;'), $wallEntries); return $wallEntryIds; }