0

Here is the code :

        foreach ($test_scores as $score) {
        switch ($score['name']) {
            case 'LE-TOD':
                $le_tod = $score['banding'];
                $le_tod_desc = $score["result_desc"];
                if($score['std_score'] == 0) {
                    $le_tod_small = $scoring['tod']['no_pref_bottom'];
                }
                else {
                    $le_tod_small = $scoring['tod']['pref_bottom'].$score['banding']; 
                }
                break;

This is where I get the error message :

    public static function generateLSPReportFile($dataInput, $auto_download = true)
{
    $file_type = $dataInput['file_type'];
    $test_type_id = $dataInput['test_type_id'];
    $he_she = array('male' => 'He', 'female' => 'She');
    $his_her = array('male' => 'his', 'female' => 'her');

    $candidate = \Candidate::where('id',$dataInput['candidate_id'])->first();

    if(!$candidate)
        return;

    $candidate = $candidate->toArray();
    $candidate_name = $candidate['first_name'].' '.$candidate['last_name'];

    $order = \Order::with('client')->find($dataInput['order_id']);

    if(!$order)
        return;

    $client = $order->client;
    $order = $order->toArray();

    //for test dates
    $order_candidate = \OrderCandidate::candidateId($dataInput['candidate_id'])->orderId($dataInput['order_id'])->first()->toArray();

    $order_tests = \OrderCandidateTest::orderCandidateId($order_candidate['id'])
                        ->status(\Config::get('kcg.candidate_test_status_taken'))
                        ->testId($dataInput['test_id'])
                        ->with(array('test' => function($query){
                            $query->select(['id', 'name', 'description', 'abbreviation']);
                        }));

    $tests_scores = \OrderCandidateTestScore::orderId($dataInput['order_id'])
                        ->candidateId($dataInput['candidate_id'])
                        ->testId($dataInput['test_id'])
                        ->with(array('test' => function($query){
                            $query->select(['id', 'name', 'description', 'test_type_id']);
                        }));
    $test_type = TestType::find($test_type_id);
    $test_scores = $tests_scores->orderBy('sequence_no')->get()->toArray();
    $order_tests = $order_tests->get()->toArray();

    if(!$order_tests)
        return;

    if(!$tests_scores)
        return;

It posted an error : ErrorException Undefined offset: 2. I'm really not sure what's causing this.

What am I doing wrong here? Please help me. Thank you

  • 1
    I'm voting to close this question as off-topic because this isn't about Craft CMS, but a general PHP related question and should be asked in StackOverflow. – carlcs Dec 10 '15 at 13:17
  • Agreed with @carlcs. Even if this is happening within the context of a Craft plugin, it's strictly a PHP issue. Migrating to Stack Overflow. – Lindsey D Dec 10 '15 at 17:51

1 Answers1

0

Typically, the Undefined offset message would be triggered by trying to access an array key which doesn't exist.

It seems that your code example might not actually be showing the part that triggered the error... In your case, I would expect the code to show something like $var[2], where the array does not actually contain an index of 2.

See this other question for a clearer representation of what that error means.

Community
  • 1
  • 1
Lindsey D
  • 2,437
  • 3
  • 17
  • 20
  • I believe this array statement is wrong and is causing all of it? 'noise_level' => array ( 'detail_id' => '88', 'detail_id_adult' => '94', 'message' => array ( 'Not affected by noise level', 'Prefers quiet environment' ) ), – Joniel Roy Rosales Dec 11 '15 at 06:07
  • I solved it. Thank you for the advice and the link, 'noise_level' => array ( 'detail_id' => '88', 'detail_id_adult' => '94', 'message' => array ( '1' => 'Not affected by noise level', '2' => 'Prefers quiet environment' ) ), – Joniel Roy Rosales Dec 11 '15 at 08:01
  • Great! Feel free to mark this answer as "accepted" (the green checkmark) if it did the trick for you. :) – Lindsey D Dec 11 '15 at 17:01