示例#1
0
 /**
  * @param string[] $tags
  * @return void
  */
 public function registerTags($tags)
 {
     $tags = explode(',', $tags);
     foreach ($tags as $tag_name) {
         $tag = NewsTag::get("NewsTag", "Tag = '" . $tag_name . "'")->first();
         if (!$tag) {
             $tag = new NewsTag();
             $tag->Tag = $tag_name;
             $tag->write();
         }
         $this->addTag($tag);
     }
 }
 /**
  * List of News tags used by articles in this section
  * @return DataList
  **/
 public function getTagList()
 {
     $articleIDs = $this->getArticleList()->column('ID');
     $articleIDs = implode(',', $articleIDs);
     $tags = NewsTag::get()->innerJoin('NewsArticle_Tags', '"NewsTag"."ID"="NewsArticle_Tags"."NewsTagID"')->where("\"NewsArticle_Tags\".\"NewsArticleID\" IN ({$articleIDs})")->sort('Title');
     return $tags;
 }
 /**
  * @return bool|void
  * @internal Il y a un 'implicit' commit de MySQL sur le create table
  * @see      http://dev.mysql.com/doc/refman/5.1/en/implicit-commit.html
  */
 public function up()
 {
     // Ajout de la colonne tag.language_id
     $this->addColumn('tag', 'language_id', 'INT(10) UNSIGNED NOT NULL DEFAULT 1 AFTER id');
     $this->addForeignKey('fk_language_id_tag', 'tag', 'language_id', 'language', 'id', 'cascade', 'cascade');
     $this->dropIndex('tag_index_name', 'tag');
     $this->createIndex('tag_index_name', 'tag', 'name, language_id', true);
     // Ajout de la table translated_news introduisant la version multilingue des textes
     $this->createTable('translated_news', array('id' => 'int(10) UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY', 'news_id' => 'int(10) UNSIGNED NOT NULL', 'language_id' => 'int(10) UNSIGNED NOT NULL', 'title' => 'varchar(255) NOT NULL', 'slug' => 'varchar(255) NOT NULL', 'description' => 'varchar(255)', 'keywords' => 'varchar(255)', 'content' => 'text', 'created_at' => 'datetime NOT NULL', 'updated_at' => 'datetime NOT NULL'), 'ENGINE = InnoDB');
     // clés dans translated_news
     $this->addForeignKey('fk_news_id_translated_news', 'translated_news', 'news_id', 'news', 'id', 'cascade', 'cascade');
     $this->addForeignKey('fk_language_id_translated_news', 'translated_news', 'language_id', 'language', 'id', 'restrict', 'cascade');
     $this->createIndex('idx_title_translated_news', 'translated_news', 'title');
     $this->createIndex('idx_slug_translated_news', 'translated_news', 'slug', true);
     // Ajout de la table d'association translated_news_has_tag
     $this->createTable('translated_news_has_tag', array('translated_news_id' => 'INT(10) UNSIGNED NOT NULL', 'tag_id' => 'INT(10) UNSIGNED NOT NULL'), 'ENGINE = InnoDB');
     // clés dans translated_news_has_tag
     $this->addPrimaryKey('PRIMARY', 'translated_news_has_tag', 'translated_news_id, tag_id');
     $this->addForeignKey('fk_translated_news_id_translated_news_has_tag', 'translated_news_has_tag', 'translated_news_id', 'translated_news', 'id', 'cascade', 'cascade');
     $this->addForeignKey('fk_tag_id_translated_news_has_tag', 'translated_news_has_tag', 'tag_id', 'tag', 'id', 'cascade', 'cascade');
     // Copie des textes depuis news vers translated_news
     /** @var $news News */
     foreach (News::model()->findAll() as $news) {
         $translated = new TranslatedNews();
         $translated->news_id = $news->id;
         $translated->language_id = $news->language_id ? $news->language_id : 1;
         $translated->title = $news->title;
         $translated->slug = $news->slug;
         $translated->description = $news->description;
         $translated->content = $news->content;
         $translated->created_at = $news->created_at;
         $translated->updated_at = $news->updated_at;
         if (!$translated->save()) {
             echo "\nErreur sur save() pour la migration de la news {$news->id}\n";
         }
     }
     // Migration de news_tag vers translated_news_has_tags
     /** @var $translation TranslatedNews */
     foreach (TranslatedNews::model()->findAll() as $translation) {
         /** @var $oldAsso NewsTag */
         // On récupère la news associée à chaque traduction : c'est l'id de cette news qui donne les tags dans news_tag
         // les news en anglais n'ont pas de tags, on corrige ça à la main
         foreach (NewsTag::model()->findAllByAttributes(array('news_id' => $translation->news_id)) as $oldAsso) {
             $newAsso = new TranslatedNewsHasTag();
             $newAsso->tag_id = $oldAsso->tag_id;
             $newAsso->translated_news_id = $translation->id;
             if (!$newAsso->save()) {
                 echo "Erreur sur newAsso->save() pour translated_news_id = {$translation->id} / tag_id = {$oldAsso->tag_id}\n";
             }
             // NB : on ne met par tag.language_id à jour car actuellement, plusieurs tags sont utilisés en fr et en en :
             // PHP, JQuery, etc...
         }
     }
     echo "\nPasser le champ language_id a anglais pour les news en anglais\n";
     echo "Faire pointer les news traduites et les news originales vers la meme news de base\n";
     echo "Penser a corriger les tags pour les articles en anglais\n";
     echo "A faire apres : nettoyer la table news et supprimer comments\n";
 }
 /**
  * Edit the cms fields in the CMS
  *
  * @return FieldList
  */
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->addFieldToTab('Root.Main', DateField::create('DatePublished', 'Enter a published date')->setConfig('dateformat', 'dd-MM-yyyy')->setConfig('dmyseparator', ' ')->setConfig('showcalendar', true));
     $fields->addFieldToTab('Root.Main', $uploadField = new UploadField($name = 'ArticleSummaryImage', $title = 'Upload an article summary image'));
     $fields->addFieldToTab('Root.Main', new HTMLEditorField('Summary', 'Summary'));
     $tagfield = TagField::create('NewsTags', 'News Tags', NewsTag::get(), $this->NewsTags())->setShouldLazyLoad(true)->setCanCreate(true);
     $fields->addFieldToTab('Root.Main', $tagfield);
     return $fields;
 }
 /**
  * getCMSFields
  * @return FieldList
  **/
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->dataFieldByName('Title')->setTitle('Article Title');
     $fields->dataFieldByName('Content')->setTitle('Article Content');
     $config = $this->config();
     // publish date
     $fields->addFieldToTab('Root.Main', DateField::create('PublishDate')->setAttribute('placeholder', $this->dbObject('Created')->Format('M d, Y')), 'Content');
     // tags
     if ($config->enable_tags) {
         $tagSource = function () {
             return NewsTag::get()->map()->toArray();
         };
         $fields->addFieldToTab('Root.Main', ListboxField::create('Tags', 'Tags', $tagSource(), null, null, true)->useAddnew('NewsTag', $tagSource), 'Content');
     }
     // author
     if ($config->author_mode == 'string') {
         $fields->addFieldToTab('Root.Main', TextField::create('Author', 'Author'), 'Content');
     }
     if ($config->author_mode == 'object') {
         $authorSource = function () {
             return NewsAuthor::get()->map('ID', 'Name')->toArray();
         };
         $fields->addFieldToTab('Root.Main', DropdownField::create('NewsAuthorID', 'Author', $authorSource())->useAddNew('NewsAuthor', $authorSource)->setHasEmptyDefault(true), 'Content');
     }
     // featured
     if ($config->enable_featured_articles) {
         $fields->addFieldToTab('Root.Main', CheckboxField::create('Featured', _t('NewsArticle.FEATURED', 'Feature this article')), 'Content');
     }
     // images
     if ($config->enable_images) {
         $fields->addFieldToTab('Root.FilesAndImages', UploadField::create('Image')->setAllowedFileCategories('image')->setAllowedMaxFileNumber(1)->setFolderName($config->get('image_folder')));
     }
     // attachments
     if ($config->enable_attachments) {
         $fields->addFieldToTab('Root.FilesAndImages', UploadField::create('Attachment')->setAllowedFileCategories('doc')->setAllowedMaxFileNumber(1)->setFolderName($config->get('attachment_folder')));
     }
     // summary
     if ($config->enable_summary) {
         $fields->addFieldToTab('Root.Main', HTMLEditorField::create('Summary', 'Article Summary'), 'Content');
     }
     // parent
     $holders = NewsHolder::get();
     if ($holders->count() > 1) {
         $fields->addFieldToTab('Root.Main', DropdownField::create('ParentID', 'News Section', $holders->map()->toArray()), 'Title');
     } else {
         $fields->addFieldToTab('Root.Main', HiddenField::create('ParentID', 'News Section', $holders->first()->ID), 'Title');
     }
     $this->extend('updateArticleCMSFields', $fields);
     return $fields;
 }
 public function show($id = null)
 {
     $tag = self::load_tag($id);
     $this->assign("tag", $tag);
     $page = 1;
     if (isset($_GET['page'])) {
         $page = $_GET['page'];
     }
     $tag_id = mysql_real_escape_string($tag->id);
     $news = NewsTag::paginate("tags.id = '{$tag_id}'", $page, 10);
     $items = array();
     foreach ($news->collection as $newsitem) {
         $items[] = News::find_by_id($newsitem->news->id);
     }
     $news->collection = $items;
     $this->assign("page", $news);
     $this->title = "View Tag";
     $this->render("tag/show.tpl");
 }
 public function Index()
 {
     $this->layout = 'homepage';
     $content = Content::find_by_permalink("index");
     $nextEvent = Event::next_event();
     $news = array();
     if ($nextEvent) {
         $permalink = mysql_real_escape_string($nextEvent->permalink);
         $newsTags = NewsTag::find_all("news.publish_at <= NOW() AND news.published AND tags.permalink = '{$permalink}'", "news.publish_at DESC", 3);
         foreach ($newsTags as $tag) {
             $tag->news->reload();
             $news[] = $tag->news;
         }
     }
     $this->assign("news", $news);
     $this->assign("content", $content);
     $this->assign("next_event", $nextEvent);
     global $config;
     $this->assign("baseurl", $config['forums']['base_url']);
     $this->render("home/index.tpl");
 }
 public function tags($tag = null)
 {
     $tag = self::load_tag($tag);
     $page = 1;
     if (isset($_GET['page'])) {
         $page = $_GET['page'];
     }
     $tag_id = mysql_real_escape_string($tag->id);
     $news = NewsTag::paginate("tags.id = '{$tag_id}' AND news.published = true AND news.publish_at < NOW()", "news.publish_at DESC", $page, 10);
     $items = array();
     foreach ($news->collection as $newsitem) {
         $item = News::find_by_id($newsitem->news->id);
         if (!$item) {
             continue;
         }
         $items[] = $item;
     }
     $news->collection = $items;
     $this->assign("page", $news);
     $this->assign("tag", $tag);
     $this->title = "News :: {$tag->tag}";
     $this->render("news/tags.tpl");
 }
示例#9
0
 public function news($reload = false)
 {
     if ($reload or !$this->news_cache) {
         $id = mysql_real_escape_string($this->id);
         $this->news_cache = NewsTag::find_all("news_tags.tag_id = '{$id}'");
     }
     return $this->news_cache;
 }
示例#10
0
 public function add_tag($tagname)
 {
     $tag = Tag::create_tag($tagname);
     $newstag = new NewsTag();
     $newstag->news_id = $this->id;
     $newstag->tag_id = $tag->id;
     $newstag->save();
 }