示例#1
0
 /**
  * @return array|string
  */
 public function cleanup()
 {
     if (!empty($this->_processor)) {
         $this->_processor->cleanup();
         $id = $this->_processor->object->get('id');
         $context_key = $this->_processor->object->get('context_key');
     } else {
         parent::cleanup();
         $id = $this->object->get('id');
         $context_key = $this->object->get('context_key');
     }
     /** @var modContext $context */
     if ($this->getProperty('syncsite') && ($context = $this->modx->getObject('modContext', array('key' => $context_key)))) {
         $context->prepare(true);
         $sessionEnabled = '';
         if (isset($context->config['session_enabled'])) {
             $sessionEnabled = $context->config['session_enabled'] == 0 ? array('preview' => 'true') : '';
         }
         $previewUrl = $context->makeUrl($id, $sessionEnabled, 'full');
     } else {
         $previewUrl = '';
     }
     $get = (require 'get.class.php');
     /** @var mxResourceGetProcessor $processor */
     $processor = new $get($this->modx, array('id' => $id, 'previewUrl' => $previewUrl));
     $processor->initialize();
     return $processor->process();
 }
示例#2
0
 public function beforeSave()
 {
     $cansave = $this->getRelatedObject();
     if ($cansave != true) {
         return $cansave;
     }
     return parent::beforeSave();
 }
示例#3
0
 /** {@inheritDoc} */
 public function clearCache()
 {
     $clear = parent::clearCache();
     /* @var msCategory $category */
     if ($category = $this->object->getOne('Category')) {
         $category->clearCache();
     }
     return $clear;
 }
 public function afterSave()
 {
     $collectionsTemplate = (int) $this->getProperty('collections_template');
     $config = $this->modx->getObject('CollectionSetting', array('collection' => $this->object->id));
     if (!$config) {
         $config = $this->modx->newObject('CollectionSetting');
         $config->set('collection', $this->object->id);
     }
     $config->set('template', $collectionsTemplate);
     $config->save();
     return parent::afterSave();
 }
 /**
  * Create the modResource object for manipulation
  * @return string|modResource
  */
 public function initialize()
 {
     /* get the class_key to determine classKey and resourceDir */
     $classKey = $this->getProperty('class_key', 'modDocument');
     $this->classKey = !empty($classKey) ? $classKey : 'modDocument';
     $initialized = parent::initialize();
     if (!$initialized) {
         return $this->modx->lexicon('resource_err_create');
     }
     if (!$this->object instanceof $this->classKey) {
         return $this->modx->lexicon('resource_err_class', array('class' => $this->classKey));
     }
     return $initialized;
 }
示例#6
0
 /** {@inheritDoc} */
 public function afterSave()
 {
     if ($this->object->alias == 'empty-resource-alias') {
         $this->object->set('alias', $this->object->id);
         $this->object->save();
     }
     // Updating resourceMap before OnDocSaveForm event
     $results = $this->modx->cacheManager->generateContext($this->object->context_key);
     if (isset($results['resourceMap'])) {
         $this->modx->context->resourceMap = $results['resourceMap'];
     }
     if (isset($results['aliasMap'])) {
         $this->modx->context->aliasMap = $results['aliasMap'];
     }
     return parent::afterSave();
 }
示例#7
0
 public function beforeSave()
 {
     $properties = $this->getProperties();
     // Проходимся по каждому указанному блогу
     if ($blogs = $this->getProperty('blogs')) {
         $BlogTopics = array();
         foreach ((array) $blogs as $blog_id) {
             // Проверяем получение блога
             if (!($blog = $this->modx->getObject('SocietyBlog', (int) $blog_id)) or !$blog instanceof SocietyBlog) {
                 // print_r($blog->toArray());
                 return 'Не был получен указанный блог';
             }
             // else
             // Устанавливаем связку Блог-Топик
             $BlogTopic = $this->modx->newObject('SocietyBlogTopic');
             $BlogTopic->addOne($blog);
             $BlogTopics[] = $BlogTopic;
         }
         $this->object->addMany($BlogTopics);
     }
     // Проверяем блоги топика
     if (!($TopicBlogs = $this->object->TopicBlogs)) {
         return "Не был указан ни один блог";
     }
     // Иначе проверяем права на блог
     foreach ($this->object->TopicBlogs as $TopicBlog) {
         $blog = $TopicBlog->Blog;
         if (!$blog instanceof SocietyBlog) {
             return "Публиковать топики можно только в блоги";
         }
         $ok = $this->checkBlogAccess($blog);
         if ($ok !== true) {
             return $ok;
         }
     }
     // Добавляем атрибуты топика
     $attributes = $this->modx->newObject('SocietyTopicAttributes', $properties);
     $this->object->addOne($attributes);
     return parent::beforeSave();
 }
