[geeklog-cvs] Geeklog-2.x/plugins/content/commands DeleteContentCommand.php, NONE, 1.1 SaveContentCommand.php, NONE, 1.1

Damien Hodgkin dhodgkin at qs1489.pair.com
Wed Aug 8 16:14:35 EDT 2007


Update of /cvsroot/geeklog2/Geeklog-2.x/plugins/content/commands
In directory qs1489.pair.com:/tmp/cvs-serv13410/plugins/content/commands

Added Files:
	DeleteContentCommand.php SaveContentCommand.php 
Log Message:
Second commit

--- NEW FILE: SaveContentCommand.php ---
<?php

/* Reminder: always indent with 4 spaces (no tabs). */

/**
 * Geeklog 2
 *
 * License details are yet to be determined.  
 *
 */

/**
 * Base command to extend
 */
require getOption('path_commands') . 'BaseCommandUserPlugin.php';

/**
 * Manager models
 */
require_once getOption('path_plugins') . 'content/models/manager/Gl2ContentManager.php';
require_once getOption('path_models') . 'manager/Gl2ItemManager.php';
require_once getOption('path_models') . 'manager/Gl2PluginManager.php';

/**
 * Item model object
 */
require_once getOption('path_models') . 'Gl2Item.php';

/**
 * List item model object
 */
require_once getOption('path_models') . 'Gl2ListItem.php';


/**
 * Provides the command to save content to the DB
 * 
 * @author Damien Hodgkin <dracul01 at gmail.com>
 * @version $Id: SaveContentCommand.php,v 1.1 2007/08/08 20:14:33 dhodgkin Exp $
 * @package net.geeklog.plugins.content.commands
 * 
 */
class content_SaveContentCommand extends Geeklog_BaseCommandUserPlugin {
	/**
	 * Gets the action names this command/view will respond to
	 *
	 * @access public
	 * @static
	 * @return array Array of logic names given to the command/view
	 * 
	 */
   	public static function getActions()	{
		return array('contentSave');
	}
	
	/**
	 * Returns the set of forwards that should be associated with this view/command
	 *
	 * @access public
	 * @static
	 * @return array Array of Geeklog_MVCnPHP_Forward instances
	 * 
	 */
	public static function getForwards() {
		$forwards = array();
		$forwards[] = new Geeklog_MVCnPHP_Forward('error',Geeklog_MVCnPHP_Forward::VIEW, 'contentEdit');
		$forwards[] = new Geeklog_MVCnPHP_Forward('successAdmin',Geeklog_MVCnPHP_Forward::REDIRECT, '/index.php/content/contentAdmin');		
		return $forwards;
	}

	/**
	 * empty container for content object
	 * @var Gl2Content
	 */
	public $content = null;
	
	/**
	 * Holds Gl2Item instance
	 * @var Gl2Item
	 */
	public $item = null;
	
    /**
     * Saves content 
     *
     * @access public
     * @return string Logical name of Geeklog_MVCnPHP_Forward to fire
     * 
     */
    public function execute() { 
        
        if(empty($_POST['Gl2Content->ContentId'])) {
            $this->content = new Gl2Content();
            $this->item = new Gl2Item();
            $this->item->setGl2User($this->user);
            
            // Default date created to current time
            $this->item->setDateCreated(time());
            
            // Assign the initial state
    		$listItems = Gl2ItemManager::getListItemsByKeyword('PLUGIN_STATE', 'approved');
    		$this->item->setGl2ListItem($listItems[0]);
        } else {
        	$this->content = Gl2ContentManager::getGl2Content((int)$_POST['Gl2Content->ContentId']);
            $this->item = $this->content->getGl2Item();
            $this->item_acl = $this->item->getGl2ItemAcls();
        }
        
        // Set the item type to content
		if (!$this->item->getPluginId()) {
		    $returnVal = Gl2PluginManager::getPluginByName('content');
		    $this->item->setGl2Plugin($returnVal[0]);
		}
		
		// Now for some magic
		$objs = $this->requestToObjects(
            array('Gl2Item'=>$this->item, 'Gl2Content'=>$this->content,'Gl2ItemAcl'=>$this->item_acl));
            
        $this->item->setLeftIndex(1);
        $this->item->setRightIndex(1);
        
        if(!$this->content->getContentId()) {
            $this->content->setContentId($this->item->getItemId());
        }
        
        // You probably still need to do this but you need to do it via a call to the Gl2ItemManager 
        // class.  Commands/Views should no longer explicitly use the DAO unless they have a unique
        //need
        //$glDao->deleteWithCondition('deleteItemAcls', array($this->item->getItemId()));
        
        // K, now we need to get the ACL's
        $this->processGroupAcls($this->item);
        
        // Now user ACL's
        $this->processUserAcls($this->item);
        
        // Tie the item to the content
        $this->content->setGl2Item($this->item);
        
        // Let the magic happen
        Gl2ContentManager::saveGl2Content($this->content);
        
        // Set success message
        $_SESSION['MVC_MESSAGES'][] = 'The content you submitted was successfully saved!';

        // Notify any other plugins that the content's save event was successfully fired
        Geeklog_ActionManager::notify('CONTENT_SAVE', array($this->content));
        
        // Return forward
        return 'successAdmin';
    }
}

?>
--- NEW FILE: DeleteContentCommand.php ---
<?php

/* Reminder: always indent with 4 spaces (no tabs). */

/**
 * Geeklog 2
 *
 * License details are yet to be determined.  
 *
 */

/**
 * Base command to extend
 */
require getOption('path_commands') . 'BaseCommandUser.php';

/**
 * Content manager model object
 */
require_once getOption('path_plugins') . 'content/models/manager/Gl2ContentManager.php';

class Content_DeleteContentCommand extends Geeklog_BaseCommandUser {
   	public static function getActions()	{
		return array('contentDelete');
	}
	
	public static function getForwards() {
		$forwards = array();
		$forwards[] = new Geeklog_MVCnPHP_Forward('error',Geeklog_MVCnPHP_Forward::VIEW, 'contentAdmin');
		$forwards[] = new Geeklog_MVCnPHP_Forward('successAdmin',Geeklog_MVCnPHP_Forward::REDIRECT, '/index.php/content/contentAdmin');		
		return $forwards;
	}

    public function __construct($urlArgs) {
        $this->urlArgs = $urlArgs;
    }	

    // empty container for content object
	public $content = null;
	
	// empty container for item object
	public $item = null;
	
    /**
     * Deletes content 
     *
     * @author Damien Hodgkin <dracul01 at gmail.com>
     * @access public
     *
     */
    public function execute() 
    {
        if(empty($this->urlArgs[2])) {
            return 'error';
        } 
        
        Gl2ContentManager::deleteGl2Content(Gl2ContentManager::getGl2Content((int)$this->urlArgs[2]));
        
        // Set success message
        $_SESSION['MVC_MESSAGES'][] = 'The content was successfully deleted!';

        // Notify any other plugins that the content's save event was successfully fired
        Geeklog_ActionManager::notify('CONTENT_DELETE', array($this->content));
    
        // Return forward
        return 'successAdmin';
    }
}

?>



More information about the geeklog-cvs mailing list