ManyToManyLinkedFull.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: ManyToManyLinkedFull.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00016     final class ManyToManyLinkedFull extends ManyToManyLinkedWorker
00017     {
00021         public function sync(&$insert, &$update = array(), &$delete)
00022         {
00023             $dao = $this->container->getDao();
00024 
00025             $db = DBPool::getByDao($dao);
00026 
00027             if ($insert)
00028                 for ($i = 0, $size = count($insert); $i < $size; ++$i) {
00029                     // check existence of new object
00030                     try {
00031                         $dao->getById($insert[$i]->getId());
00032                     } catch (ObjectNotFoundException $e) {
00033                         // ok, saving it then
00034                         $dao->add($insert[$i]);
00035                     }
00036 
00037                     $db->queryNull(
00038                         $this->makeInsertQuery($insert[$i]->getId())
00039                     );
00040                 }
00041 
00042             if ($update)
00043                 for ($i = 0, $size = count($update); $i < $size; ++$i)
00044                     $dao->save($update[$i]);
00045 
00046             if ($delete) {
00047                 $ids = array();
00048                 
00049                 foreach ($delete as $object)
00050                     $ids[] = $object->getId();
00051                 
00052                 $db->queryNull($this->makeDeleteQuery($ids));
00053                 
00054                 $dao->uncacheByIds($ids);
00055             }
00056 
00057             return $this;
00058         }
00059 
00063         public function makeFetchQuery()
00064         {
00065             return
00066                 $this->joinHelperTable(
00067                     $this->makeSelectQuery()
00068                 );
00069         }
00070     }
00071 ?>

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