Drupal completion hooks (og) - php

Drupal 7.12/organic groups 7.x-1.3
Does anyone know how I can do a quick cURL hit against a site with a few POST vars like group ID, group name, etc. when a user creates a group successfully?
I have no idea how the hooks system works in this case.

An organic group is defined as an Entity in Drupal 7, and as such you can implement hook_entity_insert in a custom module to react to a successful group creation:
function MYMODULE_entity_insert($entity, $type) {
if ($type == 'group') {
$group_id = $entity->gid;
// Install the Devel module and run the following code to get a full
// breakdown of what's available in the $entity object
dpm($entity);
// Perform your cURL here
}
}
Hope that helps

Related

Drupal 7: hook_entity_insert($entity, $type)

I'm a noob junior so I apologise in advance if this is a very basic question and if it has been asked a gazillion times before.
I am basically trying to run another function when a user registers. After some googling I came upon: hook_entity_insert($entity, $type) from (https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_entity_insert/7.x) now, even though there are code examples it does not tell me where to put the code, how to get the data that is submitted etc...
Which file do I put the sample code to test. The sample code provided is:
function hook_entity_insert($entity, $type) {
// Insert the new entity into a fictional table of all entities.
$info = entity_get_info($type);
list($id) = entity_extract_ids($type, $entity);
db_insert('example_entity')
->fields(array(
'type' => $type,
'id' => $id,
'created' => REQUEST_TIME,
'updated' => REQUEST_TIME,
))
->execute();
}
First you should understand the hook system in Drupal. For Drupal 7 this page is a good start. It gives you a quick overview and understanding of the concept.
Understanding the hook system for Drupal modules
There is a specific hook that 'fires' after an user is inserted, named hook_user_insert
You don't need to use hook_entity_insert. In your custom module use below hook
when user registers.
function yourModuleName_form_user_register_alter(&$form, &$form_state) {
// Add your own function to the array of validation callbacks
$form['#validate'][] = 'yourModuleName_user_register_validate';
}
Refer
Hook into Drupal registration and validate user info against business logic
If you want to run a function after the user has registered, use hook_user_insert (or, if this needs to be run every time a user is changed, hook_user_presave).
In general: Hooks in drupal are functions that comply with a specific naming scheme. In the places where a hook is executed (i.e., on user registration), Drupal searches for all modules that contain a function where the function name consists of the module's (machine) name, followed by the hook name. For hook user insert, you would need to implement a module (or place your code in a module you already implemented), see documentation here. Supposing your module is called "custom_module", you then implement a function like so:
function custom_module_user_insert(&$edit, $account, $category) {
//Do what you wanted to do here
}
Hope this helps

Creating Moodle plugin

