PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
ChainItem Struct Reference

#include <Chain.h>

Public Member Functions

 ChainItem ()
 
 ChainItem (ItemType t)
 
std::string CreateChainPageConfig (const std::string &tempDir) const
 
std::string BuildTestCommand (const std::string &studyPath, const std::string &subjectID) const
 
std::string GetDisplayName () const
 
bool IsPageItem () const
 

Public Attributes

ItemType type
 
std::string title
 
std::string content
 
std::string testName
 
std::string paramVariant
 
std::string language
 
int randomGroup
 

Detailed Description

Definition at line 25 of file Chain.h.

Constructor & Destructor Documentation

◆ ChainItem() [1/2]

ChainItem::ChainItem ( )
inline

Definition at line 38 of file Chain.h.

std::string paramVariant
Definition Chain.h:34
ItemType type
Definition Chain.h:26
int randomGroup
Definition Chain.h:36

◆ ChainItem() [2/2]

ChainItem::ChainItem ( ItemType  t)
inline

Definition at line 39 of file Chain.h.

39: type(t), paramVariant("default"), randomGroup(0) {}

Member Function Documentation

◆ BuildTestCommand()

std::string ChainItem::BuildTestCommand ( const std::string &  studyPath,
const std::string &  subjectID 
) const

Definition at line 79 of file Chain.cpp.

80 {
81 std::ostringstream cmd;
82
83 // Base command: pebl2 testPath/testName.pbl
84 cmd << "pebl2 " << studyPath << "/tests/" << testName << "/" << testName << ".pbl";
85
86 // Add subject ID
87 cmd << " -s " << subjectID;
88
89 // Add language if specified
90 if (!language.empty()) {
91 cmd << " --language " << language;
92 }
93
94 // Note: Parameter variant handling requires Study context to look up the actual filename
95 // from the ParameterVariant.file field. This method doesn't have that access.
96 // Use LauncherUI::ExecuteChainItem() for proper parameter file handling.
97 if (!paramVariant.empty() && paramVariant != "default") {
98 // This is incomplete - would need: --pfile params/filename.par.json
99 // where filename comes from ParameterVariant.file, not the variant name
100 cmd << " --pfile params/" << paramVariant; // Caller should pass actual filename
101 }
102
103 return cmd.str();
104}
std::string testName
Definition Chain.h:33
std::string language
Definition Chain.h:35

References language, paramVariant, and testName.

◆ CreateChainPageConfig()

std::string ChainItem::CreateChainPageConfig ( const std::string &  tempDir) const

Definition at line 47 of file Chain.cpp.

47 {
48 // Generate unique filename using timestamp + random
49 std::srand(std::time(nullptr));
50 int random = std::rand() % 10000;
51 std::string uuid = std::to_string(std::time(nullptr)) + "-" + std::to_string(random);
52#ifdef _WIN32
53 std::string configFile = tempDir + "\\chainpage-" + uuid + ".json";
54#else
55 std::string configFile = tempDir + "/chainpage-" + uuid + ".json";
56#endif
57
58 try {
59 json j;
60 j["title"] = title;
61 j["content"] = content;
62 j["page_type"] = ItemTypeToString(type);
63
64 std::ofstream file(configFile);
65 if (!file.is_open()) {
66 return "";
67 }
68
69 file << j.dump(2); // Pretty print with 2-space indent
70 file.close();
71
72 return configFile;
73
74 } catch (const std::exception& e) {
75 return "";
76 }
77}
nlohmann::json json
Definition Chain.cpp:14
std::string ItemTypeToString(ItemType type)
Definition Chain.cpp:20
std::string title
Definition Chain.h:29
std::string content
Definition Chain.h:30

References content, ItemTypeToString(), title, and type.

◆ GetDisplayName()

std::string ChainItem::GetDisplayName ( ) const

Definition at line 106 of file Chain.cpp.

106 {
107 if (IsPageItem()) {
108 return title.empty() ? ItemTypeToString(type) : title;
109 } else {
110 return testName.empty() ? "Test" : testName;
111 }
112}
bool IsPageItem() const
Definition Chain.h:52

References IsPageItem(), ItemTypeToString(), testName, title, and type.

Referenced by LauncherUI::Render().

◆ IsPageItem()

bool ChainItem::IsPageItem ( ) const
inline

Definition at line 52 of file Chain.h.

52 {
53 return type == ItemType::Instruction ||
56 }

References Completion, Consent, Instruction, and type.

Referenced by GetDisplayName(), and Chain::Validate().

Member Data Documentation

◆ content

std::string ChainItem::content

Definition at line 30 of file Chain.h.

Referenced by CreateChainPageConfig(), and Chain::Validate().

◆ language

std::string ChainItem::language

Definition at line 35 of file Chain.h.

Referenced by BuildTestCommand(), ScaleManager::CreateStudyFromScale(), and Chain::Validate().

◆ paramVariant

std::string ChainItem::paramVariant

Definition at line 34 of file Chain.h.

Referenced by BuildTestCommand(), ScaleManager::CreateStudyFromScale(), and Chain::Validate().

◆ randomGroup

int ChainItem::randomGroup

Definition at line 36 of file Chain.h.

Referenced by ScaleManager::CreateStudyFromScale().

◆ testName

std::string ChainItem::testName

◆ title

std::string ChainItem::title

Definition at line 29 of file Chain.h.

Referenced by CreateChainPageConfig(), GetDisplayName(), and Chain::Validate().

◆ type

ItemType ChainItem::type

Definition at line 26 of file Chain.h.

Referenced by CreateChainPageConfig(), GetDisplayName(), IsPageItem(), and LauncherUI::Render().


The documentation for this struct was generated from the following files: