Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
test_submission_integrity.inc
1 <?php
28 {
29 
30 
37  public static function getName()
38  {
39  return 'Submission Integrity Test';
40 
41  }//end getName()
42 
43 
50  public static function getDescription()
51  {
52  return 'A test to check the integrity of submissions';
53 
54  }//end getDescription()
55 
56 
66  public static function test(&$messages, &$errors)
67  {
68  $status = TRUE;
69  $count = 0;
70  $submission_assetids = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetIds('form_submission', TRUE);
71  foreach ($submission_assetids as $assetid) {
72  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
73 
74  // Check questions are valid
75  $attributes = $asset->attr('attributes');
76  $answers = array_get_index($attributes, 'answers', Array());
77  foreach ($answers as $id => $details) {
78  $valid_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($id, '', TRUE);
79  if (is_null($valid_asset)) {
80  $status = FALSE;
81  $count++;
82  $errors[] = 'Submission #'.$assetid.' has an answer to a question (#'.$id.') that does not exist';
83  } else {
84  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($valid_asset, TRUE);
85  }//end if
86  unset($valid_asset);
87  }//end foreach
88 
89  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset, TRUE);
90  }//end foreach
91 
92  if (!$status && !empty($count)) {
93  $messages[] = 'There are '.$count.' submissions found with problems';
94  }//end if
95 
96  return $status;
97 
98  }//end test()
99 
100 }//end class
101 ?>