I am trying to integrate jomsocial events with jomsocial groups.
What i am trying to achieve is to automatically create a group when the event is being created.
Would anyone have some hints regarding such functionality?
The approach i have in mind is to utilize a function onEventCreate($event) from jomsocial API
to call the group creation mechanism. Is that the right way to do it?
Yes, this is the approach I'd take.
You can find method save() in groups.php controller. There you've got all of the required code to implement this.
The rough code :
$my =& CFactory::getUser();
$config =& CFactory::getConfig();
$group =& JTable::getInstance( 'Group' , 'CTable' );
$group->name = $name;
$group->description = $description;
$group->categoryid = $categoryId; // Category Id must not be empty and will cause failure on this group if its empty.
$group->website = $website;
$group->ownerid = $my->id;
$group->created = gmdate('Y-m-d H:i:s');
$group->approvals = 0;
$params = new CParameter( '' );
// Here you need some code from private _bindParams()
$group->params = $params->toString();
$group->published = ( $config->get('moderategroupcreation') ) ? 0 : 1;
$group->store();
// Other useful stuff:
// - store the creator / admin into the groups members table
// - add into activity stream
Related
I am developing a custom payment gateway. It uses OrderIncrementID to identify which Order was the payment made for. I have every functionality running after the Order has been placed, i.e. after checkout, except one in the checkout page itself.
In the checkout page, Order was not created, getting an OrderIncrementID seems very difficult. We have to overwrite the order creation in the checkout such that it will be created after the payment method selection which sounds very complicated and dangerous to overwrite the flow. An alternative is to use QuoteID, but the tradeoff is that I have to implement a convertion from QuoteID to OrderIncrementID.
What can I do in this case to get an OrderIncrementID in the checkout page? especially after the payment method selection
You actually already have a reserved order id on the quote.
You just have to do :
$quote = Mage::getSingleton('checkout/session')->getQuote();
$quote->getReservedOrderId(); // this will be your order_increment_id
I developed bellow code to get next increment ID
I am not sure this will give correct result always.
But, this can help you
Please bellow code in any resource model to call
For example : place code in Names_Test_Model_Resource_Test class
public function getNextIncrementId(){
$store = Mage::app()->getStore();
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
$entityStoreTable = $resource->getTableName('eav_entity_store');
$entityTypeTable = $resource->getTableName('eav_entity_type');
$selectEntity = $readConnection->select()->from($entityTypeTable, "*")
->where("entity_type_code = 'order'");
$entityTypeRow = $readConnection->fetchRow($selectEntity);
if(isset($entityTypeRow['entity_type_id']) && $entityTypeRow['entity_type_id'] > 0){
$orderEntityTypeId = $entityTypeRow['entity_type_id'];
$entityStoreSelect = $readConnection->select()->from($entityStoreTable, "*")
->where("store_id = ? AND entity_type_id = $orderEntityTypeId", $store->getId());
$row = $readConnection->fetchRow($entityStoreSelect);
$lastIncrementId = 0;
if(isset($row['increment_last_id'])){
$lastIncrementId = $row['increment_last_id'] + 1;
}
return $lastIncrementId;
}
return 0;
}
To call this function you can use
$nextIncrementId = Mage::getResourceModel('test/test')->getNextIncrementId();
We can also find last increment id from orders table
Please comment for better solutions
What is the recommended way to get the access level for the current content (article) being rendered for the active request, using the Joomla API.
Currently I've got it hacked using a manual query but this doesn't feel right in that I assume that there should be a way to get the access level using the object model, and not by having to write a custom query.
$db = JFactory::getDBO();
$cid = JRequest::getInt('id', 0); // get the content id from the request
$query = ' SELECT #__content.access FROM #__content WHERE #__content.id="'.$cid.'"';
$db->setQuery($query);
$objList = $db->loadObjectList();
foreach($objList as $obj)
{
return $obj->access; // gets the access level for the first object
}
You can call getItem function defined in model of article in below file:
components\com_content\models\article.php
You need to load the model first and call the getItem function by passing article id.
jimport('joomla.application.component.model');
JModelLegacy::addIncludePath(JPATH_SITE.'/components/com_content/models');
$articleModel = JModelLegacy::getInstance( 'Article', 'ContentModel' );
Call the function:
$result = $articleModel->getItem($articleId);
And use the access level:
$result->access;
Hi i kinda found the way to display the modules in the component but i am wondering how could i save the parameters through component i mean editing the values in component and saving it.
The modules names and paramaters are known in advance. So the calling will be like this
jimport( 'joomla.application.module.helper' );
$module = &JModuleHelper::getModule( "ModuleName");
$params = new JParameter($module->params);
The purpose of doing so is to ease editing certain values for the customer so it is a pain for a newbie to browse all that joomla stuff(in my case).
All in all cant figure out, how to save the params of a module(s)
Hi this is the code to save the params of a component, module or plugin in Joomla.
It first loads the current params, makes its changes, then saves again; ensure you always load the current params first.
$mparams = JComponentHelper::getParams( 'com_littlehelper' );
$params = $mparams->get('params');
$mparams->set('params.favicons_sourcepath','icons');
$this->saveParams($mparams, $this->componentName);
private function saveParams($params, $extensionName, $type='component') {
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->update('#__extensions AS a');
$query->set('a.params = ' . $db->quote((string)$params));
$query->where(sprintf('a.element = %s AND a.%s = %s',
$db->quote($extensionName),
$db->quoteName('type'),
$db->quote($type)
));
$db->setQuery($query);
return $db->execute();
}
This code comes from my extension LittleHelper published on the JED.
I have created a link in Magento admin to create the invoice for individual product, But while calling the function $order->prepareInvoice($qtys) it will add all the product in invoice even I am passing only one item.
I am using below code.
$order = Mage::getModel('sales/order')->load($this->getRequest()->getParam('order_id'));
$count = $order->getTotalItemCount();
$qtys = Array
(
[370] => 1
);
$invoice = $order->prepareInvoice($qtys);
if (!$invoice->getTotalQty()) {
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.'));
}
$amount = $invoice->getGrandTotal();
$invoice->register()->pay();
$invoice->getOrder()->setIsInProcess(true);
$history = $invoice->getOrder()->addStatusHistoryComment('Partial amount of $'. $amount .' captured automatically.', false);
$history->setIsCustomerNotified(true);
$order->save();
Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder())
->save();
$invoice->save();
Any Suggestion ?
The logic found in Mage_Sales_Model_Service_Order::prepareInvoice, the method which you are ultimately calling to prepare the invoice, reveals what is at play here. The following loop is employed, and the inner else-if block is where the qty is set when an array of qtys is passed in:
foreach ($this->_order->getAllItems() as $orderItem) {
if (!$this->_canInvoiceItem($orderItem, array())) {
continue;
}
$item = $this->_convertor->itemToInvoiceItem($orderItem);
if ($orderItem->isDummy()) {
$qty = $orderItem->getQtyOrdered() ? $orderItem->getQtyOrdered() : 1;
} else if (!empty($qtys)) {
if (isset($qtys[$orderItem->getId()])) {
$qty = (float) $qtys[$orderItem->getId()];
}
} else {
$qty = $orderItem->getQtyToInvoice();
}
$totalQty += $qty;
$item->setQty($qty);
$invoice->addItem($item);
}
The $qtys variable is the array which you are passing in to the prepareInvoice call. In your case, you are only passing an index for the item you wish to add to the invoice. Per the documentation (and the above loop), this should work, except for one minor problem: the above loop is not resetting the value of $qty at the top of the loop to 0. This does not pose a problem when called from the core code which processes initialization of the invoice when created from the admin via the pre-existing form, as the form which is being submitted will always contain a value for each item on the order, and in the case of only 1 item being invoiced, all others will hold a 0 qty value thus working around the failure to reset the value of $qty.
To solve your problem, try setting your $qtys variable like so (I'm assuming 370 and 371 are the two order item entity ids):
$qtys = array(
370 => 1,
371 => 0,
);
An alternative which I might suggest would be to simply have your "Create Invoice" link set the appropriate values in the form to invoice the individual item and then submit the form directly. This way you'll be relying on the known-to-be-working core controller for the heavy lifting. This will, of course, only work if you are not doing anything fairly customized beyond invoicing the single item. :)
Fledgling Joomla / PHP developer, hitting a wall understanding how to do this. Everything I found searching has been for older versions of Joomla or other frameworks and so it's all confusing the first time around.
I want to have a helper function that I can call from anywhere in my component. Basically it takes a userID input and returns their full name, let's say hair color and height. Here's the function:
function get_profile_info($userID) {
$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query->SELECT('u.id as UserID
, u.name AS Name
, up.profile_value AS Hair
, up2.profile_value AS Height
');
$query->FROM (' #__users AS u');
$query->LEFTJOIN (' #__user_profiles AS up ON u.id = up.user_id AND up.ordering = 1');
$query->LEFTJOIN (' #__user_profiles AS up ON u.id = up.user_id AND up.ordering = 2');
$query->WHERE(' u.id = '.$userID.'');
$query->GROUPBY (' u.id
, u.name
, up.profile_value
');
$db->setQuery($query);
return $query;
}
I'd put this in a file called "lookups.php" within the "helpers" folder of my component...but here's where I'm not sure what to do next. Top of lookups.php has the obligatory:
<?php defined ( '_JEXEC' ) or die;
So two questions:
1) Do I put everything in a class or keep it as a series of functions (since there will be others)?
2) How do I pass the userID and get back the values of Name, Hair, and Height in the view (view.html.php / default.php)?
Thank you!
==================================
Edit: Based on #Shaz 's response below here's where I'm at (again, just starting off and trying to wrap my head around some of this):
lookups.php
abstract class LookupHelper {
var $Name;
var $Hair;
var $Height;
public function get_profile_info($userID) {
...
(same as above until the next line)
$db->setQuery($query);
$result=$db->loadRow();
$Name = $result[1];
$Hair = $result[2];
$Height = $result[3];
$getprofileinfo = array(Name=>$Name, Hair=>$Hair, Height=>$Height);
$return $getprofileinfo;
}
}
Then in my default.php (will probably move to view.html.php):
$getprofileinfo = Jview::loadHelper('lookups'); //got an error without this
$getprofileinfo = LookupHelper::get_profile_info($userID);
$Name = $getprofileinfo[Name];
$Hair = $getprofileinfo[Hair];
$Height = $getprofileinfo[Height];
So...it's working - but it seems like there's a much easier way of doing this (specifically manually creating an array then recalling by position). Thoughts?
Thank you!!
Create the helper class and include there all your functions:
abstract class HelloWorldHelper
{
/* functions */
}
Call the function and store the result:
$var = HelloWorldHelper::get_profile_info($thatId);
Is not possible to write your helper class inside of an existing helper Joomla file that's already being calling by all your components?
By default Joomla have helper classes doing stuff, so all you have to do is to expand the core helper classes with your owns.