cahyadsn

chickin_sync_node_insert

Dec 20th, 2018
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. <?php
  2. //----
  3. function chickin_sync_node_insert($node) {
  4.     $result=array();   
  5.     if ($node->type == 'hatching') {
  6.         //dpm($node, '$node update');    
  7.         if (!empty($node->field_hatching_distribution)) {
  8.             api_load('layerfarm');
  9.             $jumlah = 0;
  10.             foreach ($node->field_hatching_distribution[LANGUAGE_NONE] as $entity_id) {
  11.                 $entity = entity_load('field_collection_item', array($entity_id['value']));
  12.                 //dpm($entity, '$entity');
  13.                 if (!empty($entity)) {
  14.                     $entity = array_shift($entity);
  15.                     //dpm($entity, '$entity 2');
  16.                     $flock_nid = $entity->field_hatching_house[LANGUAGE_NONE][0]['target_id'];
  17.                     $number_of_bird = $entity->field_hatching_number_of_bird[LANGUAGE_NONE][0]['value'];
  18.                     dpm($flock_nid, '$flock_nid');
  19.                     dpm($number_of_bird, '$number_of_bird');
  20.                     $houses = node_load($flock_nid);
  21.                     //dpm($houses,'houses');
  22.                     $farm_nid = $houses->field_house_farm[LANGUAGE_NONE][0]['target_id'];
  23.                     dpm($farm_nid,'location');
  24.                     $arrays = array();
  25.                     $arrays[] = array('farm_id' => $farm_nid, 'quantity' => $number_of_bird);
  26.                     dpm($arrays,'jumlah');
  27.                     $result[$farm_nid] = (isset($result[$farm_nid])?$result[$farm_nid]:0)+$number_of_bird;
  28.                 }
  29.             }
  30.         }
  31.     }
  32.     return $result;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment