Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $order_number_today = render($content['field_number_today'][0]['#markup']); // Присваиваем текущее значение порядкового номера ноде
- $date_visit = render($content['field_date_visit']['#items'][0]['value']); // в формате 2016-04-16 00:00:00
- if(empty($order_number_today)) { // если порядковый номер еще не присвоен
- $order_number_today = render($content['field_number_today'][0]['#markup']);
- $date_visit = render($content['field_date_visit']['#items'][0]['value']);
- if(empty($order_number_today)) {
- $query = new EntityFieldQuery();
- $query->entityCondition('entity_type', 'node');
- $query->propertyCondition('type', 'order');
- $query->propertyCondition('status', 1);
- $query->fieldCondition('field_date_visit', 'value', $date_visit);
- $query->fieldOrderBy('field_number_today', 'value', 'DESC');
- $query->range(0, 1);
- $result = $query->execute();
- if (!empty($result['node'])) {
- $nodes = node_load_multiple(array_keys($result['node']));
- foreach ($nodes AS $node) {
- $last_number_today = $node->field_number_today['und'][0]['value']; //узнаем последний порядковый номер
- }
- $node = node_load($nid);
- $node->original = $node;
- $node->field_number_today['und'][0]['value'] = $last_number_today + 1;
- foreach (field_info_instances('node', 'order') as $field_name => $field_info) {
- if ($field_name != 'field_number_today') {
- unset($node->{$field_name});
- }
- }
- field_attach_presave('node', $node);
- field_attach_update('node', $node);
- }
- else {
- $node = node_load($nid);
- $node->original = $node;
- $node->field_number_today['und'][0]['value'] = 1;
- foreach (field_info_instances('node', 'order') as $field_name => $field_info) {
- if ($field_name != 'field_number_today') {
- unset($node->{$field_name});
- }
- }
- field_attach_presave('node', $node);
- field_attach_update('node', $node);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement