why viewscount posts not working?

Posted by Community Admin on 03-Aug-2018 22:39

why viewscount posts not working?

All Replies

Posted by Community Admin on 31-Jan-2011 00:00

Hello,
I created a post, but increasingly people viewing the post, the Views_count continues to zero. why this happens, because it is the trial version or is it that I forgot to do something else.

Posted by Community Admin on 01-Feb-2011 00:00

I also have that doubt, would help me a lot!

Posted by Community Admin on 02-Feb-2011 00:00

Hi Leandro / Renato,

Thank you for contacting us. It seems that this option isn't working. I'm logging it as a bug with ID 106713.

Greetings,
Petya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 15-Feb-2011 00:00

Hello!
can you please tell me if it will be addressed with an internal build or have I to wait till SP1?

thanks
Ilaria

Posted by Community Admin on 16-Feb-2011 00:00

Hello Leandro,

Actually there is no implementation for ViewCount. We will try to implement the logic for SP1, but it would be more complicated, since we are talking not for a bug fixing but for entire implementation. Most probably this will be included in one of the internal builds.

Best wishes,
Ivan Dimitrov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 16-Feb-2011 00:00

Hello Ivan,
sorry if I get inside this thread... I'm helping Ilaria on the demo project she's working on..... my question is why there's a viewcount member in the class (at the moment public ) if there's no code behind it?

What if we manually increment this? it's possible? Thanks

Posted by Community Admin on 17-Feb-2011 00:00

Hello Paolo,

We left the member for future implementations.
You could try manually to set the value

App.WorkWith().BlogPosts().First().Do(bp1 =>
               
                    bp1.ViewsCount = 1;
                ).SaveChanges();

Best wishes,
Ivan Dimitrov
the Telerik team

Posted by Community Admin on 17-Feb-2011 00:00

I  created  an  aspx  page  and  put  this  code  in  Page_Load  and  it  worked,  but  I  need  it  to  be  the  template  full  post,  how  do  I  put  this  code  in  the  page  that  shows  the  full  post?

Thanks

Posted by Community Admin on 18-Feb-2011 00:00

Hi Leandro,

You can drop BlogPostView control on a page and edit its SingleView template from the control designer. You can add server side code inline and subscribe for ItemCreated event of the RadListView. Inside ItemCreated you can access the data item which is the content and set the ViewCount property.

Regards,
Ivan Dimitrov
the Telerik team

Posted by Community Admin on 18-Feb-2011 00:00

Also we have this doubt

how would I add code on the server side and embedded register for this event ItemCreated of RadListView? Could you give me an example?

Posted by Community Admin on 21-Feb-2011 00:00

hello Ivan,
thanks a lot, it works!

i've got an another problem: the counter is increased by code, but only in my custom control. Where can i put the same code for increase the countview when the user open the document from the download list?
Is it possible using a workflow?

Posted by Community Admin on 21-Feb-2011 00:00

Hello,

When you view an item on the public side, the workflow is not called. Generally you should make the same changes in DownloadList control and its templates. You should work with Documents facade instead of using Blogs.

Regards,
Ivan Dimitrov
the Telerik team

Posted by Community Admin on 21-Feb-2011 00:00

Can you please me give me an example about it?

Posted by Community Admin on 21-Feb-2011 00:00

Hello Leandro,

You can create a custom control that is data-bound. Generally, Sitefinity 4.0 public controls are data-bound, and their templates are available through the widget editor.
Since we have not yet moved to the ASP.NET parser for db-stored and embedded templates, you will have to implement  a simple control. Here is a very simple, but working sample:

using System;
using System.Web.UI;
using Telerik.Sitefinity.GenericContent.Model;
using Telerik.Sitefinity.Web;
 
namespace Telerik.Sitefinity.Examples
    public class ContentItemCounter : Control
    
        private int? viewsCount = null;
 
        protected override void OnDataBinding(EventArgs e)
        
            base.OnDataBinding(e);
            var dbContainer = this.GetDataItemContainer();
            var contentItem = dbContainer != null ? dbContainer.DataItem as Content : null;
            if (contentItem != null)
            
                App.WorkWith()
                    .AnyContentItem(contentItem.GetType(), contentItem.Id)
                    .GetLive()
                    .Do(c =>
                    
                        this.viewsCount = c.ViewsCount;
                        c.ViewsCount++;
                    )                  
                    .SaveChanges();
            
        
 
        protected override void Render(HtmlTextWriter writer)
        
            if (this.viewsCount.HasValue)
            
                writer.Write(this.viewsCount.Value);
            
        
    

This code should be flexible enough to handle any kind of content item. There are few interesting things about this code:
  • It demonstrates how to implement data-context-aware control. You do so by overriding OnDataBinding, and retrieving the data-bound-context by using the Sitefinity Control method extension GetDataItemContainer. It is registered in Telerik.Sitefinity.Web, so you have to include the namespace in order to use it. Your data item will be in the DataItem property.
  • The relatively new AnyContent fluent API is used. It is an abstraction that should work on any Content-derived model, as long as it meets certain conditions (e.g. ManagerTypeAttribute).
  • Since on the public side we see only live items (published), we are guaranteed to have a live item. We skip the content lifecycle, (e.g. no CheckOut and CheckInAndPublish calls). If you are curious, they would not work, since we have not yet implemented document counting (which is much more complex than this oversimplified example), and it is not copied over lifecycle states. Finally, we SaveChanges.
  • An overly simple "render" is implemented.

Once you have put your class in an assembly and referenced it from your web project, you will have to choose which templates to use the control. I chose the List of documents for direct download widget template, and made the following changes:

<%@ Control Language="C#" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.PublicControls.BrowseAndEdit" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sitefinity" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
 
<%@ Register TagPrefix="sfEx"  Namespace="Telerik.Sitefinity.Examples" Assembly="Telerik.Sitefinity.Examples" %>
 
<sitefinity:ResourceLinks id="resourcesLinks2" runat="server" UseEmbeddedThemes="true" Theme="Default">
  <sitefinity:ResourceFile Name="Telerik.Sitefinity.Resources.Themes.Basic.Styles.icons.css" Static="true" />
</sitefinity:ResourceLinks>
<sf:BrowseAndEditToolbar ID="browseAndEditToolbar" runat="server" Mode="Edit"></sf:BrowseAndEditToolbar>
<div id="itemsContainer" runat="server">
    <asp:Repeater ID="documentsRepeater" runat="server">
        <HeaderTemplate>
            <ul class="sfdownloadList sfListMode">
        </HeaderTemplate>
        <ItemTemplate>
            <li id="docItem" runat="server" class="sfdownloadFile">
                <sitefinity:SitefinityHyperLink ID="documentLink" runat="server" CssClass="sfdownloadTitle" target="_blank" />
                <sitefinity:SitefinityLabel id="infoLabel" runat="server" WrapperTagName="div" HideIfNoText="false" CssClass="sfInfo" />
                <sfEx:ContentItemCounter ID="someID" runat="server" />
 
            </li>
        </ItemTemplate>
        <FooterTemplate>
            </ul>
        </FooterTemplate>
    </asp:Repeater>
</div>
<sitefinity:Pager id="pager" runat="server"></sitefinity:Pager>

Of course, you should change your change your Register directive to whatever your setup is. As I said before, this control is data-bound, and, therefore, inserted inside the repeater. Since it outputs a number or nothing, you can customize its output to whatever you like.

The final step for this example to work is to create and publish a page with DownloadList on it. Make sure you choose the template we've modified (edit->settings->type:list).

Regards,
Dido
the Telerik team

Posted by Community Admin on 22-Feb-2011 00:00

Hello!
I try the code you post, but the result of the contentItem is always null, at the end of this instuction:
var contentItem = dbContainer != null ? dbContainer.DataItem as Content : null;

Any suggestion?

edit:
the program return null calling this.GetDataItemContainer() too!

