|
@@ -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'),
|
|
|
+ ));
|
|
|
+}
|