/**
  * {@inheritdoc}
  */
 public function cleanup()
 {
     $nodes = node_load_multiple(array(), array('title' => $this->nodeTitle1), TRUE);
     node_delete_multiple(array_keys($nodes));
     $nodes = node_load_multiple(array(), array('title' => $this->nodeTitle2), TRUE);
     node_delete_multiple(array_keys($nodes));
 }
コード例 #2
0
 /**
  * Verify that date fields are imported correctly. When no timezone is
  * explicitly provided with the source data, we want the displayed time on the
  * Drupal site to match that in the source data. To validate that, we make
  * sure we have set a consistent timezone at the PHP and Drupal levels, and
  * that the format used on the page is not locale-dependent (no day or month
  * names). Then, we can just look for the desired date/time strings in the
  * node page.
  */
 function testDateImport()
 {
     date_default_timezone_set('America/Los_Angeles');
     variable_set('date_default_timezone', 'America/Los_Angeles');
     variable_set('date_format_medium', 'Y-m-d H:i');
     $migration = Migration::getInstance('DateExample');
     $result = $migration->processImport();
     $this->assertEqual($result, Migration::RESULT_COMPLETED, t('Variety term import returned RESULT_COMPLETED'));
     $rawnodes = node_load_multiple(FALSE, array('type' => 'date_migrate_example'), TRUE);
     $this->assertEqual(count($rawnodes), 2, t('Two sample nodes created'));
     $node = reset($rawnodes);
     $this->drupalGet('/node/' . $node->nid);
     $this->assertText('2011-05-12 19:43', t('Simple date field found'));
     $this->assertText('2011-06-13 18:32 to 2011-07-23 10:32', t('Date range field found'));
     $this->assertText('2011-07-22 12:13', t('Datestamp field found'));
     $this->assertText('2011-08-01 00:00 to 2011-09-01 00:00', t('Datestamp range field found'));
     $this->assertText('2011-11-18 15:00', t('Datetime field with +9 timezone found'));
     $this->assertText('2011-10-30 14:43 to 2011-12-31 17:59', t('Datetime range field with -5 timezone found'));
     $this->assertText('2011-11-25 09:01', t('First date repeat instance found'));
     $this->assertText('2011-12-09 09:01', t('Second date repeat instance found'));
     $this->assertNoText('2011-12-23 09:01', t('Skipped date repeat instance not found'));
     $this->assertText('2012-05-11 09:01', t('Last date repeat instance found'));
     $node = next($rawnodes);
     $this->drupalGet('/node/' . $node->nid);
     $this->assertText('2012-06-21 15:32', t('First date value found'));
     $this->assertText('2012-12-02 11:08', t('Second date value found'));
     $this->assertText('2004-02-03 01:15', t('Start for first date range found'));
     $this->assertText('2005-03-04 22:11', t('End for first date range found'));
     $this->assertText('2014-09-01 17:21', t('Start for second date range found'));
     $this->assertText('2015-12-23 00:01', t('End for first second range found'));
 }
