How to create a sub-organization in Liferay 6.1 - liferay-6

I want to create a sub-organization inside a Organization in Liferay 6.1.
Please guide me to achieve this.
Regards,
Dinesh.

To create sub organization you can use this code snippet
OrganizationLocalServiceUtil.addOrganization (
userId, parentOrganizationId, name,
type, recursable, regionId, countryId,
statusId, comments, false, serviceContext);
Note :- Pass parentOrganizationId to link sub organization to parent oraganization
HTH

Related

How to use Selector query in ZK

I was going through these pages on ZK documentation ID_Space -Selector and looked at following code
comp.query("#ok"); //look for a component whose ID's ok in the same ID space
comp.query("window #ok");
comp.queryAll("window button");
I am wondering how can I use this in my code? I am creating 2 drop downs and adding Id to both these drop downs
Listbox listbox=createListbox(widget, DetailsListRenderer.ORDERSTATUS.class, null,orderStatus);
listbox.setId(ORDER_STATUS_ID);
So when My page is getting refreshed, I am getting exception of Unique Id, I was wondering if these is a way I can query component and see if same component with same Id already exists and in case it exists, I should not add ID to that component, or should not create component at all
Any suggestion?
I tried something like
widget.getFellow( ORDER_STATUS_ID); but getting `org.zkoss.zk.ui.ComponentNotFoundException` exception.
widget.getFellow("#" + ORDER_STATUS_ID);
For widgets that co-exist in the same ID space (a.k.a fellow widgets), one may use any of the following to refernece a fellow from a certain widget:
var fellow = widget.$f('fellowID');
var fellow = widget.$f().fellowID;
var fellow = zk.Widget.$(jq('$fellowID')[0]);

How to get all courses on moodle?

I need to show all moodle courses in menu listing.
Can anyone suggest me that how can I get all courses using php code or moodle inbuilt functions.
Thanks
Assuming you are writing code to be run within Moodle, you can use the get_courses() function defined within lib/datalib.php. For example:
<?php
require_once(PATH_TO_MOODLE_ROOT . '/config.php');
$courses = get_courses();
print_r($courses);
will print out a data-dump of the returned array, showing details of all the courses in your Moodle site. This example is obviously not appropriate to use on a production site!
If you check the function definition in lib/datalib.php you will see the options available for restricting the result set to particular fields or controlling the sort order.
Include this file
require_once($CFG->dirroot . '/lib/coursecatlib.php');
Use this function to get all courses in menu listing.
$allcourses = coursecat::get(0)->get_courses(array('recursive' => true));
var_dump($allcourses);exit;
If you want to show only enrolled course to student you can use following method.
require_once($CFG->dirroot.'/blocks/course_overview/locallib.php');
global $USER,$DB;
$courses = enrol_get_users_courses($USER->id, true);
OR
If you want list all courses..
global $DB;
$query = "SELECT id, fullname, shortname from {course}";
$courselist = $DB->get_records_sql($query);
foreach ($courselist as $course) {
echo $course->fullname;
}
Thanks

How do I put a specific order to Jbehave story execution?

When you submit sorties to Jbehave with
#Override
public InjectableStepsFactory stepsFactory()
{
return new InstanceStepsFactory(configuration(),
new LoginSteps(), new PreferencesSteps(), new BetterSteps());
}
They are executed in BetterSteps, LoginSteps, PreferencesStpes fasion.
How do I make these classes having scenarios execute in a custom order which is not alphabetical?
Say LoginSteps followed by PreferenceSteps followed by BetterSteps etc?
There is a work around for your problem..
You can make your story name starting from Sn where n is 1,2,3..... like S1_LoginSteps, S2_PreferenceSteps
Jbehave will execute stories alphabetical starting from S1 then S2....
Do I understand you correctly that you have steps with identical or similar patterns in all of these steps classes and want to control which of them are used over others?
If so, have a look at step prioritization here: http://jbehave.org/reference/stable/prioritising-steps.html and apply priorities to your preferred steps.

How to get articleId dynamically?

I am using Asset Publisher and need to dynamically get the articleId of the latest journal article published.
I am using in abstracts.jsp hook:
version=JournalArticleLocalServiceUtil.getLatestVersion(assetRenderer.getGroupId(), "14405");
journalArticle = JournalArticleLocalServiceUtil.getArticle(assetRenderer.getGroupId() , "14405",version);
I have hardcoded the articleId here.
How do I avoid this??
Kindly help.
Thanks.
Use a dynamic query to get the latest Article from JournalArticleLocalServiceUtil maybe you can use ProjectionFactoryUtil.max("createDate"); to get the latest Date
DynamicQueryFactoryUtil.forClass(JournalArticle.class)
.add(ProjectionFactoryUtil.max("createDate"))
.add(PropertyFactoryUtil.forName("groupId").eq(new Long(groupId)));
List results =JournalArticleLocalServiceUtil.dynamicQuery(query);`

Liferay: how to save to portlet user information?

I have at the welcome page a weather portlet, and user can configure the portlet and select his city. Is it possible to store user information in the portlet preferences, so that every user has his one stored city? Or what is the standard workflow to store user-portlet information without to develop own (persist) service?
thx
The portlet-preferences are in liferay per default not user specific. That can be modified in liferay-portlet.xml with next lines:
<liferay-portlet-app>
<portlet>
<portlet-name>ThePortletWitchUserSpecificPreferences</portlet-name>
<icon>/icon.png</icon>
<preferences-unique-per-layout>false</preferences-unique-per-layout>
<preferences-owned-by-group>false</preferences-owned-by-group>
</portlet>
...
</liferay-portlet-app>
the two lines <preferences-... and the order are abbreviated.
for more information see:
http://rutvijshah.wordpress.com/2009/12/06/user-specific-preferences-in-liferay/
It's not a native function of the PortletPreference : the setValue method allow only a String, unfortunately you can't pass a Map.
However, i see a solution to hardcode it, but it's a little bit ugly...
Long userId = ...... ;
String userValue = ..... ;
PortletPreferences prefs = request.getPreferences();
prefs.setValue("myConfig-"+userId, myUserVal);
prefs.store();
And for retrieve the data :
String userValue = prefs.getValue("myConfig-"+userId, defaultValue);
This solution will work, but don't do that is you have a big numbers of users.
Portlet Preferences are save in xml in your database, if you have 100k+ users, it will explode :)
If you think this solution is not enough clean, you will have to create your own persistence method with the ServiceBuilder.