Accessing CCK field data (single, multiple, or shared) from another module

note- this is taken from KarenS's post to the development list

To access data stored by CCK within another module, you need to determine which table it's stored in.

To find the right table for a field for a SQL query, use the CCK API, like this:

$db_info = content_database_info($field);
$table = $db_info['table'];

That will always return the right table for the requested field.

$field needs to be the complete field array, not just the field name, so if you only have the field name, you would do:

$field = content_fields(my_field_name);
$db_info = content_database_info($field);
$table = $db_info['table'];

content_database_info($field) also contains info about the columns declared by the field so you know what field names to use in a SQL query. It returns an array that looks like:

Drupal V5.x warning: Cannot add header information

A very common error while trying to modify the user profile in Drupal 5.x is:

warning: Cannot add header information - headers already sent

This is usually an issue associated with line breaks or text file encoding.

FAQ: Frequently Asked Questions

Description

The Frequently Asked Questions (faq) module allows users with the 'administer faq' permission to create question and answer pairs which they want displayed on the 'faq' page. The 'faq' page is automatically generated from the FAQ nodes configured and the layout of this page can be modified on the settings page. Users will need the 'view faq' permission to view the 'faq page' page.

Content Injector (AdSense Injector) Insertion Template Tricks

Note: This page describes the 2.5 and later releases up to 6.x-2.x and the 7.0 release. Later releases use a different insertion template format.

Consider the default node insertion template (formatted for readability):

<div class="ad-auto-inserted" style="float:left; margin: 0 1em .25em 0;">
[adsense:120x240:1:1]
</div>
%body
<br class="clear"/>
[adsense:468x60:1:1]

On full node views, this will insert a 120x240 left-floating ad block before the node body, then, after the body text, a 468x60 ad will be appended, both ads using the adsense module's group 1 and channel 1 settings.

Now, then, what else can we do? How about putting an ad on both the left and right side of the top of the node, as well as at the bottom? We can do that very easily, using inline float styles (for the purposes of this example - it's cleaner to use stylesheet-defined CSS rules).

(Yes, this is probably annoying in-your-face advertising, and I wouldn't recommend it, but it serves to demonstrate capabilities.)

<div class="ad-auto-inserted" style="float:left; margin: 0 1em .25em 0;">
[adsense:120x240:1:1]
</div>
<div class="ad-auto-inserted" style="float:right; margin: 0 0 .25em 1em;">
[adsense:120x240:1:1]
</div>
%body
<br class="clear"/>
[adsense:468x60:1:1]

Give it a try.

Calculating depreciation and valuation

Here are a couple of snippets designed to calculate the straight-line depreciation and the estimated current value of a given node.

the user input CCK fields are two dates (requires the date module) and two (currency) values:
1. purchase_date (iso date format)
2. expire_date (iso date format)
3. purchase_value (decimal format)
4. expire_value (decimal format) - this is the 'scrap value' of the item when it reaches the end of it's useful life.

The first function calculates the annual rate of depreciation:
<?php
if (!$node->nid) node_save($node);
$start_date = date_make_date($node->field_purchase_date[0]['value']);
$start = $start_date->db->parts;
$end_date = date_make_date($node->field_expire_date[0]['value']);
$end = $end_date->db->parts;

$start_decimal = $start['year'] + ($start['mon'] / 12); // this gives the annual depreciation
$end_decimal = $end['year'] + ($end['mon'] / 12);
// $start_decimal = ($start['year'] * 12) + $start['mon']; // this would give the monthly depreciation
// $end_decimal = ($end['year'] * 12) + $end['mon'];

$useful_life = $end_decimal - $start_decimal;

$start_value = ($node->field_purchase_value[0]['value']);
$end_value = ($node->field_expire_value[0]['value']);

Computed Field

Computed Field is a module that lets you add a computed field to custom content types. You can choose whether to store your computed field in the database, or simply have it calculated upon view. You can also choose whether to display the field, and how to format it. The value of the field is set using PHP code so it can draw on anything available to Drupal, including other fields, the current user, database tables, etc. The drawback of this is of course that you must be PHP-savvy to use it.

Pages

Subscribe with RSS Subscribe to RSS - Drupal 6.x