コード例 #3
0
 /**
  * Creates four nodes and ensures that they are loaded correctly.
  */
 function testNodeMultipleLoad()
 {
     $node1 = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
     $node2 = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
     $node3 = $this->drupalCreateNode(array('type' => 'article', 'promote' => 0));
     $node4 = $this->drupalCreateNode(array('type' => 'page', 'promote' => 0));
     // Confirm that promoted nodes appear in the default node listing.
     $this->drupalGet('node');
     $this->assertText($node1->label(), 'Node title appears on the default listing.');
     $this->assertText($node2->label(), 'Node title appears on the default listing.');
     $this->assertNoText($node3->label(), 'Node title does not appear in the default listing.');
     $this->assertNoText($node4->label(), 'Node title does not appear in the default listing.');
     // Load nodes with only a condition. Nodes 3 and 4 will be loaded.
     $nodes = entity_load_multiple_by_properties('node', array('promote' => 0));
     $this->assertEqual($node3->label(), $nodes[$node3->id()]->label(), 'Node was loaded.');
     $this->assertEqual($node4->label(), $nodes[$node4->id()]->label(), 'Node was loaded.');
     $count = count($nodes);
     $this->assertTrue($count == 2, format_string('@count nodes loaded.', array('@count' => $count)));
     // Load nodes by nid. Nodes 1, 2 and 4 will be loaded.
     $nodes = node_load_multiple(array(1, 2, 4));
     $count = count($nodes);
     $this->assertTrue(count($nodes) == 3, format_string('@count nodes loaded', array('@count' => $count)));
     $this->assertTrue(isset($nodes[$node1->id()]), 'Node is correctly keyed in the array');
     $this->assertTrue(isset($nodes[$node2->id()]), 'Node is correctly keyed in the array');
     $this->assertTrue(isset($nodes[$node4->id()]), 'Node is correctly keyed in the array');
     foreach ($nodes as $node) {
         $this->assertTrue(is_object($node), 'Node is an object');
     }
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $query = \Drupal::entityQuery('node')->condition('status', 1)->condition('type', 'team_member')->sort('field_order', 'ASC');
     $nids = $query->execute();
     $nodes = node_load_multiple($nids);
     //$nodes = entity_load_multiple('node', $nids);
     $ind = 1;
     $output = '<div class="tabbable tabs-left tabcordion">
             <ul class="nav nav-tabs">';
     foreach ($nodes as $node) {
         $class = $ind == 1 ? 'active' : '';
         $output .= '<li class="' . $class . '"><a data-target="#team_member_tab' . $ind . '" data-toggle="tab">' . $node->title->value . '<span>' . $node->get('field_designation')->value . '</span></a></li>';
         $ind++;
     }
     $ind = 1;
     $output .= '</ul>
         <div class="tab-content">';
     foreach ($nodes as $node) {
         $class = $ind == 1 ? 'active' : '';
         if (is_object($node->field_image->entity)) {
             $path = $node->field_image->entity->getFileUri();
             $url = ImageStyle::load('person_picture')->buildUrl($path);
             $tab_content_html = '<div class="row"><div class="col-md-3"><img src="' . $url . '" alt=""></div><div class="col-md-9">' . $node->get('body')->value . '</div> </div>';
         } else {
             $tab_content_html = '<div>' . $node->get('body')->value . '</div>';
         }
         $output .= '<div class="tab-pane ' . $class . '" id="team_member_tab' . $ind . '"> ' . $tab_content_html . ' </div>';
         $ind++;
     }
     $output .= '</div>
       </div>';
     return array('#type' => 'markup', '#markup' => $output, '#attached' => array('library' => array('barney_river_utilities/tabcordion', 'barney_river_utilities/tabcordion_hook')));
 }
