<?php

require_once 'orm/OrmBase.php';

/**
 * Base Worker class for propagate actions to related objects.
 * This is the base for the classes that perform the "hard work".
 * It's important to note that the order of method's execution (usually 
 * implemented in the body of the public methods of this class children) is 
 * very important, because some methods depends on other method's results to 
 * obtain a correct result. So, you need to understand each process really 
 * deeply if you pretend to change it in any way.
 * 
 * @abstract
 * @author  $Author: pruna $
 * @package orm
 * @version $Revision: 1.3 $
 * @created 19-Oct-2005
 * @modified $Date: 2005/12/06 02:56:45 $
 */
abstract class OrmWorker extends OrmBase {
    
    /**
     * @const 
     */
    const ACTION_SELECT = 'select';
    
    /**
     * @const 
     */
    const ACTION_SAVE = 'save';
    
    /**
     * @const 
     */
    const ACTION_UPDATE = 'update';
    
    /**
     * @const 
     */
    const ACTION_INSERT = 'insert';
    
    /**
     * @const 
     */
    const ACTION_REMOVE = 'remove';
    
    /**
     * @const 
     */
    const ACTION_REMOVE_IF_ORPHAN = 'removeIfOrphan';
    
    /**
     * @const 
     */
    const ACTION_CLEAN_IF_ORPHAN = 'cleanIfOrphan';
    
    /**
     * @const 
     */
    const ACTION_SEARCH = 'search';
    
    /**
     * @const 
     */
    const ACTION_GET = 'get';
    
    /**
     * Internal holder for the DAO (<em>OrmCore</em>) using this class.
     *
     * @var      OrmCore
     * @access   protected
     */
    protected $dao;
    
    /**
     * Constructor. Stores the DAO <em>OrmCore</em> that uses this workers.
     * 
     * @access   public
     * @param    OrmCore     $dao    OrmCore that uses this workers.
     */
    public function __construct($dao) {
        parent::__construct();
        $this->setDao($dao);
    }
    
    /**
     * Returns stored DAO.
     *
     * @access  public
     * @return  OrmCore
     */
    public function getDao() {
        return $this->dao;
    }
    
    /**
     * Auxiliar method to simplify calls to <em>BeanUtils</em>'s getter.
     * 
     * @access   protected
     * @param    Bean            $bean     Bean that holds value
     * @param    OrmMapElement   $prop     Property which's name will be readed
     * @return   mixed
     */
    protected function getter($bean, $prop) {
        return $this->getBu()->getter($bean, $prop->getName());
    }
    
    /**
     * Stores DAO (<em>OrmCore</em>) using this class.
     * When call this method, it calls <em>setBu</em>, 
     * <em>setDb</em> and <em>setMap</em> based on this DAO.
     * This provides easier access to all this objects.
     *
     * @access  public
     * @param   OrmCore      $dao        DAO invoker
     */
    public function setDao($dao) {
        $this->dao = $dao;
        if (ObjectInspector::isA($dao, 'OrmCore')) {
            $this->setBu($dao->getBu());
            $this->setMap($dao->getMap());
            $this->setDb($dao->getDb());
        }
    }
    
}

?>