Ejemplo n.º 1
0
 /**
  * Updates the given LexEntry in $projectId
  * @param string $projectId
  * @param array $params
  * @param string $userId
  * @return LexEntryModel
  */
 public static function updateEntry($projectId, $params, $userId)
 {
     CodeGuard::checkTypeAndThrow($params, 'array');
     $project = new LexiconProjectModel($projectId);
     if (array_key_exists('id', $params) && $params['id'] != '') {
         $entry = new LexEntryModel($project, $params['id']);
         $action = 'update';
     } else {
         $entry = new LexEntryModel($project);
         $entry->authorInfo->createdByUserRef->id = $userId;
         $entry->authorInfo->createdDate = new \DateTime();
         $action = 'create';
         // TODO: Consider adding more specific activity entry: which fields were modified? 2014-09-03 RM
         // E.g., "User _____ updated entry _____ by adding a new sense with definition ______"
     }
     // set authorInfo
     $entry->authorInfo->modifiedDate = new \DateTime();
     $entry->authorInfo->modifiedByUserRef->id = $userId;
     $params = self::recursiveRemoveEmptyFieldValues($params);
     //$params = self::recursiveAlignCustomFieldsWithModel($params);
     JsonDecoder::decode($entry, $params);
     $entry->write();
     ActivityCommands::writeEntry($project, $userId, $entry, $action);
     return JsonEncoder::encode($entry);
 }
 public static function updateComment($projectId, $userId, $website, $params)
 {
     CodeGuard::checkTypeAndThrow($params, 'array');
     $project = new LexiconProjectModel($projectId);
     $rightsHelper = new RightsHelper($userId, $project, $website);
     $isNew = $params['id'] == '';
     if ($isNew) {
         $comment = new LexCommentModel($project);
     } else {
         $comment = new LexCommentModel($project, $params['id']);
         if ($comment->authorInfo->createdByUserRef->asString() != $userId && !$rightsHelper->userHasProjectRight(Domain::COMMENTS + Operation::EDIT)) {
             throw new \Exception("No permission to update other people's lex comments!");
         }
         // don't allow setting these on update
         unset($params['regarding']);
         unset($params['entryRef']);
     }
     JsonDecoder::decode($comment, $params);
     if ($isNew) {
         $comment->authorInfo->createdByUserRef->id = $userId;
         $comment->authorInfo->createdDate = new \DateTime();
     }
     $comment->authorInfo->modifiedByUserRef->id = $userId;
     $comment->authorInfo->modifiedDate = new \DateTime();
     return $comment->write();
 }
 /**
  * Updates semantic domain working set
  * @param array $data
  * @param string $projectId
  * @return string
  */
 public static function update($data, $projectId)
 {
     $projectModel = new SemDomTransProjectModel($projectId);
     $s = new SemDomTransWorkingSetModel($projectModel);
     JsonDecoder::decode($s, $data);
     $s->write();
     return $s->id->asString();
 }
 public static function updateTemplate($projectId, $params)
 {
     $projectModel = new ProjectModel($projectId);
     $questionTemplate = new QuestionTemplateModel($projectModel);
     JsonDecoder::decode($questionTemplate, $params);
     $result = $questionTemplate->write();
     return $result;
 }