I want to control actions, which user doing in test(click on answer, finish test and other)? Is it possible?
I think, that for this task need to create plugin? Am i right?
And dear community, can you help me some material - how develop plugin? Maybe can recomend some sites ot articles? Cause now I don`t understand this process.
For example, I know that plugin need to install in Moodle? But where create plugin before installing? In moodle also? But how export created in Moodle plugin to installing package?
For me very important question - how create installation package with plugin, that other users can install it.
Sorry for a lot question, and thanks for help.
These are the developer docs - https://docs.moodle.org/dev/Main_Page
Depends which plugin you need to develop - https://docs.moodle.org/dev/Plugin_types
If its part of a course then you will need to develop an activity module - https://docs.moodle.org/dev/Activity_modules
Or if not, then you will probably want a local plugin - https://docs.moodle.org/dev/Local_plugins
UPDATE:
Use a local plugin and respond to one of the quiz events.
https://docs.moodle.org/dev/Event_2#Event_observers
This is an overview:
Create a local plugin - https://docs.moodle.org/dev/Local_plugins
Then in local/yourpluginname/db/events/php have something like
defined('MOODLE_INTERNAL') || die();
$observers = array(
array(
'eventname' => '\mod_quiz\event\attempt_submitted',
'includefile' => '/local/yourpluginname/locallib.php',
'callback' => 'local_yourpluginname_attempt_submitted',
'internal' => false
),
);
This will respond to the attempt_submitted event when a user submits a quiz. I'm guessing this is the event that you will need to use. If not, then there are others here /mod/quiz/classes/event/
Then in /local/yourpluginname/locallib.php have something like
/**
* Handle the quiz_attempt_submitted event.
*
* #global moodle_database $DB
* #param mod_quiz\event\attempt_submitted $event
* #return boolean
*/
function local_yourpluginname_attempt_submitted(mod_quiz\event\attempt_submitted $event) {
global $DB;
$course = $DB->get_record('course', array('id' => $event->courseid));
$attempt = $event->get_record_snapshot('quiz_attempts', $event->objectid);
$quiz = $event->get_record_snapshot('quiz', $attempt->quiz);
$cm = get_coursemodule_from_id('quiz', $event->get_context()->instanceid, $event->courseid);
if (!($course && $quiz && $cm && $attempt)) {
// Something has been deleted since the event was raised. Therefore, the
// event is no longer relevant.
return true;
}
// Your code here to send the data to an external server.
return true;
}
That should get you started.

Joomla - any chance to override com_content/models/category.php?

I'm trying to get a template to work with a sorting menu in Joomla 3.
I'm using the category layout and a infinity load script which is working fine.
After that I made a new menu out of the categorie_list module which adds parameters like this (?category=your_category) to the a tag.
Now in order to get this system to work, I need to change the category where the blog view gets its articles from.
I already found the position at
components/com_content/models/category.php
at line 222
function getItems()
{
$limit = $this->getState('list.limit');
if ($this->_articles === null && $category = $this->getCategory())
{
$model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
$model->setState('params', JFactory::getApplication()->getParams());
$model->setState('filter.category_id', '$category->id'); // <- here!!!
$model->setState('filter.published', $this->getState('filter.published'));
$model->setState('filter.access', $this->getState('filter.access'));
$model->setState('filter.language', $this->getState('filter.language'));
$model->setState('list.ordering', $this->_buildContentOrderBy());
$model->setState('list.start', $this->getState('list.start'));
$model->setState('list.limit', $limit);
$model->setState('list.direction', $this->getState('list.direction'));
$model->setState('list.filter', $this->getState('list.filter'));
// filter.subcategories indicates whether to include articles from subcategories in the list or blog
$model->setState('filter.subcategories', $this->getState('filter.subcategories'));
$model->setState('filter.max_category_levels', $this->setState('filter.max_category_levels'));
$model->setState('list.links', $this->getState('list.links'));
if ($limit >= 0)
{
$this->_articles = $model->getItems();
if ($this->_articles === false)
{
$this->setError($model->getError());
}
}
else
{
$this->_articles = array();
}
$this->_pagination = $model->getPagination();
}
return $this->_articles;
}
Since I don't know, how to override a model within a template even having Googled it, I found nothing more than import it via a plugin.
And that is not what I need and want at all.
Maybe you guys have a handy trick for me.
1st suggestion
How to override the component mvc from the Joomla! core
http://docs.joomla.org/How_to_override_the_component_mvc_from_the_Joomla!_core
NOTICE: This method only works if you install and enable the 3rd party MVC plugin - or provide your own equivalent plugin. It is fine for advanced developers - just be aware that this is not part of Joomla! Core code.
2nd suggestion
Copy the entire core component, hack the copy and package the copy as a new component under a new name (e.g com_mycustomcontent). By doing this you will not have problems with upgrades unless there is a security issue with the original component. That means that you will be stuck if you don't know how to apply the updates of the original component to your component.

Call new php function when order is complete in Magento

I have a magento site for ecommerce. When an order is placed, I need to call another function I've created in a new php file and pass the order skus, quantities and shipping address to. I'm extremely comfortable with php, but Magento is an entirely new beast for me.
Does anyone know how to call a function when an order is placed? Even just the name of the event would be helpful.
I haven't used it personally, but sales_order_place_after sounds like it might be what you're looking for. It's used in this way in this Inchoo article, which also involves doing some things as soon as an order is placed.
Here's a page on the Magento wiki about setting up an event observer, which really is just a little XML to tell Magento to run some code when that event is dispatched, and the code you want to run.
you can try sales_order_place_before and sales_order_place_after
if you are interested in the events fired, a common approach is to temporary add
Mage::log($name); in the Mage.php (app/Mage.php) like this
public static function dispatchEvent($name, array $data = array())
{
Mage::log($name);
Varien_Profiler::start('DISPATCH EVENT:'.$name);
$result = self::app()->dispatchEvent($name, $data);
Varien_Profiler::stop('DISPATCH EVENT:'.$name);
return $result;
}
this will log any event fired during a page view or action to the var/log/system.log, if you enabled logging in the backend System->Configuration>Developer->Log Settings

Prestashop Back-Office dynamic hooks (events) not working

Hi I'm developing a custom module for my company on Prestashop and I need some help. I've recently developed the same plugin on Magento but here I'm having some troubles with events (also called dynamic hooks).
I'm trying to use the dynamic hooks on the backend to manage product stocks. I'm not able to catch prestashop backend events on my module despite I've registered the hooks in my install() method:
function install() {
if (parent::install() == false
|| !$this->registerHook('home')
|| !$this->registerHook('productFooter')
|| !$this->registerHook('orderConfirmation')
|| !$this->registerHook('shoppingCart')
|| !$this->registerHook('actionProductDelete')
|| !$this->registerHook('actionProductUpdate')) {
return false;
}
//default configuration values
...
and placed specific methods for each one.
public function hookActionProductDelete($params) { ... }
I'm logging all the process on both sides. On my module with firePHP and FileLoggerCore and on Prestashop's core classes where events are dispatched with the prestashop's FileLoggerCore.
The events like (actionProductDelete) found on Product class are dispatched but I can not capture them.
Another point that I've noticed is that hook names change between prestashop versions. In this last version 1.5 there are a lot more hooks than in previous ones. It's possible to use same hooks in versions from 1.3 to 1.5?
Sorry for my english and many thanks in advance.
check if your module is hooked in "admin > modules > positions" on actionProductDelete hook
you can use old hook name for PS 1.3-1.5 compatibility, look at ps_hook_alias DB table. For hook that doesn't exist before 1.5, I think you need override for 1.4 & code modifications for 1.3

Categories