A place for users and developers of the Xataface to discuss and receive support.
by cookie720 » Tue Jul 31, 2012 4:55 pm
I have a section bit here - Code: Select all
//issues records related to matter function section__status(&$record){ $related_records =& $record->getRelatedRecordObjects('status'); // Let's assume there is only one related record. if ( count($related_records) == 0 ) return null; $content = '<b>To Do: </b>'.$related_records[0]->htmlValue('ToDo') .'<br><br><b>Awaiting: </b>'.$related_records[0]->htmlValue('Awaiting'); return array( 'label'=> 'Status', 'class'=>'left', 'content'=> $content, 'edit_url'=>$record->getURL('-action=related_records_list&-table=status&-relationship=status'), 'order' => 2 ); } }
which doesnt appear on newly created records. If i change it to - Code: Select all
//issues records related to matter function section__status(&$record){ return array( 'label'=> 'Status', 'class'=>'left', 'records'=>$record->getRelatedRecordObjects('status'), 'edit_url'=>$record->getURL('-action=related_records_list&-table=status&-relationship=status'), 'order' => 2 ); } }
It of course appears... is there a way to do an if else statement around these? so that I can have the second function section come up if there is no records yet. and after show the top function
-
cookie720
-
- Posts: 69
- Joined: Mon Jun 04, 2012 9:22 pm
by cookie720 » Tue Jul 31, 2012 9:41 pm
I know its because you don't actually set a status for a matter when you create a matter, Its impossible I have multiple statuses... the way it works is there is only one client, and thats how it should work with the status. You create a client or add one to the matter upon creating a matter...so there is a ClientID in matters table. There is no StatusID in my matters table..... Setting a fake/default status is kind of complicated. Working on it. All the other tables have the simple section function that is why they work. They can be blank, have no related records and still appear, and you can add related records later....
So that leads onto another problem. The status table has many statuses because it creates a new status for every time you want to edit one. How can I listing the statuses so that it sorts the most recent for each matter and returning them into the status table? Probably a rendercell function or something. with select * from status where edited last desc limit 1 (for each matter though)
Please help! This is a big one! I might ened to upload a screenshot because its kind of hard to explain
-
cookie720
-
- Posts: 69
- Joined: Mon Jun 04, 2012 9:22 pm
by shannah » Wed Aug 01, 2012 7:49 am
You have a few different questions in here. I'm not sure I understand all of them. In response to your question about if/else clauses in your sections, why not just do: - Code: Select all
function section__foo(){ if ( something_is_true() ){ return array( .... ); } else { return array(....); } }
?
-
shannah
-
- Posts: 4457
- Joined: Wed Dec 31, 1969 5:00 pm
by cookie720 » Wed Aug 01, 2012 4:47 pm
in theory that should be working but this code - Code: Select all
$related_records =& $record->getRelatedRecordObjects('status'); Let's assume there is only one related record. if ( count($related_records) == 0 ) return null; $content = '<b>To Do: </b>'.$related_records[0]->htmlValue('ToDo') .'<br><br><b>Awaiting: </b>'.$related_records[0]->htmlValue('Awaiting');
in my function makes the section not show up. If I take it out, it shows up. So here is my complete function: - Code: Select all
function section__status(&$record){ $related_records =& $record->getRelatedRecordObjects('status'); // Let's assume there is only one related record. if ( count($related_records) == 0 ) return null; $content = '<b>To Do: </b>'.$related_records[0]->htmlValue('ToDo') .'<br><br><b>Awaiting: </b>'.$related_records[0]->htmlValue('Awaiting'); if ( count($related_records) == 0 ) { //this first array should come allow the section to appear with blank related rows, allowing a user to add a related row return array( 'label'=> 'Status', 'class'=>'left', 'records'=>$record->getRelatedRecordObjects('status'), 'edit_url'=>$record->getURL('-action=related_records_list&-table=status&-relationship=status'), 'order' => 2 ); } else { else return this array which does its own job return array( 'label'=> 'Status', 'class'=>'left', 'content'=> $content, 'edit_url'=>$record->getURL('-action=related_records_list&-table=status&-relationship=status'), 'order' => 2 ); } }
I hope its not a catch 22 because I really need both arrays to work, and the code at the top grabs the content from the related record to show it using certain fields.
-
cookie720
-
- Posts: 69
- Joined: Mon Jun 04, 2012 9:22 pm
by shannah » Fri Aug 03, 2012 1:20 pm
Not sure what you're trying to do here exactly. Your 2nd if statement will either not be reached or it will always evaluate as false (yielding the "else" case).
There will never be a case when it will evaluate to true - i.e. you will never execute the code inside the "if" branch.
-Steve
-
shannah
-
- Posts: 4457
- Joined: Wed Dec 31, 1969 5:00 pm
by cookie720 » Sun Aug 05, 2012 2:59 am
I need to...The if 'block' array needs to appear, and after a related record is created, the else 'block' array should work (with content showing)
If this isnt possible, I think I would need to insert a 'fake' row automatically when a matter is created, with default values, because when I just use the content array (the else block) If I manually add a record, using phpmyadmin, it appears to work. With no record manually added, The 'status' related table section doesnt even appear.
-
cookie720
-
- Posts: 69
- Joined: Mon Jun 04, 2012 9:22 pm
by shannah » Sun Aug 05, 2012 9:35 am
Everything is possible. You just have a logic flaw in your code that prevents the if statement from evaluating to true. This is because the line: - Code: Select all
if ( count($related_records) == 0 ) return null;
Catches this case, so the later: - Code: Select all
if ( count($related_records) == 0 ) {
Will only be reached if the previous if statement was false. -Steve
-
shannah
-
- Posts: 4457
- Joined: Wed Dec 31, 1969 5:00 pm
by cookie720 » Mon Aug 06, 2012 4:57 pm
im not sure how to go about it then, If i delete the - Code: Select all
if ( count($related_records) == 0 ) return null;
altogether, i get an error - Code: Select all
Fatal error: Call to a member function htmlValue() on a non-object in C:\wamp\www\live_matters\tables\matters\matters.php on line 94
where i have the lines getting the most recent current fields - Code: Select all
$content = '<b>To Do: </b>'.$related_records[0]->htmlValue('ToDo') .'<br><br><b>Awaiting: </b>'.$related_records[0]->htmlValue('Awaiting')
to me, the best logic would be to do this: - Code: Select all
//issues records related to matter function section__status(&$record){ $related_records =& $record->getRelatedRecordObjects('status'); // Let's assume there is only one related record.
if ( count($related_records) == 0 ) { return array( 'label'=> 'Status', 'class'=>'left', 'records'=>$record->getRelatedRecordObjects('status'), 'edit_url'=>$record->getURL('-action=related_records_list&-table=status&-relationship=status'), 'order' => 2 ); } else { $related_records =& $record->getRelatedRecordObjects('status'); // Let's assume there is only one related record. $content = '<b>To Do: </b>'.$related_records[0]->htmlValue('ToDo') .'<br><br><b>Awaiting: </b>'.$related_records[0]->htmlValue('Awaiting');
return array( 'label'=> 'Status', 'class'=>'left', 'content'=> $content, 'edit_url'=>$record->getURL('-action=related_records_list&-table=status&-relationship=status'), 'order' => 2 ); } }
-
cookie720
-
- Posts: 69
- Joined: Mon Jun 04, 2012 9:22 pm
Return to Xataface Users
Who is online
Users browsing this forum: No registered users and 7 guests
|