diff options
author | Sashi20 | 2020-01-16 12:57:21 +0530 |
---|---|---|
committer | GitHub | 2020-01-16 12:57:21 +0530 |
commit | bfbbddc8b842e5269d31c0d0df5af979de1fcb95 (patch) | |
tree | d4b0d91a649545a0b98e326962508e28aad0a21a | |
parent | 81d6706693a54638348faf28fe418f6403b24350 (diff) | |
parent | ed52d9caf03329c2956b811a364d5e0df17fdbdd (diff) | |
download | fellowship_testimonials-bfbbddc8b842e5269d31c0d0df5af979de1fcb95.tar.gz fellowship_testimonials-bfbbddc8b842e5269d31c0d0df5af979de1fcb95.tar.bz2 fellowship_testimonials-bfbbddc8b842e5269d31c0d0df5af979de1fcb95.zip |
Merge pull request #2 from Sashi20/master
Enable option to edit the testimonials
-rwxr-xr-x | fellowship_testimonials.module | 2 | ||||
-rw-r--r-- | testimonials_add.inc | 201 |
2 files changed, 55 insertions, 148 deletions
diff --git a/fellowship_testimonials.module b/fellowship_testimonials.module index e84ec28..862f570 100755 --- a/fellowship_testimonials.module +++ b/fellowship_testimonials.module @@ -15,7 +15,7 @@ 'file' => 'testimonials_add.inc' ); $items["fellowship-testimonials/edit"] = array( - "title" => "Edit fellowship_testimonials", + "title" => "Edit fellowship testimonials", "page callback" => "fellowship_testimonials_edit_all", "access arguments" => array("manage fellowship_testimonials"), "type" => MENU_CALLBACK, diff --git a/testimonials_add.inc b/testimonials_add.inc index a38eaaa..43fa17b 100644 --- a/testimonials_add.inc +++ b/testimonials_add.inc @@ -7,6 +7,7 @@ function fellowship_testimonials_add_all() { } function fellowship_testimonials_add_form($form,$form_state, $testimonial_id = 0) { $testimonial_id = arg(2); + //var_dump($testimonial_id);die; $query = db_select('fellowship_testimonials'); $query->fields('fellowship_testimonials'); $query->condition('id', $testimonial_id); @@ -42,74 +43,6 @@ function fellowship_testimonials_add_form($form,$form_state, $testimonial_id = 0 '#size' => 90, "#required" => TRUE ); - /*$form['fellows_fieldset'] = array( - '#type' => 'fieldset', - '#tree' => TRUE, - '#prefix' => '<div id="fellows-fieldset-wrapper">', - '#suffix' => '</div>' - ); - if (empty($form_state['num_fellows'])) { - $form_state['num_fellows'] = 1; - } - $temp = 0; - for ($i = 0; $i < $form_state['num_fellows']; $i++) { - $temp1 = $i; - $form['fellows_fieldset'][$i]["s_text"] = array( - "#type" => "item", - "#markup" => "<h4><label>fellow : " . ($temp1 + 1) . "</label></h4>" - ); - $form['fellows_fieldset'][$i]["fellowname"] = array( - "#type" => "textfield", - "#title" => "Name: ", - "#default_value" => "" - ); - $form['fellows_fieldset'][$i]["institute"] = array( - "#type" => "textfield", - "#title" => "Institute: ", - "#default_value" => "" - ); - $form['fellows_fieldset'][$i]["place"] = array( - "#type" => "textfield", - "#title" => "Place: ", - "#default_value" => "" - ); - } - $form["fellows_count"] = array( - "#type" => "hidden", - "#value" => $temp1 - ); - $form['fellows_fieldset']['add_fellows'] = array( - '#type' => 'submit', - '#value' => t('Add fellow'), - '#limit_validation_errors' => array(), - '#submit' => array( - 'fellows_add_more_add_one' - ), - '#ajax' => array( - 'callback' => 'fellows_add_more_callback', - 'wrapper' => 'fellows-fieldset-wrapper' - ) - ); - if ($form_state['num_fellows'] > 1) { - $form['fellows_fieldset']['remove_fellows'] = array( - '#type' => 'submit', - '#value' => t('Remove Fellow'), - '#limit_validation_errors' => array(), - '#submit' => array( - 'fellows_add_more_remove_one' - ), - '#ajax' => array( - 'callback' => 'fellows_add_more_callback', - 'wrapper' => 'fellows-fieldset-wrapper' - ) - ); - } - if ($no_js_use) { - if (!empty($form['fellows_fieldset']['remove_fellows']['#ajax'])) { - unset($form['fellows_fieldset']['remove_fellows']['#ajax']); - } - unset($form['fellows_fieldset']['add_fellows']['#ajax']); - }*/ $query_s = db_select('fellows'); $query_s->fields('fellows'); $query_s->condition('t_id', $row->id); @@ -134,9 +67,9 @@ function fellowship_testimonials_add_form($form,$form_state, $testimonial_id = 0 "#type" => "item", "#markup" => "<h4><label>fellows : " . ($temp + 1) . "</label></h4>" ); - $form['fellows_fieldset'][$i]["s_id"] = array( + $form['fellows_fieldset'][$i]["f_id"] = array( "#type" => "hidden", - "#default_value" => $row_s->s_id + "#default_value" => $row_s->f_id ); $form['fellows_fieldset'][$i]["fellowname"] = array( "#type" => "textfield", @@ -153,7 +86,6 @@ function fellowship_testimonials_add_form($form,$form_state, $testimonial_id = 0 "#title" => "Place", "#default_value" => $row_s->place ); - $i++; } @@ -267,18 +199,6 @@ 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 = " - UPDATE fellowship_testimonials SET - name = '%s', department = '%s', university = '%s', - contribution = '%s', reference = '%s', body = '%s' - WHERE id = %d - "; - $result = db_query($query, - $v["name"], $v["department"], $v["university"], - $v["contribution"], $v["reference"], $v["body"], - $v["testimonial_id"] - );*/ - $query = db_update('fellowship_testimonials'); $query->fields(array( 'year' => $v["fellowship_year"], @@ -287,66 +207,34 @@ function fellows_add_more_remove_one($form, &$form_state) { )); $query->condition('id', $v["testimonial_id"]); $result = $query->execute(); - } else { - /*$query = " - INSERT INTO fellowship_testimonials - (name, department, university, contribution, reference, body) - VALUES - ('%s', '%s', '%s', '%s', '%s', '%s') - "; - $result = db_query($query, - $v["name"], $v["department"], $v["university"], - $v["contribution"], $v["reference"], $v["body"] - );*/ - - $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; - $fellowsupload = 0; - for ($i = 0; $i <= $v["fellows_count"]; $i++) { - $s_id=$v['fellows_fieldset'][$i]["f_id"]; - if ($s_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( + $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]["s_id"]); + $query->condition('f_id', $v['fellows_fieldset'][$i]["f_id"]); $result = $query->execute(); if ($result != 0) { $fellowsupload++; } } } - else { + else { if ($v['fellows_fieldset'][$i]["fellowname"] != "") { - $fellowsquery = " - INSERT INTO fellows - (t_id,name,institute,place) - VALUES - (:t_id,:name,:institute,:place) - "; + $fellowsquery = "INSERT INTO fellows (t_id,name,institute,place) VALUES (:t_id,:name,:institute,:place)"; $fellowsargs = array( ":t_id" => $result, - ":name" => $v['fellows_fieldset'][$i]["fellowname"], - ":institute" => $v['fellows_fieldset'][$i]["institute"], - ":place" => $v['fellows_fieldset'][$i]["place"] + ":name" => trim($v['fellows_fieldset'][$i]["fellowname"]), + ":institute" => trim($v['fellows_fieldset'][$i]["institute"]), + ":place" => trim($v['fellows_fieldset'][$i]["place"]) ); /* storing the row id in $result */ $fellowsresult = db_query($fellowsquery, $fellowsargs, array( @@ -357,53 +245,72 @@ 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 = " - SELECT * FROM fellowship_testimonials - ORDER BY time DESC - "; - $result = db_query($query);*/ - $speakerquery = db_select('fellows'); - $speakerquery->fields('fellows'); - - $speakerresult = $speakerquery->execute(); - while($speakerrow = $speakerresult->fetchObject()){ $query = db_select('fellowship_testimonials'); $query->fields('fellowship_testimonials'); // $query->orderBy('time', 'DESC'); - $query->condition('id', $speakerrow->t_id); + //$query->condition('id', $speakerrow->t_id); $result = $query->execute(); $headers = array( - "Name", "University", "Action" + "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( - $speakerrow->name, - $speakerrow->institute, - l("Edit", "fellowship_testimonials/edit/{$row->id}") ." | ". - l("Delete", "fellowship_testimonials/delete/{$row->id}") + $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 )); |