PDA

View Full Version : [SOLVED]Exclude Addon PHP Functions


bpr
04-28-2010, 04:49 AM
Hi guys,
I got a question about excluding parts of my php files in combination with the db class.

First of all, lets call my file "test.php". In that file I got like 500 Lines of php code, lets say 100 lines is all over the same something like this:
$dataForSquadTodo = array();
while ($tododata = $vbulletin->db->fetch_array($DATAFROMOUTSIDEFUNCTION) )
{
//make a class so that you can adjust bg for tr
switch ($tododata['priority'])
{
case "Sehr Hoch":
$style = 'rhigh';
break;

case "Hoch":
$style = 'high';
break;

case "Mittel":
$style = 'medium';
break;

case "Niedrig":
$style = 'low';
break;

}

// nun stehen die Daten in $userdata zur Verf?gung
$data = array(
'id' => $tododata['id'],
'title' => $tododata['title'],
'description' => $tododata['description'],
'squad' => $tododata['squadname'],
'status' => $tododata['status'],
'priority' => $tododata['priority'],
'style' => $style
);
$dataForSquadTodo[] = $data;
}

foreach ($dataForSquadTodo as $item => $value)
{
$templater = vB_Template::create('todo_table_list');
$templater->register('item', $item);
$templater->register('value', $value);
$todoDataSquad .= $templater->render();
}

I tried to put this in a function such and called it something like
"getDataAndProduceArray( $data )"

However, there was no way, that I was able to use "$DATAFROMOUTSIDEFUNCTION" - I just got a blank site. It was even in the test.php and I didnt give it to another php file in includes/ or somewhere else. Does anybody know, why I cant do it like that ? Why is my script not recognising my function ?

All the best
bpr

Lynne
04-28-2010, 01:38 PM
There is no reason why you can't create a function in another file and pass it information. But, since you didn't post the exact code you wrote for the function, nor the exact code you wrote to call the function, it's impossible for us to tell you what you did wrong.

bpr
04-28-2010, 05:09 PM
Ook - here the exactly code:

todo.php:

// ######################### REQUIRE BACK-END ############################
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/path/to/your/forums');
require_once('./global.php');
require_once('./includes/class_todo.php');

Later on in the todo.php


//Todo Class
$todoCLS = new Todo();

And then the usage of it in todo.php

///////////////////////////////////
//TODO to do
///////////////////////////////////
$result = $vbulletin->db->query_read("SELECT todo.id, todo.title, todo.description, todo_squad.title as squadname, todo_status.title as status, todo_priority.title as priority FROM " . TABLE_PREFIX . " todo LEFT JOIN ( todo_squad, todo_priority, todo_status) ON ( todo.squad=todo_squad.id AND todo.status=todo_status.id AND todo.priority=todo_priority.id) WHERE todo.status>=2 AND active=1 ORDER BY todo.priority ASC");
#$resultset = $vbulletin->db->fetch_array($result);
$dataForTemplate = Array();
$dataForTemplate =$todoCLS->makeArray( $result );

//if empty dont show table
if ( count( $dataForTemplate ) == 0 )
{
$dataForTemplate[] = $noData;
}

foreach ($dataForTemplate as $item => $value)
{
$templater = vB_Template::create('todo_table_list');
$templater->register('value', $value);
$todoData .= $templater->render();
}

So I got the line
$dataForTemplate =$todoCLS->makeArray( $result );
this was just replaced, everything was working, thats the only line I replaced.

So lets got to the file:
/includes/class_todo.php
<?php

class Todo
{
/*
* return Array for Todo Table creation
*/
public function makeArray( $result )
{
while ($tododata = $vbulletin->db->fetch_array($result) )
{
//make a class so that you can adjust bg for tr
switch ($tododata['priority'])
{
case "Sehr Hoch":
$style = 'rhigh';
break;

case "Hoch":
$style = 'high';
break;

case "Mittel":
$style = 'medium';
break;

case "Niedrig":
$style = 'low';
break;

}

// nun stehen die Daten in $userdata zur Verf?gung
$data = array(
'id' => $tododata['id'],
'title' => $tododata['title'],
'description' => $tododata['description'],
'squad' => $tododata['squadname'],
'status' => $tododata['status'],
'priority' => $tododata['priority'],
'style' => $style
);
$dataForTemplate[] = $data;
}
}
}

?>

If I request the site I will get a white - blank page!

What did I do wrong ?
I read something about ob_start(); and so on ? Do I need to do that ?

All the best,
bpr

//edit
the problem was that i didnt have
global $vbulletin in my other php files!