コード例 #5
0
function getRelatedPosts($ntype, $nid)
{
    $nids = db_query("SELECT n.nid, title FROM {node} n WHERE n.status = 1 AND n.type = :type AND n.nid <> :nid ORDER BY RAND() LIMIT 0,2", array(':type' => $ntype, ':nid' => $nid))->fetchCol();
    $nodes = node_load_multiple($nids);
    $return_string = '';
    if (!empty($nodes)) {
        foreach ($nodes as $node) {
            $field_image = field_get_items('node', $node, 'field_image_blog');
            $return_string .= '<li class="item content-in col-md-6"><div class="widget-post-wrap">';
            $return_string .= '<div class="thumb"><a href="' . url("node/" . $node->nid) . '">';
            $return_string .= '<img src="' . file_create_url($node->field_image['und'][0]['uri']) . '" alt="' . $node->title . '">';
            $return_string .= '</a></div>';
            $return_string .= '<div class="article-content-wrap">';
            $return_string .= '<h4 class="title"><a href="' . url("node/" . $node->nid) . '">';
            $return_string .= $node->title . '</a></h4>';
            $return_string .= '<div class="excerpt">' . substr($node->body['und'][0]['value'], 0, 100) . '...' . '</div>';
            $return_string .= '<div class="meta-bottom">';
            /*			$return_string .= '<div class="post-cat"><span><i class="fa fa-folder"></i></span>'.strip_tags(render($content['field_blog_category']),'<a>').'</div>';*/
            $return_string .= '<div class="post-date"><span><i class="fa fa-clock-o"></i></span>' . format_date($node->created, 'custom', 'M j,Y') . '</div>';
            $return_string .= '<div class="meta-comment"><span><i class="fa fa-comments-o"></i></span><a href="' . url("node/" . $node->nid) . '">' . $node->comment_count . '</a></div>';
            $return_string .= '</div></div>';
            $return_string .= '<a class="bk-cover-link" href="' . url("node/" . $node->nid) . '"></a></div>';
            $return_string .= '</li>';
        }
    }
    return $return_string;
}
コード例 #6
0
 public function actionList()
 {
     $sels = new Sels();
     $easyNewsall = array();
     $query = new EntityFieldQuery();
     $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'clue')->propertyOrderBy('nid', 'DESC')->propertyCondition('status', 1)->range(0, 20);
     if (isset($_POST['lastnewsid'])) {
         $query->propertyCondition('nid', $_POST['lastnewsid'], '<');
     }
     $result = $query->execute();
     if (isset($result['node'])) {
         $news_items_nids = array_keys($result['node']);
         $news = node_load_multiple($news_items_nids);
     }
     foreach ($news as $new) {
         $easyNews['id'] = $new->nid;
         $easyNews['title'] = $new->title;
         $easyNews['img1'] = str_replace("public://", BigImg, $new->field_tux['und'][0]['uri']);
         array_push($easyNewsall, $easyNews);
     }
     $sels->articles = $easyNewsall;
     $jsonObj = CJSON::encode($sels);
     /* if(isset($key))
     	   $cache->set($key,$jsonObj,0,new CDbCacheDependency('select max(id) from tbl_dblogs'));
     	  */
     echo $jsonObj;
 }
    private function scanReports () {
        $this->affected = array();

        $query = new \EntityFieldQuery();
        $query->entityCondition('entity_type', 'node');
        $query->propertyCondition('type', NODE_TYPE_REPORT);
        $query->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT');
        $result = $query->execute();
        $reportNids = isset($result['node']) ? array_keys($result['node']) : NULL;
        $reportNodes = node_load_multiple($reportNids);
        
        foreach ( $reportNodes as $node ) {
            $datasetName = get_node_field_value($node,'field_report_dataset_sysnames');
            if ( empty($datasetName) ) {
                $patient = array(
                    'info' => array(
                        'reportNodeId' => $node->nid,
                        'reportTitle' => $node->title,
                        'published' => $node->status,
                        'type' => $node->type,
                        'datasetName' => $datasetName
                    ),
                    'notes' => 'Dataset field is empty.'
                );

                $this->attachTreatment($patient);
                $this->affected[] = $patient;
                continue;
            }

            // lookup dataset
            $datasourceQuery = new \EntityFieldQuery();
            $datasourceQuery->entityCondition('entity_type', 'node');
            $datasourceQuery->propertyCondition('type', NODE_TYPE_DATASET);
            $datasourceQuery->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT');
            $datasourceQuery->fieldCondition('field_dataset_sysname', 'value', $datasetName);
            $datasourceQuery->fieldCondition('field_dataset_datasource', 'value', get_node_field_value($node,'field_report_datasource'));
            $datasourceEntities = $datasourceQuery->execute();
            $datasource_nids = isset($datasourceEntities['node']) ? array_keys($datasourceEntities['node']) : NULL;

            if (count($datasource_nids) != 1) {
                $patient = array(
                    'info' => array(
                        'reportNodeId' => $node->nid,
                        'reportTitle' => $node->title,
                        'published' => $node->status,
                        'type' => $node->type,
                        'datasetName' => $datasetName
                    ),
                    'notes' => 'Dataset does not exist.'
                );

                $this->attachTreatment($patient);
                $this->affected[] = $patient;
                continue;
            }
        }
    }
