2

I am using the following modules.

  1. Quiz, Version 7.x-4.0-rc2
  2. Date, Version 7.x-2.9

When adding a quiz, in the availability options tab, I want to be able to set the time as well.

In the open date and close date, there should be an hour and minute option as well.

I did the following things.
1. In the hook_form_alter(), added the below code

if($form_id == 'quiz_node_form'){
  $form['quiz_availability']['quiz_open']['#type'] = 'date_select';
}

This gave a warning on the node/add/quizpage.

Warning: strlen() expects parameter 1 to be string, array given in date_default_date()

2.So added a patch in date_api_elements.inc
https://www.drupal.org/files/date-element-default-value-2038057-1.patch This removed the warning but upon adding the date and time in the availability options and saving the form, it throws the huge error below.

Please supply a valid date. PDOException: SQLSTATE[01000]:

Warning: 1265 Data truncated for column 'quiz_open' at row 1: INSERT INTO {quiz_node_properties} (vid, nid, aid, number_of_random_questions, max_score_for_random, randomization, backwards_navigation, repeat_until_correct, quiz_open, quiz_close, takes, show_attempt_stats, keep_results, time_limit, pass_rate, summary_pass, summary_pass_format, summary_default, summary_default_format, quiz_always, feedback_time, display_feedback, tid, has_userpoints, userpoints_tid, allow_skipping, allow_resume, allow_jumping, show_passed, mark_doubtful, max_score) VALUES ....

3.In the hook_node_presave, printed the $node.

It stores the date as below.

  [quiz_open] => 2016-05-12 21:17

but it expects the date to be stored like this.

 [quiz_close] => Array(
      [month] => 6
      [day] => 11
      [year] => 2016
    )

How to store the date as an array or is there an alternative solution to the problem.

1 Answer 1

0

You can convert it to an array using the php function substr

// lets assume $date = Array ('quiz_open' => '2016-05-12 21:17');

$year = substr($date['quiz_open'], 0, 4); // grabs 2016
$month = substr($date['quiz_open'], 5, 2); // grabs 05
$day = substr($date['quiz_open'], 8, 2); // grabs 12

$date = array ('quiz_close' => array (
                                'day' => $day,
                                'month' => $month,
                                'year' => $year,
                                     )
              );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.