/php/lib/complex_builder/complex_builder.class.php
PHP | 375 lines | 323 code | 21 blank | 31 comment | 3 complexity | d781d630872541e124574fd0520450b0 MD5 | raw file
- <?php
- namespace repository;
-
- use common\libraries\ObjectTable;
-
- use common\libraries\ComplexMenuSupport;
- use common\libraries\Request;
- use common\libraries\Translation;
- use common\libraries\Path;
- use common\libraries\Utilities;
- use common\libraries\EqualityCondition;
- use common\libraries\ResourceManager;
- use common\libraries\Theme;
- use common\libraries\BasicApplication;
- use common\libraries\SubManager;
-
- use admin\AdminDataManager;
- use admin\Registration;
-
- use Exception;
-
- /**
- * $Id: complex_builder.class.php 200 2009-11-13 12:30:04Z kariboe $
- * @package repository.lib.complex_builder
- */
- require_once dirname(__FILE__) . '/complex_menu.class.php';
-
- /**
- * This class represents a basic complex builder structure.
- * When a builder is needed for a certain type of complex learning object an extension should be written.
- * We will make use of the repoviewer for selection, creation of learning objects
- *
- * @author Sven Vanpoucke
- *
- */
- abstract class ComplexBuilder extends SubManager
- {
- const PARAM_BUILDER_ACTION = 'builder_action';
- const PARAM_COMPLEX_CONTENT_OBJECT_ITEM_ID = 'cloi';
- const PARAM_SELECTED_COMPLEX_CONTENT_OBJECT_ITEM_ID = 'selected_cloi';
- const PARAM_DELETE_SELECTED_COMPLEX_CONTENT_OBJECT_ITEM = 'delete_selected_cloi';
- const PARAM_MOVE_SELECTED_COMPLEX_CONTENT_OBJECT_ITEM = 'move_selected_cloi';
- const PARAM_TYPE = 'type';
- const PARAM_DIRECTION = 'direction';
-
- const ACTION_BROWSE = 'browser';
- const ACTION_DELETE_COMPLEX_CONTENT_OBJECT_ITEM = 'deleter';
- const ACTION_VIEW_COMPLEX_CONTENT_OBJECT_ITEM = 'viewer';
- const ACTION_UPDATE_COMPLEX_CONTENT_OBJECT_ITEM = 'updater';
- const ACTION_CREATE_COMPLEX_CONTENT_OBJECT_ITEM = 'creator';
- const ACTION_MOVE_COMPLEX_CONTENT_OBJECT_ITEM = 'mover';
- const ACTION_CHANGE_PARENT = 'parent_changer';
-
- const DEFAULT_ACTION = self :: ACTION_BROWSE;
-
- protected $menu;
-
- /**
- * The current item in treemenu to determine where we are in the structure
- * @var ComplexContentObjectItem
- */
- private $complex_content_object_item;
-
- /**
- * The item we select to execute an action like update / delete / move etc
- * @var ComplexContentObjectItem
- */
- private $selected_complex_content_object_item;
-
- /**
- * The selected parent content object
- * @var ContentObject
- */
- private $parent_content_object;
-
- function __construct($parent)
- {
- parent :: __construct($parent);
-
- $complex_content_object_item_id = Request :: get(self :: PARAM_COMPLEX_CONTENT_OBJECT_ITEM_ID);
- if ($complex_content_object_item_id)
- {
- $this->complex_content_object_item = RepositoryDataManager :: get_instance()->retrieve_complex_content_object_item($complex_content_object_item_id);
- }
-
- $selected_complex_content_object_item_id = Request :: get(self :: PARAM_SELECTED_COMPLEX_CONTENT_OBJECT_ITEM_ID);
- if ($selected_complex_content_object_item_id)
- {
- $this->selected_complex_content_object_item = RepositoryDataManager :: get_instance()->retrieve_complex_content_object_item($selected_complex_content_object_item_id);
- }
-
- $this->set_action(Request :: get(self :: PARAM_BUILDER_ACTION));
- $this->parse_input_from_table();
- }
-
- //Singleton
- private static $instance;
-
- static function factory($parent, $type)
- {
- //$file = Path :: get_repository_path() . 'lib/content_object/' . $type . '/builder/' . $type . '_builder.class.php';
- $file = dirname(__FILE__) . '/../../../content_object/' . $type . '/php/builder/' . $type . '_builder.class.php';
- require_once $file;
- $class = Utilities :: underscores_to_camelcase($type) . 'Builder';
- return new $class($parent);
- }
-
- /**
- * @param string $type
- * @param Application $application
- */
- static function launch($type, $application)
- {
- $file = dirname(__FILE__) . '/../../../content_object/' . $type . '/php/builder/' . $type . '_builder.class.php';
-
- if (! file_exists($file))
- {
- throw new Exception(Translation :: get('ComplexBuilderTypeDoesNotExist', array('TYPE' => $type)));
- }
-
- require_once $file;
- //TODO just a hack needs some cleaner code ?
- $name_space = __NAMESPACE__ . '\\' . 'content_object\\' . $type . '\\';
- $class = $name_space . Utilities :: underscores_to_camelcase($type) . 'Builder';
- parent :: launch($class, $application);
- }
-
- protected function parse_input_from_table()
- {
- if (isset($_POST['action']))
- {
- $selected_ids = $_POST[RepositoryBrowserTable :: DEFAULT_NAME . ObjectTable :: CHECKBOX_NAME_SUFFIX];
- if (empty($selected_ids))
- {
- $selected_ids = array();
- }
- elseif (! is_array($selected_ids))
- {
- $selected_ids = array($selected_ids);
- }
- switch ($_POST['action'])
- {
- case self :: PARAM_DELETE_SELECTED_COMPLEX_CONTENT_OBJECT_ITEM :
- $this->set_action(self :: ACTION_DELETE_COMPLEX_CONTENT_OBJECT_ITEM);
- Request :: set_get(self :: PARAM_SELECTED_COMPLEX_CONTENT_OBJECT_ITEM_ID, $selected_ids);
- break;
- case self :: PARAM_MOVE_SELECTED_COMPLEX_CONTENT_OBJECT_ITEM :
- $this->set_action(self :: ACTION_CHANGE_PARENT);
- Request :: set_get(self :: PARAM_SELECTED_COMPLEX_CONTENT_OBJECT_ITEM_ID, $selected_ids);
- break;
- }
- }
- }
-
- function get_action()
- {
- return $this->get_parameter(self :: PARAM_BUILDER_ACTION);
- }
-
- function set_action($action)
- {
- $this->set_parameter(self :: PARAM_BUILDER_ACTION, $action);
- }
-
- function get_root_content_object()
- {
- return $this->get_parent()->get_root_content_object();
- }
-
- function get_complex_content_object_item()
- {
- return $this->complex_content_object_item;
- }
-
- function get_selected_complex_content_object_item()
- {
- return $this->selected_complex_content_object_item;
- }
-
- function get_root_content_object_id()
- {
- return $this->get_parent()->get_root_content_object()->get_id();
- }
-
- function get_complex_content_object_item_id()
- {
- if ($this->complex_content_object_item)
- {
- return $this->complex_content_object_item->get_id();
- }
- }
-
- function get_selected_complex_content_object_item_id()
- {
- if ($this->selected_complex_content_object_item)
- {
- return $this->selected_complex_content_object_item->get_id();
- }
- }
-
- function get_parent_content_object_id()
- {
- if ($this->complex_content_object_item)
- {
- return $this->get_complex_content_object_item()->get_ref();
- }
-
- return $this->get_root_content_object_id();
- }
-
- function get_parent_content_object()
- {
- if (! $this->parent_content_object)
- {
- $this->parent_content_object = RepositoryDataManager :: get_instance()->retrieve_content_object($this->get_parent_content_object_id());
- }
- return $this->parent_content_object;
- }
-
- /**
- * Common functionality
- */
-
- function get_complex_content_object_table_html($show_subitems_column = true, $model = null, $renderer = null)
- {
- $parameters = $this->get_parameters();
- $parameters[self :: PARAM_COMPLEX_CONTENT_OBJECT_ITEM_ID] = $this->get_complex_content_object_item_id();
-
- $table = new ComplexBrowserTable($this, $parameters, $this->get_complex_content_object_table_condition(), $show_subitems_column, $model, $renderer);
- return $table->as_html();
- }
-
- function get_complex_content_object_table_condition()
- {
- if ($this->get_complex_content_object_item())
- {
- return new EqualityCondition(ComplexContentObjectItem :: PROPERTY_PARENT, $this->get_complex_content_object_item()->get_ref(), ComplexContentObjectItem :: get_table_name());
- }
- return new EqualityCondition(ComplexContentObjectItem :: PROPERTY_PARENT, $this->get_root_content_object_id(), ComplexContentObjectItem :: get_table_name());
- }
-
- function get_complex_content_object_menu()
- {
- if (is_null($this->menu))
- {
- $this->build_complex_content_object_menu();
- }
- return $this->menu->render_as_tree();
- }
-
- function get_complex_content_object_breadcrumbs()
- {
- if (is_null($this->menu))
- {
- $this->build_complex_content_object_menu();
- }
- return $this->menu->get_breadcrumbs();
- }
-
- protected function build_complex_content_object_menu()
- {
- $this->menu = new ComplexMenu($this->get_root_content_object(), $this->get_complex_content_object_item(), $this->get_url(array(
- self :: PARAM_BUILDER_ACTION => self :: ACTION_BROWSE)));
- }
-
- //url building
-
-
- function get_complex_content_object_item_edit_url($selected_content_object_item_id)
- {
-
- return $this->get_url(array(self :: PARAM_BUILDER_ACTION => self :: ACTION_UPDATE_COMPLEX_CONTENT_OBJECT_ITEM,
- self :: PARAM_SELECTED_COMPLEX_CONTENT_OBJECT_ITEM_ID => $selected_content_object_item_id,
- self :: PARAM_COMPLEX_CONTENT_OBJECT_ITEM_ID => $this->get_complex_content_object_item_id()));
- }
-
- function get_complex_content_object_item_delete_url($selected_content_object_item_id)
- {
- return $this->get_url(array(self :: PARAM_BUILDER_ACTION => self :: ACTION_DELETE_COMPLEX_CONTENT_OBJECT_ITEM,
- self :: PARAM_SELECTED_COMPLEX_CONTENT_OBJECT_ITEM_ID => $selected_content_object_item_id,
- self :: PARAM_COMPLEX_CONTENT_OBJECT_ITEM_ID => $this->get_complex_content_object_item_id()));
- }
-
- function get_complex_content_object_item_view_url($selected_content_object_item_id)
- {
- return $this->get_url(array(self :: PARAM_BUILDER_ACTION => self :: ACTION_VIEW_COMPLEX_CONTENT_OBJECT_ITEM,
- self :: PARAM_SELECTED_COMPLEX_CONTENT_OBJECT_ITEM_ID => $selected_content_object_item_id,
- self :: PARAM_COMPLEX_CONTENT_OBJECT_ITEM_ID => $this->get_complex_content_object_item_id()));
- }
-
- function get_complex_content_object_item_move_url($selected_content_object_item_id, $direction)
- {
- return $this->get_url(array(self :: PARAM_BUILDER_ACTION => self :: ACTION_MOVE_COMPLEX_CONTENT_OBJECT_ITEM,
- self :: PARAM_SELECTED_COMPLEX_CONTENT_OBJECT_ITEM_ID => $selected_content_object_item_id,
- self :: PARAM_COMPLEX_CONTENT_OBJECT_ITEM_ID => $this->get_complex_content_object_item_id(),
- self :: PARAM_DIRECTION => $direction));
- }
-
- function get_complex_content_object_parent_changer_url($selected_content_object_item_id)
- {
- return $this->get_url(array(self :: PARAM_BUILDER_ACTION => self :: ACTION_CHANGE_PARENT,
- self :: PARAM_SELECTED_COMPLEX_CONTENT_OBJECT_ITEM_ID => $selected_content_object_item_id,
- self :: PARAM_COMPLEX_CONTENT_OBJECT_ITEM_ID => $this->get_complex_content_object_item_id()));
- }
-
- function get_browse_url()
- {
- return $this->get_url(array(self :: PARAM_BUILDER_ACTION => self :: ACTION_BROWSE,
- self :: PARAM_COMPLEX_CONTENT_OBJECT_ITEM_ID => $this->get_complex_content_object_item_id()));
- }
-
- function get_create_complex_content_object_item_url()
- {
- return $this->get_url(array(self :: PARAM_BUILDER_ACTION => self :: ACTION_CREATE_COMPLEX_CONTENT_OBJECT_ITEM,
- self :: PARAM_COMPLEX_CONTENT_OBJECT_ITEM_ID => $this->get_complex_content_object_item_id()));
- }
-
- function get_additional_links()
- {
- return array();
- }
-
- function get_content_object_type_creation_url($type)
- {
- return $this->get_url(array(self :: PARAM_BUILDER_ACTION => self :: ACTION_CREATE_COMPLEX_CONTENT_OBJECT_ITEM,
- self :: PARAM_TYPE => $type,
- self :: PARAM_COMPLEX_CONTENT_OBJECT_ITEM_ID => $this->get_complex_content_object_item_id()));
- }
-
- function is_allowed_to_create($type)
- {
- return true;
- }
-
- function get_creation_links($content_object, $types = array())
- {
- if (count($types) == 0)
- {
- $types = $content_object->get_allowed_types();
- }
-
- $type_selector = new ContentObjectTypeSelector($this, $types, $this->get_additional_links(), null, $this->get_url(array(
- self :: PARAM_BUILDER_ACTION => self :: ACTION_CREATE_COMPLEX_CONTENT_OBJECT_ITEM,
- self :: PARAM_COMPLEX_CONTENT_OBJECT_ITEM_ID => $this->get_complex_content_object_item_id())));
- $html[] = $type_selector->as_html();
-
- return implode("\n", $html);
- }
-
- function get_application_component_path()
- {
- return Path :: get_repository_path() . 'lib/complex_builder/component/';
- }
-
- /**
- * @return boolean
- * @deprecated Use instanceof ComplexMenuSupport directly from now on
- */
- function show_menu()
- {
- return $this instanceof ComplexMenuSupport;
- }
-
- function redirect_away_from_complex_builder($message, $error_message)
- {
- $this->get_parent()->redirect_away_from_complex_builder($message, $error_message);
- }
-
- function get_action_bar(ContentObject $content_object)
- {
- return '';
- }
- }
-
- ?>