Ejemplo n.º 1
0
 public function beforeSave()
 {
     # print_r($this->properties);
     // Устанавливаем теги
     $tags = (array) $this->object->Tags;
     if ($topic_tags = $this->getProperty('topic_tags', array())) {
         if (!is_array($topic_tags)) {
             $topic_tags = array_map('trim', explode(',', $topic_tags));
         }
     }
     # print_r($topic_tags);
     // Преобразуем все теги к нижнему регистру
     $words = array();
     foreach ($topic_tags as $topic_tag) {
         $topic_tag = strip_tags($topic_tag);
         $words[mb_convert_case($topic_tag, MB_CASE_LOWER, 'utf-8')] = $topic_tag;
     }
     // Перебираем уже имеющиеся теги.
     // Отсутствующие снимаем с активности.
     // Имеющиеся активируем.
     foreach ($tags as &$tag) {
         $lower_word = mb_convert_case($tag->tag, MB_CASE_LOWER, 'utf-8');
         if (!array_key_exists($lower_word, $words)) {
             $tag->active = 0;
         } else {
             $tag->active = 1;
             unset($words[$lower_word]);
         }
     }
     // Оставшиеся слова добавляем в виде новых тегов
     foreach ($words as $word) {
         $tags[] = $this->modx->newObject('SocietyTopicTag', array("tag" => $word, "active" => 1));
     }
     $this->object->Tags = $tags;
     $validator = new modWebSocietyTopicsValidator($this);
     $ok = $validator->validate();
     if ($ok !== true) {
         return $ok;
     }
     // return "Debug";
     return parent::beforeSave();
 }
Ejemplo n.º 2
0
 public function beforeSave()
 {
     $topic =& $this->object;
     # $topic->fromArray(array(
     #     "published" => 1,
     #     "publishedon"   => time(),
     #     "createdby"     => $this->modx->user->id,
     # ));
     // Проверяем наличие публикаций за сегодняшний день.
     if (!$this->modx->hasPermission('modxclub.create_unlimited_topics')) {
         $time = strtotime(date('Y-m-d'));
         $q = $this->modx->newQuery($this->classKey);
         $q->where(array("createdby" => $this->modx->user->id, "createdon:>" => $time));
         if ($this->modx->getCount($this->classKey, $q)) {
             return "Вам нельзя публиковать более одного топика в день";
         }
     }
     // Устанавливаем теги
     if ($topic_tags = $this->getProperty('topic_tags', array())) {
         $tags = array();
         if (!is_array($topic_tags)) {
             $topic_tags = array_map('trim', explode(',', $topic_tags));
         }
         foreach ($topic_tags as &$tag) {
             $tag = strip_tags($tag);
             $newTag = $this->modx->newObject('SocietyTopicTag', array("tag" => $tag, "active" => 1));
             $tags[] = $newTag;
         }
         $topic->Tags = $tags;
     }
     parent::beforeSave();
     $validator = new modWebSocietyTopicsValidator($this);
     $ok = $validator->validate();
     if ($ok !== true) {
         return $ok;
     }
     /*
         Ниже все изменено
     */
     # /*
     #     Если указан блог компании, то меняем родителя и шаблон
     # */
     # foreach($topic->TopicBlogs as $TopicBlog){
     #
     #     $blog = $TopicBlog->Blog;
     #
     #     if($blog->template == 27){
     #         $topic->fromArray(array(
     #             "parent"    => $blog->id,
     #             "template"  => 28,
     #
     #         ));
     #     }
     # }
     # $this->modx->log(1, print_r($this->properties, 1));
     # $this->modx->log(1, print_r($this->getProperty('no_send_emails')));
     # return 'debug';
     return !$this->hasErrors();
 }