[Typo3-dev] Help with extension (TCA?)

Joshua Preston jpreston at americatab.com
Sun Mar 20 18:54:38 CET 2005


Hey group,

I am writing a front end mailing system, which thus far works 
fabulously.  I do have a couple of problems however.

I created 2 new db tables.  I'm only working on one at the moment, the 
messages.  It's structure (from the kickstarter is)

m_sent 	Date the message was sent 	Date and time 	
	
m_received 	Date the message was recieved 	Date and time 	
	
m_sender 	Sender of the message 	Database relation 	
	fe_users
m_to 	Recipients of the message 	Database relation 	
	fe_users
m_cc 	Carbon Copied Recipients of the message 	Database relation 	
	fe_users
m_bcc 	Blind Carbon Copied Recipients of the message 	Database relation 	
	fe_users
m_subject 	Subject of the message 	String input 	
	
m_body 	Body of the message 	Text area with RTE 	
	Typical (based on CSS)
m_reciept 	Return Reciept is requested? 	Checkbox, single 	
	
m_priority 	Priority of the message 	Selectorbox 	
	4 options
m_attachments 	File attachments 	Files 	
	images, 5 files, 500 kB



The problem I am experiencing is a novice error I'm sure.  I have 
successfully been able to filter the messages by the user.  Basically 
what I did was write two new functions which translated the UID to the 
username and checked the TO,CC,BCC table fields to see if the currently 
logged in user can view the current message.  This works, but the count 
is not correct.

I guess I was wondering how I can make a select where the uid must be in 
any TO, CC or BCC.  The two functions I wrote look like this:

    /**
     * returns the name of the user
     */
    function getUserName($uid) {
        if ( strlen($uid) > 0 ) {
            $str = '';
            $users = explode(',',$uid);
            $i = 0;
            // lookup all the users
            do {
               
$dbres=$GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,name','fe_users','uid='.$users[$i],'','name');
                $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres);
                // if we're working on the first one, we don't need a 
comma, if we aren't we do!
                $str .= ($i == 0) ? $row['name'] : ', ' . $row['name'];
                $i++;
            } while ( $i < count($users) );
            return $str;
        } else {
            return '';
        }
    }

    /**
     * returns true/false if the user is allowed to view the current 
message...
     */
    function canUserView() {
        $m_to = $this->getFieldContent("m_to_uid");
        $m_cc = $this->getFieldContent("m_cc_uid");
        $m_bcc = $this->getFieldContent("m_bcc_uid");
        $m_to = explode(',',$m_to);
        $m_cc = explode(',',$m_cc);
        $m_bcc = explode(',',$m_bcc);
        $canViewTo = 
array_search($GLOBALS['TSFE']->fe_user->user['uid'], $m_to);
        $canViewCC = 
array_search($GLOBALS['TSFE']->fe_user->user['uid'], $m_to);
        $canViewBCC = 
array_search($GLOBALS['TSFE']->fe_user->user['uid'], $m_to);
        if ($canViewTo > -1) {
            return true;
        }
        if ($canViewCC > -1) {

            return true;

        }
        if ($canViewBCC > -1) {
            return true;
        }
            return false;
    }

They work, but I shouldn't be using my functions to do this because the 
$this->internal is handling the DB call.  Is there a way to filter the 
messages based on the current user id against the comma separated list 
of the UID relation to fe_users?  The problem that I am having is that 
the results that are returned are all messages, not filtered ones.  The 
end-result is that even if the user has no messages displayed (filtered 
with my functions), it still reports the number of rows from the 
unfiltered list.  The other problem is that if a user has 2 messages, 
and those messages are not in the same result set (page 1 vs page 2), 
they still have to go to the next page to view the next message.

I've tried adding to the SELECT statement, but the problem is that 
smaller number can fit into bigger ones (ie 2 is in 12 and 22 and 2000).

Any help would be greatly appreciated.

Thanks!

Joshua Preston.





More information about the TYPO3-dev mailing list