문제

I have created a content type named history when ever users want to opens specific page the content history should be inserted with new row.

I'm using rules but stucked with query.

I have written a simple query to insert the data it even works but the problem when I fetch the data in view it doesn't show up.

도움이 되었습니까?

해결책

Don't good way to create content type for logs. Just create simple table with columns: nid (node id), visited (datetime of visit), uid (user id, for guests = 0)

In your module add this:


/**
 * Implementation of hook_exit().
 */
function YOURMODULENAME_exit() {
  drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH);

  if ((arg(0) == 'node') && is_numeric(arg(1)) && (!arg(2))) {
    global $user;
    $node = node_load(arg(1));
    if (in_array($node->type, array('some_content_types'))) {
      db_query('INSERT INTO {somelogtable} VALUES(%d, %d, %d)', $node->nid, time(), $user->uid);
    }
  }
}

And somewhere you can show listing of this nodes.
For more example. look statistics module as sayed above.

다른 팁

Can't the Statistics module help you? "It counts how many times, and from where each of your posts is viewed".

Book가 저자에 속한 경우 도메인 모델에서 지우지 않습니다.그렇다면 Tom Metz가 말한 것처럼 도메인 모델과 쿼리에 해당 사실을 추가해야합니다.

이 권리를 얻게하십시오.제목 (또는 ID) i.e. '책 1'및 '책 2'로 책을 쓰는 작성자 [s]를 찾고 싶습니다. 수표 작업을하기 위해 책을 '도서 1'으로 참여하고 책 제목을 'Book2'로 가입하는 책 제목을 비교해야합니다.

다음 테스트가 작동해야한다고 가정 할 수 있습니다 :

void setUp() {
    def author = new Author(name: "Ted Jones").save(flush: true)
    def author2 = new Author(name:  "Beth Peters").save(flush: true)
    def author3 = new Author(name:  "Foo Bar").save(flush: true)
    def book1 = new Book(title: 'Book 1').save(flush: true)
    def book2 = new Book(title: 'Book 2').save(flush: true)
    def book3 = new Book(title: 'Book 3').save(flush: true)
    def book4 = new Book(title: 'Book 4').save(flush: true)
    author.addToBooks(book1)
    author.addToBooks(book3)

    author2.addToBooks(book2)
    author2.addToBooks(book4)

    author3.addToBooks(book1)
    author3.addToBooks(book2)
}

void testAuthorCrit() {
    def result = Author.withCriteria() {
        books {
            eq("title", "Book 1")
        }
        books {
            eq("title", "Book 3")
        }
    }
    assert 1 == result.size()
    assertTrue(result.first().name == "Ted Jones")
}
.

그러나 결과 집합이 비어 있음을 밝혀냅니다.Grails는 각 책 폐쇄의 진술을 하나의 조인으로 병합합니다.

결과 쿼리입니다.

 select this_.id as id1_1_, this_.version as version1_1_, this_.name as name1_1_, books3_.author_books_id as author1_1_, books_alia1_.id as book2_, books3_.books_idx as books3_, books_alia1_.id as id0_0_, books_alia1_.version as version0_0_, books_alia1_.title as title0_0_ from author this_ inner join author_book books3_ on this_.id=books3_.author_books_id inner join book books_alia1_ on books3_.book_id=books_alia1_.id where (books_alia1_.title=?) and (books_alia1_.title=?)
.

ASFAIK 이는 Grails Criteria API를 사용하여 아카서 v 방지 할 수 없습니다. 그러나 대신 HQL을 사용할 수 있습니다.다음 테스트 작업 :

void testAuthorHql() {
    def result = Author.executeQuery("select a from Author a join a.books bookOne join a.books bookTwo where bookOne.title=? and bookTwo.title=?", ['Book 1', 'Book 3'])
    assert 1 == result.size()
    assertTrue(result.first().name == "Ted Jones")
}
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top