Location: PHPKode > projects > Blackwolf CMF > projectBlackWolf/lib/Module/Module.class.php
<?php
/* Please see the README and LICENSE files. */

/**
 * Abstraction for specific Modules
 */
abstract class Module_Module {
    protected $models;
    
    /**
     * Add a specified model to the modules internal storage
     * 
     * @param String model The model to add
     * @param String name The name of the model
     */
    public function add_model($model,$name=NULL) {
        $this->models[$name==NULL?$model->name:$name] = $model;
    }
    
    /**
     * Restore the module to it's initial state
     */
    public function clean(){
        $this->models = array();
    }
    
    /**
     * Execute a specific command on the module
     * 
     * @param Module_Command cmd The command to execute
     */
    public function exe($cmd){
        if(!Permission_Subsystem::can_exec_cmd($cmd)){
            return false;
        }
        if($cmd instanceof Module_Command){
            $this->update_from($cmd->run($this));
        }
    }
    
    /**
     * Update from the command
     * 
     * @param Data_Module $module The "from"
     */
    protected function update_from($module){
        if($this->has_models()){
            $this->models = array_unique(
                                array_merge($module->get_models(),
                                $this->models));
        }
    }
    
    /**
     * Checks if any models have been added
     * 
     * @return boolean True if models are added
     */
    public function has_models() {
        return count($this->models)>0?true:false;
    }
    
    /**
     * Checks if a specific model has been added
     * 
     * @param String name The name of the module
     * @return boolean True if the model exists
     */
    public function has_model($name){
        return array_key_exists($name,$this->models);
    }
    
    /**
     * Get all of the models added
     * 
     * @return Mission_Module[] All of the added Modules
     */
    public function get_models() {
        return $this->models;
    }
    
    /**
     * Get a specific model
     * 
     * @param String name The name of the model
     * @return Mission_Model The requested model
     */
    public function get_model($name) {
        return $this->has_model($name) ?
                $this->models[$name]:
                false;
    }
    
    /**
     * Gets the first model added
     * 
     * @return Mission_Model The first model
     */
    public function get_first_model() {
        if($this->has_models()){
            reset($this->models);
            return current($this->models);
        }
    }
    
    /**
     * Gets the last model added
     * 
     * @return Mission_Model The last model
     */
    public function get_last_model(){
        return end($this->models);
    }
}

?>
Return current item: Blackwolf CMF