public function run() { $message = ''; $projectList = new ProjectListModel(); $projectList->read(); $projectIds = array_map(function ($e) { return $e['id']; }, $projectList->entries); $emptyQuestionTitles = 0; foreach ($projectIds as $projectId) { $project = new ProjectModel($projectId); $activityEntries = ActivityListDto::getActivityForProject($project); foreach ($activityEntries as $activity) { if (key_exists('questionRef', $activity) && key_exists('question', $activity['content'])) { $questionId = $activity['questionRef']; $questionTitle = $activity['content']['question']; if ($questionTitle == '') { $emptyQuestionTitles++; $questionModel = new QuestionModel($project, $questionId); $activityModel = new ActivityModel($project, $activity['id']); $newTitle = $questionModel->getTitleForDisplay(); $activityModel->actionContent['question'] = $newTitle; $message .= "Fixing activity " . $activity['action'] . " with title '" . $newTitle . "'\n"; $activityModel->write(); } } } } if ($emptyQuestionTitles > 0) { $message .= "\n\nFixed up {$emptyQuestionTitles} empty question titles in the activity log\n\n"; } else { $message .= "\n\nNo empty question titles were found in the activity log \n\n"; } return $message; }
/** * * @param ProjectModel $projectModel * @param string $questionId * @param string $answerId * @param string $userId * @param string $mode * @return string activity id */ public static function updateScore($projectModel, $questionId, $answerId, $userId, $mode = 'increase') { $question = new QuestionModel($projectModel, $questionId); $text = new TextModel($projectModel, $question->textRef->asString()); $answer = $question->answers[$answerId]; $user = new UserModel($userId); $user2 = new UserModel($answer->userRef->asString()); $activity = new ActivityModel($projectModel); $activity->action = $mode == 'increase' ? ActivityModel::INCREASE_SCORE : ActivityModel::DECREASE_SCORE; $activity->userRef->id = $userId; $activity->textRef->id = $text->id->asString(); $activity->questionRef->id = $questionId; $activity->addContent(ActivityModel::TEXT, $text->title); $activity->addContent(ActivityModel::QUESTION, $question->getTitleForDisplay()); $activity->addContent(ActivityModel::ANSWER, $answer->content); $activity->addContent(ActivityModel::USER, $user->username); $activity->addContent(ActivityModel::USER, $user2->username); $activityId = $activity->write(); UnreadActivityModel::markUnreadForProjectMembers($activityId, $projectModel); return $activityId; }