1<?php
2
3/**
4 * Class ilDclTextFieldRepresentation
5 *
6 * @author  Michael Herren <mh@studer-raimann.ch>
7 * @version 1.0.0
8 */
9class ilDclTextFieldRepresentation extends ilDclBaseFieldRepresentation
10{
11
12    /**
13     * @inheritdoc
14     */
15    public function addFilterInputFieldToTable(ilTable2GUI $table)
16    {
17        $input = $table->addFilterItemByMetaType("filter_" . $this->getField()->getId(), ilTable2GUI::FILTER_TEXT, false, $this->getField()->getId());
18        $input->setSubmitFormOnEnter(true);
19
20        $this->setupFilterInputField($input);
21
22        return $this->getFilterInputFieldValue($input);
23    }
24
25
26    /**
27     * @inheritdoc
28     */
29    public function passThroughFilter(ilDclBaseRecordModel $record, $filter)
30    {
31        $pass = parent::passThroughFilter($record, $filter);
32
33        $value = $record->getRecordFieldValue($this->getField()->getId());
34        if (!$filter || strpos(strtolower($value), strtolower($filter)) !== false) {
35            $pass = true;
36        }
37
38        return $pass;
39    }
40
41
42    /**
43     * @inheritdoc
44     */
45    public function getInputField(ilPropertyFormGUI $form, $record_id = 0)
46    {
47        $input = new ilDclTextInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId());
48        if ($this->getField()->hasProperty(ilDclBaseFieldModel::PROP_TEXTAREA)) {
49            $input = new ilTextAreaInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId());
50        }
51
52        if ($this->getField()->hasProperty(ilDclBaseFieldModel::PROP_LENGTH)) {
53            $input->setInfo($this->lng->txt("dcl_max_text_length") . ": " . $this->getField()->getProperty(ilDclBaseFieldModel::PROP_LENGTH));
54            if (!$this->getField()->getProperty(ilDclBaseFieldModel::PROP_TEXTAREA)) {
55                $input->setMaxLength($this->getField()->getProperty(ilDclBaseFieldModel::PROP_LENGTH));
56            }
57        }
58
59        if ($this->getField()->hasProperty(ilDclBaseFieldModel::PROP_URL)) {
60            $input->setInfo($this->lng->txt('dcl_text_email_detail_desc'));
61            $title_field = new ilDclTextInputGUI($this->lng->txt('dcl_text_email_title'), 'field_' . $this->getField()->getId() . '_title');
62            $title_field->setInfo($this->lng->txt('dcl_text_email_title_info'));
63            $input->addSubItem($title_field);
64        }
65
66        $this->setupInputField($input, $this->getField());
67
68        return $input;
69    }
70
71
72    /**
73     * @inheritDoc
74     */
75    public function buildFieldCreationInput(ilObjDataCollection $dcl, $mode = 'create')
76    {
77        $opt = parent::buildFieldCreationInput($dcl, $mode);
78
79        $prop_length = new ilNumberInputGUI($this->lng->txt('dcl_length'), $this->getPropertyInputFieldId(ilDclBaseFieldModel::PROP_LENGTH));
80        $prop_length->setSize(5);
81        $prop_length->setMaxValue(4000);
82        $prop_length->setInfo($this->lng->txt('dcl_length_info'));
83
84        $opt->addSubItem($prop_length);
85
86        $prop_regex = new ilDclTextInputGUI($this->lng->txt('dcl_regex'), $this->getPropertyInputFieldId(ilDclBaseFieldModel::PROP_REGEX));
87        $prop_regex->setInfo($this->lng->txt('dcl_regex_info'));
88
89        $opt->addSubItem($prop_regex);
90
91        $prop_url = new ilDclCheckboxInputGUI($this->lng->txt('dcl_url'), $this->getPropertyInputFieldId(ilDclBaseFieldModel::PROP_URL));
92        $opt->addSubItem($prop_url);
93
94        $prop_textarea = new ilDclCheckboxInputGUI($this->lng->txt('dcl_text_area'), $this->getPropertyInputFieldId(ilDclBaseFieldModel::PROP_TEXTAREA));
95        $opt->addSubItem($prop_textarea);
96
97        $prop_page_details = new ilDclCheckboxInputGUI($this->lng->txt('dcl_link_detail_page'), $this->getPropertyInputFieldId(ilDclBaseFieldModel::PROP_LINK_DETAIL_PAGE_TEXT));
98        $opt->addSubItem($prop_page_details);
99
100        return $opt;
101    }
102}
103