コード例 #8
0
/**
 * Get all project (nodes) from Drupal
 *
 * @param string $url
 * @return string $data
 */
function _ten_thousand_feet_get_all_projects()
{
    try {
        return node_load_multiple(array(), array('type' => 'project'));
    } catch (Exception $e) {
        # Log the exception to watchdog.
        watchdog_exception('database', $e);
    }
}
コード例 #9
0
 /**
  * Override the behavior of title(). Get the title of the node.
  */
 public function titleQuery()
 {
     $titles = array();
     $nodes = node_load_multiple($this->value);
     foreach ($nodes as $node) {
         $titles[] = String::checkPlain($node->label());
     }
     return $titles;
 }
コード例 #10
0
 /**
  * Loads all nodes that have associated images.
  * @return Array of nodes
  */
 function loadNodesWithImages()
 {
     $query = db_select('file_usage', 'u');
     $query->join('node', 'n', 'u.id = n.nid');
     $query->fields('u', ['id'])->condition('n.status', NODE_PUBLISHED);
     $result = $query->execute();
     $nids = array_keys($result->fetchAllAssoc('id'));
     return node_load_multiple($nids);
 }
コード例 #11
0
ファイル: Rss.php プロジェクト: anatalsceo/en-classe
 public function preRender($values)
 {
     $nids = array();
     foreach ($values as $row) {
         $nids[] = $row->{$this->field_alias};
     }
     if (!empty($nids)) {
         $this->nodes = node_load_multiple($nids);
     }
 }
コード例 #12
0
/**
 * Displays the list of department nodes and their contact info
 */
function _cob_directory()
{
    $d = node_load_multiple([], ['type' => 'department']);
    usort($d, function ($a, $b) {
        if ($a->title == $b->title) {
            return 0;
        }
        return $a->title < $b->title ? -1 : 1;
    });
    return theme('cob_directory', ['departments' => $d]);
}
コード例 #13
0
 /**
  * Tests the Drupal 6 term-node association to Drupal 8 migration.
  */
 public function testTermNode()
 {
     $nodes = node_load_multiple(array(1, 2), TRUE);
     $node = $nodes[1];
     $this->assertEqual(count($node->vocabulary_1_i_0_), 1);
     $this->assertEqual($node->vocabulary_1_i_0_[0]->target_id, 1);
     $node = $nodes[2];
     $this->assertEqual(count($node->vocabulary_2_i_1_), 2);
     $this->assertEqual($node->vocabulary_2_i_1_[0]->target_id, 2);
     $this->assertEqual($node->vocabulary_2_i_1_[1]->target_id, 3);
 }
コード例 #14
0
 protected function getContent($type = 'page')
 {
     $content = array();
     $result = \Drupal::entityQuery('node')->condition('type', $type)->condition('status', 1)->execute();
     if (!empty($result)) {
         $nodes = node_load_multiple($result);
         foreach ($nodes as $node) {
             $content[] = ['title' => $node->getTitle(), 'url' => $node->url()];
         }
     }
     return $content;
 }
コード例 #15
0
 /**
  * Visit a node page given its type and title.
  *
  * @param string $type
  *    The node type.
  * @param string $title
  *    The node title.
  *
  * @Then I visit the :type content with title :title
  */
 public function visitContentPage($type, $title)
 {
     $nodes = node_load_multiple([], ['title' => $title, 'type' => $type], TRUE);
     if (!$nodes) {
         throw new \InvalidArgumentException("Node of type '{$type}' and title '{$title}' not found.");
     }
     // Get node path without any base path by setting 'base_url' and 'absolute'.
     $node = array_shift($nodes);
     $path = 'node/' . $node->nid;
     cache_clear_all($path, 'cache_path');
     $path = url($path, ['base_url' => '', 'absolute' => TRUE]);
     // Visit newly created node page.
     $this->visitPath($path);
 }
