OneToManyLinkedLazy.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: OneToManyLinkedLazy.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00016     final class OneToManyLinkedLazy extends OneToManyLinkedWorker
00017     {
00021         public function makeFetchQuery()
00022         {
00023             $query =
00024                 $this->makeSelectQuery()->
00025                 dropFields()->
00026                 get($this->container->getChildIdField());
00027             
00028             return $this->targetize($query);
00029         }
00030         
00035         public function sync(&$insert, &$update = array(), &$delete)
00036         {
00037             Assert::isTrue($update === array());
00038             
00039             $db = DBPool::getByDao($this->container->getDao());
00040             
00041             $uc = $this->container;
00042             $dao = $uc->getDao();
00043 
00044             if ($insert)
00045                 $db->queryNull($this->makeMassUpdateQuery($insert));
00046 
00047             if ($delete) {
00048                 // unlink or drop
00049                 $uc->isUnlinkable()
00050                     ?
00051                         $db->queryNull($this->makeMassUpdateQuery($delete))
00052                     :
00053                         $db->queryNull(
00054                             OSQL::delete()->from($dao->getTable())->
00055                             where(
00056                                 Expression::in(
00057                                     $uc->getChildIdField(),
00058                                     $delete
00059                                 )
00060                             )
00061                         );
00062                 
00063                 $dao->uncacheByIds($delete);
00064             }
00065 
00066             return $this;
00067         }
00068         
00072         private function makeMassUpdateQuery(&$ids)
00073         {
00074             $uc = $this->container;
00075             
00076             return
00077                 OSQL::update($uc->getDao()->getTable())->
00078                 set($uc->getParentIdField(), null)->
00079                 where(
00080                     Expression::in(
00081                         $uc->getChildIdField(),
00082                         $ids
00083                     )
00084                 );
00085         }
00086     }
00087 ?>

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