Location: PHPKode > projects > Entier Studio > entierstudio/office/classes/datas/data.DirectoryProjectUserSet.php
<?php
/**
 * Entier Studio
 *
 * LICENSE
 *
 *	Copyright 2006 Entier Studio team.
 *
 *	Licensed under the Apache License, Version 2.0 (the "License");
 *	you may not use this file except in compliance with the License.
 *	You may obtain a copy of the License at
 *
 *		http://www.apache.org/licenses/LICENSE-2.0
 *
 *	Unless required by applicable law or agreed to in writing, software
 *	distributed under the License is distributed on an "AS IS" BASIS,
 *	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *	See the License for the specific language governing permissions and
 *	limitations under the License.
 *
 * @package    entier.office
 * @copyright  Copyright (c) 2006 Entier Studio team. All rights reserved.
 * @version	   $Id: data.DirectoryProjectUserSet.php 81 2008-01-17 23:08:21Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefDirectoryProjectUserSet")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefDirectoryProjectUserSet", "1");
    //-------------------------------------------------------------------------
    //	Include
    @require_once (FRAMEWORK_DIR . DATASETOBJECT);
    //-------------------------------------------------------------------------
    //	Class
    class DirectoryProjectUserSet extends DataSet {
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         *
         * @param	integer	 DirectoryProject	$DIRPROJPKID		//	foreign key
         * @param	integer	 DirectoryUser		$DIRUSERPKID		//	foreign key
         *
         */
        function DirectoryProjectUserSet($DIRPROJPKID = 0, $DIRUSERPKID = 0) {
            //
            $this->m_TableDef = "tbl_directory_project_user";
            $this->m_indexSet[PRIMARYKEY] = "DIRPUSRPKID";
            $this->m_indexSet[NATURALKEY] = "DIRUSERNAME";
            $this->m_indexSet[FOREIGNKEY] = "DIRPROJPKID";
            //
            $this->m_querySet["DIRPROJPKID"] = $DIRPROJPKID;
            $this->m_querySet["DIRUSERPKID"] = $DIRUSERPKID;
        }
        /*
        *
        * @access	protected
        *
        * @param	integer	index type
        * @param	integer	order type
        * @param	string	order mode
        *
        */
        function getSelectQuery($indexType = FOREIGNKEY, $orderType = NATURALKEY, $orderMode = "") {
            //
            switch ($indexType) {
                case FOREIGNKEY:
                    //
                    $index1 = $this->m_querySet["DIRPROJPKID"];
                    $index2 = $this->m_querySet["DIRUSERPKID"];
                    //
                    //	1e- case
                    /*
                    *
                    *	SELECT
                    *				tbl_directory_project_user	as t1
                    *			<-> tbl_directory_project		as t2
                    *	ON
                    *			DIRPROJPKID
                    */
                    if ($index1 != 0) {
                        //
                        $selectSQL = "SELECT 
										t1.DIRPUSRPKID,
										t1.DIRPUSRSTAT,
										t2.DIRPROJPKID, 
										t2.DIRPROJNAME,
										t2.DIRPROJCODE,
										t2.DIRPROJDATE,
										t2.DIRPROJSTAT,
										t3.DIRUSERPKID,
										t3.DIRUSERNAME
									FROM 
										tbl_directory_project_user as t1,
										tbl_directory_project as t2,
										tbl_directory_user as t3
									WHERE 
										t1.DIRPROJPKID=$index1
									AND 
										t1.DIRPUSRSTAT>0 
									AND
										t1.DIRPROJPKID=t2.DIRPROJPKID
									AND 
										t2.DIRPROJSTAT>0
									AND
										t1.DIRUSERPKID=t3.DIRUSERPKID 
									AND 
										t3.DIRUSERSTAT>0";
                        //
                        switch ($orderType) {
                            case PRIMARYKEY:
                                return ($selectSQL . " ORDER BY t2.DIRPROJPKID $orderMode");
                            case NATURALKEY:
                                return ($selectSQL . " ORDER BY t2.DIRPROJNAME $orderMode");
                            default:
                                return ($selectSQL . " ORDER BY t2.DIRPROJNAME");
                        }
                    }
                    //
                    //	2e- case
                    /*
                    *
                    *	SELECT
                    *				tbl_directory_project_user	as t1
                    *			<-> tbl_directory_project		as t2
                    *	ON
                    *			DIRUSERPKID
                    */
                    if ($index2 != 0) {
                        //
                        $selectSQL = "SELECT 
										t1.DIRPUSRPKID,
										t1.DIRPUSRSTAT, 
										t2.DIRPROJPKID, 
										t2.DIRPROJNAME,
										t2.DIRPROJCODE,
										t2.DIRPROJDATE,
										t2.DIRPROJSTAT,
										t3.DIRUSERPKID,
										t3.DIRUSERNAME
									FROM 
										tbl_directory_project_user as t1,
										tbl_directory_project as t2,
										tbl_directory_user as t3
									WHERE 
										t1.DIRUSERPKID=$index2
									AND 
										t1.DIRPUSRSTAT>0 
									AND
										t1.DIRPROJPKID=t2.DIRPROJPKID
									AND 
										t2.DIRPROJSTAT>0
									AND
										t1.DIRUSERPKID=t3.DIRUSERPKID 
									AND 
										t3.DIRUSERSTAT>0";
                        //
                        switch ($orderType) {
                            case PRIMARYKEY:
                                return ($selectSQL . " ORDER BY t2.DIRPROJPKID $orderMode");
                            case NATURALKEY:
                                return ($selectSQL . " ORDER BY t2.DIRPROJNAME $orderMode");
                            default:
                                return ($selectSQL . " ORDER BY t2.DIRPROJNAME");
                        }
                    }
                    //
                    
                break;
                default:
                    /*
                    *
                    *	SELECT
                    *				tbl_directory_user			as t1
                    *			NOT IN
                    *				tbl_directory_project_user	as t2
                    *	ON
                    *			DIRUSERPKID
                    */
                    //
                    $index = $this->m_querySet["DIRPROJPKID"];
                    //
                    if ($index != 0) {
                        //
                        $selectSQL = "SELECT DISTINCT
										t1.DIRUSERPKID,
										t1.DIRUSERNAME
									FROM 
										tbl_directory_user as t1
									LEFT JOIN
										tbl_directory_project_user as t2
									ON
										t1.DIRUSERPKID=t2.DIRUSERPKID
									AND
										t2.DIRPROJPKID=$index
									WHERE
										t1.DIRUSERSTAT>0
									AND
										t2.DIRUSERPKID IS NULL";
                        //
                        switch ($orderType) {
                            case PRIMARYKEY:
                                return ($selectSQL . " ORDER BY t1.DIRUSERPKID $orderMode");
                            case NATURALKEY:
                                return ($selectSQL . " ORDER BY t1.DIRUSERNAME $orderMode");
                            case STATUSKEY:
                                return ($selectSQL . " ORDER BY t1.DIRUSERDATE $orderMode");
                            default:
                                return ($selectSQL . " ORDER BY t1.DIRUSERNAME");
                        }
                    }
                    //
                    
                break;
            }
            //
            return ("");
        }
    };
    //	Class
    //-------------------------------------------------------------------------
    
}
//	namespace
//-----------------------------------------------------------------------------
?>
Return current item: Entier Studio