\n";
$this->showFormButtons($options);
return true;
}
/**
* Get a translation for a value
*
* @param $item item to translate
* @param $field field to return (default 'name')
*
* @return the field translated if a translation is available, or the original field if not
**/
static function getTranslatedValue(KnowbaseItem $item, $field="name") {
global $DB;
$obj = new self;
$found = $obj->find("`knowbaseitems_id` = '".$item->getID().
"' AND `language` = '".$_SESSION['glpilanguage']."'");
if ((count($found) > 0)
&& in_array($field, array('name', 'answer'))) {
$first = array_shift($found);
return $first[$field];
}
return $item->fields[$field];
}
/**
* Is kb item translation functionnality active
*
* @return true if active, false if not
**/
static function isKbTranslationActive() {
global $CFG_GLPI;
return $CFG_GLPI['translate_kb'];
}
/**
* Check if an item can be translated
* It be translated if translation if globally on and item is an instance of CommonDropdown
* or CommonTreeDropdown and if translation is enabled for this class
*
* @param item the item to check
*
* @return true if item can be translated, false otherwise
**/
static function canBeTranslated(CommonGLPI $item) {
return (self::isKbTranslationActive()
&& $item instanceof KnowbaseItem);
}
/**
* Return the number of translations for an item
*
* @param item
*
* @return the number of translations for this item
**/
static function getNumberOfTranslationsForItem($item) {
return countElementsInTable(getTableForItemType(__CLASS__),
"`knowbaseitems_id`='".$item->getID()."'");
}
/**
* Get already translated languages for item
*
* @param item
*
* @return array of already translated languages
**/
static function getAlreadyTranslatedForItem($item) {
global $DB;
$tab = array();
foreach ($DB->request(getTableForItemType(__CLASS__),
"`knowbaseitems_id`='".$item->getID()."'") as $data) {
$tab[$data['language']] = $data['language'];
}
return $tab;
}
}
?>