/** * @param LexProjectModel $projectModel * @param string $fieldName * @param string $jsonFilePath * @return bool true on success, false otherwise * @throws \Exception */ public static function CreateFromJson($projectModel, $fieldName, $jsonFilePath) { $optionList = new LexOptionListModel($projectModel); $listCode = LexConfig::flexOptionlistCode($fieldName); if (!$optionList->readByProperty('code', $listCode)) { $optionList->name = LexConfig::flexOptionlistName($listCode); $optionList->code = $listCode; $optionList->canDelete = false; $optionList->readFromJson($jsonFilePath); $optionList->write(); return true; } return false; }
/** * Convert a LIFT range to an option list of the right code * Usage example: rangeToOptionList($projectModel, 'grammatical-info', 'Part of Speech', $liftRanges['grammatical-info']) * @param LexiconProjectModel $projectModel * @param string $optionListCode * @param string $optionListName * @param LiftRange $liftRange * @param string $interfaceLang */ public static function rangeToOptionList($projectModel, $optionListCode, $optionListName, $liftRange, $interfaceLang = 'en') { $optionList = new LexOptionListModel($projectModel); $optionList->readByProperty('code', $optionListCode); $optionList->code = $optionListCode; $optionList->name = $optionListName; $optionList->canDelete = false; // start with an empty list $optionList->items->exchangeArray(array()); foreach ($liftRange->rangeElements as $id => $elem) { if ($elem->label && array_key_exists($interfaceLang, $elem->label)) { $label = $elem->label[$interfaceLang]->value; if (isset($elem->abbrev)) { $abbrev = $elem->abbrev[$interfaceLang]->value; } else { $abbrev = null; } $optionListItem = new LexiconOptionListItem($label, $id); $optionListItem->abbreviation = $abbrev; $optionList->items->append($optionListItem); } } $optionList->write(); }
/** * Initialize the optionlists in a project */ public function initializeNewProject() { // setup default option lists $optionList = new LexOptionListModel($this); $listCode = LexiconConfigObj::flexOptionlistCode(LexiconConfigObj::POS); if (!$optionList->readByProperty('code', $listCode)) { $optionList->name = LexiconConfigObj::flexOptionlistName($listCode); $optionList->code = $listCode; $optionList->canDelete = false; $optionList->readFromJson(APPPATH . 'json/languageforge/lexicon/partOfSpeech.json'); $optionList->write(); } /* $optionList = new LexOptionListModel($this); $optionList->name = 'Semantic Domains'; $optionList->code = 'semdom'; $optionList->canDelete = false; $optionList->readFromJson(APPPATH . 'json/languageforge/lexicon/semdom.json'); $optionList->write(); // we should have a default list for every delivered field that is an option list type $optionList = new LexOptionListModel($this); $optionList->name = 'Environments'; $optionList->code = 'environments'; $optionList->canDelete = false; $optionList->readFromJson($environmentsFilePath); $optionList->write(); */ // repeat for other delivered option list types }