示例#8
0
 public function beforeSave()
 {
     $afterSave = parent::beforeSave();
     // Make sure this is not saved anywhere it shouldn't be
     $parent = $this->modx->getObject('modResource', $this->object->get('parent'));
     if ($parent) {
         $this->modx->log(1, print_r($parent->toArray(), true));
     }
     /*
             if ($parent) {
                 $this->object->setProperties($container->getProperties('articles'),'articles');
             }
     */
     //        $this->isPublishing = $this->object->isDirty('published') && $this->object->get('published');
     return $afterSave;
 }
示例#9
0
 /**
  * Override modResourceCreateProcessor::afterSave to force certain attributes.
  * @return boolean
  */
 public function afterSave()
 {
     $this->object->set('class_key', 'Term');
     $this->object->set('cacheable', true);
     $this->object->set('isfolder', true);
     return parent::afterSave();
 }
示例#10
0
 /**
  * @return mixed
  */
 public function cleanup()
 {
     $this->processFiles();
     return parent::cleanup();
 }
示例#11
0
 public function initialize()
 {
     $this->setProperties(array('class_key' => 'SocietyBlog'));
     return parent::initialize();
 }
示例#12
0
 public function afterSave()
 {
     $this->setProperty('clearCache', true);
     return parent::afterSave();
 }
示例#13
0
 public function afterSave()
 {
     $afterSave = parent::afterSave();
     $this->saveTemplateVariables();
     $this->clearContainerCache();
     if ($this->isPublishing) {
         $this->object->notifyUpdateServices();
         $this->object->sendNotifications();
     }
     return $afterSave;
 }
 /**
  * Override modResourceCreateProcessor::afterSave to provide custom functionality
  * {@inheritDoc}
  * @return boolean
  */
 public function afterSave()
 {
     $this->addContainerId();
     $this->removeFromArchivistIds();
     $this->setProperty('clearCache', true);
     return parent::afterSave();
 }
