public function afterIteration(array $list)
 {
     $list = parent::afterIteration($list);
     // Получаем всех пользователей, кому отправлять рассылку
     $users_query = $this->modx->newQuery('modUser');
     $alias = $users_query->getAlias();
     $users_query->distinct();
     $users_query->innerJoin('modUserProfile', 'Profile');
     $users_query->leftJoin('SocietyNoticeUser', 'Notices');
     $users_query->leftJoin('SocietyNoticeType', 'NoticeType', "NoticeType.target = 'modResource' AND NoticeType.id = Notices.notice_id");
     $users_query->innerJoin('modUserGroupMember', 'UserGroupMembers');
     $users_query->select(array("{$alias}.*", "Profile.email"));
     $users_query->where(array("active" => 1, "Profile.blocked" => 0, "NoticeType.id" => 3));
     # $users_query->where(array(
     #     "UserGroupMembers.user_group"    => '1',
     #     # "id" => 422,
     # ));
     $users_query->where(array("Profile.blockeduntil" => 0, "OR:Profile.blockeduntil:<" => time()));
     # $users_query->prepare();
     # print $users_query->toSQL();
     $date = date('d-m-Y');
     $site_name = $this->modx->getOption('site_name');
     $this->modx->smarty->assign('articles', $list);
     $auth_link_salt = $this->modx->getOption('modsociety.auth_link_salt');
     foreach ($this->modx->getIterator('modUser', $users_query) as $user) {
         # print_r($user->toArray());
         $this->modx->smarty->assign('user', $user);
         $message = $this->modx->smarty->fetch('messages/society/articles/mailling/letter.tpl');
         # print $message;
         # exit;
         $subject = "Рассылка {$site_name} {$date}";
         if ($emailmessage = $this->modx->newObject('SocietyEmailMessage', array("user_id" => $user->id, "subject" => $subject, "message" => $message))) {
             # print_r($emailmessage->toArray());
             # $manager = $modx->getManager();
             // $manager->createObjectContainer('SocietyEmailMessage');
             $emailmessage->save();
         }
     }
     # print_r($users_query->stmt->errorInfo());
     # print $message;
     return $list;
 }
 public function afterIteration(array $data)
 {
     $data = parent::afterIteration($data);
     $can_edit_document = $this->modx->hasPermission('edit_document');
     $can_delete_document = $this->modx->hasPermission('delete_document');
     $can_delete_document = $this->modx->hasPermission('delete_document');
     $can_publish_document = $this->modx->hasPermission('publish_document');
     $can_unpublish_document = $this->modx->hasPermission('unpublish_document');
     $can_change_document_parent = $this->modx->hasPermission('change_document_parent');
     # $can_set_rss = $this->modx->hasPermission('can_set_rss');
     # $can_set_news_list = $this->modx->hasPermission('can_set_news_list');
     foreach ($data as &$d) {
         $menu = array();
         if ($can_edit_document) {
             $menu[] = array('text' => 'Редактировать', 'handler' => 'this.editResource');
         }
         $menu[] = array('text' => 'Просмотр', 'handler' => 'this.showResource');
         if ($d['published']) {
             if ($can_unpublish_document) {
                 $menu[] = array('text' => 'Снять с публикации', 'handler' => 'this.unpublicateResource');
             }
             if ($d['hidemenu']) {
                 $menu[] = array('text' => 'Вывести в ленту', 'handler' => 'this.unhideResource');
             } else {
                 $menu[] = array('text' => 'Скрыть из ленты', 'handler' => 'this.hideResource');
             }
         } else {
             if ($can_publish_document) {
                 $menu[] = array('text' => 'Опубликовать', 'handler' => 'this.publicateResource');
             }
         }
         $menu[] = array('text' => 'Сменить изображение', 'handler' => 'this.changeImage');
         if ($can_delete_document) {
             $menu[] = array('text' => 'Удалить', 'handler' => 'this.deleteResource');
         }
         // Смена раздела
         if ($can_change_document_parent or $d['createdby'] == $this->modx->user->id) {
             $menu[] = array('text' => 'Изменить раздел', 'handler' => 'this.changeSection');
         }
         // Отправка на редактуру
         if ($d['article_status'] == '0' and $d['createdby'] == $this->modx->user->id) {
             $menu[] = array('text' => 'Отправить на редактуру', 'handler' => 'this.sendForRedacting');
         }
         // Смена RSS
         # if(
         #     $can_set_rss
         #     OR $d['createdby'] == $this->modx->user->id
         # ){
         #     if($d['rss']){
         #         $menu[] = array(
         #             'text' => 'Исключить из RSS',
         #             'handler' => 'this.unsetRSS',
         #         );
         #     }
         #     else{
         #         $menu[] = array(
         #             'text' => 'Выгружать в RSS',
         #             'handler' => 'this.setRSS',
         #         );
         #     }
         # }
         // Смена Новостной ленты
         # if(
         #     $can_set_news_list
         #     OR $d['createdby'] == $this->modx->user->id
         # ){
         #     if($d['news_list']){
         #         $menu[] = array(
         #             'text' => 'Исключить из новостной ленты',
         #             'handler' => 'this.unsetNewsList',
         #         );
         #     }
         #     else{
         #         $menu[] = array(
         #             'text' => 'Выводить в новостную ленту',
         #             'handler' => 'this.setNewsList',
         #         );
         #     }
         # }
         # $menu[] = array(
         #     'text' => 'Просмотр',
         #     'handler' => 'this.showResource',
         # );
         // Формируем меню для определенных типов объектов
         if (!empty($d['object_type'])) {
             // Для моделей товаров
             if ($d['object_type'] == 'model') {
                 $menu[] = array('text' => 'Изменить цены', 'handler' => 'this.changeModelPrices');
                 $menu[] = array('text' => 'Изменить картинку', 'handler' => 'this.changeModelImage');
             } else {
                 if ($d['object_type'] == 'product') {
                 }
             }
         }
         $d['menu'] = $menu;
         # $d['content'] = '';
         unset($d['content']);
     }
     # return array();
     return $data;
 }