public static function updateComment($projectId, $userId, $website, $params) { CodeGuard::checkTypeAndThrow($params, 'array'); $project = new LexProjectModel($projectId); ProjectCommands::checkIfArchivedAndThrow($project); $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 = UniversalTimestamp::now(); } $comment->authorInfo->modifiedByUserRef->id = $userId; $comment->authorInfo->modifiedDate = UniversalTimestamp::now(); 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); ProjectCommands::checkIfArchivedAndThrow($projectModel); $questionTemplate = new QuestionTemplateModel($projectModel); JsonDecoder::decode($questionTemplate, $params); $result = $questionTemplate->write(); return $result; }
/** * Update the optionlist with params * @param $projectId * @param array $params (encoded LexOptionListModel) * @return string $optionlistId */ public static function updateList($projectId, $params) { CodeGuard::checkTypeAndThrow($params, 'array'); $project = new LexProjectModel($projectId); ProjectCommands::checkIfArchivedAndThrow($project); if (array_key_exists('id', $params) && $params['id'] != '') { $optionlist = new LexOptionListModel($project, $params['id']); } else { $optionlist = new LexOptionListModel($project); } JsonDecoder::decode($optionlist, $params); return $optionlist->write(); }
public function testEncodeDecodeUniversalTimestamp_HistoricalDate_Same() { $model = new TestJsonDateModel(); $model->universalTimestamp = UniversalTimestamp::fromStringTimestamp(self::StringTimestampWithMilliseconds); $encoded = JsonEncoder::encode($model); $this->assertInternalType('string', $encoded['universalTimestamp']); // var_dump($encoded); $decodedModel = new TestJsonDateModel(); JsonDecoder::decode($decodedModel, $encoded); $iso8601 = $decodedModel->universalTimestamp->asFormattedString(UniversalTimestamp::ISO8601_WITH_MILLISECONDS); $this->assertEquals($encoded['universalTimestamp'], $iso8601); $this->assertEquals($model->universalTimestamp, $decodedModel->universalTimestamp); // var_dump($iso8601); }
/** * 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 LexProjectModel($projectId); ProjectCommands::checkIfArchivedAndThrow($project); 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; }
/** * @param string $projectId * @param array $object (json encoded) * @return string Id of text updated/added */ public static function updateText($projectId, $object) { $projectModel = new ProjectModel($projectId); ProjectCommands::checkIfArchivedAndThrow($projectModel); $textModel = new 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; }
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; } }
/** * Updates the ProjectSettingsModel which are settings accessible only to site administrators * @param string $projectId * @param array<SmsSettings> $smsSettingsArray * @param array<EmailSettings> $emailSettingsArray * @return string $result id to the projectSettingsModel */ public static function updateProjectSettings($projectId, $smsSettingsArray, $emailSettingsArray) { $projectSettings = new ProjectSettingsModel($projectId); ProjectCommands::checkIfArchivedAndThrow($projectSettings); $smsSettings = new SmsSettings(); $emailSettings = new EmailSettings(); JsonDecoder::decode($smsSettings, $smsSettingsArray); JsonDecoder::decode($emailSettings, $emailSettingsArray); $projectSettings->smsSettings = $smsSettings; $projectSettings->emailSettings = $emailSettings; $result = $projectSettings->write(); return $result; }
/** * 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); ProjectCommands::checkIfArchivedAndThrow($projectModel); $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; }
/** * @param string $validationKey * @param array $params * @param Website $website * @throws \Exception * @return string $userId */ public static function updateFromRegistration($validationKey, $params, $website) { $user = new UserModelWithPassword(); if (!$user->readByProperty('validationKey', $validationKey)) { return false; } if (!$user->validate()) { throw new \Exception("Sorry, your registration link has expired."); } $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(); }
public function testDecode_ReadOnlyPropertiesInTwoMaps_PropertiesNotChanged() { $objectData = new PropertyObject(); $objectData->name = 'can change name'; $objectData->shouldBeReadOnly = 'cannot change this'; $key = 'key1'; $object1 = new PropertyObjectInMap(); $object1->name = 'can change name'; $object1->data[$key] = $objectData; $object = new PropertyObjectInMap2(); $object->name = 'can change name'; $object->data2[$key] = $object1; $params = json_decode(json_encode(JsonEncoder::encode($object)), true); $this->assertArrayHasKey('name', $params); $this->assertArrayHasKey('shouldBeReadOnly', $params['data2'][$key]['data'][$key]); $this->assertEquals($object->data2[$key]->data[$key]->shouldBeReadOnly, $params['data2'][$key]['data'][$key]['shouldBeReadOnly']); $params['name'] = 'different name2'; $params['data2'][$key]['name'] = 'different name1'; $params['data2'][$key]['data'][$key]['name'] = 'different name'; $params['data2'][$key]['data'][$key]['shouldBeReadOnly'] = 'changed'; JsonDecoder::decode($object, $params); $this->assertEquals('different name2', $object->name); $this->assertEquals('different name1', $object->data2[$key]->name); $this->assertEquals('different name', $object->data2[$key]->data[$key]->name); $this->assertEquals('cannot change this', $object->data2[$key]->data[$key]->shouldBeReadOnly); }