Skip to content

Instantly share code, notes, and snippets.

View nicaralava's full-sized avatar

Jean Nica Ralava nicaralava

View GitHub Profile
@nicaralava
nicaralava / anagram.php
Last active August 26, 2017 19:10
anagram
<?php
/**
* User: jralava
* Date: 8/26/2017
* Time: 8:39 PM
*/
$value1 = 'toto';
$value2 = 'toot';
@nicaralava
nicaralava / your_module.module.php
Last active August 26, 2017 17:37
Drupal Delete their own content
<?php
/**
* Implements of hook_form_alter()
*
* Filtrer la supression d'un contenu, supression de son propre contenu
*/
function your_module_form_alter(&$form,&$form_state, $form_id) {
global $user;
$user_id = $user->uid;
@$field_uid = strip_tags($form['#node']->field_user_dash_my_doc['und'][0]['uid']);
@nicaralava
nicaralava / dd-to-dms-or-inverse.php
Created August 26, 2017 17:48
How to convert decimal degrees to degrees,minutes,seconds or inverse
<?php
function DDtoDMS($dd)
{
$d = intval(abs($dd));
$m = intval(($dd - $d) * 60);
$s = intval(($dd - $d - $m/60) * 3600);
return array("deg"=>intval($d),"min"=>intval($m),"sec"=>intval($s));
}
function DMStoDD($deg,$min,$sec,$cardinaux,$coordonnee)
@nicaralava
nicaralava / all-node.module.php
Last active August 26, 2017 17:58
Drupal Return the list of nodes of a given content type as a parameter
<?php
/*
* Returns the list of nodes of a given content type as a parameter
* $type: String, id du type de contenu
* return array(),
*/
function utils_load_all_node($type,$autoloadNode = TRUE){
$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'node')
->entityCondition('bundle', $type)
@nicaralava
nicaralava / taxonomy.module.php
Created August 26, 2017 17:58
Drupal Return a taxonomy list of a VID
<?php
//return a taxonomy list of a VID
function litse_taxonomy_term_by_taxonomy_machine_name($machine_name){
if ($vocabulary = taxonomy_vocabulary_machine_name_load($machine_name)) {
$table_name= array();
$tree = taxonomy_get_tree($vocabulary->vid);
foreach ($tree as $terms) {
$tid = $terms->tid;
if($tid!=-1){
$term = taxonomy_term_load($tid);
@nicaralava
nicaralava / current-node.module.php
Created August 26, 2017 18:00
Drupal get current Node
<?php
function utils_getCurrentNode(){
$node = null;
if (arg(0) == 'node' && is_numeric(arg(1))) {
$nid = arg(1);
if ($nid) {
$node = node_load($nid);
}
}
return $node;
@nicaralava
nicaralava / my_module.module.php
Last active August 26, 2017 18:12
Drupal - delet or insert into the database when the node is updated or inserted
<?php
function my_module_node_insert($node) {
updateHubSocial($node);
}
function my_module_node_update($node) {
updateHubSocial($node);
}
function updateHubSocial($node) {
@nicaralava
nicaralava / my_ws_module.services.inc.php
Last active August 26, 2017 18:42
Create a Rest Web Service with Drupal
<?php
function my_ws_module_services_resource() {
$api = array(
'my-section' => array(
'actions' => array(
'articles' => array(
'help' => 'Text info.',
'callback' => 'my_ws_module_services_resource_retrieve',
'args' => array(
array(
@nicaralava
nicaralava / gist:83e86f72ee51e4715f1c0fe637d0f543
Created August 26, 2017 18:46
Enable and revert Features use drush Drupal
drush en module_name -y
drush fr module_name --force
drush cc all
@nicaralava
nicaralava / gist:3d633974bee4c983a4c7e3aea92257d3
Created August 26, 2017 18:48
Download and Enable a module with Drush Drupal
drush dl module_name
drush en module_name -y
drush cc all