# UnifiedContainerWorker.class.php

Go to the documentation of this file.

    00001 <?php
    00002 /***************************************************************************
    00003  *   Copyright (C) 2005-2009 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
    00017     abstract class UnifiedContainerWorker
    00018     {
    00019         protected $criteria     = null;
    00020         protected $container    = null;
    00021
    00022         abstract public function makeFetchQuery();
    00023         abstract public function sync($insert, $update = array(), $delete);
    00024
    00025         public function __construct(UnifiedContainer $uc)
    00026         {
    00027             $this->container = $uc;
    00028         }
    00029
    00033         public function setCriteria(Criteria $criteria)
    00034         {
    00035             $this->criteria = $criteria;
    00036
    00037             return $this;
    00038         }
    00039
    00043         public function getCriteria()
    00044         {
    00045             return $this->criteria;
    00046         }
    00047
    00051         public function makeCountQuery()
    00052         {
    00053             $query = $this->makeFetchQuery();
    00054
    00055             if ($query->isDistinct()) {
    00056                 $countFunction =
    00057                     SQLFunction::create(
    00058                         'count',
    00059                         DBField::create(
    00060                             $this->container->getDao()->getIdName(),
    00061                             $this->container->getDao()->getTable()
    00062                         )
    00063                     )->
    00064                     setAggregateDistinct();
    00065
    00066                 $query->unDistinct();
    00067
    00068             } else {
    00069                 $countFunction = SQLFunction::create('count', DBValue::create('*'));
    00070             }
    00071
    00072             return $query->
    00073                 dropFields()->
    00074                 dropOrder()->
    00075                 dropLimit()->
    00076                 get(
    00077                     $countFunction->setAlias('count')
    00078                 );
    00079         }
    00080
    00081         public function dropList()
    00082         {
    00083             $dao = $this->container->getDao();
    00084
    00085             DBPool::getByDao($dao)->queryNull(
    00086                 OSQL::delete()->from($this->container->getHelperTable())->
    00087                 where(
    00088                     Expression::eq(
    00089                         $this->container->getParentIdField(),
    00090                         $this->container->getParentObject()->getId()
    00091                     )
    00092                 )
    00093             );
    00094
    00095             $dao->uncacheLists();
    00096
    00097             return $this;
    00098         }
    00099
    00103         protected function makeSelectQuery()
    00104         {
    00105             if ($this->criteria)
    00106                 return $this->criteria->toSelectQuery();
    00107
    00108             return $this->container->getDao()->makeSelectHead();
    00109         }
    00110     }
    00111 ?>