1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8class Search_ContentSource_BlogPostSource implements Search_ContentSource_Interface, Tiki_Profile_Writer_ReferenceProvider 9{ 10 private $db; 11 12 function __construct() 13 { 14 $this->db = TikiDb::get(); 15 } 16 17 function getReferenceMap() 18 { 19 return [ 20 'blog_id' => 'blog', 21 ]; 22 } 23 24 function getDocuments() 25 { 26 return $this->db->table('tiki_blog_posts')->fetchColumn('postId', []); 27 } 28 29 function getDocument($objectId, Search_Type_Factory_Interface $typeFactory) 30 { 31 $bloglib = TikiLib::lib('blog'); 32 33 $post = $bloglib->get_post($objectId); 34 35 if (! $post) { 36 return false; 37 } 38 39 $data = [ 40 'title' => $typeFactory->sortable($post['title']), 41 'language' => $typeFactory->identifier('unknown'), 42 'creation_date' => $typeFactory->timestamp($post['created']), 43 'modification_date' => $typeFactory->timestamp($post['created']), 44 'date' => $typeFactory->timestamp($post['created']), 45 'contributors' => $typeFactory->multivalue([$post['user']]), 46 47 'blog_id' => $typeFactory->identifier($post['blogId']), 48 'blog_excerpt' => $typeFactory->wikitext($post['excerpt']), 49 'blog_content' => $typeFactory->wikitext($post['data']), 50 51 'parent_object_type' => $typeFactory->identifier('blog'), 52 'parent_object_id' => $typeFactory->identifier($post['blogId']), 53 'view_permission' => $typeFactory->identifier('tiki_p_read_blog'), 54 'parent_view_permission' => $typeFactory->identifier('tiki_p_read_blog'), 55 ]; 56 57 return $data; 58 } 59 60 function getProvidedFields() 61 { 62 return [ 63 'title', 64 'language', 65 'creation_date', 66 'modification_date', 67 'date', 68 'contributors', 69 70 'blog_id', 71 'blog_excerpt', 72 'blog_content', 73 74 'view_permission', 75 'parent_view_permission', 76 'parent_object_id', 77 'parent_object_type', 78 ]; 79 } 80 81 function getGlobalFields() 82 { 83 return [ 84 'title' => true, 85 'date' => true, 86 87 'blog_excerpt' => false, 88 'blog_content' => false, 89 ]; 90 } 91} 92