ManyToManyLinkedWorker.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2005-2007 by Konstantin V. Arkhipov                     *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 /* $Id: ManyToManyLinkedWorker.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00016     abstract class ManyToManyLinkedWorker extends UnifiedContainerWorker
00017     {
00021         protected function makeInsertQuery($childId)
00022         {
00023             $uc = $this->container;
00024             
00025             return
00026                 OSQL::insert()->into($uc->getHelperTable())->
00027                 set(
00028                     $uc->getParentIdField(),
00029                     $uc->getParentObject()->getId()
00030                 )->
00031                 set($uc->getChildIdField(), $childId);
00032         }
00033         
00039         protected function makeDeleteQuery(&$delete)
00040         {
00041             $uc = $this->container;
00042             
00043             return
00044                 OSQL::delete()->from($uc->getHelperTable())->
00045                 where(
00046                     Expression::eq(
00047                         new DBField($uc->getParentIdField()),
00048                         new DBValue($uc->getParentObject()->getId())
00049                     )
00050                 )->
00051                 andWhere(
00052                     Expression::in(
00053                         $uc->getChildIdField(),
00054                         $delete
00055                     )
00056                 );
00057         }
00058         
00062         protected function joinHelperTable(SelectQuery $query)
00063         {
00064             $uc = $this->container;
00065             
00066             return
00067                 $query->
00068                     join(
00069                         $uc->getHelperTable(),
00070                         Expression::eq(
00071                             new DBField(
00072                                 $uc->getParentTableIdField(),
00073                                 $uc->getDao()->getTable()
00074                             ),
00075                             new DBField(
00076                                 $uc->getChildIdField(),
00077                                 $uc->getHelperTable()
00078                             )
00079                         )
00080                     )->
00081                     andWhere(
00082                         Expression::eq(
00083                             new DBField(
00084                                 $uc->getParentIdField(),
00085                                 $uc->getHelperTable()
00086                             ),
00087                             new DBValue($uc->getParentObject()->getId())
00088                         )
00089                     );
00090         }
00091     }
00092 ?>

Generated on Sun Dec 9 21:56:24 2007 for onPHP by  doxygen 1.5.4