protected override void OnDataBinding(EventArgs e)
       
           base.OnDataBinding(e);
           var dbContainer = this.GetDataItemContainer();
           var contentItem = dbContainer != null ? dbContainer.DataItem as Content : null;

Posted by Community Admin on 14-Mar-2011 00:00

Hi Leandro,

First, I would like to apologise for the late response.

The most probable reason is that you inserted the item in a context that is not data-bound.
A possible problem with this sample code is that it could throw an exception if the user does not have the permissions to modify the item. Another drawback is that the performance would degrade siginficantly if you displayed a lot of items on the same page. Those are acceptable for demonstration purposes.

I am packing you a working project. You could use it as a starting point for your own customizations. Of course, you should change the paths in project.xml and the VS project to point to a valid location on your computer. You should also populate the bin directory of the web site. A detached database of mssql 2008r2 is included in the archive.

Kind regards,
Dido
the Telerik team

Posted by Community Admin on 11-Apr-2011 00:00

hello Telerik,
will this feature be fixed with the relaese of 14 april?
Thanks

Posted by Community Admin on 12-Apr-2011 00:00

Hello Paolo,

This has been scheduled for Q2.

Regards,
Georgi
the Telerik team

Posted by Community Admin on 12-Apr-2011 00:00

And when it is scheduled for delivery Q2?

Posted by Community Admin on 12-Apr-2011 00:00

Hello, you gave me a complete system that is already working with the count, only that there were several inconsistencies with my system, instead of me you spend an entire project already working as you did, you could not pass me what changes should I do my project for the dll Telerik.Support.Samples spotting it and what must change in my project to run the count of the dll?

Makes a little tutorial for all of us, I'm sure that will not only meet me.

Already

Thanks

Posted by Community Admin on 13-Apr-2011 00:00

Hi Leandro,

After Q1 release we will spend some time creating a blog post or KB about this implementation. I see that Dido has attached entire project, so I do not think that there are issues with it.

Greetings,
Ivan Dimitrov
the Telerik team


Posted by Community Admin on 16-May-2011 00:00

Hi,

I am wondering if I can get some help with something similar.

I want the system to log in the database whenever a user has viewed a news item, by logging
the page title (e.g. News Item 1).

1 - I have created a simple User Control that does the database stuff in the Page_Load event.

// Get the currently logged in user.
var manager = UserManager.GetManager();
var currentUser = manager.GetUser(SecurityManager.GetCurrentUser().Identity.Name);
 
var m = PageManager.GetManager();
string itemTitle = m.GetPageNode(new Guid(SiteMapBase.GetCurrentProvider().CurrentNode.Key)).Page.Title.ToString();
 
// Establish a connection with the Database.
var dataConfig = Config.Get<DataConfig>();
string conStr = dataConfig.ConnectionStrings["SeflBriefing"].ConnectionString;
SqlConnection connection = new SqlConnection(conStr);
connection.Open();
 
try
    // Try inserting into the database a new record of the current user and document.
    SqlCommand command = new SqlCommand("dbo.spLogUserActivity", connection);
    command.CommandType = System.Data.CommandType.StoredProcedure;
    command.Parameters.Add(new SqlParameter("@firstname", SqlDbType.NVarChar, 50)).Value = currentUser.FirstName;
    command.Parameters.Add(new SqlParameter("@lastname", SqlDbType.NVarChar, 50)).Value = currentUser.LastName;
    command.Parameters.Add(new SqlParameter("@accessedwhat", SqlDbType.NVarChar, 255)).Value = itemTitle;
    command.Parameters.Add(new SqlParameter("@accesstime", SqlDbType.DateTime2)).Value = DateTime.Now;
    command.ExecuteNonQuery();
// finally, make sure the connection is closed.
finally if (connection.State != ConnectionState.Closed) connection.Close();

2 - Then I have registered the User Control in the single news item template.
<%@ Control Language="C#" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.ContentUI" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.PublicControls.BrowseAndEdit" Assembly="Telerik.Sitefinity" %>
 