Ejemplo n.º 5
0
 public function testEncodeDecode_Same()
 {
     $model = new TestJsonDateModel();
     $encoded = JsonEncoder::encode($model);
     $this->assertIsA($encoded['date'], 'string');
     //         var_dump($encoded);
     $otherModel = new TestJsonDateModel();
     JsonDecoder::decode($otherModel, $encoded);
     $iso8601 = $otherModel->date->format(DateTime::ISO8601);
     $this->assertEqual($encoded['date'], $iso8601);
     //         var_dump($iso8601);
 }
 /**
  * Update the optionlist with params
  * @param $projectId
  * @param LexOptionListModel $params
  */
 public static function updateList($projectId, $params)
 {
     CodeGuard::checkTypeAndThrow($params, 'array');
     $project = new LexiconProjectModel($projectId);
     if (array_key_exists('id', $params) && $params['id'] != '') {
         $optionlist = new LexOptionListModel($project, $params['id']);
     } else {
         $optionlist = new LexOptionListModel($project);
     }
     JsonDecoder::decode($optionlist, $params);
     $optionlist->write();
 }
 /**
  * Create or update project
  * @param string $projectId
  * @param string $userId
  * @param array<projectModel> $object
  * @throws UserUnauthorizedException
  * @throws \Exception
  * @return string projectId
  */
 public static function updateProject($projectId, $userId, $object)
 {
     $project = new LexiconProjectModel($projectId);
     if (!$project->hasRight($userId, Domain::USERS + Operation::EDIT)) {
         throw new UserUnauthorizedException("Insufficient privileges to update project in method 'updateProject'");
     }
     $oldDBName = $project->databaseName();
     $object['id'] = $projectId;
     JsonDecoder::decode($project, $object);
     $newDBName = $project->databaseName();
     if ($oldDBName != '' && $oldDBName != $newDBName) {
         if (MongoStore::hasDB($newDBName)) {
             throw new \Exception("Cannot rename '{$oldDBName}' to ' {$newDBName}' . New project name {$newDBName} already exists.  Not renaming.");
         }
         MongoStore::renameDB($oldDBName, $newDBName);
     }
     $projectId = $project->write();
     return $projectId;
 }
 public function testDecode_readOnlyProperties_propertiesNotChanged()
 {
     $test = new PropertiesTest();
     $test->name = 'test';
     $test->shouldBeReadOnly = 'cannot change this';
     $data = json_decode(json_encode(JsonEncoder::encode($test)), true);
     $this->assertTrue(array_key_exists('name', $data));
     $this->assertTrue(array_key_exists('shouldBeReadOnly', $data));
     $this->assertEqual($test->shouldBeReadOnly, $data['shouldBeReadOnly']);
     // change some data
     $data['name'] = 'different';
     // this can be changed
     $data['shouldBeReadOnly'] = 'changed';
     // this prop is read-only
     $test2 = new PropertiesTest();
     JsonDecoder::decode($test2, $data);
     $this->assertEqual($test2->name, 'different');
     $this->assertEqual($test2->shouldBeReadOnly, 'default');
 }
Ejemplo n.º 9
0
 /**
  * @param string $projectId
  * @param JSON $object
  * @return ID of text updated/added
  */
 public static function updateText($projectId, $object)
 {
     $projectModel = new \Api\Model\ProjectModel($projectId);
     $textModel = new \Api\Model\TextModel($projectModel);
     $isNewText = $object['id'] == '';
     if (!$isNewText) {
         $textModel->read($object['id']);
     }
     JsonDecoder::decode($textModel, $object);
     TextCommands::makeValidRange($object);
     if (TextCommands::hasRange($object)) {
         $usxTrimHelper = new UsxTrimHelper($textModel->content, $object['startCh'] || 0, $object['startVs'] || 0, $object['endCh'] || 0, $object['endVs'] || 0);
         $textModel->content = $usxTrimHelper->trimUsx();
     }
     $textId = $textModel->write();
     if ($isNewText) {
         ActivityCommands::addText($projectModel, $textId, $textModel);
     }
     return $textId;
 }
Ejemplo n.º 10
0
 public function read()
 {
     $json = file_get_contents(APPPATH . "angular-app/bellows/js/assets/inputSystems_languages.js");
     $json = str_replace(";", "", substr($json, strpos($json, '[')));
     $arr = json_decode($json, true);
     foreach ($arr as $obj) {
         $language = new Language();
         JsonDecoder::decode($language, $obj);
         $this[$language->code->three] = $language;
         // duplicate any two letter code languages with two letter code keys
         if ($language->code->two) {
             $this[$language->code->two] = $language;
         }
     }
     // add the unlisted language if it doesn't already exist
     $unlisted = new Language('Unlisted Language', 'qaa');
     $unlisted->country[] = '?';
     $unlistedCode = $unlisted->code->three;
     if (!array_key_exists($unlistedCode, $this)) {
         $this[$unlistedCode] = $unlisted;
     }
 }
