} if ($checkifitis == 0) { $nodes[] = node_load($nid); } } usort($nodes, 'sortByTitle'); foreach ($nodes as $nid1) { if ($node->nid != $nid1->nid) { $output = $output . "<li><a href=\"" . url('node/' . $nid1->nid) . "\" title=\"" . $nid1->title . "\">" . $nid1->title . "</a></li>"; } } // $output = $output . "<li class=\"active active-trail\"><a href=\"#\">Lorem ipsum dolor</a></li>"; $output = $output . "</ul>"; $output = $output . "</li>"; // GET ALL NOTES FROM KLE REF BY TERM KLE $a = taxonomy_select_nodes($bterm->field_os2web_base_field_kle_ref['und'], $pager = FALSE); $nodes = array(); foreach ($a as $nid2) { $checkifitis = 0; // check if node are allready there foreach ($nodes as $n) { if ($n->nid == $nid2) { $checkifitis = 1; } } if ($checkifitis == 0) { $nodes[] = node_load($nid2); } } usort($nodes, 'sortByTitle'); foreach ($nodes as $nid1) {
<?php /** * @file * This template is used to print a single field in a view. * * It is not actually used in default Views, as this is registered as a theme * function which has better performance. For single overrides, the template is * perfectly okay. * * Variables available: * - $view: The view object * - $field: The field handler object that can process the input * - $row: The raw SQL result that can be used * - $output: The processed output that will normally be used. * * When fetching output from the $row, this construct should be used: * $data = $row->{$field->field_alias} * * The above will guarantee that you'll always get the correct data, * regardless of any changes in the aliasing that might happen if * the view is modified. */ $data = taxonomy_select_nodes($row->tid, FALSE); if (count($data) == 1) { $node = node_load($data[0]); $alias = drupal_lookup_path('alias', "node/{$data[0]}"); $output = l($row->{$field->field_alias}, $alias); } print $output;
print "<div class='view-header'><p>Archives</p></div><ul class='list_months'>"; foreach ($dates as $key => $value) { if ($key <= 5) { print "<li><a target='_blank' href='" . $base_path . "blog/" . $dates[$key] . "'>" . date('F, Y', strtotime($dates[$key])) . "</a></li>"; } } print "</ul>"; ?> </div> <div id="list_categories" class="list"> <div class='view-header'><p>Categories</p></div> <ul class="list_categories"> <?php $categories = taxonomy_get_tree(8, $parent = 0); foreach ($categories as $key => $value) { $nodes_term = taxonomy_select_nodes($categories[$key]->tid); if (!empty($nodes_term)) { print "<li><a target='_blank' href='/blog/all/" . $categories[$key]->tid . "'>" . $categories[$key]->name . "</a></li>"; } } ?> </ul></div> <?php print views_embed_view('blog', 'block_1'); ?> </div>
foreach ($entity as $entity_data) { $tax_node = node_load($entity_data->nid); break; } break; } } if ($tax_node) { ?> <h2><?php echo $taxonomy->name; ?> </h2> <?php echo $tax_node->body['und'][0]['safe_value']; $assoc_nodes = taxonomy_select_nodes($taxonomy->tid); if (count($assoc_nodes) > 0) { $pageData = array(); foreach ($assoc_nodes as $this_assoc_node) { $assoc_node = node_load($this_assoc_node); $thisPage = array('nid' => $this_assoc_node, 'created' => $assoc_node->created, 'title' => $assoc_node->title, 'html' => $assoc_node->body['und'][0]['safe_value'], 'weight' => $assoc_node->nodeorder[$taxonomy->tid]['weight']); $thisPage['html'] = parseWistia($thisPage['html'], findWistia($thisPage['html']), $assoc_node); $thisPage['html'] = parseSurvey($thisPage['html'], findSurvey($thisPage['html']), $assoc_node); $thisPage['html'] = parseVideo($thisPage['html'], findVideo($thisPage['html']), $assoc_node); array_push($pageData, $thisPage); } usort($pageData, 'sortAssociatedNodes'); foreach ($pageData as $thisPage) { ?> <h3><?php echo $thisPage['title'];
/** * Callback function to calculate the min and max timestamps of normalized- * electricity data related to the meter. * * @param $wrapper * A wrapper to the meter object. * * @return array * { * min: min timestamp, * max: max timestmp * } * If no electricity data is found, return false. */ protected function electricityMinMax($wrapper) { // Find normalized-electricity entities that are related to this meter // min and max timestamps // First, list all children categories of the category. $categories = $this->getChildren($wrapper); $categories[] = $wrapper->getIdentifier(); // Gather the meters related to these categories. $meters = array(); foreach ($categories as $category) { $meters = array_merge($meters, taxonomy_select_nodes($category)); } if (empty($meters)) { return NULL; } // Query min and max timestamps of the meters. $query = db_select('negawatt_electricity_normalized', 'e'); // Find electricity entities which are related to the relevant meters. $query->condition('e.meter_nid', $meters, 'IN'); // Add a query for electricity min and max timestamps. $query->addExpression('MIN(e.timestamp)', 'min'); $query->addExpression('MAX(e.timestamp)', 'max'); // Set grouping. $query->groupBy('e.meter_nid'); return $query->execute()->fetchObject(); }
* The above will guarantee that you'll always get the correct data, * regardless of any changes in the aliasing that might happen if * the view is modified. */ $all_service_statistics = array(); if ($term = taxonomy_term_load($output)) { // If ministry term. $nodes = array(); $child_terms = taxonomy_get_children($term->tid); if (!empty($child_terms)) { foreach ($child_terms as $tid => $term_object) { $term_nodes = taxonomy_select_nodes($term_object->tid, FALSE); $nodes = array_merge($nodes, $term_nodes); } } else { $nodes = taxonomy_select_nodes($term->tid, FALSE); } if (!empty($nodes)) { foreach ($nodes as $nid) { $service_statistics = _teenus_get_statistics($nid, $view->old_view[0]->exposed_data['field_fcf_mootmise_aasta_tid']); if (!is_null(@$total_statistics['rahuolu'])) { @($all_service_statistics['rahuolu'] += $service_statistics['total']['rahuolu']); } elseif (isset($all_service_statistics['rahuolu']) && !is_null($all_service_statistics['rahuolu'])) { @($all_service_statistics['rahuolu'] = $total_statistics['rahuolu']); } else { @($all_service_statistics['rahuolu'] = NULL); } @($all_service_statistics['rahuolu_counter'] += !is_null($service_statistics['total']['rahuolu']) ? 1 : 0); @($all_service_statistics['rahuolu2'] += $service_statistics['total']['totalsum']); //sum get from function _teenus_get_statistics @($all_service_statistics['rahuolu_counter2'] += $service_statistics['total']['totalcount']);
/** * If $filter contains filter for 'meter_category', modify $query to catch the * given category, and all its parent categories. * * @param $query * @param $filter * @return array */ protected function handleMeterCategoryFilter($query, &$filter, $addGrouping = TRUE) { // Handle meter categories. // Bother handling category filtering only if no 'meter' filter exists. // If meter filter exists, it'll also filter for the category. $result_type = 'meter'; if (!empty($filter['meter'])) { // Just set group by meter-nid if ($addGrouping) { $query->groupBy('meter_nid'); } return array('result_type' => $result_type); } $meter_account = $filter['meter_account']; // If no category filter was given, take 0 (root) as default. $parent_category = !empty($filter['meter_category']) ? $filter['meter_category'] : 0; // Figure out vocab id from group id (the reverse of og_vocab_relation_get() function). $vocabulary_id = negawatt_meter_vocab_id_from_group_id($meter_account); // Get list of child taxonomy terms. $taxonomy_array = taxonomy_get_tree($vocabulary_id, $parent_category); if (empty($taxonomy_array)) { // No sub categories were found. Show division by meters. $result_type = 'meter'; // Find all meters attached to the category. $meters = taxonomy_select_nodes($parent_category, FALSE); // Check that there are meters in this category. if (empty($meters)) { // Return empty total section. $summary['type'] = $result_type; $summary['values'] = new stdClass(); return array('summary' => $summary); } // Modify the query to sum electricity according to the meters in the category. $query->condition('negawatt_electricity_normalized.meter_nid', $meters, 'IN'); $query->fields('negawatt_electricity_normalized', array('meter_nid')); if ($addGrouping) { $query->groupBy('negawatt_electricity_normalized.meter_nid'); } } else { // Sub categories were found, show division by sub categories. $result_type = 'category'; // Build a mapping array: cat_id => array(all child cat ids); $child_cat_mapping = array(); foreach ($taxonomy_array as $term) { if ($term->depth == 0) { // Direct child, add new row to child-cat-mapping. $child_cat_mapping[$term->tid] = array($term->tid); } else { // Deep level child, add to the proper row. foreach ($child_cat_mapping as $key => $map) { // @fixme: is it possible that a term will have more than one parent? $parent = $term->parents[0]; // Look for the parent in each map row. if (in_array($parent, $map)) { // Add the term to the list under key. $child_cat_mapping[$key][] = $term->tid; break; } } } } // Extract only tid from the taxonomy terms. $child_categories = array_map(function ($term) { return $term->tid; }, $taxonomy_array); // Modify the query to sum electricity in each of the sub categories. // If parent category is 0 (that is, root category), there's no need to // add 'IN' condition for categories - just grab all of them. if ($parent_category != 0) { $query->condition('cat.og_vocabulary_target_id', $child_categories, 'IN'); } $query->join('taxonomy_term_data', 'tax', 'tax.tid = cat.og_vocabulary_target_id'); $query->fields('tax', array('tid', 'name')); if ($addGrouping) { $query->groupBy('cat.og_vocabulary_target_id'); } } unset($filter['meter_category']); return array('result_type' => $result_type, 'child_cat_mapping' => $child_cat_mapping); }
<?php $sql = "select t5.tid, d1.name as l1, d2.name as l2, d3.name as l3, d4.name as l4, d5.name as l5 from {taxonomy_term_hierarchy} t1 inner join {taxonomy_term_hierarchy} t2 on t2.parent = t1.tid inner join {taxonomy_term_hierarchy} t3 on t3.parent = t2.tid inner join {taxonomy_term_hierarchy} t4 on t4.parent = t3.tid inner join {taxonomy_term_hierarchy} t5 on t5.parent = t4.tid inner join taxonomy_term_data d5 on d5.tid = t5.tid inner join taxonomy_term_data d4 on d4.tid = t4.tid inner join taxonomy_term_data d3 on d3.tid = t3.tid inner join taxonomy_term_data d2 on d2.tid = t2.tid inner join taxonomy_term_data d1 on d1.tid = t1.tid limit 100;"; $result = db_query($sql); $data = $result->fetchAllAssoc('tid'); $output = array(); foreach ($data as $row) { $nids = taxonomy_select_nodes($row->tid, FALSE); if ($nids) { drush_log('Fixing ' . $row->tid . ': ' . $row->l1 . ' > ' . $row->l2 . ' > ' . $row->l3 . ' > ' . $row->l4 . ' > ' . $row->l5); $parent = taxonomy_get_parents($row->tid); $parent_id = reset(array_keys($parent)); $nids = array_unique($nids); drush_print_r($nids); $nodes = node_load_multiple($nids); foreach ($nodes as $node) { if (isset($node->field_locations)) { foreach ($node->field_locations as $lang => $items) { $parent_found = FALSE; foreach ($items as $i => $item) { // Check if parent exists. if ($item['target_id'] == $parent_id) { $parent_found = TRUE; } } if ($parent_found) { // Remove child. foreach ($items as $i => $item) { if ($item['target_id'] == $row->tid) { unset($node->field_locations[$lang][$i]); break;