Issues (50)

src/Models/SearchSynonym.php (4 issues)

Severity
1
<?php
2
/**
3
 *
4
 * @package Firesphere\Search\Search
5
 * @author Simon `Firesphere` Erkelens; Marco `Sheepy` Hermo
6
 * @copyright Copyright (c) 2018 - now() Firesphere & Sheepy
7
 */
8
9
namespace Firesphere\SearchBackend\Models;
10
11
use SilverStripe\Forms\FieldList;
12
use SilverStripe\ORM\DataObject;
13
14
/**
15
 * Class \Firesphere\SearchBackend\Models\SearchSynonym
16
 *
17
 * @property string $Keyword
18
 * @property string $Synonym
19
 */
20
class SearchSynonym extends DataObject
21
{
22
    /**
23
     * @var string Table name
24
     */
25
    private static $table_name = 'SearchSynonym';
26
27
    /**
28
     * @var string Singular name
29
     */
30
    private static $singular_name = 'Search synonym';
0 ignored issues
show
The private property $singular_name is not used, and could be removed.
Loading history...
31
32
    /**
33
     * @var string Plural name
34
     */
35
    private static $plural_name = 'Search synonyms';
0 ignored issues
show
The private property $plural_name is not used, and could be removed.
Loading history...
36
37
    /**
38
     * @var array DB Fields
39
     */
40
    private static $db = [
0 ignored issues
show
The private property $db is not used, and could be removed.
Loading history...
41
        'Keyword' => 'Varchar(255)',
42
        'Synonym' => 'Text'
43
    ];
44
45
    /**
46
     * @var array Summary fields
47
     */
48
    private static $summary_fields = [
0 ignored issues
show
The private property $summary_fields is not used, and could be removed.
Loading history...
49
        'Keyword',
50
        'Synonym'
51
    ];
52
53
    /**
54
     * Get the required CMS Fields for this synonym
55
     *
56
     * @return FieldList
57
     */
58
    public function getCMSFields()
59
    {
60
        $fields = parent::getCMSFields();
61
62
        $fields->dataFieldByName('Synonym')->setDescription(
63
            _t(
64
                __CLASS__ . '.SYNONYM',
65
                'Create synonyms for a given keyword, add as many synonyms comma separated.'
66
            )
67
        );
68
69
        return $fields;
70
    }
71
72
    /**
73
     * Combine this synonym in to a string for the synonyms, like Solr synonyms.txt file
74
     *
75
     * @return string
76
     */
77
    public function getCombinedSynonym()
78
    {
79
        return sprintf("%s,%s", $this->Keyword, $this->Synonym);
80
    }
81
82
    /**
83
     * Get an ID for usage as reference, e.g. in Solr.
84
     * Using the Table name as an identifier from the Base synonyms
85
     * @return string
86
     */
87
    public function getModifiedID(): string
88
    {
89
        return sprintf("%s-%s", self::$table_name, $this->ID);
90
    }
91
}
92