→  Да простит меня музицирующий друпальщик

published 27 July 2011

Выборка с условием:

// Drupal 6 $nodes = db_query(“SELECT nid, title FROM {node} WHERE type = ‘%s’ AND uid = %d”, ‘page’, 1);

// Drupal 7, вариант 1 $nodes = db_query(“SELECT nid, title FROM {node} WHERE type = :type AND uid = :uid”, array(’:type’ => ‘page’, ‘:uid’ => 1));

// Drupal 7, вариант 2 (более правильный) $nodes = db_select(’node’, ’n’) ->fields(’n’, array(’nid’, ’title’)) ->condition(’n.type’, ‘page’) ->condition(’n.uid’, 1) ->execute(); Выборка из двух таблиц соединённых с помощью INNER JOIN:

 →  Функция вывода списка

published 27 July 2011

//for drupal 6 $title = MYTITLE; $type = ‘ul’; $attributes = array( ‘id’ => ‘MYITEMLISTID’, ); $page_contents .= theme(‘item_list’, $items, $title, $type, $attributes);

//for drupal 7 $output = theme(‘item_list’, array(‘items’ => $items, ’type’ => ‘ul’, ‘attrebutes’ => $attributes ));

 →  Запрос в drupal 6

published 26 July 2011

db_query(“SELECT us.name FROM {user_relationships} ur INNER JOIN {users} us ON ur.requestee_id = us.uid WHERE ur.requester_id = ‘%s’ AND ur.approved = %d”, $uid, 1);

%s - means string

%d -means integer

%b - means Binary

%% -means Inserts a literal % sign

%f - means Float

while ($item = db_fetch_object($result)) { $options[$item->name] = $item->name; }

 →  Вывод блока

published 26 July 2011

For Drupal 7 :

$block = module_invoke(‘block’, ‘block_view’, 30);

@arg 1 : module name @arg 2 : hook name like block_view, block_info @arg 3 : id or delta of the block e.g 30, map-block_1

for Drupal 6 :

$block = module_invoke(‘block’, ‘block’, ‘view’, 30);

@arg 1 : module name @arg 2 : hook name like block @arg 3 : $op of hook_block e.g. info, view, configure @arg 4 : id or delta of the block e.g 30, map-block_1

 →  Вывод меню в шаблон

published 26 July 2011

menu_navigation_links(‘menu-mobile-menu’), ‘attributes’ => array( ‘class’ => array (‘mobile-menu’), ), )); ?>

 →  Симулятор Opera mini

published 26 July 2011

Симулятор мобильной оперы. http://www.opera.com/mobile/demo/

 →  Подключение скриптов и стилей в модуле

published 23 July 2011

$path = drupal_get_path(‘module’, ‘j_catalog’); drupal_add_js($path . ‘scripts/j.js’, ‘file’); drupal_add_css($path . ‘css/j.css’, ‘file’);

 →  Два селекта на ajax

published 23 July 2011

Два селекта: марка и модель. Выбираем марку и у нас подгружается список моделей. В коллбэк функции возвращаем форму, которую хотим изменить. Через** $form_state** получаем значение. Будьте внимательны, форма перестраивается занова, но визуально меняется только изменяющийся элемент.

//функция создания формы function bull_form($form, $form_state,$nid = NULL) { //запрос к таксономии для заполнения селекта $query = db_select(’taxonomy_term_data’, ’t’); $query->innerJoin(’taxonomy_term_hierarchy’, ‘r’, ’t.tid = r.tid’); $query->fields(‘r’,array(‘parent’)); $query->fields(’t’); $query->condition(‘r.parent’, PARENT, ‘=’ ); $query->orderBy(’t.name’, ‘ASC’); $result = $query->execute(); $options = array(); //заполняем option для select foreach($result as $item){ $options[$item->tid] = $item->name; } //проверям выбрана ли марка, делаем запрос по моделям этой марки (то есть пришел ли запрос от аякса) if(isset($form_state[‘values’][‘marka’])) { $tid = $form_state[‘values’][‘marka’]; $query = db_select(’taxonomy_term_data’, ’t’); $query->innerJoin(’taxonomy_term_hierarchy’, ‘r’, ’t.tid = r.tid’); $query->fields(’t’); $query->fields(‘r’,array(‘parent’)); $query->condition(‘r.parent’, $tid, ‘=’ ); $query->orderBy(’t.name’, ‘ASC’); $result = $query->execute(); $options2 = array(); //собираем опции для селекта foreach($result as $item){ $options2[$item->tid] = $item->name; } } // селект марки $form[’left’][‘marka’] = array ( ‘#type’ => ‘select’, ‘#title’ => t(‘Producer’), ‘#options’ => $options, ‘#ajax’ => array( //прописываем какую звать функцию при изменение селекта ‘callback’ => ‘ajax_get_models’, //какой элемент html в форме заменять ‘wrapper’ => ‘replace_models_div’, ),
); $form[‘right’][‘model’] = array ( ‘#type’ => ‘select’, ‘#title’ => t(‘Model’), ‘#options’ => (isset($options2)) ? $options2 : array(‘choose model’), //оборачиваем в div для замены ‘#prefix’ => ‘’, ‘#suffix’ => ‘’,
); return $form;

 →  tar

published 20 July 2011

Creating a tar file:

linux# tar -cvf file.tar myfile.txt

Создание tar.gz файла

tar -zcvf  file.tar.gz myfile.txt

Распаковка:

tar -zxvf  file.tar.gz myfile.txt
linux# tar -cvf home.tar home/

Extracting the files from a tar file:

linux# tar -xvf myfile.tar
linux# tar -xvzf myfile.tar.gz

flags

tar
« 1 2 3 4 5 6 7 8 9 10 11 »