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 
00015     abstract class ManyToManyLinkedWorker extends UnifiedContainerWorker
00016     {
00020         protected function makeInsertQuery($childId)
00021         {
00022             $uc = $this->container;
00023             
00024             return
00025                 OSQL::insert()->into($uc->getHelperTable())->
00026                 set(
00027                     $uc->getParentIdField(),
00028                     $uc->getParentObject()->getId()
00029                 )->
00030                 set($uc->getChildIdField(), $childId);
00031         }
00032         
00038         protected function makeDeleteQuery($delete)
00039         {
00040             $uc = $this->container;
00041             
00042             return
00043                 OSQL::delete()->from($uc->getHelperTable())->
00044                 where(
00045                     Expression::eq(
00046                         new DBField($uc->getParentIdField()),
00047                         new DBValue($uc->getParentObject()->getId())
00048                     )
00049                 )->
00050                 andWhere(
00051                     Expression::in(
00052                         $uc->getChildIdField(),
00053                         $delete
00054                     )
00055                 );
00056         }
00057         
00061         protected function joinHelperTable(SelectQuery $query)
00062         {
00063             $uc = $this->container;
00064             
00065             if (!$query->hasJoinedTable($uc->getHelperTable()))
00066                 $query->
00067                     join(
00068                         $uc->getHelperTable(),
00069                         Expression::eq(
00070                             new DBField(
00071                                 $uc->getParentTableIdField(),
00072                                 $uc->getDao()->getTable()
00073                             ),
00074                             new DBField(
00075                                 $uc->getChildIdField(),
00076                                 $uc->getHelperTable()
00077                             )
00078                         )
00079                     );
00080             
00081             return
00082                 $query->
00083                     andWhere(
00084                         Expression::eq(
00085                             new DBField(
00086                                 $uc->getParentIdField(),
00087                                 $uc->getHelperTable()
00088                             ),
00089                             new DBValue($uc->getParentObject()->getId())
00090                         )
00091                     );
00092         }
00093     }
00094 ?>