diff options
Diffstat (limited to 'testimonials_add.inc')
-rw-r--r-- | testimonials_add.inc | 251 |
1 files changed, 98 insertions, 153 deletions
diff --git a/testimonials_add.inc b/testimonials_add.inc index 43fa17b..15c95f7 100644 --- a/testimonials_add.inc +++ b/testimonials_add.inc @@ -5,7 +5,7 @@ function fellowship_testimonials_add_all() { $page_content .= drupal_render($fellowship_testimonials_add_form); return $page_content; } -function fellowship_testimonials_add_form($form,$form_state, $testimonial_id = 0) { +function fellowship_testimonials_add_form($form,$form_state, $no_js_use = FALSE, $testimonial_id = 0) { $testimonial_id = arg(2); //var_dump($testimonial_id);die; $query = db_select('fellowship_testimonials'); @@ -20,7 +20,6 @@ function fellowship_testimonials_add_form($form,$form_state, $testimonial_id = 0 '#attributes' => array( 'placeholder' => t('For eg: 2019') ), - "#default_value" => $row->year, "#required" => TRUE ); $form["fellowship_task"] = array( @@ -29,74 +28,74 @@ function fellowship_testimonials_add_form($form,$form_state, $testimonial_id = 0 '#attributes' => array( 'placeholder' => t('For eg: Python, DWSIM, eSim etc') ), - "#default_value" => $row->fellowship_task, "#required" => TRUE ); - + $form["opt_text_or_video"] = array( + "#type" => 'select', + "#title" => t('Select the type of testimonial'), + "#options" => array( + 'T' => 'Text', + 'V' => 'Video' + ), + "#required" => TRUE, + '#ajax' => array( + 'callback' => 'ajax_testimonial_type' + ) + ); + /*$form["testimonial_text"] = array( + "#type" => 'textfield', + //'#format' => 'full_html', + "#title" => t('Enter the testimonial by user'), + "#required" => TRUE, + '#states' => array( + 'visible' => array( + ':input[name="opt_text_or_video"]' => array( + 'value' => 'T' + ) + ) + ), + '#default_value' => $row->testimonial_text + );*/ + $form["testimonial_text"] = array( + "#type" => "text_format", + '#format' => 'full_html', + "#title" => "Testimonial text", + '#prefix' => '<div id="testimonial-text">', + '#suffix' => '</div>', + // "#required" => TRUE, + '#states' => array( + 'visible' => array( + ':input[name="opt_text_or_video"]' => array( + 'value' => 'T' + ) + ) + ), + ); $form["testimonial_video"] = array( "#type" => "textfield", "#title" => "Testimonial Video", '#attributes' => array( 'placeholder' => t('Copy paste the static url of the video, for eg: https://static.fossee.in/fossee/videos/FOSSEE_intern_Video/DSC_0006.m4v') ), - "#default_value" => $row->testimonial_video, '#size' => 90, - "#required" => TRUE + '#prefix' => '<div id="testimonial-video">', + '#suffix' => '</div>', + //"#required" => TRUE, + '#states' => array( + 'visible' => array( + ':input[name="opt_text_or_video"]' => array( + 'value' => 'V' + ) + ) + ), ); - $query_s = db_select('fellows'); - $query_s->fields('fellows'); - $query_s->condition('t_id', $row->id); - $result_s = $query_s->execute(); - $num_of_fellowresults = $result_s->rowCount(); $form['fellows_fieldset'] = array( '#type' => 'fieldset', '#tree' => TRUE, '#prefix' => '<div id="fellows-fieldset-wrapper">', '#suffix' => '</div>' - ); - - if ($num_of_fellowresults != 0) { - - $form_state['num_fellows'] = $num_of_fellowresults; - $temp = 0; - $i = 0; - while ($row_s = $result_s->fetchObject()) { - $temp = $i; - $form['fellows_fieldset'][$i]["s_text"] = array( - "#type" => "item", - "#markup" => "<h4><label>fellows : " . ($temp + 1) . "</label></h4>" - ); - $form['fellows_fieldset'][$i]["f_id"] = array( - "#type" => "hidden", - "#default_value" => $row_s->f_id - ); - $form['fellows_fieldset'][$i]["fellowname"] = array( - "#type" => "textfield", - "#title" => "Name", - "#default_value" => $row_s->name - ); - $form['fellows_fieldset'][$i]["institute"] = array( - "#type" => "textfield", - "#title" => "Institute", - "#default_value" => $row_s->institute - ); - $form['fellows_fieldset'][$i]["place"] = array( - "#type" => "textfield", - "#title" => "Place", - "#default_value" => $row_s->place - ); - $i++; - } - - - $form["fellows_count"] = array( - "#type" => "hidden", - "#value" => $temp - ); - - } - else { + ); if (empty($form_state['num_fellows'])) { $form_state['num_fellows'] = 1; } @@ -160,12 +159,6 @@ function fellowship_testimonials_add_form($form,$form_state, $testimonial_id = 0 } unset($form['fellows_fieldset']['add_fellows']['#ajax']); } - } - - $form["testimonial_id"] = array( - "#type" => "hidden", - "#value" => $testimonial_id - ); $form["submit"] = array( "#type" => "submit", "#value" => "Submit" @@ -173,6 +166,22 @@ function fellowship_testimonials_add_form($form,$form_state, $testimonial_id = 0 return $form; } +function ajax_testimonial_type($form, $form_state){ + $type = $form_state['values']['opt_text_or_video']; + if($type == 'V'){ + $commands[] = ajax_command_replace('#testimonial-video', drupal_render($form['testimonial_video'])); + $commands[] = ajax_command_html('#testimonial-text', ''); + } + else{ + $commands[] = ajax_command_replace('#testimonial-text', drupal_render($form['testimonial_text'])); + $commands[] = ajax_command_html('#testimonial-video', ''); + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); +} + function fellows_add_more_callback($form, $form_state) { return $form['fellows_fieldset']; } @@ -198,36 +207,36 @@ function fellows_add_more_remove_one($form, &$form_state) { function fellowship_testimonials_add_form_submit($form, &$form_state) { $v = $form_state["values"]; - if($v["testimonial_id"]) { - $query = db_update('fellowship_testimonials'); - $query->fields(array( - 'year' => $v["fellowship_year"], - 'fellowship_task' => $v["fellowship_task"], - 'testimonial_video' => $v["testimonial_video"] - )); - $query->condition('id', $v["testimonial_id"]); - $result = $query->execute(); - + + if($v['opt_text_or_video'] == 'V'){ + $query = " + INSERT INTO fellowship_testimonials(year, fellowship_task, testimonial_video, testimonial_type) + VALUES (:year, :fellowship_task, :testimonial_video, :testimonial_type)"; + $args = array( + ':year' => $v["fellowship_year"], + ':fellowship_task' => $v["fellowship_task"], + ':testimonial_video' => $v["testimonial_video"], + ':testimonial_type' => 'V' + ); + } + else if($v['opt_text_or_video'] == 'T'){ + $query = " + INSERT INTO fellowship_testimonials(year, fellowship_task, testimonial_text, testimonial_text_format, testimonial_type) + VALUES (:year, :fellowship_task, :testimonial_text, :testimonial_text_format, :testimonial_type)"; + $args = array( + ':year' => $v["fellowship_year"], + ':fellowship_task' => $v["fellowship_task"], + ':testimonial_text' => $v["testimonial_text"]["value"], + ':testimonial_text_format' => $v["testimonial_text"]["format"], + ':testimonial_type' => 'T' + ); + } + $result = db_query($query,$args, array( + 'return' => Database::RETURN_INSERT_ID + )); $fellowsupload = 0; for ($i = 0; $i <= $v["fellows_count"]; $i++) { - $f_id=$v['fellows_fieldset'][$i]["f_id"]; - //var_dump($f_id);die; - if ($f_id != "") { - if ($v['fellows_fieldset'][$i]["fellowname"] != "") { - $query = db_update('fellows'); - $query->fields(array( - 'name' => $v['fellows_fieldset'][$i]["fellowname"], - 'institute' => $v['fellows_fieldset'][$i]["institute"], - 'place' => $v['fellows_fieldset'][$i]["place"] - )); - $query->condition('f_id', $v['fellows_fieldset'][$i]["f_id"]); - $result = $query->execute(); - if ($result != 0) { - $fellowsupload++; - } - } - } - else { + //$f_id=$v['fellows_fieldset'][$i]["f_id"]; if ($v['fellows_fieldset'][$i]["fellowname"] != "") { $fellowsquery = "INSERT INTO fellows (t_id,name,institute,place) VALUES (:t_id,:name,:institute,:place)"; $fellowsargs = array( @@ -245,75 +254,11 @@ function fellows_add_more_remove_one($form, &$form_state) { } } } - - } - } - else { - $query = " - INSERT INTO fellowship_testimonials(year, fellowship_task, testimonial_video) - VALUES (:year, :fellowship_task, :testimonial_video)"; - $args = array( - ':year' => $v["fellowship_year"], - ':fellowship_task' => $v["fellowship_task"], - ':testimonial_video' => $v["testimonial_video"] - ); - - $result = db_query($query,$args, array( - 'return' => Database::RETURN_INSERT_ID - )); //var_dump($result->name);die; - } if(!$result) { drupal_set_message("Something went wrong, please try again.", "error"); } else { drupal_set_message("Testimonial added successfully", "status"); } drupal_goto('fellowship-testimonials/edit'); - } - -function fellowship_testimonials_edit_all($testimonial_id=0) { - - $page_content = ""; - //var_dump($testimonial_id);die; - if($testimonial_id){ - - $fellowship_testimonials_add_form = drupal_get_form("fellowship_testimonials_add_form", $testimonial_id); - $page_content .= drupal_render($fellowship_testimonials_add_form); - } else { - $query = db_select('fellowship_testimonials'); - $query->fields('fellowship_testimonials'); - // $query->orderBy('time', 'DESC'); - //$query->condition('id', $speakerrow->t_id); - $result = $query->execute(); - - $headers = array( - "Name", "Institute", "Action" - ); - $rows = array(); - while($row = $result->fetchObject()) { - $speakerquery = db_query("SELECT GROUP_CONCAT(name separator ', ') as name, GROUP_CONCAT(institute separator ', ') as institute FROM fellows WHERE t_id = :t_id GROUP BY t_id", array( - ":t_id" => $row->id - )); - /*$speakerquery = db_select('fellows'); - $speakerquery->fields('fellows'); - $speakerquery->condition('t_id', $row->id); - $speakerresult = $speakerquery->execute();*/ - while($speakerrow = $speakerquery->fetchObject()){ - $fellow_name = $speakerrow->name; - $institute = $speakerrow->institute; - } - //$speakerrow = $speakerresult->fetchObject(); - $item = array( - $fellow_name, - $institute, - l("Edit", "fellowship-testimonials/edit/{$row->id}") - // l("Delete", "fellowship-testimonials/delete/{$row->id}") - ); - array_push($rows, $item); - //} - } - //$page_content .= theme("table", $headers, $rows); - $page_content .= theme('table', array('header' => $headers, 'rows' => $rows )); - } - return $page_content; - } + }
\ No newline at end of file |