| 1 |
<?php |
<?php |
| 2 |
// $Id: nodefamily.module,v 1.19.2.14 2007/10/04 08:53:48 fago Exp $ |
// $Id: nodefamily.module,v 1.19.2.15 2008/06/08 14:49:48 fago Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 72 |
if ($form_values['parent'] == $form_values['child']) { |
if ($form_values['parent'] == $form_values['child']) { |
| 73 |
form_set_error('child', t('You have to select two different content types.')); |
form_set_error('child', t('You have to select two different content types.')); |
| 74 |
} |
} |
| 75 |
|
|
| 76 |
$relations = variable_get('nodefamily_relations',array()); |
$relations = variable_get('nodefamily_relations', array()); |
| 77 |
if (nodefamily_check_cycle($form_values['parent'], $form_values['child'], $relations)) { |
if (nodefamily_check_cycle($form_values['parent'], $form_values['child'], $relations)) { |
| 78 |
form_set_error('child', t('You must not add this relation as it would result in a loop.')); |
form_set_error('child', t('You must not add this relation as it would result in a loop.')); |
| 79 |
} |
} |
| 119 |
* Display the existing content type relations in a table. |
* Display the existing content type relations in a table. |
| 120 |
*/ |
*/ |
| 121 |
function nodefamily_ct_relation_overview() { |
function nodefamily_ct_relation_overview() { |
| 122 |
$relations = variable_get('nodefamily_relations',array()); |
$relations = variable_get('nodefamily_relations', array()); |
| 123 |
if (!$relations) { |
if (!$relations) { |
| 124 |
return ''; |
return ''; |
| 125 |
} |
} |
| 126 |
|
|
| 127 |
if (arg(3) && arg(4)) { |
if (arg(3) && arg(4)) { |
| 128 |
// delete the relation |
// delete the relation |
| 129 |
nodefamily_ct_relation_remove(arg(3), arg(4)); |
nodefamily_ct_relation_remove(arg(3), arg(4)); |
| 130 |
drupal_goto('admin/content/nodefamily'); |
drupal_goto('admin/content/nodefamily'); |
| 131 |
} |
} |
| 132 |
|
|
| 133 |
$header = array(t('Parent type'), t('Child type'), ''); |
$header = array(t('Parent type'), t('Child type'), ''); |
| 134 |
$rows = array(); |
$rows = array(); |
| 135 |
$typenames = node_get_types('names'); |
$typenames = node_get_types('names'); |
| 136 |
foreach($relations as $key => $value) { |
foreach ($relations as $key => $value) { |
| 137 |
$rows = array_merge($rows, _nodefamily_relation_overview_dive($key, $value, $typenames)); |
$rows = array_merge($rows, _nodefamily_relation_overview_dive($key, $value, $typenames)); |
| 138 |
} |
} |
| 139 |
|
|
| 140 |
return theme('table', $header, $rows, array('class' => 'nodefamily')); |
return theme('table', $header, $rows, array('class' => 'nodefamily')); |
| 141 |
} |
} |
| 142 |
|
|
| 143 |
function _nodefamily_relation_overview_dive($parent, $array, $typenames) { |
function _nodefamily_relation_overview_dive($parent, $array, $typenames) { |
| 144 |
$rows = array(); |
$rows = array(); |
| 145 |
foreach($array as $key => $value) { |
foreach ($array as $key => $value) { |
| 146 |
$rows[] = array($typenames[$parent], $typenames[$key], |
$rows[] = array($typenames[$parent], $typenames[$key], |
| 147 |
l(t('delete'),'admin/content/nodefamily/' . $parent .'/'. $key)); |
l(t('delete'), 'admin/content/nodefamily/'. $parent .'/'. $key)); |
| 148 |
if ($value && is_array($value)) { |
if ($value && is_array($value)) { |
| 149 |
$rows = array_merge($rows, _nodefamily_relation_overview_dive($key, $value, $typenames)); |
$rows = array_merge($rows, _nodefamily_relation_overview_dive($key, $value, $typenames)); |
| 150 |
} |
} |
| 160 |
*/ |
*/ |
| 161 |
function nodefamily_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { |
function nodefamily_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { |
| 162 |
|
|
| 163 |
switch($op) { |
switch ($op) { |
| 164 |
case 'insert': |
case 'insert': |
| 165 |
$parents = nodefamily_get_parent_types($node->type); |
$parents = nodefamily_get_parent_types($node->type); |
| 166 |
$children = nodefamily_get_child_types($node->type); |
$children = nodefamily_get_child_types($node->type); |
| 167 |
|
|
| 168 |
if ($parents) { |
if ($parents) { |
| 169 |
foreach ($parents as $parent_typename) { |
foreach ($parents as $parent_typename) { |
| 170 |
nodefamily_relatives_set_parent($parent_typename, $node->uid, $node); |
nodefamily_relatives_set_parent($parent_typename, $node->uid, $node); |
| 176 |
} |
} |
| 177 |
} |
} |
| 178 |
break; |
break; |
| 179 |
|
|
| 180 |
case 'delete': |
case 'delete': |
| 181 |
nodefamily_relation_remove_parents($node); |
nodefamily_relation_remove_parents($node); |
| 182 |
nodefamily_relation_remove_children($node); |
nodefamily_relation_remove_children($node); |
| 183 |
break; |
break; |
| 184 |
|
|
| 185 |
case 'validate': |
case 'validate': |
| 186 |
if (!$node->nid && user_access('administer nodes')) { |
if (!$node->nid && user_access('administer nodes')) { |
| 187 |
if ($account = user_load(array('name' => $node->name))) { |
if ($account = user_load(array('name' => $node->name))) { |
| 191 |
$node->uid = 0; |
$node->uid = 0; |
| 192 |
} |
} |
| 193 |
} |
} |
| 194 |
|
|
| 195 |
if (!$node->nid && nodefamily_content_type_is_max($node->type, $node->uid)) { |
if (!$node->nid && nodefamily_content_type_is_max($node->type, $node->uid)) { |
| 196 |
form_set_error('name', t("You can't create more nodes of this type for this user.")); |
form_set_error('name', t("You can't create more nodes of this type for this user.")); |
| 197 |
$form = NULL; |
$form = NULL; |
| 198 |
} |
} |
| 199 |
break; |
break; |
| 200 |
case 'submit': |
case 'submit': |
| 201 |
if ($node->nid && user_access('administer nodes')) { |
if ($node->nid && user_access('administer nodes')) { |
| 202 |
$parents = nodefamily_get_parent_types($node->type); |
$parents = nodefamily_get_parent_types($node->type); |
| 203 |
$children = nodefamily_get_child_types($node->type); |
$children = nodefamily_get_child_types($node->type); |
| 204 |
$oldnode = node_load($node->nid); |
$oldnode = node_load($node->nid); |
| 205 |
if ($oldnode->uid != $node->uid) { |
if ($oldnode->uid != $node->uid) { |
| 206 |
//we have to update the relations because the node author changed |
//we have to update the relations because the node author changed |
| 207 |
if ($parents) { |
if ($parents) { |
| 214 |
nodefamily_relation_remove_children($node); |
nodefamily_relation_remove_children($node); |
| 215 |
foreach ($children as $child_typename) { |
foreach ($children as $child_typename) { |
| 216 |
nodefamily_relatives_set_child($node, $child_typename, $node->uid); |
nodefamily_relatives_set_child($node, $child_typename, $node->uid); |
| 217 |
} |
} |
| 218 |
} |
} |
| 219 |
} |
} |
| 220 |
} |
} |
| 268 |
form_set_error($formelement['#parents'][0], t('Entry must be an integer.')); |
form_set_error($formelement['#parents'][0], t('Entry must be an integer.')); |
| 269 |
} |
} |
| 270 |
else if ($formelement['#value'] < 0) { |
else if ($formelement['#value'] < 0) { |
| 271 |
form_set_error($formelement['#parents'][0], t('Entry must be at least 0.')); |
form_set_error($formelement['#parents'][0], t('Entry must be at least 0.')); |
| 272 |
} |
} |
| 273 |
} |
} |
| 274 |
|
|
| 309 |
* and the maximum population variable. |
* and the maximum population variable. |
| 310 |
*/ |
*/ |
| 311 |
function nodefamily_node_type($op, $info) { |
function nodefamily_node_type($op, $info) { |
| 312 |
switch ($op){ |
switch ($op) { |
| 313 |
case 'delete': |
case 'delete': |
| 314 |
_nodefamily_content_type_del_max($info->type); // maximum population |
_nodefamily_content_type_del_max($info->type); // maximum population |
| 315 |
nodefamily_ct_relation_remove_all($info->type); // relations |
nodefamily_ct_relation_remove_all($info->type); // relations |
| 408 |
$relations = variable_get('nodefamily_relations', array()); |
$relations = variable_get('nodefamily_relations', array()); |
| 409 |
|
|
| 410 |
$parent_typenames = array(); |
$parent_typenames = array(); |
| 411 |
foreach($relations as $parent_typename => $children) { |
foreach ($relations as $parent_typename => $children) { |
| 412 |
if ($typename == NULL || in_array($typename, array_keys($children))) { |
if ($typename == NULL || in_array($typename, array_keys($children))) { |
| 413 |
$parent_typenames[] = $parent_typename; |
$parent_typenames[] = $parent_typename; |
| 414 |
} |
} |
| 467 |
function nodefamily_relatives_set_parent($parent_typename, $uid, &$childnode) { |
function nodefamily_relatives_set_parent($parent_typename, $uid, &$childnode) { |
| 468 |
|
|
| 469 |
$result = db_query("SELECT nid FROM {node} WHERE uid=%d AND type='%s'", |
$result = db_query("SELECT nid FROM {node} WHERE uid=%d AND type='%s'", |
| 470 |
$uid, $parent_typename); |
$uid, $parent_typename); |
| 471 |
|
|
| 472 |
while ($node = db_fetch_object($result)) { |
while ($node = db_fetch_object($result)) { |
| 473 |
nodefamily_relation_add($node, $childnode); |
nodefamily_relation_add($node, $childnode); |
| 481 |
function nodefamily_relatives_set_child($parentnode, $child_typename, $uid) { |
function nodefamily_relatives_set_child($parentnode, $child_typename, $uid) { |
| 482 |
|
|
| 483 |
$result = db_query("SELECT nid FROM {node} WHERE uid=%d AND type='%s'", |
$result = db_query("SELECT nid FROM {node} WHERE uid=%d AND type='%s'", |
| 484 |
$uid, $child_typename); |
$uid, $child_typename); |
| 485 |
|
|
| 486 |
while ($node = db_fetch_object($result)) { |
while ($node = db_fetch_object($result)) { |
| 487 |
nodefamily_relation_add($parentnode, $node); |
nodefamily_relation_add($parentnode, $node); |
| 502 |
|
|
| 503 |
function nodefamily_relation_add(&$parent_node, &$child_node) { |
function nodefamily_relation_add(&$parent_node, &$child_node) { |
| 504 |
|
|
| 505 |
db_query("INSERT INTO {nodefamily} (parent_nid, child_nid) VALUES(%d, %d)", |
db_query("INSERT INTO {nodefamily} (parent_nid, child_nid) VALUES(%d, %d)", |
| 506 |
$parent_node->nid, $child_node->nid); |
$parent_node->nid, $child_node->nid); |
| 507 |
} |
} |
| 508 |
|
|
| 509 |
function nodefamily_relation_remove(&$parent_node, &$child_node) { |
function nodefamily_relation_remove(&$parent_node, &$child_node) { |
| 510 |
|
|
| 511 |
db_query("DELETE FROM {nodefamily} WHERE parent_nid = %d AND child_nid = %d", |
db_query("DELETE FROM {nodefamily} WHERE parent_nid = %d AND child_nid = %d", |
| 512 |
$parent_node->nid, $child_node->nid); |
$parent_node->nid, $child_node->nid); |
| 513 |
} |
} |
| 514 |
|
|
| 523 |
} |
} |
| 524 |
|
|
| 525 |
function nodefamily_relation_remove_by_type(&$parent_typename, &$child_typename) { |
function nodefamily_relation_remove_by_type(&$parent_typename, &$child_typename) { |
| 526 |
|
|
| 527 |
db_query("DELETE FROM {nodefamily} WHERE parent_nid IN ". |
db_query("DELETE FROM {nodefamily} WHERE parent_nid IN ". |
| 528 |
"(SELECT nid FROM {node} WHERE type ='%s') AND ". |
"(SELECT nid FROM {node} WHERE type ='%s') AND ". |
| 529 |
"child_nid IN (SELECT nid FROM {node} WHERE type ='%s')", |
"child_nid IN (SELECT nid FROM {node} WHERE type ='%s')", |
| 530 |
$parent_typename, $child_typename); |
$parent_typename, $child_typename); |
| 531 |
} |
} |
| 532 |
|
|
| 533 |
function nodefamily_relation_add_by_type(&$parent_typename, &$child_typename) { |
function nodefamily_relation_add_by_type(&$parent_typename, &$child_typename) { |
| 534 |
|
|
| 535 |
db_query("INSERT INTO {nodefamily} (parent_nid, child_nid) ". |
db_query("INSERT INTO {nodefamily} (parent_nid, child_nid) ". |
| 536 |
"SELECT n1.nid,n2.nid FROM {node} n1 ". |
"SELECT n1.nid,n2.nid FROM {node} n1 ". |
| 537 |
"JOIN {node} n2 ON n2.type = '%s' ". |
"JOIN {node} n2 ON n2.type = '%s' ". |
| 538 |
"LEFT JOIN {nodefamily} nf ON nf.parent_nid = n1.nid AND nf.child_nid = n2.nid ". |
"LEFT JOIN {nodefamily} nf ON nf.parent_nid = n1.nid AND nf.child_nid = n2.nid ". |
| 539 |
"WHERE n1.type = '%s' AND nf.parent_nid IS NULL AND n1.uid = n2.uid", |
"WHERE n1.type = '%s' AND nf.parent_nid IS NULL AND n1.uid = n2.uid", |
| 540 |
$child_typename, $parent_typename); |
$child_typename, $parent_typename); |
| 541 |
} |
} |
| 542 |
|
|
| 543 |
/** |
/** |
| 551 |
|
|
| 552 |
if (!is_object($node)) { |
if (!is_object($node)) { |
| 553 |
//$node is the nid |
//$node is the nid |
| 554 |
$node2 = node_load($node); |
$node2 = node_load($node); |
| 555 |
return is_object($node2) ? nodefamily_relation_load_all_nids($node2) : FALSE; |
return is_object($node2) ? nodefamily_relation_load_all_nids($node2) : FALSE; |
| 556 |
} |
} |
| 557 |
|
|
| 558 |
$result = db_query("SELECT child_nid FROM {nodefamily} WHERE parent_nid = %d", $node->nid); |
$result = db_query("SELECT child_nid FROM {nodefamily} WHERE parent_nid = %d", $node->nid); |
| 559 |
|
|
| 560 |
$node->children = array(); |
$node->children = array(); |
| 561 |
while ($row = db_fetch_object($result)) { |
while ($row = db_fetch_object($result)) { |
| 562 |
$node->children[$row->child_nid] = $row->child_nid; |
$node->children[$row->child_nid] = $row->child_nid; |
| 572 |
* @param $status The minimum status value a node must have to be included. Use 0 for all nodes. |
* @param $status The minimum status value a node must have to be included. Use 0 for all nodes. |
| 573 |
*/ |
*/ |
| 574 |
function nodefamily_relation_load(&$node, $status = 1) { |
function nodefamily_relation_load(&$node, $status = 1) { |
| 575 |
|
|
| 576 |
if (!is_object($node)) { |
if (!is_object($node)) { |
| 577 |
//$node is the nid |
//$node is the nid |
| 578 |
$node2 = node_load($node); |
$node2 = node_load($node); |
| 579 |
return is_object($node2) ? nodefamily_relation_load($node2, $status) : FALSE; |
return is_object($node2) ? nodefamily_relation_load($node2, $status) : FALSE; |
| 580 |
} |
} |
| 581 |
|
|
| 607 |
$node2 = node_load($node); |
$node2 = node_load($node); |
| 608 |
return is_object($node2) ? nodefamily_relation_load_by_type($node2, $status) : FALSE; |
return is_object($node2) ? nodefamily_relation_load_by_type($node2, $status) : FALSE; |
| 609 |
} |
} |
| 610 |
|
|
| 611 |
$result = db_query(db_rewrite_sql("SELECT n.nid FROM {node} n ". |
$result = db_query(db_rewrite_sql("SELECT n.nid FROM {node} n ". |
| 612 |
"JOIN {nodefamily} nf ON nf.child_nid = n.nid WHERE nf.parent_nid = %d AND n.status >= %d ORDER BY n.nid"), $node->nid, $status); |
"JOIN {nodefamily} nf ON nf.child_nid = n.nid WHERE nf.parent_nid = %d AND n.status >= %d ORDER BY n.nid"), $node->nid, $status); |
| 613 |
|
|
| 631 |
|
|
| 632 |
if (!is_object($node)) { |
if (!is_object($node)) { |
| 633 |
//$node is the nid |
//$node is the nid |
| 634 |
$node2 = node_load($node); |
$node2 = node_load($node); |
| 635 |
return is_object($node2) ? nodefamily_relation_load_parents($node2, $status) : FALSE; |
return is_object($node2) ? nodefamily_relation_load_parents($node2, $status) : FALSE; |
| 636 |
} |
} |
| 637 |
|
|
| 638 |
$result = db_query(db_rewrite_sql("SELECT n.nid FROM {node} n ". |
$result = db_query(db_rewrite_sql("SELECT n.nid FROM {node} n ". |
| 639 |
"JOIN {nodefamily} nf ON nf.parent_nid = n.nid WHERE nf.child_nid = %d AND n.status >= %d ORDER BY n.nid"), $node->nid, $status); |
"JOIN {nodefamily} nf ON nf.parent_nid = n.nid WHERE nf.child_nid = %d AND n.status >= %d ORDER BY n.nid"), $node->nid, $status); |
| 640 |
|
|
| 641 |
|
|
| 642 |
$node->parents = array(); |
$node->parents = array(); |
| 643 |
while ($row = db_fetch_object($result)) { |
while ($row = db_fetch_object($result)) { |
| 644 |
if ($parent = node_load($row->nid)) { |
if ($parent = node_load($row->nid)) { |
| 660 |
|
|
| 661 |
if (!is_object($node)) { |
if (!is_object($node)) { |
| 662 |
//$node is the nid |
//$node is the nid |
| 663 |
$node2 = node_load($node); |
$node2 = node_load($node); |
| 664 |
return is_object($node2) ? nodefamily_relation_load_siblings($node2, $status) : FALSE; |
return is_object($node2) ? nodefamily_relation_load_siblings($node2, $status) : FALSE; |
| 665 |
} |
} |
| 666 |
//load the parents |
//load the parents |
| 693 |
|
|
| 694 |
$types = node_get_types(); |
$types = node_get_types(); |
| 695 |
$typename = arg(1); |
$typename = arg(1); |
| 696 |
|
|
| 697 |
if (!$types[$typename] || nodefamily_content_type_get_max($typename) != 1) { |
if (!$types[$typename] || nodefamily_content_type_get_max($typename) != 1) { |
| 698 |
drupal_not_found(); |
drupal_not_found(); |
| 699 |
exit; |
exit; |
| 700 |
} |
} |
| 701 |
|
|
| 702 |
$uid = (arg(2) && is_numeric(arg(2))) ? arg(2) : NULL; |
$uid = (arg(2) && is_numeric(arg(2))) ? arg(2) : NULL; |
| 703 |
|
|
| 704 |
return nodefamily_lonely_node_page($typename, $uid); |
return nodefamily_lonely_node_page($typename, $uid); |
| 705 |
} |
} |
| 706 |
|
|
| 707 |
|
|
| 708 |
function nodefamily_lonely_node_page($typename, $uid = NULL) { |
function nodefamily_lonely_node_page($typename, $uid = NULL) { |
| 709 |
global $user; |
global $user; |
| 710 |
|
|
| 711 |
$node = node_load(array('type' => $typename, 'uid' => $uid ? $uid : $user->uid)); |
$node = node_load(array('type' => $typename, 'uid' => $uid ? $uid : $user->uid)); |
| 712 |
|
|
| 713 |
if (!$node) { |
if (!$node) { |
| 714 |
// show add form |
// show add form |
| 715 |
return node_add($typename); |
return node_add($typename); |
| 778 |
|
|
| 779 |
function theme_nodefamily_lonely_node_view_empty($type_name) { |
function theme_nodefamily_lonely_node_view_empty($type_name) { |
| 780 |
return '<div class="nodefamily-empty">'. |
return '<div class="nodefamily-empty">'. |
| 781 |
t('You have not created a @type yet. Go ahead and create one!', array('@type' => $type_name)) .'</div>'; |
t('You have not created a @type yet. Go ahead and create one!', array('@type' => $type_name)) .'</div>'; |
| 782 |
} |
} |
| 783 |
|
|
| 784 |
/* |
/* |
| 807 |
function nodefamily_lonely_node_types($op = 'names') { |
function nodefamily_lonely_node_types($op = 'names') { |
| 808 |
$types = node_get_types($op); |
$types = node_get_types($op); |
| 809 |
$lonely_node_types = array(); |
$lonely_node_types = array(); |
| 810 |
foreach($types as $typename => $type) { |
foreach ($types as $typename => $type) { |
| 811 |
if (nodefamily_content_type_get_max($typename) == 1) { |
if (nodefamily_content_type_get_max($typename) == 1) { |
| 812 |
$lonely_node_types[$typename] = $type; |
$lonely_node_types[$typename] = $type; |
| 813 |
} |
} |
| 841 |
* Implementation of hook_views_fusion(). |
* Implementation of hook_views_fusion(). |
| 842 |
*/ |
*/ |
| 843 |
function nodefamily_views_fusion() { |
function nodefamily_views_fusion() { |
| 844 |
|
|
| 845 |
return array('nodefamily_parent' => array( |
return array('nodefamily_parent' => array( |
| 846 |
'title' => t('nodefamily relation: parent - child'), |
'title' => t('nodefamily relation: parent - child'), |
| 847 |
'field' => 'child_nid', |
'field' => 'child_nid', |
| 848 |
), |
), |
| 849 |
'nodefamily_child' => array( |
'nodefamily_child' => array( |
| 850 |
'title' => t('nodefamily relation: child - parent'), |
'title' => t('nodefamily relation: child - parent'), |
| 851 |
'field' => 'parent_nid', |
'field' => 'parent_nid', |
| 852 |
), |
), |
| 853 |
); |
); |
| 854 |
} |
} |
| 855 |
|
|
| 856 |
function nodefamily_views_tables() { |
function nodefamily_views_tables() { |
| 875 |
'#options' => node_get_types('names'), |
'#options' => node_get_types('names'), |
| 876 |
), |
), |
| 877 |
'handler' => 'nodefamily_views_filter', |
'handler' => 'nodefamily_views_filter', |
| 878 |
'help' => t('This allows you to filter by child node ID.').t('You can optionally restrict the filter to a certain content type, which makes sense to use in conjunctions with the NOT EQUAL operator.'), |
'help' => t('This allows you to filter by child node ID.') . t('You can optionally restrict the filter to a certain content type, which makes sense to use in conjunctions with the NOT EQUAL operator.'), |
| 879 |
), |
), |
| 880 |
), |
), |
| 881 |
); |
); |
| 900 |
'#options' => node_get_types('names'), |
'#options' => node_get_types('names'), |
| 901 |
), |
), |
| 902 |
'handler' => 'nodefamily_views_filter', |
'handler' => 'nodefamily_views_filter', |
| 903 |
'help' => t('This allows you to filter by parent node ID.').t('You can optionally restrict the filter to a certain content type, which makes sense to use in conjunctions with the NOT EQUAL operator.'), |
'help' => t('This allows you to filter by parent node ID.') . t('You can optionally restrict the filter to a certain content type, which makes sense to use in conjunctions with the NOT EQUAL operator.'), |
| 904 |
), |
), |
| 905 |
), |
), |
| 906 |
); |
); |
| 963 |
|
|
| 964 |
|
|
| 965 |
function nodefamily_views_handler_arg_parent_nid($op, &$query, $argtype, $arg = '') { |
function nodefamily_views_handler_arg_parent_nid($op, &$query, $argtype, $arg = '') { |
| 966 |
switch($op) { |
switch ($op) { |
| 967 |
case 'summary': |
case 'summary': |
| 968 |
// do nothing. field name parent_nid makes troubles... |
// do nothing. field name parent_nid makes troubles... |
| 969 |
break; |
break; |
| 973 |
case 'filter': |
case 'filter': |
| 974 |
$num = $query->add_table('nodefamily_child'); |
$num = $query->add_table('nodefamily_child'); |
| 975 |
$tablename = $query->get_table_name('nodefamily_child', $num); |
$tablename = $query->get_table_name('nodefamily_child', $num); |
| 976 |
$query->add_where($tablename. ".parent_nid = %d", $arg); |
$query->add_where($tablename .".parent_nid = %d", $arg); |
| 977 |
break; |
break; |
| 978 |
case 'link': |
case 'link': |
| 979 |
return l($query->parent_nid, "$arg/$query->parent_nid"); |
return l($query->parent_nid, "$arg/$query->parent_nid"); |
| 985 |
|
|
| 986 |
|
|
| 987 |
function nodefamily_views_handler_arg_child_nid($op, &$query, $argtype, $arg = '') { |
function nodefamily_views_handler_arg_child_nid($op, &$query, $argtype, $arg = '') { |
| 988 |
switch($op) { |
switch ($op) { |
| 989 |
case 'summary': |
case 'summary': |
| 990 |
// do nothing. field name child_nid makes troubles... |
// do nothing. field name child_nid makes troubles... |
| 991 |
break; |
break; |
| 995 |
case 'filter': |
case 'filter': |
| 996 |
$num = $query->add_table('nodefamily_parent'); |
$num = $query->add_table('nodefamily_parent'); |
| 997 |
$tablename = $query->get_table_name('nodefamily_parent', $num); |
$tablename = $query->get_table_name('nodefamily_parent', $num); |
| 998 |
$query->add_where($tablename. ".child_nid = %d", $arg); |
$query->add_where($tablename .".child_nid = %d", $arg); |
| 999 |
break; |
break; |
| 1000 |
case 'link': |
case 'link': |
| 1001 |
return l($query->child_nid, "$arg/$query->child_nid"); |
return l($query->child_nid, "$arg/$query->child_nid"); |
| 1006 |
} |
} |
| 1007 |
|
|
| 1008 |
function nodefamily_views_handler_arg_grand_child_nid($op, &$query, $argtype, $arg = '') { |
function nodefamily_views_handler_arg_grand_child_nid($op, &$query, $argtype, $arg = '') { |
| 1009 |
switch($op) { |
switch ($op) { |
| 1010 |
case 'summary': |
case 'summary': |
| 1011 |
// do nothing. field name child_nid makes troubles... |
// do nothing. field name child_nid makes troubles... |
| 1012 |
break; |
break; |
| 1022 |
$joininfo['left']['field'] = 'child_nid'; |
$joininfo['left']['field'] = 'child_nid'; |
| 1023 |
$num = $query->add_table('nodefamily_parent', false, 1, $joininfo); |
$num = $query->add_table('nodefamily_parent', false, 1, $joininfo); |
| 1024 |
$tablename = $query->get_table_name('nodefamily_parent', $num); |
$tablename = $query->get_table_name('nodefamily_parent', $num); |
| 1025 |
$query->add_where($tablename. ".child_nid = %d", $arg); |
$query->add_where($tablename .".child_nid = %d", $arg); |
| 1026 |
break; |
break; |
| 1027 |
case 'link': |
case 'link': |
| 1028 |
return l($query->child_nid, "$arg/$query->child_nid"); |
return l($query->child_nid, "$arg/$query->child_nid"); |
| 1033 |
} |
} |
| 1034 |
|
|
| 1035 |
function nodefamily_views_handler_arg_grand_parent_nid($op, &$query, $argtype, $arg = '') { |
function nodefamily_views_handler_arg_grand_parent_nid($op, &$query, $argtype, $arg = '') { |
| 1036 |
switch($op) { |
switch ($op) { |
| 1037 |
case 'summary': |
case 'summary': |
| 1038 |
// do nothing. field name child_nid makes troubles... |
// do nothing. field name child_nid makes troubles... |
| 1039 |
break; |
break; |
| 1049 |
$joininfo['left']['field'] = 'parent_nid'; |
$joininfo['left']['field'] = 'parent_nid'; |
| 1050 |
$num = $query->add_table('nodefamily_child', false, 1, $joininfo); |
$num = $query->add_table('nodefamily_child', false, 1, $joininfo); |
| 1051 |
$tablename = $query->get_table_name('nodefamily_child', $num); |
$tablename = $query->get_table_name('nodefamily_child', $num); |
| 1052 |
$query->add_where($tablename. ".parent_nid = %d", $arg); |
$query->add_where($tablename .".parent_nid = %d", $arg); |
| 1053 |
break; |
break; |
| 1054 |
case 'link': |
case 'link': |
| 1055 |
return l($query->parent_nid, "$arg/$query->parent_nid"); |
return l($query->parent_nid, "$arg/$query->parent_nid"); |
| 1063 |
function nodefamily_views_filter($op, $filter, $filterinfo, &$query) { |
function nodefamily_views_filter($op, $filter, $filterinfo, &$query) { |
| 1064 |
$query->ensure_table($filterinfo['table']); |
$query->ensure_table($filterinfo['table']); |
| 1065 |
$query->add_where("%s.%s %s '%s'", $filterinfo['table'], $filterinfo['field'], $filter['operator'], $filter['value']); |
$query->add_where("%s.%s %s '%s'", $filterinfo['table'], $filterinfo['field'], $filter['operator'], $filter['value']); |
| 1066 |
|
|
| 1067 |
if ($filter['options']) { |
if ($filter['options']) { |
| 1068 |
$table = ($filterinfo['table'] == 'nodefamily_child') ? 'nf_node_parent' : 'nf_node_child'; |
$table = ($filterinfo['table'] == 'nodefamily_child') ? 'nf_node_parent' : 'nf_node_child'; |
| 1069 |
$num = $query->add_table($table); |
$num = $query->add_table($table); |