Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
test_form_integrity.inc
1 <?php
28 {
29 
30 
37  public static function getName()
38  {
39  return 'Form Integrity Test';
40 
41  }//end getName()
42 
43 
50  public static function getDescription()
51  {
52  return 'A test to check the integrity of forms';
53 
54  }//end getDescription()
55 
56 
66  public static function test(&$messages, &$errors)
67  {
68  $status = TRUE;
69  $count = 0;
70  $form_assetids = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetIds('form', FALSE);
71  foreach ($form_assetids as $assetid) {
72  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
73  $invalid = FALSE;
74 
75  // Check sections/questions are valid
76  $questions = $asset->getAllQuestions();
77  foreach ($questions as $question_id => $question_details) {
78  $question = $GLOBALS['SQ_SYSTEM']->am->getAsset($question_id, '', TRUE);
79  if (is_null($question)) {
80  $status = FALSE;
81  $invalid = TRUE;
82  $errors[] = 'Question #'.$question_id.' on Form #'.$assetid.' is invalid';
83  } else {
84  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($question);
85  }//end if
86  unset($question);
87  }//end foreach
88 
89  // Check submissions are completed (ECommerce Form does have a submission folder so ignore)
90  if (strtolower($asset->type()) !== 'form_ecommerce') {
91  $submission_folder = $asset->getSubmissionsFolder();
92  if (is_null($submission_folder)) {
93  $status = FALSE;
94  $invalid = TRUE;
95  $errors[] = 'Submission Folder does not exist for Form #'.$assetid;
96  } else {
97  $submissions_found = $GLOBALS['SQ_SYSTEM']->am->getChildren($submission_folder->id, 'form_submission', FALSE);
98  foreach ($submissions_found as $sub_id => $sub_type_code) {
99  $sub = $GLOBALS['SQ_SYSTEM']->am->getAsset($sub_id, '', TRUE);
100  if (is_null($sub)) {
101  $status = FALSE;
102  $invalid = TRUE;
103  $errors[] = 'Submission #'.$sub_id.' under Form #'.$assetid.' and could not be loaded';
104  } else {
105  $sub_complete = $sub->attr('complete');
106  if (!$sub_complete) {
107  $status = FALSE;
108  $invalid = TRUE;
109  $errors[] = 'Submission #'.$sub_id.' under Form #'.$assetid.' and not completed';
110  }//end if
111  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($sub, TRUE);
112  }//end if
113  }//end foreach
114  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($submission_folder, TRUE);
115  }//end if
116  }//end if
117 
118  // Valid form actions
119  $actions = $asset->attr('actions');
120  foreach ($actions as $action) {
121  $action_type = $action['type_code'];
122  $GLOBALS['SQ_SYSTEM']->am->includeAsset($action_type);
123 
124  if (!$action['active'] && !call_user_func(Array($action_type, 'isValid'), $asset, $action['settings'])) {
125  $status = FALSE;
126  $invalid = TRUE;
127  $errors[] = 'Form #'.$assetid.' has an invalid form action ('.$action_type.')';
128  }//end if
129  }//end foreach
130 
131  // Ok, this form has issues
132  if ($invalid) $count++;
133 
134  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset, TRUE);
135  }//end foreach
136 
137  if (!$status) {
138  $messages[] = 'There are '.$count.' forms found on the system with problems';
139  }//end if
140 
141  return $status;
142 
143  }//end test()
144 
145 }//end class
146 ?>