Passed
Push — master ( 6e4405...4199c0 )
by Marco
04:48
created

SearchSynonym::getCombinedSynonym()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * class SearchSynonym|Firesphere\SolrSearch\Models\SearchSynonym Object for handling synonyms from the CMS
4
 *
5
 * @package Firesphere\SolrSearch\Models
6
 * @author Simon `Firesphere` Erkelens; Marco `Sheepy` Hermo
7
 * @copyright Copyright (c) 2018 - now() Firesphere & Sheepy
8
 */
9
10
namespace Firesphere\SolrSearch\Models;
11
12
use SilverStripe\Forms\FieldList;
13
use SilverStripe\ORM\DataObject;
14
15
/**
16
 * Class \Firesphere\SolrSearch\Models\SearchSynonym
17
 * Manageable synonyms in the CMS
18
 *
19
 * @package Firesphere\SolrSearch\Models
20
 * @property string $Keyword
21
 * @property string $Synonym
22
 */
23
class SearchSynonym extends DataObject
24
{
25
    /**
26
     * @var string Table name
27
     */
28
    private static $table_name = 'SearchSynonym';
29
30
    /**
31
     * @var string Singular name
32
     */
33
    private static $singular_name = 'Search synonym';
34
35
    /**
36
     * @var string Plural name
37
     */
38
    private static $plural_name = 'Search synonyms';
39
40
    /**
41
     * @var array DB Fields
42
     */
43
    private static $db = [
44
        'Keyword' => 'Varchar(255)',
45
        'Synonym' => 'Text'
46
    ];
47
48
    /**
49
     * @var array Summary fields
50
     */
51
    private static $summary_fields = [
52
        'Keyword',
53
        'Synonym'
54
    ];
55
56
    /**
57
     * Get the required CMS Fields for this synonym
58
     *
59
     * @return FieldList
60
     */
61 1
    public function getCMSFields()
62
    {
63 1
        $fields = parent::getCMSFields();
64
65 1
        $fields->dataFieldByName('Synonym')->setDescription(
66 1
            _t(
67 1
                __CLASS__ . '.SYNONYM',
68 1
                'Create synonyms for a given keyword, add as many synonyms comma separated.'
69
            )
70
        );
71
72 1
        return $fields;
73
    }
74
75
    /**
76
     * Combine this synonym in to a string for the Solr synonyms.txt file
77
     *
78
     * @return string
79
     */
80 1
    public function getCombinedSynonym()
81
    {
82 1
        return sprintf("\n%s,%s", $this->Keyword, $this->Synonym);
83
    }
84
}
85