<%@ Register TagPrefix="cpRR" TagName="ReaderRegister" Src="~/Controls/ReaderRegister.ascx"%>
 
<telerik:RadListView ID="DetailsView" ItemPlaceholderID="ItemContainer" AllowPaging="False" runat="server" EnableEmbeddedSkins="false" EnableEmbeddedBaseStylesheet="false">
 
    <LayoutTemplate>
        <div class="sfnewsDetails">
            <div class="sfnewsLinksWrp">
                <sf:MasterViewHyperLink class="sfnewsBack" Font-Size="20px" Text="<%$ Resources:NewsResources, AllNews %>" runat="server" />
            </div>
            <asp:PlaceHolder ID="ItemContainer" runat="server" />
        </div>
    </LayoutTemplate>
 
    <ItemTemplate>
 
<div>
    <table style="width:100%;text-align:left;font-size:x-large;border-top:1px solid Black;border-bottom:1px solid Black;">
        <tr>
            <td colspan="2" style="font-weight:bold;">Text</td>
        </tr>
        <tr>
            <td style="font-weight:bold;">Some Text</td>
            <td>
                <table style="width:100%;">
                    <tr>
                        <td style="text-align:right;font-weight:bold;">Staff Notice:</td>
                        <td style="text-align:right;width:150px;">
                            <sitefinity:TextField runat="server" DisplayMode="Read" Value='<%# Eval("ReferenceCode")%>' />
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td>Some more text here</td>
            <td>
                <table style="width:100%;">
                    <tr>
                        <td style="text-align:right;font-weight:bold;">Issued:</td>
                        <td style="text-align:right;width:150px;">
                            <sf:FieldListView ID="PublicationDate1" runat="server" Format="PublicationDate.ToLocal():dd-MM-yyyy" />
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</div>       
 
<h1 class="sfnewsTitle">
            <asp:Literal Text='<%# Eval("Title") %>' runat="server" />
        </h1>
 
        <div style="font-size:medium;">
            <asp:Literal ID="Literal1" Text='<%# Eval("Content") %>' runat="server" />
        </div>
 
<div style="font-size:large;">
    <asp:Literal ID="signatureLine" Text='_______________________________' runat="server" />
    <sitefinity:TextField runat="server" DisplayMode="Read" Value='<%# Eval("Author")%>' />   
    <sitefinity:TextField runat="server" DisplayMode="Read" Value='<%# Eval("SourceName")%>' />        
    <sf:FieldListView ID="PublicationDate" runat="server" Format="PublicationDate.ToLocal():dd MMM yyyy" />
    <cpRR:ReaderRegister ID="ucReaderRegister" runat="server" />
</div>
 
    </ItemTemplate>
</telerik:RadListView>

But all it registers in the database is the page title of the page on which the news list is placed.
Why and what do I do to get the title of the actual news item in the database.?

Many thanks,
Andrei


Posted by Community Admin on 16-May-2011 00:00

Hi Andrei,

The single item page is a dynamic not existing in the SiteMap page. It is formatted based on the content item title. You should be able to get the news item title in DetailsView template

<asp:Literal Text='<%# Eval("Title") %>' runat="server" />


All the best,
Ivan Dimitrov
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 17-May-2011 00:00

Ivan,

Break it down for me. I am not sure what you mean. 

Can I programmatically get the Title in my UserControl?

Give a code example based on the UserControl that I have submitted if possible.

Many thanks,
Andrei

Posted by Community Admin on 17-May-2011 00:00

Hi Andrei,

In your code you get the title in the same way

<h1 class="sfnewsTitle">
            <asp:Literal Text='<%# Eval("Title") %>' runat="server" />
        </h1>


This returns the time as per your request "Why and what do I do to get the title of the actual news"

All the best,
Ivan Dimitrov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 17-May-2011 00:00

Ivan,

Thank you very much. Its working now. I was being a bit silly.
Got it now, by placing the data fields in my own ASCX.

Many thanks,
Andrei

This thread is closed