From e31dc0d4fc4a94208f43254be32a4902d74b1126 Mon Sep 17 00:00:00 2001 From: bachy Date: Fri, 18 May 2012 22:43:44 +0200 Subject: [PATCH] first RC Signed-off-by: bachy --- idmaterio.info | 29 ++++++++++++++++++++++ idmaterio.module | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 idmaterio.info create mode 100644 idmaterio.module diff --git a/idmaterio.info b/idmaterio.info new file mode 100644 index 00000000..f1a2418b --- /dev/null +++ b/idmaterio.info @@ -0,0 +1,29 @@ +name = Idmaterio +description = "The description of this module" + +; Core version (required) +core = 7.x + +; Package name (see http://drupal.org/node/542202 for a list of names) +; package = + +; PHP version requirement (optional) +; php = 5.2 + +; Loadable code files +; files[] = idmaterio.module +; files[] = idmaterio.admin.inc +; files[] = idmaterio.class.inc + +; Module dependencies +; dependencies[] = mymodule +; dependencies[] = theirmodule (1.2) +; dependencies[] = anothermodule (>=2.4) +; dependencies[] = views (3.x) + +; Configuration page +; configure = admin/config/idmaterio + + +; For further information about configuration options, see +; - http://drupal.org/node/542202 diff --git a/idmaterio.module b/idmaterio.module new file mode 100644 index 00000000..c8887c5c --- /dev/null +++ b/idmaterio.module @@ -0,0 +1,64 @@ +entityCondition('entity_type', $entity_type) + ->entityCondition('bundle', $entity->type) + ->fieldCondition('field_famille', 'value', $entity->field_famille['und'][0]['value']); + $result = $query->execute(); + if(is_array($result[$entity_type])){ + $entities = entity_load($entity_type, array_keys($result[$entity_type])); + + // get identifiants fo these entities + $ids = array(); + foreach ($entities as $id => $e) { + $identifiant = field_view_field($entity_type, $e, 'field_identifiant'); + $ids[] = $identifiant[0]['#markup'] ? intval($identifiant[0]['#markup']) : 0; + } + sort($ids); + + $value = strval(array_pop($ids) + 1); + }else{ + $value = '1'; + } + + // parse the value to a string as 0023 or 4458 or 0001 + $value_parts = str_split($value); + while (count($value_parts) < 4) { + array_unshift($value_parts, "0"); + } + + // record the result + $entity_field[0]['value'] = implode('', $value_parts); + } +} + +function computed_field_field_identifiant_display($field, $entity_field_item, $entity_lang, $langcode) { + return $entity_field_item['value']; +} \ No newline at end of file