示例#15
0
 public function afterSave()
 {
     parent::afterSave();
     $topic =& $this->object;
     $can_send_notices = $this->modx->hasPermission('modxclub.send_notices');
     $no_send_emails = $this->getProperty('no_send_emails', false);
     $site_name = $this->modx->getOption('site_name');
     $use_delayed_emails = $this->modx->getOption('modsociety.use_delayed_emails', null, false);
     // Обновляем псевдоним
     # $topic->alias .= " " . $topic->id;
     # $topic->save();
     $this->modx->cacheManager->refresh();
     /*
         Рассылаем уведомления
     */
     if (empty($this->modx->smarty)) {
         $this->modx->invokeEvent('OnHandleRequest');
     }
     $this->modx->smarty->assign('topic', $topic->toArray());
     // Кому уже отправлялось, чтобы не отправлять повторно
     // Сразу добавляем и того, кто пишет
     $sended_to = array($this->modx->user->id);
     #
     # // Не используем этот объект запроса, а только его клоны
     # $users_query = $this->modx->newQuery('modUser');
     #
     # $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->where(array(
     #     "active"    => 1,
     #     "Profile.blocked"   => 0,
     #     "id:not in" => $sended_to,
     # ));
     #
     # $users_query->where(array(
     #     "Profile.blockeduntil"    => 0,
     #     "OR:Profile.blockeduntil:<" => time(),
     # ));
     // Отправляем всем, кто подписан на топики или по выбранный уровням уведомлений
     # if($can_send_notices && !$no_send_emails){
     #     $sended_to = array_unique($sended_to);
     #     $q = clone($users_query);
     #
     #     if($sended_to){
     #         $q->where(array(
     #             "id:not in"    => $sended_to,
     #         ));
     #     }
     #
     #     if(
     #         $notices = $this->getProperty('notices')
     #         AND is_array($notices)
     #     ){
     #         $q->where(array(
     #             "NoticeType.id:in"   => $notices,
     #         ));
     #     }
     #     else{
     #         $q->where(array(
     #             "NoticeType.type"   => "new_topic",
     #         ));
     #     }
     #
     #     # if($users = $this->modx->getCollection('modUser', $q)){
     #         # foreach($users as $user){
     #         foreach($this->modx->getIterator('modUser', $q) as $user){
     #             if($topic->checkPolicy('view', null, $user)){
     #                 $this->modx->smarty->assign('auth_user_id', $user->id);
     #                 $message = $this->modx->smarty->fetch('messages/society/new_topic/subscribers.tpl');
     #                 $subject = "Новый топик на сайте {$site_name}";
     #                 /*
     #                     Пытаемся записать в отложенную рассылку
     #                 */
     #                 if(
     #                     !$use_delayed_emails
     #                     OR !$emailmessage = $this->modx->newObject('SocietyEmailMessage', array(
     #                         "user_id"   => $user->id,
     #                         "subject"   => $subject,
     #                         "message"   => $message,
     #                     ))
     #                     OR !$emailmessage->save()
     #                 ){
     #                     $user->sendEmail($message, array(
     #                         "subject"   => $subject,
     #                     ));
     #                     $this->modx->mail->reset();
     #                 }
     #
     #                 $sended_to[] = $user->id;
     #             }
     #             # else{
     #             #     // Если нет права на топик, сразу добавляем в исключения
     #             #     $sended_to[] = $user->id;
     #             # }
     #         }
     #         $this->modx->smarty->assign('auth_user_id', false);
     #     # }
     # }
     // 1. Администрации
     $q = $this->modx->newQuery('modUser');
     $q->innerJoin('modUserProfile', 'Profile');
     $q->innerJoin('modUserGroupMember', 'UserGroupMembers');
     $q->where(array("active" => 1, "Profile.blocked" => 0, "UserGroupMembers.user_group" => 7, "id:not in" => $sended_to));
     if ($users = $this->modx->getCollection('modUser', $q)) {
         $message = $this->modx->smarty->fetch('messages/society/new_topic/administration.tpl');
         foreach ($users as $user) {
             $user->sendEmail($message, array("subject" => "Новый топик на сайте {$site_name}"));
             $this->modx->mail->reset();
         }
     }
     return true;
 }
示例#16
0
 /**
  * Override modResourceUpdateProcessor::beforeSave to provide custom functionality, saving settings for the container
  * to a custom field in the DB
  * {@inheritDoc}
  * @return boolean
  */
 public function beforeSave()
 {
     $raw = $this->getProperties();
     // <-- this will have raw values
     $properties = $this->object->getProperties('moxycart');
     //<-- we need to update these values
     $this->object->set('class_key', 'Store');
     //$this->modx->log(1,'beforeSave raw values: '.print_r($raw,true));
     //$this->modx->log(1,'beforeSave raw POST values: '.print_r($_POST,true));
     $properties['product_type'] = $this->modx->getOption('product_type', $raw);
     $properties['product_template'] = $this->modx->getOption('product_template', $raw);
     $properties['track_inventory'] = $this->modx->getOption('track_inventory', $raw) == 'Yes' ? 1 : 0;
     $properties['sort_order'] = $this->modx->getOption('sort_order', $raw);
     $properties['qty_alert'] = $this->modx->getOption('qty_alert', $raw);
     $this->object->setProperties($properties, 'moxycart');
     return parent::beforeSave();
 }