Skip to content
Snippets Groups Projects
Commit 744dea0e authored by root on s1's avatar root on s1
Browse files

initial check-in from s1.ned.univie.ac.at

parent 037f8a54
No related branches found
No related tags found
No related merge requests found
Showing with 679 additions and 0 deletions
name = Filters for Dutch+
description = Filters for displaying content in Dutch+
core = 7.x
package = Others
configure = admin/settings/filters_dp
stylesheets[all][] = style/filters_dp.css
scripts[] = js/filters_dp.js
<?php
/*
* @file
* Install file of filters_dp
*
*/
/**
* Implements hook_schema().
*/
function filters_dp_schema() {
$schema = array();
$schema['filters_dp_content'] = array(
'description' => t('Links the content with the filters'),
'fields' => array(
'id' => array(
'type' => 'serial', // incremental
'unsigned' => TRUE, // no negative integers
'size' => 'normal', // tiny, small, medium, normal, big
'not null' => TRUE, // default FALSE
'description' => t('The primary identifier.'),
),
'nid' => array(
'type' => 'int',
'size' => 'normal',
'not null' => TRUE,
'description' => t('Node id')
),
'fid' => array(
'type' => 'int',
'size' => 'normal',
'not null' => TRUE,
'description' => t('Filter id')
),
),
'primary key' => array('id'),
);
$schema['filters_dp_list'] = array(
'description' => t('Filters list'),
'fields' => array(
'id' => array(
'type' => 'serial',
'unsigned' => TRUE,
'size' => 'normal',
'not null' => TRUE,
'description' => t('The primary identifier for a possibility.'),
),
'title' => array(
'type' => 'text',
'size' => 'normal',
'description' => t('Title of the filter'),
),
'main_page' => array(
'type' => 'int',
'size' => 'normal',
'description' => t('The node of the main page of the filter'),
),
),
'primary key' => array('id'),
);
return $schema;
}
/**
* Implements hook_install().
*/
function filters_dp_install() {
_filters_dp_install_db();
}
/**
* Introduces the example filters
*/
function _filters_dp_install_db() {
$filter = array();
$filter[1] = array(
'title' => 'Beginners'
);
$filter[2] = array(
'title' => 'Docenten'
);
$filter[3] = array(
'title' => 'English'
);
foreach ($filter as $value) {
db_insert('filters_dp_list')
->fields(array('title'))
->values($value)
->execute();
}
}
/**
* Adds main page field for each filter
*/
function filters_dp_update_7100() {
$spec = array(
'type' => 'int',
'size' => 'normal',
'description' => t('The node of the main page of the filter'),
);
db_add_field('filters_dp_list', 'main_page', $spec);
}
<?php
/*
* @file
* Module file of filters_dp
*/
module_load_include('inc', 'filters_dp', 'forms');
module_load_include('inc', 'filters_dp', 'functions');
module_load_include('inc', 'filters_dp', 'views');
/**
* Implements hook_menu().
*
* Here we set up the URLs (menu entries) for the
* form examples. Note that most of the menu items
* have page callbacks and page arguments set, with
* page arguments set to be functions in external files.
*/
function filters_dp_menu() {
// Admin menus
$items['admin/settings/filters_dp'] = array(
'title' => 'Filters Dutch+ Configuration',
'page callback' => 'drupal_get_form',
'page arguments' => array('filters_dp_settings_form'),
'access arguments' => array('administer filters_dp'),
'type' => MENU_NORMAL_ITEM
);
$items['admin/settings/filters_dp/list'] = array(
'title' => 'Filters Dutch+ Configuration',
'page callback' => 'drupal_get_form',
'page arguments' => array('filters_dp_admin_settings_form'),
'access arguments' => array('administer filters_dp'),
'type' => MENU_NORMAL_ITEM
);
$items['set-filter/%'] = array(
'title' => 'Filter Callback',
'page callback' => '_filters_dp_activate_filter',
'page arguments' => array(1),
'type' => MENU_CALLBACK,
'access callback' => TRUE,
);
return $items;
}
/**
* Implements hook_permission().
*
* Since the access to our new custom pages will be granted based on
* special permissions, we need to define what those permissions are here.
* This ensures that they are available to enable on the user role
* administration pages.
*/
function filters_dp_permission() {
$permissions = array(
'administer filters_dp' => array(
'title' => t('Administer Filters Dutch+'),
'description' => t('Associate nodes with filters'),
'restrict access' => TRUE,
),
);
return $permissions;
}
function filters_dp_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'filters_dp_settings_form') {
$form['#submit'][] = '_filters_dp_admin_submit_handler';
}
}
/**
* Implements hook_block_info().
*/
function filters_dp_block_info() {
$blocks = array();
$blocks['filters'] = array(
'info' => t('Filters'),
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function filters_dp_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'filters':
$block['subject'] = '';
$block['content'] = _filters_dp_block_content();
break;
}
return $block;
}
/**
* Implements hook_library();
*/
function filters_dp_library() {
$libraries['filters_dp_js'] = array(
'title' => 'filters_dp',
'version' => '1',
'js' => array(
drupal_get_path('module', 'filters_dp') . '/js/filters_dp.js' => array(),
),
);
return $libraries;
$libraries['filters_dp'] = array(
'title' => 'filters_dp',
'version' => '1',
'js' => array(
array(
'type' => 'setting',
'data' => array('fid' => 1),
),
),
);
return $libraries;
}
/**
* Implements hook_page_alter(&$page);
*/
function filters_dp_page_alter(&$page) {
if (isset($_SESSION['filters_dp'])) {
drupal_add_js(array('filters_dp' => $_SESSION['filters_dp']), 'setting');
}
}
<?php
/**
* @file - All forms go in this file
*/
function filters_dp_settings_form($form, &$form_state) {
$form = array();
$form['list'] = array(
'#markup' => _filters_dp_get_nodes(),
);
$filters = _filters_dp_get_filters();
$options = array();
foreach ($filters as $filter) {
$options[$filter->id] = $filter->title;
}
$form['filter'] = array(
'#type' => 'select',
'#title' => t('Select filter'),
'#options' => $options,
);
$form['node'] = array(
'#type' => 'textfield',
'#title' => t('Nid'),
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Add'),
);
return $form;
}
function filters_dp_settings_form_submit($form, &$form_state) {
$nid = $form_state['values']['node'];
$fid = $form_state['values']['filter'];
_filters_dp_insert_record($nid, $fid);
drupal_set_message(t('Node added to filter'));
}
function filters_dp_admin_settings_form($form, &$form_state) {
$form = array();
$form['list'] = array(
'#markup' => _filters_dp_list_filters(),
);
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#required' => TRUE,
);
$form['main_page'] = array(
'#type' => 'textfield',
'#title' => t('Nid of the main page'),
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
function filters_dp_admin_settings_form_submit($form, &$form_state) {
$title = $form_state['values']['title'];
$main_page = $form_state['values']['main_page'];
_filters_dp_list_insert_record($title, $main_page);
drupal_set_message(t('Node added'));
}
<?php
/**
* @file - Diverse functions
*/
function _filters_dp_insert_record($nid, $fid) {
$value = new stdClass();
$value->nid = $nid;
$value->fid = $fid;
$key = _filters_dp_find_record($nid, $fid);
drupal_write_record('filters_dp_content', $value, $key);
}
function _filters_dp_find_record($nid, $fid) {
$key = array();
$query = db_select('filters_dp_content', 'c')
->fields('c', array('id'))
->condition('nid', $nid)
->condition('fid', $fid)
->execute();
$id = $query->fetchAssoc();
if (!empty($id)) {
$key = array('id');
}
return $key;
}
function _filters_dp_get_filters() {
$query = db_select('filters_dp_list', 'l')
->fields('l')
->execute();
$filters = $query->fetchAll();
return $filters;
}
function _filters_dp_get_nodes() {
$header = array(
'Node ID',
'Title',
'Filter',
);
$rows = array();
$results = db_select('filters_dp_content', 'c')
->fields('c')
->execute();
foreach ($results as $value) {
if ($value->nid != 0) {
$node = node_load($value->nid);
$filter = _filters_dp_load_filter($value->fid);
$rows[] = array(
$value->nid,
$node->title,
$filter->title,
);
}
}
return theme('table', array('header' => $header, 'rows' => $rows));
}
function _filters_dp_load_filter($fid) {
$query = db_select('filters_dp_list', 'l')
->fields('l')
->condition('id', $fid)
->execute();
return $query->fetch();
}
function _filters_dp_admin_submit_handler(&$form, &$form_state) {
$form_state['redirect'] = 'admin/settings/filters_dp';
}
function _filters_dp_activate_filter($fid) {
if ($fid != 0) {
$_SESSION['filters_dp']['nodes'] = _filters_dp_get_nodeID_by_fid($fid);
if ((isset($_SESSION['filters_dp']['fid']) && $_SESSION['filters_dp']['fid'] != $fid) || !isset($_SESSION['filters_dp']['fid'])) {
$_SESSION['filters_dp']['fid'] = $fid;
$nid = get_filter_main_page($fid);
drupal_goto("node/" . $nid);
}
else {
_filters_dp_remove_filter();
drupal_goto('<front>');
}
}
else {
_filters_dp_remove_filter();
drupal_goto('<front>');
}
}
function _filters_dp_get_nodeID_by_fid($fid) {
$query = db_select('filters_dp_content', 'c')
->fields('c')
->condition('fid', $fid)
->execute();
$nids = array();
foreach ($query as $result) {
$nids[] = $result->nid;
}
return $nids;
}
function _filters_dp_remove_filter() {
unset($_SESSION['filters_dp']['nodes']);
$_SESSION['filters_dp']['fid'] = 1;
}
function get_filter_main_page($fid) {
$query = db_select('filters_dp_list', 'c')
->fields('c', array('main_page'))
->condition('id', $fid)
->execute();
$nid = $query->fetchField();
return $nid;
}
function _filters_dp_list_insert_record($title, $main_page) {
$value = new stdClass();
$value->title = $title;
$value->main_page = $main_page;
drupal_write_record('filters_dp_list', $value, array());
}
function _filters_dp_list_filters() {
$header = array(
'Filter ID',
'Title',
'Main Page',
);
$rows = array();
$results = db_select('filters_dp_list', 'c')
->fields('c')
->execute();
foreach ($results as $value) {
$node = node_load($value->main_page);
$rows[] = array(
$value->id,
$value->title,
$node->title,
);
}
return theme('table', array('header' => $header, 'rows' => $rows));
}
images/beginners_off.jpg

12.4 KiB

images/beginners_on.jpg

12.7 KiB

images/docenten_off.jpg

29.4 KiB

images/docenten_on.jpg

29.5 KiB

images/engels_off.jpg

12.7 KiB

images/engels_on.jpg

13 KiB

(function($) {
Drupal.behaviors.filters_dp = {
attach: function(context, settings) {
if (Drupal.settings.filters_dp && Drupal.settings.filters_dp.fid) {
switch(Drupal.settings.filters_dp.fid) {
case "1":
break;
case "2":
var color = "#f6f4b7";
var hoverColor = '#faf9d7';
break;
case "3":
var color = "#c9e1ea";
var hoverColor = '#e2edf1';
break;
case "4":
var color = "#b5cb88";
var hoverColor = '#cddeab';
break;
}
if (color) {
var menu = $("#main-menu ul.menu li");
menu.each(function( index ) {
var link = $(this).find("a").attr("href");
link = link.replace("/node/","");
if ($.inArray(link, Drupal.settings.filters_dp.nodes) > -1) {
$(this).css({"backgroundColor": color});
// Add hover color too
$(this).hover(
function() {
$(this).css({"backgroundColor": hoverColor});
},
function() {
$(this).css({"backgroundColor": color});
}
);
// Color also the parent menus
$(this).parents("li").css({"backgroundColor": color});
$(this).parents("li").hover(
function() {
$(this).css({"backgroundColor": hoverColor});
},
function() {
$(this).css({"backgroundColor": color});
}
);
}
});
}
// Starting page
var pathname = window.location.pathname;
var node = pathname.replace("/node/", "");
var pages = ["33", "34", "179"];
if ($.inArray(node, pages) > -1) {
url = "https://dutchplusplus.ned.univie.ac.at/sites/all/modules/custom/filters_dp/js/img" + pages[$.inArray(node, pages)] + ".png";
$("h1.title").css({"background": "url(" + url + ") no-repeat"});
$("h1.title").css({"height": "60px"});
$("h1.title").css({"text-align": "center"});
$("h1.title").css({"padding-top": "20px"});
$("h1.title").css({"margin-left": "50px"});
}
}
}
}
})(jQuery);
js/img179.png

88.1 KiB

js/img33.png

15.8 KiB

js/img34.png

134 KiB

/**
* Filter block
*/
#filters {
margin: 70px auto;
font-family: "PT Sans", sans-serif;
width: 300px;
}
.filter-box {
width: 84px;
height: 137px;
display: inline-block;
margin-left: 15px;
}
.filter-box p {
margin: auto;
font-size: 11px;
font-family: "Open Sans", sans-serif;
}
.filter-box img {
}
.filter-box h1 {
font-size: 18px;
font-weight: bold;
margin: auto;
text-align: center;
background-color: #fff;
height: 40px;
padding-top: 10px;
}
.filter-box h2 {
font-size: 18px;
font-weight: bold;
color: #89898b;
margin: 5px;
margin-left: 29px;
}
.filter-box a {
color: #fff;
font-weight: bold;
text-decoration: none;
font-size: 15px;
}
.filter-box .button-on {
color: #fff;
padding: 5px;
width: 25px;
margin: 0px auto;
float: left;
}
#beginners {
background-color: #f6f4b7;
color: #e9eb3b;
}
#docenten {
background-color: #c9e1ea;
color: #005b7f;
}
#engels {
background-color: #b5cb88;
color: #309515;
}
.button-off {
padding: 5px;
background-color: #89898b;
width: 25px;
float: left;
}
.filter-box p.button-on {
margin-left: 23px;
float: left;
}
.button-engels {
background-color: #309515;
}
.button-beginners {
background-color: #e9eb3b;
}
.button-docenten {
background-color: #005b7f;
}
style/images/beginners.png

17.2 KiB

style/images/docenten.png

15.3 KiB

style/images/engels.png

11 KiB

style/images/standaard.png

17.2 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment