How to get Project Site creation date? - liferay

I created a Project Site in Liferay 6.1.1 CE GA2 and i want to know the creation date of that site using Liferay API.
So, any body can help me out?
Thanks in advance

Liferay stores informations about a site in many tables but the site identifier is the group stored in _group table.
Columns from this table's rows are mapped into the Group interface from Liferay API. http://docs.liferay.com/portal/6.1/javadocs/com/liferay/portal/model/Group.html
Unfortunately no creation date is stored in this table, consequently the Group interface it's unuseful.
Anyway I founded that when you create a new site, two layout sets are created into the layoutset table (private and public) and creation dates for those are stored. So as a sort of hack you could use information from those layout sets to know when your site was created.
Don't know if it's your case but for example the LayoutSetLocalServiceUtil class could be used in portlet jsp page this way:
<%
long groupId = company.getGroupId();
LayoutSet sitePrivateLayoutSet = LayoutSetLocalServiceUtil.getLayoutSet(groupId, true);
Date siteCreationDate = sitePrivateLayoutSet.getCreateDate();
%>
Note that you will need liferay theme taglib initialized this way:
<%# taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<liferay-theme:defineObjects />
Hope this helps!

Related

Kentico - Show sibling document name on the parent repeater

I got the following tree structure.
I have a repeater on Podcast page and need to display the latest sibiling document name on each item on the repeater. So for example, I will have the following in the repeater
MHPN Presents Ageing Well -
Latest: Episod 1
MHPN Presents Trauma and Resilience -
Latest: Trauma and Resilience: Trauma, a history
You could use webpart within the transformation. Something like that could do what you want. You have to change the ClassNames, SiteName, TransformationName with the one you want. This OrderBy will display the first on the tree. You can change it accordingly if you want something else.
<%# Control Language="C#" AutoEventWireup="true" Inherits="CMSWebParts_Viewers_Documents_cmsrepeater" Codebehind="~/CMSWebParts/Viewers/Documents/cmsrepeater.ascx.cs" %>
<cms:CMSRepeater ID="CMSRepeater1" runat="server" Path="./%" ClassNames="podcast.episode" SiteName="YourSite" TransformationName="podcast.episode.latest" TopN="1" OrderBy="NodeLevel, NodeOrder, NodeName" />
You can have a similar results using a Hierarchical viewer as well. However, since you require only one sibling you cannot do it that easily.
You can find an example at xperience and kentico
There might be small differences depending on the Kentico version you are using.
Dimitris

Liferay 7.3: How to preconfigure a portlet embedded in a page fragment?

We're using Liferay 7.3 (CE) and are trying to embrace the relatively new feature of "Content Pages" with "Page Fragments". We're able to develop page fragments that already include portlets (named "widgets" in the context of content pages), using the <lfr-widget-WIDGETALIAS> tag. So far, that works.
Now we're trying to prepare page fragments that embed portlets with special portlet configuration applied. For example, we want to prepare a page fragment that just shows an asset publisher portlet configured to list WebContent articles from a pre-defined category. The user should be able to just put that fragment onto the page without having to care about the configuration of the asset publisher portlet.
We did not find any direct way to achieve that -- our first guess that the configuration could be written as attributes or content of the <lfr-widget-...> tag was deterred by a hint in the liferay docs that there are no valid attributes or content to attach to that tag.
Does anybody have an inkling of an idea on how to achieve embedding portlets in page fragments with pre-defined portlet configuration applied? (including out-of-the-box Liferay portlets?)
I figured it out myself.
That one thing that the Fragment Editor does not tell you is that the HTML part of a fragment actually is interpreted as a Freemarker template, with the caveat that only Freemarkers alternative syntax is allowed.
That, in turn, means that Liferays taglibs are available, which means we can use the tag <liferay-portlet:runtime> (ported to freemarker alternative syntax, of course), which does accept a defaultPreferences attribute. Now we can just configure the portlet once, find its portletPreferences XML data in the DB (see table PortletPreferences), remove values we do not want to preconfigure and then just use the resulting preferences XML as a value for the defaultPreferences attribute of the <liferay-portlet:runtime> tag.
Care has to be taken for any IDs (e.g. if you want to preconfigure an AssetCategory filter). Better fetch the corresponding object from the corresponding service and get the ID from that object.
This example provides the HTML part for a page fragment that places an AssetPublisher onto the page, preconfigured to show 12 items (instead of the default 20). (CSS, JS and Configuration of the fragment is the default as given by the Page Fragment editor.)
<div class="fragment-12345">
[#assign assetPublisherPortletPreferences="<portlet-preferences>
<preference>
<name>delta</name>
<value>12</value>
</preference>
</portlet-preferences>" /]
[#liferay_portlet["runtime"]
instanceId="${fragmentEntryLinkNamespace}assets"
portletName="com_liferay_asset_publisher_web_portlet_AssetPublisherPortlet"
defaultPreferences="${assetPublisherPortletPreferences}"
/]
</div>
Thank you for this, #orithena. You saved me a lot of trouble.
Another option, to achieve the same result but with simpler syntax, is to use the built-in freeMarkerPortletPreferences:
[#assign assetPublisherPortletPreferences=freeMarkerPortletPreferences.getPreferences({
"delta": "12",
} /]

How to add an existing portlet to Web Content Display using Velocity templates

I want to create a new page using Web Content Display with Velocity Templates and Structures.
On my page I would like to have multiple tabs and on each tab needs to be added programatically from a template of an existing portlet.
I know how to add an existing portlet to my theme ($theme.runtime("portlet_id")) but I can't find a way to add the portlets to a velocity template since $theme object is not available in a Web Content Display template.
Can you please tell me if it is possible to add a portlet to a template?
If yes, how?
Thank you.
You can use the runtime-portlet tag in the velocity templates:
<div id="portlet-inside-wc">
<runtime-portlet name="portlet-id" instance="instanceID" queryString=""/>
</div>
Where name is the portlet ID, instance is the 4 letter unique (Alpha Numeric) word and Querystring can be portlet preferences.

what is the easiest way to filter articles in liferay theme

Excuse me if I'm asking silly or easy question, but I just can't figure it out.
So, I have a theme, I want to render only portlets, skipping any journal articles.
Which is the most appropriate way to do it?
In your theme's resources, there is a portlet.vm template available in the _diffs/template directory. This template allows you to override the default presentation of portlets in general (e.g. change the configuration icons, remove the title bar, ...).
However, inside portlet.vm Liferay injects a predefined variable called $portletDisplay. This is an instance of the com.liferay.portal.theme.PortletDisplay class and represents the portlet that is currently printed.
You can use the $portletDisplay.portletName attribute to check for 56, which is the ID for all Web Content Display portlets. So, in short, encapsulate the parent <div> inside portlet.vm with the following condition:
#if($portletDisplay.portletName == '56')
<div class="portlet" ...>
...
</div>
#end

Can I Do This In Grails 2: Secure Individual Tabs with Spring Security

If I create tabs using one of the Grails GUI options (which one should I use), is it possible to turn tabs on and off, based on the current user? For example only users with a role of admin should see the Manage Users tab. And even anonymous users should see the Main Content tab.
Ideally, I'd like to use Spring Security ACL.
Just to add, sometimes you can add too much logic and coding in the view (GSP). You can push more of the code to the controller by using other options such as the navigation plugin along with the Spring-Security plugin. The nice thing is the view is just cleaner removing condition tags.
grails install-plugin navigation
Then in the controller just use the #Secured annotation. For example I created two tabs with two corresponding controllers.
#Secured(['ROLE_ADMIN'])
class SlidesController {
static navigation = [
group:'tabs', order:10, title:'Users', action:'index'
]
def index = {
.....
}
#Secured(['ROLE_ADMIN'])
class ProgramsController {
static navigation = [
group:'tabs', order:10, title:'Programs & Presentation', action:'index'
]
def index = {
.....
}
In the view:
<head>
... other head elems.
<nav:resources/>
</head>
<body>
<nav:render/>
... Your other stuff
</body>
Tabs automatically appears (would be also useful to make this view a layout GSP).
Yes, it's possible and pretty easy with the Acegi (Spring Security Plugin), see this section of the docs. You'll need to define some roles, and then describe how those roles apply to different URLS. Example (from link above):
/admin/=ROLE_USER
/book/test/=IS_AUTHENTICATED_FULLY
/book/**=ROLE_SUPERVISOR
There is also explanation about exactly how to do this in Grails In Action book.
Spring Security has a nice tag library for this. You can delimit rendering the tabs by using something similar to this:
<sec:authorize access="hasRole('supervisor')">
This content will only be visible to users who have
the "supervisor" authority in their list of <tt>GrantedAuthority</tt>s.
</sec:authorize>
You can just enable the jsp tag as normal:
<%# taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
Read more about it here if you like

Resources