コード例 #16
0
/**
 * Implements hook_block_view();
 * Define what a block defined in hook_block_info has to display
 */
function modulestarter_block_view($delta)
{
    $block = array();
    if ($delta == 'modulestarter_article_list') {
        // appelle de notre classe métier pour générer le contenu d'un bloc
        $article = new modulestarter_article();
        $block['subject'] = t('Module starter example block');
        // #theme is the template to used for rendering.
        // #articles and others keys will be arguments passed to the theme function.
        // @see hook_theme
        $block['content'] = array('#theme' => 'modulestarter_article_list', '#articles' => node_load_multiple($article->get_list()));
    }
    return $block;
}
コード例 #17
0
 /**
  * Override the behavior of title(). Get the title of the revision.
  */
 public function titleQuery()
 {
     $titles = array();
     $results = $this->database->query('SELECT nr.vid, nr.nid, npr.title FROM {node_revision} nr WHERE nr.vid IN (:vids)', array(':vids' => $this->value))->fetchAllAssoc('vid', PDO::FETCH_ASSOC);
     $nids = array();
     foreach ($results as $result) {
         $nids[] = $result['nid'];
     }
     $nodes = node_load_multiple(array_unique($nids));
     foreach ($results as $result) {
         $nodes[$result['nid']]->set('title', $result['title']);
         $titles[] = String::checkPlain($nodes[$result['nid']]->label());
     }
     return $titles;
 }
コード例 #18
0
    /**
     * {@inheritdoc}
     */
    public function build()
    {
        $query = \Drupal::entityQuery('node')->condition('status', 1)->condition('type', 'slideshow_slide')->sort('field_order', 'ASC');
        $nids = $query->execute();
        $nodes = node_load_multiple($nids);
        $ind = 0;
        $output_slide_add_logo = $output_slide = $output_slide_bullet = $output = '';
        $logo = theme_get_setting('logo', 'zircon');
        foreach ($nodes as $node) {
            $output_slide_add_logo = "";
            $class = $ind == 0 ? 'active' : '';
            $output_slide_bullet .= '<li data-target="#myCarousel" data-slide-to="' . $ind . '" class="' . $class . '"></li>';
            $path = $node->field_image->entity->url();
            if ($node->field_add_logo->entity) {
                $logo_path = explode("public://", $node->field_add_logo->entity->uri->value);
                $output_slide_add_logo = '<div class="logo_on_slider">
                                   <img src="sites/default/files/' . $logo_path[1] . '" alt="Logo">
                                      </div>';
            }
            $output_slide .= '<div class="item ' . $class . '">

                           <img src="' . $path . '" alt="">
' . $output_slide_add_logo . '
                          </div>';
            $ind++;
        }
        $output_slide_bullet_wrap = $ind > 1 ? '<ol class="carousel-indicators">' . $output_slide_bullet . '</ol>' : '';
        $output = '<div id="myCarousel" class="carousel slide" data-ride="carousel">
                <!-- Indicators -->
                  ' . $output_slide_bullet_wrap . '

                <!-- Wrapper for slides -->
                <div class="carousel-inner" role="listbox">
                  ' . $output_slide . '
                </div>

                <!-- Left and right controls -->
                <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
                  <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
                  <span class="sr-only">Previous</span>
                </a>
                <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
                  <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
                  <span class="sr-only">Next</span>
                </a>
              </div>';
        return array('#type' => 'markup', '#markup' => $output);
    }
