Created
February 7, 2018 00:48
-
-
Save rivaadara111/f8e998a530f9c9c7e496592def400629 to your computer and use it in GitHub Desktop.
An admin panel to keep track of infinite scroll items. Uses PHP & mySQL to build out custom form & results page.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//gs_infscroll_admin.info | |
name = GS Infinite Scroll Admin | |
description = Admin panel support for Infinite Scroll | |
project = "gs_infscroll_admin" | |
package = Custom | |
version = "7.x-1.0" | |
core = "7.x" | |
//gs_infscroll_admin.module | |
<?php | |
/** | |
* Implementation of hook_menu(). | |
*/ | |
function gs_infscroll_admin_menu() { | |
$items = array(); | |
$items['admin/dashboard/infscroll'] = array( | |
'title' => 'Infinite Scroll Admin', | |
'description' => 'A form viewing infinite scroll items.', | |
'page callback' => 'infscroll_admin_page', | |
'file' => 'gs_infscroll_admin.forms.inc', | |
'access callback' => 'user_access', | |
'access arguments' => array('create article content'), | |
'type' => MENU_CALLBACK | |
); | |
return $items; | |
} | |
function infscroll_admin_page() { | |
$output = array(); | |
$output['search'] = drupal_get_form('gs_infscroll_admin_search_form'); | |
$output['admin'] = drupal_get_form('gs_infscroll_admin_form'); | |
return $output; | |
} | |
/** | |
* Implements hook_preprocess_html(). | |
*/ | |
function gs_infscroll_admin_preprocess_html(&$vars) { | |
$current_path = current_path(); | |
if ($current_path == 'admin/dashboard/infscroll') { | |
$element = array( | |
'#type' => 'html_tag', | |
'#tag' => 'meta', | |
'#attributes' => array( | |
'name' => 'viewport', | |
'content' => 'user-scalable=no,width=device-width,initial-scale=1.0,maximum-scale=1' | |
), | |
); | |
drupal_add_html_head($element, 'meta_viewport'); | |
drupal_add_css(drupal_get_path('module', 'gs_infscroll_admin') . '/gs_infscroll_admin.css',array('group' => CSS_DEFAULT, 'every_page' => FALSE)); | |
} | |
} | |
//gs_infscroll_admin_forms.inc | |
<?php | |
function gs_infscroll_admin_form($form, &$form_state) { | |
$url = drupal_parse_url(request_uri()); | |
if (!empty($url['query']['search'])): | |
$formnid = $url['query']['search']; | |
$node_query = db_select('node', 'n'); | |
$node_query ->leftjoin('field_data_field_campaign_id', 'cid', 'n.nid = cid.entity_id'); | |
$node_result = $node_query | |
->fields('n', array('nid', 'title', 'type')) | |
->fields('cid', array('field_campaign_id_value')) | |
->condition('n.nid', $formnid, '=') | |
->execute() | |
->fetchAll(); | |
if(empty($node_result)): | |
drupal_set_message('The node you searched for does not exist.', 'warning'); | |
else: | |
foreach($node_result as $result) { | |
if (strpos($result->field_campaign_id_value, 'infscroll') !== false) { | |
$title_nid = $result->field_campaign_id_value; | |
break; | |
} | |
} | |
$arr1 = str_split($title_nid, 11); | |
$lead_query = db_select('node', 'n'); | |
$lead_query ->leftjoin('field_data_field_campaign_id', 'cid', 'n.nid = cid.entity_id'); | |
$lead_result = $lead_query | |
->fields('n', array('title', 'nid', 'type') ) | |
->fields('cid', array('field_campaign_id_value') ) | |
->condition('n.nid', $arr1[1], '=') | |
->execute() | |
->fetchAll(); | |
$trail_query = db_select('node', 'n'); | |
$trail_query ->leftjoin('field_data_field_campaign_id', 'cid', 'n.nid = cid.entity_id'); | |
$trail_result = $trail_query | |
->fields('n', array('title', 'nid', 'type') ) | |
->fields('cid', array('field_campaign_id_value') ) | |
->condition('cid.field_campaign_id_value', 'infscroll--'.$node_result[0]->nid, '=') | |
->execute() | |
->fetchAll(); | |
if(count($trail_result) > 0): | |
$form['section'] = array( | |
'#type' => 'container', | |
'#prefix' => '<div class="section"><p>Links from:</p>', | |
'#suffix' => '</div>' | |
); | |
foreach ($trail_result as $trail): | |
$form['section']['trail-'.$trail->nid] = array( | |
'#type' => 'container', | |
'#prefix' => '<div class="trail-container">', | |
'#suffix' => '</div>' | |
); | |
$form['section']['trail-'.$trail->nid]['trail_nid'] = array( | |
'#type' => 'markup', | |
'#markup' => 'NID: ' . $trail->nid, | |
'#prefix' => '<div class="nid">', | |
'#suffix' => '</div>' | |
); | |
$form['section']['trail-'.$trail->nid]['trail_type'] = array( | |
'#type' => 'markup', | |
'#markup' => 'Type: ' . $trail->type, | |
'#prefix' => '<div class="type">', | |
'#suffix' => '</div>' | |
); | |
$form['section']['trail-'.$trail->nid]['trail_title'] = array( | |
'#type' => 'markup', | |
'#markup' => $trail->title, | |
'#prefix' => '<div class="title">', | |
'#suffix' => '</div>' | |
); | |
$form['section']['trail-'.$trail->nid]['edit'] = array( | |
'#type' => 'markup', | |
'#markup' => l(t('Edit'),'node/'.$trail->nid.'/edit' ), | |
'#prefix' => '<div class="edit">', | |
'#suffix' => '</div>' | |
); | |
endforeach; | |
else: | |
$form['section'] = array( | |
'#type' => 'container', | |
'#prefix' => '<div class="section"><p> No results.</p>', | |
'#suffix' => '</div>' | |
); | |
endif; | |
$form['arrow'] = array( | |
'#type' => 'markup', | |
'#markup' =>'➡', | |
'#prefix' => '<div class="arrow">', | |
'#suffix' => '</div>' | |
); | |
$form['section1'] = array( | |
'#type' => 'container', | |
'#prefix' => '<div class="section"><p>You Searched for:</p>', | |
'#suffix' => '</div>' | |
); | |
$form['section1']['node'] = array( | |
'#type' => 'container', | |
'#prefix' => '<div class="node-container">', | |
'#suffix' => '</div>' | |
); | |
$form['section1']['node']['nid'] = array( | |
'#type' => 'markup', | |
'#markup' => 'NID: ' . $node_result[0]->nid, | |
'#prefix' => '<div class="nid">', | |
'#suffix' => '</div>' | |
); | |
$form['section1']['node']['type'] = array( | |
'#type' => 'markup', | |
'#markup' => 'Type: ' . $node_result[0]->type, | |
'#prefix' => '<div class="type">', | |
'#suffix' => '</div>' | |
); | |
$form['section1']['node']['title'] = array( | |
'#type' => 'markup', | |
'#markup' => $node_result[0]->title, | |
'#prefix' => '<div class="title">', | |
'#suffix' => '</div>' | |
); | |
$form['section1']['node']['edit'] = array( | |
'#type' => 'markup', | |
'#markup' => l(t('Edit'),'node/'.$node_result[0]->nid.'/edit' ), | |
'#prefix' => '<div class="edit">', | |
'#suffix' => '</div>' | |
); | |
$form['arrow2'] = array( | |
'#type' => 'markup', | |
'#markup' =>'➡', | |
'#prefix' => '<div class="arrow">', | |
'#suffix' => '</div>' | |
); | |
if(count($lead_result) > 0): | |
$form['section2'] = array( | |
'#type' => 'container', | |
'#prefix' => '<div class="section"><p>Links to:</p>', | |
'#suffix' => '</div>' | |
); | |
$form['section2']['lead'] = array( | |
'#type' => 'container', | |
'#prefix' => '<div class="lead-container">', | |
'#suffix' => '</div>' | |
); | |
$form['section2']['lead']['lead_nid'] = array( | |
'#type' => 'markup', | |
'#markup' => 'NID: ' . $lead_result[0]->nid, | |
'#prefix' => '<div class="nid">', | |
'#suffix' => '</div>' | |
); | |
$form['section2']['lead']['lead_type'] = array( | |
'#type' => 'markup', | |
'#markup' => 'Type: ' . $lead_result[0]->type, | |
'#prefix' => '<div class="type">', | |
'#suffix' => '</div>' | |
); | |
$form['section2']['lead']['lead_title'] = array( | |
'#type' => 'markup', | |
'#markup' =>$lead_result[0]->title, | |
'#prefix' => '<div class="title">', | |
'#suffix' => '</div>' | |
); | |
$form['section2']['lead']['edit'] = array( | |
'#type' => 'markup', | |
'#markup' => l(t('Edit'),'node/'.$lead_result[0]->nid.'/edit' ), | |
'#prefix' => '<div class="edit">', | |
'#suffix' => '</div>' | |
); | |
else: | |
$form['section2'] = array( | |
'#type' => 'container', | |
'#prefix' => '<div class="section"><p>No results.</p>', | |
'#suffix' => '</div>' | |
); | |
endif; | |
return $form; | |
endif; | |
endif; | |
} | |
function gs_infscroll_admin_search_form($form, &$form_state) { | |
$form = array(); | |
$form['search'] = array( | |
'#type' => 'textfield', | |
'#title' => t('Search by article'), | |
'#required' => TRUE, | |
'#length' => 25, | |
'#default_value' => $node->title, | |
); | |
$form['submit'] = array( | |
'#type' => 'submit', | |
'#submit' => array('gs_infscroll_admin_search_form_submit'), | |
'#value' => t('Search'), | |
); | |
$form['reset'] = array( | |
'#markup' => '<a href="/admin/dashboard/infscroll">Reset Search</a>', | |
); | |
return $form; | |
} | |
function gs_infscroll_admin_search_form_submit($form, &$form_state){ | |
if (isset($form_state['values']['search'])): | |
$keyword = check_plain($form_state['values']['search']); | |
$url = 'admin/dashboard/infscroll'; | |
$form_state['redirect'] = array($url, | |
array( | |
'query' => array( | |
'search' => $keyword, | |
) | |
) | |
); | |
endif; | |
} | |
//gs_infscroll-admin.css | |
@media (min-width:500px) { | |
#gs-infscroll-admin-search-form{ | |
margin-left: .5rem; | |
} | |
} | |
.form-item-search input { | |
width: 100%; | |
} | |
@media (min-width:500px) { | |
.form-item-search input { | |
width: 300px; | |
} | |
} | |
#gs-infscroll-admin-form > div{ | |
display: flex; | |
flex-direction: column; | |
justify-content: center; | |
align-items: center; | |
} | |
@media (min-width:500px) { | |
#gs-infscroll-admin-form > div {flex-direction: row;} | |
} | |
.node-container{background-color: rgba(224, 224, 216, .50);} | |
.node-container, | |
.trail-container, | |
.lead-container { | |
border: 1px solid black; | |
margin: 0 .5rem; | |
padding: 1rem; | |
} | |
.nid, .title, .edit{line-height: 1.25rem;} | |
.arrow { | |
zoom:2; | |
margin-top: 2rem; | |
-webkit-transform: rotate(90deg); | |
-ms-transform: rotate(90deg); | |
transform: rotate(90deg); | |
} | |
@media (min-width:500px) { | |
.arrow { | |
-webkit-transform: rotate(0deg); | |
-ms-transform: rotate(0deg); | |
transform: rotate(0deg); | |
} | |
} | |
.section p{margin: 2.5em 1.5em 0 0.5rem;} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment