Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
feat(package): add display preferences
Browse files Browse the repository at this point in the history
and fix display of icon in list

Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry authored and DIOHz0r committed May 8, 2018
1 parent 9c23914 commit 4290a52
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 17 deletions.
30 changes: 24 additions & 6 deletions inc/package.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function prepareInputForAdd($input) {
}
try {
$uploadedFile = $preparedFile['uploadedFile'];
$input['filename'] = 'flyvemdm/package/' . $this->fields['entities_id'] . '/' . uniqid() . '_' . basename($uploadedFile);
$input['filename'] = 'flyvemdm/package/' . $input['entities_id'] . '/' . uniqid() . '_' . basename($uploadedFile);
$destination = GLPI_PLUGIN_DOC_DIR . '/' . $input['filename'];
$this->createEntityDirectory(dirname($destination));
if (rename($uploadedFile, $destination)) {
Expand Down Expand Up @@ -350,11 +350,6 @@ protected function createEntityDirectory($dir) {
public function getSearchOptionsNew() {
$tab = parent::getSearchOptionsNew();

$tab[0] = [
'id' => 'common',
'name' => __s('Package', 'flyvemdm'),
];

$tab[] = [
'id' => '2',
'table' => $this->getTable(),
Expand Down Expand Up @@ -693,4 +688,27 @@ protected function addExtraFileInfo() {
$this->fields['filesize'] = ($isFile) ? fileSize($filename) : 0;
$this->fields['mime_type'] = ($isFile) ? mime_content_type($filename) : '';
}

/**
* Define how to display a specific value in search result table
*
* @param string $field Name of the field as define in $this->getSearchOptions()
* @param string $values The value as it is stored in DB
* @param array $options Options (optional)
* @return string Value to be displayed
*/
public static function getSpecificValueToDisplay($field, $values, array $options = []) {
if (!is_array($values)) {
$values = [$field => $values];
}
switch ($field) {
case 'icon':
if (!isAPI()) {
$output = '<img style="height: 14px" src="data:image/png;base64,'. $values[$field] .'">';
return $output;
}
break;
}
return parent::getSpecificValueToDisplay($field, $values, $options);
}
}
57 changes: 46 additions & 11 deletions install/installer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -879,52 +879,87 @@ protected function deleteRelations() {
protected function createDisplayPreferences() {
$displayPreference = new DisplayPreference();
$itemtype = PluginFlyvemdmFile::class;
$rank = 1;
$criteria = "`itemtype` = '$itemtype' AND `num` = '1' AND `users_id` = '0'";
if (count($displayPreference->find($criteria)) == 0) {
$displayPreference->add([
'itemtype' => PluginFlyvemdmFile::class,
'itemtype' => $itemtype,
'num' => '1',
'rank' => '1',
'rank' => $rank,
User::getForeignKeyField() => '0'
]);
}
$rank++;
$criteria = "`itemtype` = '$itemtype' AND `num` = '4' AND `users_id` = '0'";
if (count($displayPreference->find($criteria)) == 0) {
$displayPreference->add([
'itemtype' => PluginFlyvemdmFile::class,
'itemtype' => $itemtype,
'num' => '4',
'rank' => '2',
'rank' => $rank,
User::getForeignKeyField() => '0'
]);
}

$itemtype = PluginFlyvemdmInvitation::class;
$rank = 1;
$criteria = "`itemtype` = '$itemtype' AND `num` = '3' AND `users_id` = '0'";
if (count($displayPreference->find($criteria)) == 0) {
$displayPreference->add([
'itemtype' => PluginFlyvemdmInvitation::class,
'itemtype' => $itemtype,
'num' => '3',
'rank' => '2',
'rank' => $rank,
User::getForeignKeyField() => '0'
]);
}

$rank++;
$criteria = "`itemtype` = '$itemtype' AND `num` = '4' AND `users_id` = '0'";
if (count($displayPreference->find($criteria)) == 0) {
$displayPreference->add([
'itemtype' => PluginFlyvemdmInvitation::class,
'itemtype' => $itemtype,
'num' => '4',
'rank' => '2',
'rank' => $rank,
User::getForeignKeyField() => '0'
]);
}
$rank++;
$criteria = "`itemtype` = '$itemtype' AND `num` = '5' AND `users_id` = '0'";
if (count($displayPreference->find($criteria)) == 0) {
$displayPreference->add([
'itemtype' => $itemtype,
'num' => '5',
'rank' => $rank,
User::getForeignKeyField() => '0'
]);
}

$itemtype = PluginFlyvemdmPackage::class;
$rank = 1;
$criteria = "`itemtype` = '$itemtype' AND `num` = '3' AND `users_id` = '0'";
if (count($displayPreference->find($criteria)) == 0) {
$displayPreference->add([
'itemtype' => $itemtype,
'num' => '3',
'rank' => $rank,
User::getForeignKeyField() => '0'
]);
}
$rank++;
$criteria = "`itemtype` = '$itemtype' AND `num` = '4' AND `users_id` = '0'";
if (count($displayPreference->find($criteria)) == 0) {
$displayPreference->add([
'itemtype' => $itemtype,
'num' => '4',
'rank' => $rank,
User::getForeignKeyField() => '0'
]);
}
$rank++;
$criteria = "`itemtype` = '$itemtype' AND `num` = '5' AND `users_id` = '0'";
if (count($displayPreference->find($criteria)) == 0) {
$displayPreference->add([
'itemtype' => PluginFlyvemdmInvitation::class,
'itemtype' => $itemtype,
'num' => '5',
'rank' => '2',
'rank' => $rank,
User::getForeignKeyField() => '0'
]);
}
Expand Down

0 comments on commit 4290a52

Please sign in to comment.