コード例 #19
0
    public static function findEntities ( array $params = array() ) {
        $sql = 'SELECT entityId, entityType FROM {gd_role_permission} ';

        $binds = array();
        $where = array();
        if ( !empty($params) ) {
            foreach ( $params as $key => $value ) {
                $binds[':'.$key] = $value;
                $where[] = $key .' = :'.$key;
            }
        }

        if ( !empty($where) ) {
            $sql .= 'WHERE '.implode(' AND ',$where);
        }

        $result = db_query($sql,$binds);

        if ( !$result || !$result->rowCount() ) {
            return array();
        }

        $results = $result->fetchAll();

        $entities = array();
        if ( isset($params['entityType']) && $params['entityType'] === 'datasource' ) {
            $datasources = gd_datasource_get_all();
            foreach ( $datasources as $datasourceName => $DS ) {
                foreach ( $results as $record ) {
                    if ( $record->entityId === $datasourceName ) {
                        $entities[$datasourceName] = $DS;
                    }
                }
            }
        } else if ( isset($params['entityType']) && $params['entityType'] === 'dashboard' ) {
            $dashboard_nids = array();
            foreach ( $results as $record ) {
                $dashboard_nids[] = $record->entityId;
            }
            $entities = node_load_multiple($dashboard_nids);
        } else {
            throw new \Exception('Unsupported EntityType');
        }

        return $entities;
    }
コード例 #20
0
    public static function getExportables($datasourceName) {
        if ( $datasourceName != gd_datasource_get_active() ) {
            gd_datasource_set_active($datasourceName);
        }

        $metamodel = data_controller_get_metamodel();
        // get datasets
        $datasetNids = array();
        foreach ($metamodel->datasets as $dataset) {
            if (!isset($dataset->nid)) {
                continue;
            }
            $datasetNids[] = $dataset->nid;
        }

        return node_load_multiple($datasetNids);
    }
コード例 #21
0
 /**
  * Test upload migration from Drupal 6 to Drupal 8.
  */
 function testUpload()
 {
     $nodes = node_load_multiple(array(1, 2), TRUE);
     $node = $nodes[1];
     $this->assertEqual(count($node->upload), 1);
     $this->assertEqual($node->upload[0]->target_id, 1);
     $this->assertEqual($node->upload[0]->description, 'file 1-1-1');
     $this->assertEqual($node->upload[0]->isDisplayed(), FALSE);
     $node = $nodes[2];
     $this->assertEqual(count($node->upload), 2);
     $this->assertEqual($node->upload[0]->target_id, 3);
     $this->assertEqual($node->upload[0]->description, 'file 2-3-3');
     $this->assertEqual($node->upload[0]->isDisplayed(), FALSE);
     $this->assertEqual($node->upload[1]->target_id, 2);
     $this->assertEqual($node->upload[1]->isDisplayed(), TRUE);
     $this->assertEqual($node->upload[1]->description, 'file 2-3-2');
 }
    private function scanReportConfigs () {
        $this->affected = array();

        $query = new \EntityFieldQuery();
        $query->entityCondition('entity_type', 'node');
        $query->propertyCondition('type', NODE_TYPE_REPORT);
        $query->propertyCondition('status', NODE_PUBLISHED);
        $query->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT');
        $result = $query->execute();
        $reportNids = isset($result['node']) ? array_keys($result['node']) : NULL;
        $reportNodes = node_load_multiple($reportNids);
        
        foreach ( $reportNodes as $node ) {

            \LogHelper::log_info(t('Inspecting report @nid', array('@nid' => $node->nid)));

            $reportConfigText = get_node_field_value($node, 'field_report_conf', 0, 'value', FALSE);
            $reportConfig = isset($reportConfigText) ? json_decode($reportConfigText) : NULL;
            if (!isset($reportConfig)) {
                \LogHelper::log_info('Report configuration is EMPTY');
                continue;
            }

            // loop through filters
            if (!empty($reportConfig->model->filters)) {
                foreach ($reportConfig->model->filters as $key => $value) {
                    $result = $this->detectInvalidFilter($value);
                    if ($result) {
                        $patient = array(
                            'info' => array(
                                'reportNodeId' => $node->nid,
                                'reportTitle' => $node->title,
                                'filter' => $value,
                                'published' => $node->status,
                                'configPath' => 'model/filters'
                            ),
                            'notes' => $result
                        );
                        $this->attachTreatment($patient);
                        $this->affected[] = $patient;
                    }
                }
            }
        }
    }