Ejemplo n.º 11
0
 /**
  * Sets the public properties of $model to values from $values[propertyName]
  * @param object $model
  * @param array $values A mixed array of JSON (like) data.
  * @param string $id
  */
 public static function decode($model, $values, $id = '')
 {
     $decoder = new JsonDecoder();
     $decoder->_decode($model, $values, $id);
 }
Ejemplo n.º 12
0
 public static function updateProjectSettings($projectId, $smsSettingsArray, $emailSettingsArray)
 {
     $smsSettings = new \Api\Model\Sms\SmsSettings();
     $emailSettings = new \Api\Model\EmailSettings();
     JsonDecoder::decode($smsSettings, $smsSettingsArray);
     JsonDecoder::decode($emailSettings, $emailSettingsArray);
     $projectSettings = new ProjectSettingsModel($projectId);
     $projectSettings->smsSettings = $smsSettings;
     $projectSettings->emailSettings = $emailSettings;
     $result = $projectSettings->write();
     return $result;
 }
Ejemplo n.º 13
0
 /**
  * Creates / Updates a comment on the given answer.
  * @param string $projectId
  * @param string $questionId
  * @param string $answerId
  * @param array $comment
  * @param string $userId
  * @return array Dto
  */
 public static function updateComment($projectId, $questionId, $answerId, $comment, $userId)
 {
     $projectModel = new ProjectModel($projectId);
     $questionModel = new QuestionModel($projectModel, $questionId);
     $authorId = $userId;
     if ($comment['id'] != '') {
         // update existing comment
         $oldComment = $questionModel->readComment($answerId, $comment['id']);
         $authorId = $oldComment->userRef->asString();
     }
     $commentModel = new CommentModel();
     JsonDecoder::decode($commentModel, $comment);
     $commentModel->userRef->id = $authorId;
     $commentId = QuestionModel::writeComment($projectModel->databaseName(), $questionId, $answerId, $commentModel);
     $questionModel->read($questionId);
     $newComment = $questionModel->readComment($answerId, $commentId);
     $commentDTO = QuestionCommentDto::encodeComment($newComment);
     if ($comment['id'] != '') {
         // TODO log the activity after we confirm that the comment was successfully updated ; cjh 2013-08
         ActivityCommands::updateComment($projectModel, $questionId, $answerId, $newComment);
     } else {
         ActivityCommands::addComment($projectModel, $questionId, $answerId, $newComment);
     }
     $dto = array();
     $dto[$commentId] = $commentDTO;
     return $dto;
 }
Ejemplo n.º 14
0
 /**
  *
  * @param string $validationKey
  * @param array $params
  * @param Website $website
  */
 public static function updateFromRegistration($validationKey, $params, $website)
 {
     $user = new \Api\Model\UserModelWithPassword();
     if ($user->readByProperty('validationKey', $validationKey)) {
         if ($user->validate()) {
             $params['id'] = $user->id->asString();
             JsonDecoder::decode($user, $params);
             $user->setPassword($params['password']);
             $user->validate();
             $user->role = SystemRoles::USER;
             $user->siteRole[$website->domain] = $website->userDefaultSiteRole;
             $user->active = true;
             return $user->write();
         } else {
             throw new \Exception("Sorry, your registration link has expired.");
         }
     }
 }
Ejemplo n.º 15
0
 /**
  * @param string $key
  * @param object $model
  * @param MongoDate $data
  */
 public function decodeMapOf($key, $model, $data)
 {
     foreach ($data as $k => $item) {
         self::decodeDollarDot($k, $data);
     }
     parent::decodeMapOf($key, $model, $data);
 }