/**
  * 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
 }
 /**
  * @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();
 }
 public function testLiftImportMerge_ExistingData_RangesChanged()
 {
     $liftFilePath = self::$environ->createTestLiftFile(self::liftWithRangesV0_13, 'LiftWithRangesV0_13.lift');
     self::$environ->createTestLiftFile(self::liftRangesV0_13, 'TestLangProj.lift-ranges');
     $project = self::$environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $mergeRule = LiftMergeRule::IMPORT_WINS;
     $skipSameModTime = false;
     LiftImport::get()->merge($liftFilePath, $project, $mergeRule, $skipSameModTime);
     $optionList = new LexOptionListModel($project);
     $optionList->readByProperty('code', LexConfig::flexOptionlistCode(LexConfig::POS));
     $this->assertEquals(3, $optionList->items->count());
     $this->assertEquals('article', $optionList->items[0]->value);
     self::$environ->createTestLiftFile(self::liftRangesAnotherPosV0_13, 'TestLangProj.lift-ranges');
     $importer = LiftImport::get()->merge($liftFilePath, $project, $mergeRule, $skipSameModTime);
     $this->assertEquals(1, $importer->stats->existingEntries);
     $optionList = new LexOptionListModel($project);
     $optionList->readByProperty('code', LexConfig::flexOptionlistCode(LexConfig::ANTHROPOLOGYCATEGORIES));
     $this->assertEquals(0, $optionList->items->count());
     $optionList->readByProperty('code', LexConfig::flexOptionlistCode(LexConfig::STATUS));
     $this->assertEquals(4, $optionList->items->count());
     $optionList->readByProperty('code', LexConfig::flexOptionlistCode(LexConfig::ACADEMICDOMAINS));
     $this->assertEquals(2, $optionList->items->count());
     $optionList->readByProperty('code', LexConfig::flexOptionlistCode(LexConfig::POS));
     $this->assertEquals(1, $optionList->items->count());
     $this->assertEquals('adjunct', $optionList->items[0]->value);
 }