コード例 #23
0
 /**
  * Implements EntityReferenceHandler::getReferencableEntities().
  */
 public function getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0)
 {
     $nids = array_keys(oa_teams_get_teams_for_space());
     $teams = node_load_multiple($nids);
     $options = array(OA_TEAM_TYPE => array());
     $count = 0;
     foreach ($teams as $nid => $team) {
         $count++;
         $label = $this->getLabel($team);
         if (!$match || stripos($label, $match) !== FALSE) {
             $options[OA_TEAM_TYPE][$nid] = check_plain($this->getLabel($team));
         }
         if ($limit && $count == $limit) {
             break;
         }
     }
     return $options;
 }
コード例 #24
0
ファイル: SupController.php プロジェクト: dingruoting/tydaily
 public function actionList()
 {
     if (isset($_POST['uid'])) {
         $tids = user_load($_POST['uid'])->field__danwei;
     } else {
         $tids = array();
         $tids['und'][0]['tid'] = '62';
     }
     //var_dump($tids);
     $sels = new Sels();
     $easyNewsall = array();
     $query = new EntityFieldQuery();
     $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'sup')->propertyOrderBy('nid', 'DESC')->propertyCondition('status', 1)->range(0, 20);
     if (isset($_POST['lastnewsid'])) {
         $query->propertyCondition('nid', $_POST['lastnewsid'], '<');
     }
     $result = $query->execute();
     if (isset($result['node'])) {
         $news_items_nids = array_keys($result['node']);
         $news = node_load_multiple($news_items_nids);
         foreach ($news as $new) {
             //$power=false;
             //echo '标题:'.$new->title.'<br>';
             //var_dump($new->field__danwei['und']);
             //var_dump($tids['und']);
             foreach ($tids['und'] as $tid) {
                 //echo '$tid:'.$tid.'<br>';
                 if (in_array($tid, $new->field__danwei['und'])) {
                     //$power=true;
                     $easyNews['id'] = $new->nid;
                     $easyNews['title'] = $new->title;
                     $easyNews['img1'] = str_replace("public://", BigImg, $new->field_tux['und'][0]['uri']);
                     $easyNews['label'] = $new->field_biaoqian['und'][0]['value'];
                     array_push($easyNewsall, $easyNews);
                     break;
                 }
             }
         }
     }
     $sels->articles = $easyNewsall;
     $jsonObj = CJSON::encode($sels);
     echo $jsonObj;
 }
コード例 #25
0
 /**
  * Tests the Drupal 6 book structure to Drupal 8 migration.
  */
 public function testBook()
 {
     $nodes = node_load_multiple(array(4, 5, 6, 7, 8));
     $this->assertEqual($nodes[4]->book['bid'], 4);
     $this->assertEqual($nodes[4]->book['pid'], 0);
     $this->assertEqual($nodes[5]->book['bid'], 4);
     $this->assertEqual($nodes[5]->book['pid'], 4);
     $this->assertEqual($nodes[6]->book['bid'], 4);
     $this->assertEqual($nodes[6]->book['pid'], 5);
     $this->assertEqual($nodes[7]->book['bid'], 4);
     $this->assertEqual($nodes[7]->book['pid'], 5);
     $this->assertEqual($nodes[8]->book['bid'], 8);
     $this->assertEqual($nodes[8]->book['pid'], 0);
     $tree = \Drupal::service('book.manager')->bookTreeAllData(4);
     $this->assertEqual($tree['49990  4']['link']['nid'], 4);
     $this->assertEqual($tree['49990  4']['below']['50000  5']['link']['nid'], 5);
     $this->assertEqual($tree['49990  4']['below']['50000  5']['below']['50000  6']['link']['nid'], 6);
     $this->assertEqual($tree['49990  4']['below']['50000  5']['below']['50000  7']['link']['nid'], 7);
     $this->assertIdentical($tree['49990  4']['below']['50000  5']['below']['50000  6']['below'], array());
     $this->assertIdentical($tree['49990  4']['below']['50000  5']['below']['50000  7']['below'], array());
 }
