ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilBiblAdminFieldGUI.php
Go to the documentation of this file.
1 <?php
2 
9 abstract class ilBiblAdminFieldGUI
10 {
11  use \ILIAS\Modules\OrgUnit\ARHelper\DIC;
12  const CMD_INIT_OVERVIEW_MODELS = 'initOverviewModels';
13  const CMD_INIT_DEFAULT_FIELDS_AND_SORTING = 'initDefaultFieldsAndSorting';
14  const SUBTAB_RIS = 'subtab_ris';
15  const SUBTAB_BIBTEX = 'subtab_bibtex';
16  const FIELD_IDENTIFIER = 'field_id';
17  const DATA_TYPE = 'data_type';
18  const CMD_STANDARD = 'index';
19  const CMD_CANCEL = 'cancel';
20  const CMD_EDIT = 'edit';
21  const CMD_UPDATE = 'update';
22  const CMD_APPLY_FILTER = 'applyFilter';
23  const CMD_RESET_FILTER = 'resetFilter';
24  const CMD_SAVE = 'save';
28  protected $facade;
29 
30 
37  {
38  $this->facade = $facade;
39  }
40 
41 
42  public function executeCommand()
43  {
44  $nextClass = $this->ctrl()->getNextClass();
45  $this->tabs()->activateTab(ilObjBibliographicAdminGUI::TAB_FIELDS);
46  switch ($nextClass) {
47  case strtolower(ilBiblTranslationGUI::class):
48  $this->tabs()->clearTargets();
49  $target = $this->ctrl()->getLinkTarget($this);
50  $this->tabs()->setBackTarget($this->lng()->txt('back'), $target);
51 
52  $field_id = $this->http()->request()->getQueryParams()[self::FIELD_IDENTIFIER];
53  if (!$field_id) {
54  throw new ilException("Field not found");
55  }
56  $this->ctrl()->saveParameter($this, self::FIELD_IDENTIFIER);
57  $field = $this->facade->fieldFactory()->findById($field_id);
58 
59  $gui = new ilBiblTranslationGUI($this->facade, $field);
60  $this->ctrl()->forwardCommand($gui);
61  break;
62 
63  default:
64  $this->performCommand();
65  }
66  }
67 
68 
69  private function initDefaultFieldsAndSorting()
70  {
71  $this->checkPermissionAndFail('write');
72  $tf = new ilBiblTypeFactory();
73  $bib_default_sorting = [
74  'title', 'author',
75  ];
76  $bib = $tf->getInstanceForType(ilBiblTypeFactory::DATA_TYPE_BIBTEX);
77  $ff_bib = new ilBiblFieldFactory($bib);
78  foreach ($bib->getStandardFieldIdentifiers() as $i => $identifier) {
79  $field = $ff_bib->findOrCreateFieldByTypeAndIdentifier($bib->getId(), $identifier);
80  $field->setPosition($i + 1);
81  $field->store();
82  $array_search = array_search($identifier, $bib_default_sorting);
83  if ($array_search !== false) {
84  $field->setPosition((int) $array_search + 1);
85  $ff_bib->forcePosition($field);
86  }
87  }
88  $ris_default_sorting = [
89  'T1', 'AU',
90  ];
91  $ris = $tf->getInstanceForType(ilBiblTypeFactory::DATA_TYPE_RIS);
92  $ff_ris = new ilBiblFieldFactory($ris);
93  foreach ($ris->getStandardFieldIdentifiers() as $i => $identifier) {
94  $field = $ff_ris->findOrCreateFieldByTypeAndIdentifier($ris->getId(), $identifier);
95  $field->setPosition($i + 1);
96  $field->store();
97  $array_search = array_search($identifier, $ris_default_sorting);
98  if ($array_search !== false) {
99  $field->setPosition((int) $array_search + 1);
100  $ff_bib->forcePosition($field);
101  }
102  }
103  $this->ctrl()->redirect($this, self::CMD_STANDARD);
104  }
105 
106 
107  private function initOverviewModels()
108  {
109  $this->checkPermissionAndFail('write');
110  global $DIC;
111  $ilDB = $DIC->database();
112 
113  // TODO fill filetype_id with the correct values
114  if ($ilDB->tableExists('il_bibl_overview_model')) {
115  $type = function ($filetype_string) {
116  if (strtolower($filetype_string) == "bib"
117  || strtolower($filetype_string) == "bibtex"
118  ) {
119  return 2;
120  }
121 
122  return 1;
123  };
124 
125  if (!$ilDB->tableColumnExists('il_bibl_overview_model', 'file_type_id')) {
126  $ilDB->addTableColumn('il_bibl_overview_model', 'file_type_id', array("type" => "integer", 'length' => 4));
127  }
128 
129  $res = $ilDB->query("SELECT * FROM il_bibl_overview_model");
130  while ($d = $ilDB->fetchObject($res)) {
131  $type_id = (int) $type($d->filetype);
132  $ilDB->update(
133  "il_bibl_overview_model",
134  [
135  "file_type_id" => ["integer", $type_id],
136  ],
137  ["ovm_id" => ["integer", $d->ovm_id]]
138  );
139  }
140  // $ilDB->dropTableColumn('il_bibl_overview_model', 'filetype');
141  }
142 
143  $this->ctrl()->redirect($this, self::CMD_STANDARD);
144  }
145 
146 
147  protected function performCommand()
148  {
149  $cmd = $this->ctrl()->getCmd(self::CMD_STANDARD);
150  switch ($cmd) {
151  case self::CMD_STANDARD:
152  case self::CMD_EDIT:
153  case self::CMD_UPDATE:
154  case self::CMD_SAVE:
155  case self::CMD_APPLY_FILTER:
156  case self::CMD_RESET_FILTER:
157  case self::CMD_INIT_OVERVIEW_MODELS:
158  case self::CMD_INIT_DEFAULT_FIELDS_AND_SORTING:
159  if ($this->access()->checkAccess('write', "", $this->facade->iliasRefId())) {
160  $this->{$cmd}();
161  break;
162  } else {
163  ilUtil::sendFailure($this->lng()->txt("no_permission"), true);
164  break;
165  }
166  }
167  }
168 
169 
170  protected function index()
171  {
172  $this->setSubTabs();
173  // Buttons for restoring emthods
174  /*$default_sorting = ilLinkButton::getInstance();
175  $default_sorting->setCaption('init_default_fields');
176  $default_sorting->setUrl($this->ctrl()->getLinkTarget($this, self::CMD_INIT_DEFAULT_FIELDS_AND_SORTING));
177  $this->toolbar()->addButtonInstance($default_sorting);*/
178 
179  // Buttons for restoring emthods
180  /*$overview_models = ilLinkButton::getInstance();
181  $overview_models->setCaption('init_overview_models');
182  $overview_models->setUrl($this->ctrl()->getLinkTarget($this, self::CMD_INIT_OVERVIEW_MODELS));
183  $this->toolbar()->addButtonInstance($overview_models);*/
184 
185  $ilBiblAdminFieldTableGUI = new ilBiblAdminFieldTableGUI($this, $this->facade);
186  $this->tpl()->setContent($ilBiblAdminFieldTableGUI->getHTML());
187  }
188 
189 
190  protected function setSubTabs()
191  {
192  $this->tabs()->addSubTab(
193  self::SUBTAB_RIS,
194  $this->lng()->txt('ris'),
195  $this->ctrl()->getLinkTargetByClass(
196  array(
197  ilObjBibliographicAdminGUI::class, ilBiblAdminRisFieldGUI::class,
198  ),
200  )
201  );
202  $this->tabs()->activateSubTab(self::SUBTAB_RIS);
203 
204  $this->tabs()->addSubTab(
205  self::SUBTAB_BIBTEX,
206  $this->lng()->txt('bibtex'),
207  $this->ctrl()->getLinkTargetByClass(
208  array(
209  ilObjBibliographicAdminGUI::class, ilBiblAdminBibtexFieldGUI::class,
210  ),
212  )
213  );
214  switch ($this->facade->type()->getId()) {
216  $this->tabs()->activateSubTab(self::SUBTAB_BIBTEX);
217  break;
219  $this->tabs()->activateSubTab(self::SUBTAB_RIS);
220  break;
221  }
222  }
223 
224 
225  protected function save()
226  {
227  foreach ($_POST['position'] as $set) {
228  $field_id = (int) key($set);
229  $position = (int) current($set);
230 
231  $ilBiblField = $this->facade->fieldFactory()->findById((int) $field_id);
232  $ilBiblField->setPosition((int) $position);
233  $ilBiblField->store();
234  }
235 
236  ilUtil::sendSuccess($this->lng()->txt("changes_successfully_saved"));
237  $this->ctrl()->redirect($this, self::CMD_STANDARD);
238  }
239 
240 
241  protected function applyFilter()
242  {
243  $ilBiblAdminFieldTableGUI = new ilBiblAdminFieldTableGUI($this, $this->facade);
244  $ilBiblAdminFieldTableGUI->writeFilterToSession();
245  $this->ctrl()->redirect($this, self::CMD_STANDARD);
246  }
247 
248 
249  protected function resetFilter()
250  {
251  $ilBiblAdminFieldTableGUI = new ilBiblAdminFieldTableGUI($this, $this->facade);
252  $ilBiblAdminFieldTableGUI->resetFilter();
253  $ilBiblAdminFieldTableGUI->resetOffset();
254  $this->ctrl()->redirect($this, self::CMD_STANDARD);
255  }
256 }
Class ilBiblTypeFactory.
$type
global $DIC
Definition: saml.php:7
Class ilBiblTranslationGUI.
Class ilBiblAdminFieldGUI.
static http()
Fetches the global http state from ILIAS.
foreach($_POST as $key=> $value) $res
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
Class ilBiblAdminFieldTableGUI.
__construct(ilBiblAdminFactoryFacadeInterface $facade)
ilBiblAdminFieldGUI constructor.
Class ilBiblFieldFactory.
global $ilDB
$ris
Definition: simple_test.php:17
$i
Definition: disco.tpl.php:19
$target
Definition: test.php:19
$_POST["username"]
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296