first draft of materio_contactops module : shows company taged materials for a user contactop
This commit is contained in:
parent
b9c809d2c7
commit
4b2ab455c9
23
sites/all/modules/gui/materiobasemod/materio_contactops.info
Normal file
23
sites/all/modules/gui/materiobasemod/materio_contactops.info
Normal file
@ -0,0 +1,23 @@
|
||||
name = Materio Contact Operationels
|
||||
description = "Materio Contact Operationels module"
|
||||
|
||||
; Core version (required)
|
||||
core = 7.x
|
||||
|
||||
; Package name (see http://drupal.org/node/542202 for a list of names)
|
||||
package = Materio
|
||||
|
||||
; PHP version requirement (optional)
|
||||
; php = 5.2
|
||||
|
||||
; Loadable code files
|
||||
; files[] = materio_ctools_automodal.module
|
||||
|
||||
; Module dependencies
|
||||
; dependencies[] = user
|
||||
|
||||
; Configuration page
|
||||
; configure = admin/config/materiobasemod
|
||||
|
||||
; For further information about configuration options, see
|
||||
; - http://drupal.org/node/542202
|
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_init().
|
||||
*/
|
||||
// function materio_contactops_init() {
|
||||
// drupal_add_js(drupal_get_path('module', 'materio_contactops').'/js/materio_contactops.js');
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
function materio_contactops_permission() {
|
||||
$perms = array(
|
||||
'view own company related materials' => array(
|
||||
'title' => t('view own company related materials'),
|
||||
'description' => t('view own company related materials'),
|
||||
)
|
||||
);
|
||||
|
||||
return $perms;
|
||||
}
|
||||
|
||||
function materio_contactops_menu(){
|
||||
$items = array();
|
||||
|
||||
$base = array(
|
||||
);
|
||||
|
||||
$items['user/%user/materials'] = array(
|
||||
'title' => t('Materials'),
|
||||
'page callback' => 'materio_contactops_materials',
|
||||
'page arguments' => array(1),
|
||||
'access arguments' => array('view own company related materials'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'file' => 'materio_contactops.pages.inc',
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
function materio_contactops_theme($existing, $type, $theme, $path) {
|
||||
return array(
|
||||
'materio_contactops_materials' => array(
|
||||
'template' => 'materio-contactops-materials',
|
||||
'path' => drupal_get_path('module', 'materio_contactops').'/templates',
|
||||
'arguments' => array(
|
||||
'items' => array(),
|
||||
'view_mode' => "teaser",
|
||||
'pager' => NULL,
|
||||
'count' => 0,
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function template_preprocess_materio_contactops_materials(&$vars){
|
||||
// dsm($vars, 'template_preprocess_materio_contactops_materials | vars');
|
||||
|
||||
// $vars['actualities_infos'] = t('Actualities by materiO\'');
|
||||
$vars['materials_infos'] = t('');
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
function materio_contactops_materials($current_user){
|
||||
// dsm($current_user, 'current_user');
|
||||
|
||||
global $language;
|
||||
global $user;
|
||||
// dsm($user, 'user');
|
||||
|
||||
|
||||
|
||||
// get user company tag
|
||||
$company_tid = $current_user->field_company['und'][0]['tid'];
|
||||
// dsm($company_tid,'company_tid');
|
||||
|
||||
# retrieve viewmode and then use it to define the query range
|
||||
$viewmode = isset($user->data['materiosearchapi_viewmode'])
|
||||
? $user->data['materiosearchapi_viewmode']
|
||||
: variable_get('defaultviewmode', 'full');
|
||||
|
||||
$limit = variable_get($viewmode.'_limite', '10');
|
||||
// dsm($limit, "limit");
|
||||
|
||||
$offset = pager_find_page() * $limit; //$page*$limit;//
|
||||
// dsm($offset, "offset");
|
||||
|
||||
// get materials taged with this company
|
||||
$query = new EntityFieldQuery;
|
||||
$query
|
||||
->entityCondition('entity_type', 'node')
|
||||
->propertyCondition('status', 1)
|
||||
->entityCondition('bundle', array('materiau'))
|
||||
// ->fieldCondition('field_company_distrib', 'tid', $company_tid, '=')
|
||||
->fieldCondition('field_company_fab', 'tid', $company_tid, '=')
|
||||
->propertyOrderBy('created', 'DESC')
|
||||
->range($offset,$limit);
|
||||
$result = $query->execute();
|
||||
// dsm($result, '$result');
|
||||
foreach ($result['node'] as $nid => $n) {
|
||||
$items[] = node_load($nid);
|
||||
}
|
||||
|
||||
$count_query = new EntityFieldQuery;
|
||||
$count_query
|
||||
->entityCondition('entity_type', 'node')
|
||||
->propertyCondition('status', 1)
|
||||
->entityCondition('bundle', array('materiau'))
|
||||
// ->fieldCondition('field_company_distrib', 'tid', $company_tid, '=')
|
||||
->fieldCondition('field_company_fab', 'tid', $company_tid, '=');
|
||||
// dsm($count, 'count');
|
||||
|
||||
$count = $count_query->count()->execute();
|
||||
|
||||
$query = new EntityFieldQuery;
|
||||
$query
|
||||
->entityCondition('entity_type', 'node')
|
||||
->propertyCondition('status', 1)
|
||||
->entityCondition('bundle', array('materiau'))
|
||||
->fieldCondition('field_company_distrib', 'tid', $company_tid, '=')
|
||||
// ->fieldCondition('field_company_fab', 'tid', $company_tid, '=')
|
||||
->propertyOrderBy('created', 'DESC')
|
||||
->range($offset,$limit);
|
||||
$result = $query->execute();
|
||||
// dsm($result, '$result');
|
||||
foreach ($result['node'] as $nid => $n) {
|
||||
$items[] = node_load($nid);
|
||||
}
|
||||
|
||||
$count_query = new EntityFieldQuery;
|
||||
$count_query
|
||||
->entityCondition('entity_type', 'node')
|
||||
->propertyCondition('status', 1)
|
||||
->entityCondition('bundle', array('materiau'))
|
||||
// ->fieldCondition('field_company_distrib', 'tid', $company_tid, '=')
|
||||
->fieldCondition('field_company_fab', 'tid', $company_tid, '=');
|
||||
// dsm($count, 'count');
|
||||
|
||||
$count += $count_query->count()->execute();
|
||||
|
||||
pager_default_initialize($count, $limit);
|
||||
|
||||
drupal_set_title(t(''));
|
||||
|
||||
return theme('materio_contactops_materials', array(
|
||||
'items' => $items,
|
||||
'view_mode' => $viewmode,
|
||||
'count' => $count,
|
||||
'pager' => theme('pager'),
|
||||
));
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
// dsm($items, 'items');
|
||||
?>
|
||||
<section class="materiobase-contactops-materials">
|
||||
<?php if($count): ?>
|
||||
<p class="materials-infos"><?php print $materials_infos; ?></p>
|
||||
<div class="actuality-items">
|
||||
<?php $entity_view = entity_view('node', $items, $view_mode); ?>
|
||||
<?php print render($entity_view); ?>
|
||||
</div>
|
||||
<div class="pager">
|
||||
<?php print $pager; ?>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<div class="materials-no-items">
|
||||
<h2><?php print t('There is now materials for now.');?></h2>
|
||||
</div>
|
||||
<?php endif ;?>
|
||||
</section>
|
Loading…
x
Reference in New Issue
Block a user