コード例 #26
0
/**
 * Getter callback for skills property.
 */
function redesign_activity_property_skills_getter_callback($item)
{
    $skill_list = array();
    if ($item->type == 'activity') {
        // Start a new EFQ
        $query = new EntityFieldQuery();
        $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'skill')->fieldCondition('field_activity', 'target_id', $item->nid, '=');
        $result = $query->execute();
        // If results are returned, it will be in node key
        if (isset($result['node'])) {
            $nids = array_keys($result['node']);
            // Load all the nodes that were returned.
            $skills = node_load_multiple($nids, array('type' => 'skill'));
            $skill_list = array();
            // Build array of node titles.
            foreach ($skills as $skill) {
                // Unlinked title of the node.
                $skill_list[] = entity_label('node', $skill);
            }
        }
    }
    return $skill_list;
}
コード例 #27
0
ファイル: MsController.php プロジェクト: dingruoting/tydaily
 public function actionList($pageSize, $pageNo)
 {
     $sels = new Sels();
     $easyNewsall = array();
     $query = new EntityFieldQuery();
     $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'sr')->propertyCondition('status', 1)->fieldOrderBy('field_riq', 'value', 'DESC')->range($pageNo * $pageSize, $pageSize);
     $result = $query->execute();
     if (isset($result['node'])) {
         $news_items_nids = array_keys($result['node']);
         $news = node_load_multiple($news_items_nids);
     }
     foreach ($news as $new) {
         $easyNews = new EasyNews();
         $easyNews->id = $new->nid;
         $easyNews->title = $new->title;
         $easyNews->label = $new->field_status['und'][0]['value'];
         $easyNews->subTitle = "";
         $easyNews->img1 = str_replace("public://", BigImg, $new->field_tux['und'][0]['uri']);
         array_push($easyNewsall, $easyNews);
     }
     $sels->articles = $easyNewsall;
     $jsonObj = CJSON::encode($sels);
     echo $jsonObj;
 }
 /**
  *  @method:
  *    This is used to load all referenced node given the node ids
  */
 private function _load_referenced_nodes($node_ids = array())
 {
     $nodes = node_load_multiple($node_ids);
     return $nodes;
 }
コード例 #29
0
ファイル: httprl.examples.php プロジェクト: kreynen/elmsln
// Echo what was returned.
echo httprl_pr($results);
?>


Load nodes 50-100 using httprl_batch_callback and node_load_multiple as user 1.

<?php 
// List of nodes to load; 50-100.
$nids = range(50, 100);
// Run not parallel if background callbacks are disabled.
if (!httprl_is_background_callback_capable()) {
    // Run node_load_multiple as user 1
    $current_account = $GLOBALS['user']->uid;
    $GLOBALS['user'] = user_load(1);
    $results = node_load_multiple($nids);
    // Set global user back.
    $GLOBALS['user'] = $current_account;
} else {
    // Set options.
    $options = array('context' => array('uid' => 1));
    // Queue & Execute requests.
    $results = httprl_batch_callback('node_load_multiple', $nids, $options);
}
// Echo what was returned.
echo httprl_pr($results);
?>



Run a function in the background. Notice that there is no return.
コード例 #30
0
 /**
  * Get a node from the database based on its title.
  *
  * @param $title
  *   A node title, usually generated by $this->randomName().
  * @param $reset
  *   (optional) Whether to reset the internal node_load() cache.
  *
  * @return
  *   A node entity matching $title.
  */
 function backdropGetNodeByTitle($title, $reset = FALSE)
 {
     $nodes = node_load_multiple(array(), array('title' => $title), $reset);
     // Load the first node returned from the database.
     $returned_node = reset($nodes);
     return $returned_node;
 }