Apache Zeta Components Manual :: File Source for persistent_object.php

Source for file persistent_object.php

Documentation is available at persistent_object.php

  1. <?php
  2. /**
  3.  * File containing the ezcTreePersistentObjectDataStore class.
  4.  *
  5.  * Licensed to the Apache Software Foundation (ASF) under one
  6.  * or more contributor license agreements.  See the NOTICE file
  7.  * distributed with this work for additional information
  8.  * regarding copyright ownership.  The ASF licenses this file
  9.  * to you under the Apache License, Version 2.0 (the
  10.  * "License"); you may not use this file except in compliance
  11.  * with the License.  You may obtain a copy of the License at
  12.  * 
  13.  *   http://www.apache.org/licenses/LICENSE-2.0
  14.  * 
  15.  * Unless required by applicable law or agreed to in writing,
  16.  * software distributed under the License is distributed on an
  17.  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18.  * KIND, either express or implied.  See the License for the
  19.  * specific language governing permissions and limitations
  20.  * under the License.
  21.  *
  22.  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  23.  * @version //autogentag//
  24.  * @filesource
  25.  * @package TreePersistentObjectTiein
  26.  */
  27.  
  28. /**
  29.  * ezcTreePersistentObjectDataStore is a tree data store that stores persistent
  30.  * objects.
  31.  *
  32.  * @package TreePersistentObjectTiein
  33.  * @version //autogentag//
  34.  * @mainclass
  35.  */
  36. class ezcTreePersistentObjectDataStore implements ezcTreeXmlDataStoreezcTreeDbDataStore
  37. {
  38.     /**
  39.      * Contains the persistent session object.
  40.      *
  41.      * @var ezcPersistentSession 
  42.      */
  43.     private $session;
  44.  
  45.     /**
  46.      * Contains the class name of the objects that belong to the tree.
  47.      *
  48.      * @var string 
  49.      */
  50.     private $class;
  51.  
  52.     /**
  53.      * Contains the name of the table field that contains the ID.
  54.      *
  55.      * @var string 
  56.      */
  57.     private $idField null;
  58.  
  59.     /**
  60.      * Contains the name of the object property that contains the ID.
  61.      *
  62.      * @var string 
  63.      */
  64.     private $idProperty null;
  65.  
  66.     /**
  67.      * Contains the DOM representing this tree this data store stores data for.
  68.      *
  69.      * @var DOMDocument 
  70.      */
  71.     protected $dom;
  72.  
  73.     /**
  74.      * Constructs a new storage backend that stores objects through persistent
  75.      * objects.
  76.      *
  77.      * The store will use the persistent session specified by $session. The
  78.      * $class parameter specifies which object class is used.  The class'
  79.      * property that is matched against the node ID is specified with
  80.      * $idProperty.
  81.      *
  82.      * @param ezcPersistentSession $session 
  83.      * @param string $class 
  84.      * @param string $idProperty 
  85.      */
  86.     public function __constructezcPersistentSession $session$class$idProperty )
  87.     {
  88.         $this->session $session;
  89.         $this->class $class;
  90.  
  91.         // figure out which column belongs to the property in $idProperty
  92.         $def $session->definitionManager->fetchDefinition$class );
  93.  
  94.         $this->idField $def->idProperty->columnName;
  95.         $this->idProperty $idProperty;
  96.     }
  97.  
  98.     /**
  99.      * Deletes the data for the node $node from the data store.
  100.      *
  101.      * @param ezcTreeNode $node 
  102.     public function deleteDataForNode( ezcTreeNode $node )
  103.     {
  104.     }
  105.      */
  106.  
  107.     /**
  108.      * Deletes the data for all the nodes in the node list $nodeList.
  109.      *
  110.      * @param ezcTreeNodeList $nodeList 
  111.      */
  112.     public function deleteDataForNodesezcTreeNodeList $nodeList )
  113.     {
  114.         $session $this->session;
  115.  
  116.         $nodeIdsToDelete array();
  117.         foreach array_keys$nodeList->nodes as $id )
  118.         {
  119.             $nodeIdsToDelete[= (string) $id;
  120.         }
  121.  
  122.         $q $session->createDeleteQuery$this->class );
  123.         $q->where$q->expr->in$this->session->database->quoteIdentifier$this->idField )$nodeIdsToDelete ) );
  124.         $session->deleteFromQuery$q );
  125.     }
  126.  
  127.     /**
  128.      * Deletes the data for all the nodes in the store.
  129.      */
  130.     public function deleteDataForAllNodes()
  131.     {
  132.         $session $this->session;
  133.  
  134.         $q $session->createDeleteQuery$this->class );
  135.         $session->deleteFromQuery$q );
  136.     }
  137.  
  138.     /**
  139.      * Retrieves the data for the node $node from the data store and assigns it
  140.      * to the node's 'data' property.
  141.      *
  142.      * @param ezcTreeNode $node 
  143.      */
  144.     public function fetchDataForNodeezcTreeNode $node )
  145.     {
  146.         $session $this->session;
  147.  
  148.         try
  149.         {
  150.             $q $session->load$this->class$node->id );
  151.         }
  152.         catch ezcPersistentQueryException $e )
  153.         {
  154.             throw new ezcTreeDataStoreMissingDataException$node->id );
  155.         }
  156.  
  157.         $node->data $q;
  158.         $node->dataFetched true;
  159.     }
  160.  
  161.     /**
  162.      * This method *tries* to fetch the data for all the nodes in the node list
  163.      * $nodeList and assigns this data to the nodes' 'data' properties.
  164.      *
  165.      * @param ezcTreeNodeList $nodeList 
  166.      */
  167.     public function fetchDataForNodesezcTreeNodeList $nodeList )
  168.     {
  169.         $session $this->session;
  170.  
  171.         $nodeIdsToFetch array();
  172.         foreach $nodeList->nodes as $node )
  173.         {
  174.             if $node->dataFetched === false )
  175.             {
  176.                 $nodeIdsToFetch[$node->id;
  177.             }
  178.         }
  179.  
  180.         $q $session->createFindQuery$this->class );
  181.         $q->where$q->expr->in$this->session->database->quoteIdentifier$this->idField )$nodeIdsToFetch ) );
  182.         $objects $session->find$q$this->class );
  183.  
  184.         foreach $objects as $object )
  185.         {
  186.             $nodeList[$object->id]->data $object;
  187.             $nodeList[$object->id]->dataFetched true;
  188.         }
  189.     }
  190.  
  191.     /**
  192.      * Stores the data in the node to the data store.
  193.      *
  194.      * @param ezcTreeNode $node 
  195.      */
  196.     public function storeDataForNodeezcTreeNode $node )
  197.     {
  198.         $session $this->session;
  199.  
  200.         $idProperty $this->idProperty;
  201.  
  202.         // if the object's ID property is null, populate it with the node's ID
  203.         $currentState $node->data->getState();
  204.         if $currentState[$idProperty=== null )
  205.         {
  206.             $node->data->setStatearray$idProperty => $node->id ) );
  207.         }
  208.         $session->saveOrUpdate$node->data );
  209.  
  210.         $node->dataStored true;
  211.     }
  212.  
  213.     /**
  214.      * Associates the DOM tree for which this data store stores data for with
  215.      * this store.
  216.      *
  217.      * This method is only needed for when a data store is used
  218.      * with an XML based tree backend. XML based tree backends call this method
  219.      * to associate the DOM tree with the store. This is not needed for this
  220.      * data store so the method is a no-op.
  221.      *
  222.      * @param DOMDocument $dom 
  223.      */
  224.     public function setDomTreeDOMDocument $dom )
  225.     {
  226.     }
  227. }
  228. ?>
Documentation generated by phpDocumentor 1.4.3