Commits

Goulwen Reboux committed d08038b Merge

Merge with trunk

Comments (0)

Files changed (96)

.hgignore

File contents unchanged.

.hgtags

File contents unchanged.

Copy of packages.xml

-<?xml version="1.0" encoding="UTF-8"?>
-<packages>
-        <package>
-                <name>Personal Messenger</name>
-                <code>personal_messenger</code>
-                <section>application</section>
-                <category>communication</category>
-                <authors></authors>
-                <version>1.0.0</version>
-                <release>
-                        <phase>general_availability</phase>
-                        <realm>main</realm>
-                </release>
-                <filename>pool/main/application/p/personal_messenger/personal_messenger-1.0.0.zip</filename>
-                <size></size>
-                <md5></md5>
-                <sha1></sha1>
-                <sha256></sha256>
-                <sha512></sha512>
-                <tagline></tagline>
-                <description>An online messaging system to provide communication between users.</description>
-                <homepage></homepage>
-                <dependencies>
-                        <server>
-                                <dependency>
-                                        <id>php</id>
-                                        <version type="4">5.3.0</version>
-                                        <severity>1</severity>
-                                </dependency>
-                        </server>
-                        <content_objects>
-                                <dependency>
-                                        <id>personal_message</id>
-                                        <version type="4">1.0.0</version>
-                                        <severity>1</severity>
-                                </dependency>
-                        </content_objects>
-                </dependencies>
-        </package>
-        <package>
-                <name>Administration</name>
-                <code>admin</code>
-                <section>core</section>
-                <category>core</category>
-                <authors></authors>
-                <version>1.0.0</version>
-                <release>
-                        <phase>general_availability</phase>
-                        <realm>main</realm>
-                </release>
-                <filename>pool/main/core/a/admin/admin-1.0.0.zip</filename>
-                <size></size>
-                <md5></md5>
-                <sha1></sha1>
-                <sha256></sha256>
-                <sha512></sha512>
-                <tagline></tagline>
-                <description></description>
-                <homepage></homepage>
-                <dependencies>
-                        <server>
-                                <dependency>
-                                        <id>php</id>
-                                        <version type="4">5.3.0</version>
-                                        <severity>1</severity>
-                                </dependency>
-                        </server>
-                </dependencies>
-        </package>
-        <package>
-                <name>External repository manager</name>
-                <code>external_repository_manager</code>
-                <section>extension</section>
-                <category>core</category>
-                <authors>
-                        <author>
-                                <name>Hans De Bisschop</name>
-                                <email>hans.de.bisschop@ehb.be</email>
-                                <company>Erasmushogeschool Brussel</company>
-                        </author>
-                        <author>
-                                <name>Magali Gillard</name>
-                                <email>magali.gillard@ehb.be</email>
-                                <company>Erasmushogeschool Brussel</company>
-                        </author>
-                </authors>
-                <version>1.0.0</version>
-                <release>
-                        <phase>general_availability</phase>
-                        <realm>main</realm>
-                </release>
-                <filename>pool/main/extension/e/external_repository_manager/external_repository_manager-1.0.0.zip</filename>
-                <size></size>
-                <md5></md5>
-                <sha1></sha1>
-                <sha256></sha256>
-                <sha512></sha512>
-                <tagline></tagline>
-                <description>An abstraction layer to implement external content repositories in a generalized way, using general components wherever possible.</description>
-                <homepage></homepage>
-                <dependencies>
-                        <server>
-                                <dependency>
-                                        <id>php</id>
-                                        <version type="4">5.3.0</version>
-                                        <severity>1</severity>
-                                </dependency>
-                        </server>
-                </dependencies>
-        </package>
-</packages>

admin/php/blocks/type/system_announcements.class.php

 class AdminSystemAnnouncements extends AdminBlock
 {
 
+    function is_visible()
+    {
+        return true; //i.e.display on homepage when anonymous
+    }
+    
     function as_html()
     {
         $configuration = $this->get_configuration();

application/handbook/php/blocks/handbook_connector.class.php

+<?php
+
+namespace application\handbook;
+
+use common\libraries\Translation;
+use common\libraries\EqualityCondition;
+use common\libraries\Session;
+use repository\content_object\rss_feed\RssFeed;
+use repository\content_object\link\Link;
+use common\libraries\AndCondition;
+use common\libraries\OrCondition;
+use repository\ContentObject;
+use repository\RepositoryDataManager;
+
+require_once dirname(__FILE__) . '/type/display.class.php';
+
+/**
+ * Helper class for handbook blocks.
+ *
+ * @copyright (c) 2011 University of Geneva
+ * @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
+ * @author lopprecht
+ * @package handbook.block
+ * @author Hans De Bisschop
+ */
+class HandbookBlockConnector {
+
+    /**
+     * Returns a list of objects for the specified types.
+     *
+     * @param array $types
+     * @return array
+     */
+    static function get_objects($types) {
+        $result = array();
+
+        $conditions = array();
+        $conditions[] = new EqualityCondition(ContentObject :: PROPERTY_OWNER_ID, Session :: get_user_id());
+
+        $types_condition = array();
+        foreach ($types as $type) {
+            $types_condition[] = new EqualityCondition(ContentObject :: PROPERTY_TYPE, $type);
+        }
+        $conditions[] = new OrCondition($types_condition);
+        $condition = new AndCondition($conditions);
+
+        $rdm = RepositoryDataManager :: get_instance();
+        $objects = $rdm->retrieve_content_objects($condition);
+
+        if ($objects->size() == 0) {
+            $result[0] = Translation :: get('CreateObjectFirst');
+        } else {
+            while ($object = $objects->next_result()) {
+                $result[$object->get_id()] = $object->get_title();
+            }
+        }
+
+        return $result;
+    }
+
+    /**
+     * Returns a list of objects that can be linked to a handbook block.
+     *
+     * @return array
+     */
+    function get_handbook_objects() {
+        return self::get_objects(HandbookDisplay::get_supported_types());
+    }
+
+
+}
+
+?>

application/handbook/php/blocks/type/display.class.php

+<?php
+
+namespace application\handbook;
+
+use common\libraries\Translation;
+use common\libraries\Theme;
+use common\libraries\CoreApplication;
+use home\HomeManager;
+use common\libraries\Application;
+use repository\content_object\handbook\Handbook;
+use common\libraries\EqualityCondition;
+use common\libraries\StringUtilities;
+use repository\content_object\handbook_item\HandbookItem;
+use repository\content_object\document\Document;
+use application\handbook\HandbookManager;
+use repository\content_object\glossary\Glossary;
+use common\libraries\ToolbarItem;
+use repository\ContentObjectBlock;
+use repository\ContentObjectDisplay;
+use repository\RepositoryDataManager;
+use repository\ComplexContentObjectItem;
+use repository\content_object\handbook_topic\HandbookTopic;
+use common\libraries\Redirect;
+use repository\content_object\link\Link;
+use repository\RepositoryManager;
+
+require_once CoreApplication :: get_application_class_path('repository') . 'blocks/content_object_block.class.php';
+require_once CoreApplication :: get_application_class_path('handbook') . 'lib/handbook_menu.class.php';
+
+/**
+ * Block to display a handbook's content
+ *
+ * @copyright (c) 2011 University of Geneva
+ * @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
+ * @author lopprecht
+ * @package handbook.block
+ */
+class HandbookDisplay extends ContentObjectBlock {
+
+    /**
+     * Returns the list of type names that this block can map to.
+     *
+     * @return array
+     */
+    static function get_supported_types() {
+        $result = array();
+        $result[] = Handbook::get_type_name();
+        return $result;
+    }
+
+    function __construct($parent, $block_info) {
+        parent::__construct($parent, $block_info);
+        $this->default_title = Translation::get('Handbook');
+    }
+    
+    function is_visible()
+    {
+        return true; //i.e.display on homepage when anonymous
+    }
+
+//    function get_title() {
+//        $content_object = $this->get_object();
+//        if (empty($content_object)) {
+//            return $this->get_default_title();
+//        }
+//        $title = $content_object->get_title();
+//        $href = $this->get_view_handbook_url($content_object);
+//
+//        $result = "<a href=\"$href\">$title</a>";
+//        return $result;
+//    }
+
+    /**
+     * Returns the html to display when the block is configured.
+     *
+     * @return string
+     */
+    function display_content() {
+        $content_object = $this->get_object();
+        $display = ContentObjectDisplay :: factory($content_object);
+        $DESCRIPTION = $display->get_description();
+
+        $html = array();
+        $children = $this->get_children();
+        foreach ($children as $coid => $child) {
+            $html[] = $this->display_child($child, $coid);
+        }
+        $CHILDREN = implode(StringUtilities::NEW_LINE, $html);
+
+        $result = $this->get_content_template();
+        return $this->process_template($result, get_defined_vars());
+    }
+
+    function get_content_template() {
+        $html = array();
+        $html[] = '{$DESCRIPTION}';
+        $html[] = '<div class="tool_menu">';
+        $html[] = '<ul>';
+        $html[] = '{$CHILDREN}';
+        $html[] = '</ul>';
+        $html[] = '</div>';
+        return implode(StringUtilities::NEW_LINE, $html);
+    }
+
+    function display_child($child, $coid) {
+        $handbook = $this->get_object();
+        $display = ContentObjectDisplay :: factory($child);
+        if ($child instanceof Glossary || $child instanceof HandbookTopic) {
+            $preview_url = $this->get_simple_view_url($child);
+            $onclick = '" onclick="javascript:openPopup(\'' . $preview_url . '\'); return false;';
+            $toolbar_item = new ToolbarItem(' ' . $child->get_title(),
+                            Theme :: get_content_object_image_path($child->get_type_name()),
+                            $preview_url, ToolbarItem::DISPLAY_ICON_AND_LABEL, false, $onclick, '_blank');
+            $DESCRIPTION = $toolbar_item->as_html();
+        } else if ($child instanceof Link) {
+            $preview_url = $child->get_url();
+            $toolbar_item = new ToolbarItem(' ' . $child->get_title(),
+                            Theme :: get_content_object_image_path($child->get_type_name()),
+                            $preview_url, ToolbarItem::DISPLAY_ICON_AND_LABEL, false, '', '_blank');
+            $DESCRIPTION = $toolbar_item->as_html();
+        } else if ($child instanceof Document) {
+            $preview_url = RepositoryManager :: get_document_downloader_url($child->get_id());
+            $toolbar_item = new ToolbarItem(' ' . $child->get_title(),
+                            Theme :: get_content_object_image_path($child->get_type_name()),
+                            $preview_url, ToolbarItem::DISPLAY_ICON_AND_LABEL, false, '', '');
+            $DESCRIPTION = $toolbar_item->as_html();
+        } else if ($child instanceof Handbook) {
+            $preview_url = $this->get_view_handbook_url($handbook);
+            $toolbar_item = new ToolbarItem(' ' . $child->get_title(),
+                            Theme :: get_content_object_image_path($child->get_type_name()),
+                            $preview_url, ToolbarItem::DISPLAY_ICON_AND_LABEL, false, '', '');
+            $DESCRIPTION = $toolbar_item->as_html();
+        } else {
+            $DESCRIPTION = $display->get_short_html();
+        }
+
+        $result = $this->get_display_child_template();
+        return $this->process_template($result, get_defined_vars());
+    }
+
+    function get_display_child_template() {
+        $html = array();
+        $html[] = '<li class="tool_list_menu">{$DESCRIPTION}</li>';
+        return implode(StringUtilities::NEW_LINE, $html);
+    }
+
+    function get_children() {
+        $result = array();
+
+        $content_object = $this->get_object();
+        $store = RepositoryDataManager::get_instance();
+        $condition = new EqualityCondition(ComplexContentObjectItem :: PROPERTY_PARENT, $content_object->get_id(), ComplexContentObjectItem :: get_table_name());
+        $children = $store->retrieve_complex_content_object_items($condition);
+
+        while ($complex_item = $children->next_result()) {
+            $item = $store->retrieve_content_object($complex_item->get_ref());
+            if ($item instanceof HandbookItem) {
+                $child = $store->retrieve_content_object($item->get_reference());
+                $result[$complex_item->get_id()] = $child;
+            } else if ($item instanceof Handbook) {
+                $result[$complex_item->get_id()] = $item;
+            }
+        }
+        return $result;
+    }
+
+    function get_simple_view_url($child) {
+        $params = array();
+        $params[Application::PARAM_APPLICATION] = HandbookManager::APPLICATION_NAME;
+        $params[HandbookManager :: PARAM_ACTION] = HandbookManager :: ACTION_ITEM_SIMPLE_VIEWER;
+        $params[HandbookManager :: PARAM_HANDBOOK_SELECTION_ID] = $child->get_id();
+
+        $url = Redirect::get_link('Handbook', $params);
+        return $url;
+    }
+
+    function get_view_handbook_url($handbook) {
+        $params = array();
+        $params[Application::PARAM_APPLICATION] = HandbookManager::APPLICATION_NAME;
+        $params[HandbookManager :: PARAM_ACTION] = HandbookManager :: ACTION_VIEW_HANDBOOK;
+        $params[HandbookManager :: PARAM_HANDBOOK_ID] = $handbook->get_id();
+        $params[HandbookManager :: PARAM_HANDBOOK_PUBLICATION_ID] = $this->retrieve_handbook_publication($handbook);
+        $params[HandbookManager :: PARAM_TOP_HANDBOOK_ID] = $params[HandbookManager :: PARAM_HANDBOOK_PUBLICATION_ID];
+        return Redirect::get_link(HandbookManager::APPLICATION_NAME, $params);
+    }
+
+    function retrieve_handbook_publication($handbook = null) {
+        $handbook = empty($handbook) ? $this->get_object() : $handbook;
+        $handbook_id = $handbook->get_id();
+        $store = HandbookDataManager :: get_instance();
+        $condition = new EqualityCondition(HandbookPublication :: PROPERTY_CONTENT_OBJECT_ID, $handbook_id);
+        $publications = $store->retrieve_handbook_publications($condition);
+        if (count($publications == 1)) {
+            return $publications->next_result()->get_id();
+        } else {
+            return 0;
+        }
+    }
+
+}
+
+?>

application/handbook/php/blocks/type/display.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<block name="handbook_display">
+    <settings>
+        <category name="object">
+            <setting name="use_object" field="select" default="0">
+                <options type="dynamic" source="get_handbook_objects" />
+            </setting>
+        </category>
+    </settings>
+</block>

application/handbook/php/lib/handbook_manager/component/handbook_item_simple_viewer.class.php

+<?php
+
+namespace application\handbook;
+
+use common\libraries\BreadcrumbTrail;
+use common\libraries\Breadcrumb;
+use common\libraries\Request;
+use common\libraries\Translation;
+use common\libraries\Utilities;
+use common\libraries\ActionBarRenderer;
+use common\libraries\ActionBarSearchForm;
+use common\libraries\Application;
+use common\libraries\PatternMatchCondition;
+use common\libraries\AndCondition;
+use repository\ContentObject;
+use repository\RepositoryDataManager;
+use application\context_linker\ContextLinkerManager;
+use application\context_linker\ContextLinkBrowserTable;
+use repository\ContentObjectDisplay;
+use common\libraries\Display;
+
+require_once dirname(__FILE__) . '/../handbook_manager.class.php';
+//require_once dirname(__FILE__) . '/../../forms/handbook_publication_form.class.php';
+//require_once dirname(__FILE__) . '/handbook_alternatives_picker/handbook_alternatives_picker_table.class.php';
+//require_once dirname(__FILE__) . '/../../../../../context_linker/php/lib/context_linker_manager/component/context_link_browser/context_link_browser_table.class.php';
+
+/**
+ * Display an item topic. That is the default's html for the content object with small header/footer.
+ *
+ * @copyright (c) 2011 University of Geneva
+ * @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
+ * @author lopprecht
+ * @package handbook.block
+ */
+class HandbookManagerHandbookItemSimpleViewerComponent extends HandbookManager {
+
+    /**
+     * Runs this component and displays its output.
+     */
+    function run() {
+        $this->display_header(null, false);
+        $this->display_content();
+        $this->display_footer();
+    }
+
+    function has_menu(){
+        return false;
+    }
+
+    function display_header() {
+        Display :: small_header();
+    }
+
+    function display_footer(){
+        Display::small_footer();
+    }
+
+    function display_content(){
+        $id = Request :: get(HandbookManager::PARAM_HANDBOOK_SELECTION_ID);
+        $child = RepositoryDataManager::get_instance()->retrieve_content_object($id);
+        $display = ContentObjectDisplay :: factory($child);
+        echo $display->get_full_html();
+    }
+
+    function get_menu(){
+        return '';
+    }
+
+}
+
+?>

application/handbook/php/lib/handbook_manager/handbook_manager.class.php

     const PARAM_HANDBOOK_OWNER_ID = 'handbook_owner';
     const PARAM_SEARCH_QUERY = 'sq';
 
+    const ACTION_ITEM_SIMPLE_VIEWER = 'handbook_item_simple_viewer';
     const ACTION_DELETE_HANDBOOK_PUBLICATION = 'handbook_publication_deleter';
     const ACTION_EDIT_HANDBOOK_PUBLICATION = 'handbook_publication_editor';
     const ACTION_CREATE_HANDBOOK_PUBLICATION = 'handbook_publication_creator';

application/handbook/php/lib/import/cpo/cpo_import.class.php

 use application\metadata\MetadataDataManager;
 use repository\ComplexContentObjectItem;
 use application\metadata\ContentObjectMetadataPropertyValue;
+use repository\content_object\handbook\Handbook;
 
 /**
  * Exports content object to the chamilo learning object format (xml)
  * TODO: this is just a temporary class untill the cpo-export from the repository is refactored
+ * code for metadata export should go to metadata, code for co-object export should go to repository/co
+ * code for context link export should go to context linker
  */
 class HandbookCpoImport extends ContentObjectImport
 {
+    const MODE_NEW = 'new';
+    const MODE_EXTEND = 'extend';
+    const MODE_FULL = 'full';
 
+    const LINK_ORIGINAL = 'orig';
+    const LINK_ALTERNATIVE ='alt';
+    const LINK_METADATA = 'meta';
+
+    private $option_strict = false;
+    private $option_limited = false;
+    private $mode = self::MODE_NEW;
+    private $metadata_limitations = array();
     /**
      * @var RepositoryDataManager
      */
     private $log = array();
     private $copies;
     private $linked_to_copy;
+    private $not_in_scope;
+
 
     function __construct($content_object_file, $user, $category)
     {
         $this->update_references();
         $this->update_learning_path_prerequisites();
         $this->update_hotspot_questions();
-//        $this->create_context_links();
+        $this->create_context_links();
 
-        var_dump($this->context_links);
-        var_dump($this->content_object_reference);
 
         if ($temp)
         {
         return true;
     }
 
+    public function create_context_links()
+    {
+        foreach ($this->context_links as $context_link_data)
+        {
+            if (!in_array($context_link_data[self::LINK_ORIGINAL], $this->copies) && !in_array($context_link_data[self::LINK_ORIGINAL], $this->linked_to_copy))
+            {
+                //original was not a copy so add context-link
+                $orig_id = $this->content_object_reference[$context_link_data[self::LINK_ORIGINAL]];
+                $alt_id = $this->content_object_reference[$context_link_data[self::LINK_ALTERNATIVE]];
+                if ($alt_id != null && $orig_id != null)
+                {
+                    $this->log[] = '<i> create the context link between ' . $context_link_data[self::LINK_ORIGINAL] . ' and ' . $context_link_data[self::LINK_ALTERNATIVE] . ' here (on metadata = ' . $context_link_data[self::LINK_METADATA] . ')</i>';
+                }
+                else
+                {
+                    $this->log[] = '<i> something went wrong on creating the context link between ' . $context_link_data[self::LINK_ORIGINAL] . ' and ' . $context_link_data[self::LINK_ALTERNATIVE] . ' here (on metadata = ' . $context_link_data[self::LINK_METADATA] . ')</i>';
+                }
+            }
+            else
+            {
+                $this->log[] = '<i> contextlink for ' . $context_link_data[self::LINK_ORIGINAL] . ' and ' . $context_link_data[self::LINK_ALTERNATIVE] . ' (on metadata = ' . $context_link_data[self::LINK_METADATA] . ') not created since the original is a copy or linked to copy</i>';
+                if ($this->mode == self::MODE_NEW)
+                {
+                    //do nothing
+                }
+                else if ($this->mode == self::MODE_EXTEND)
+                {
+                    $this->log[] = 'add new context links';
+                }
+                else if ($this->mode == self::MODE_FULL)
+                {
+                    $this->log[] = 'add new context links and replace data in existing co\'s with data from import';
+                }
+            }
+        }
+    }
+
     private function import_files($dir)
     {
         $user = $this->get_user();
 
     public function create_metadata_schema($schema)
     {
-//        $prefix = $schema->getAtribute('prefix');
-//        $name = $schema->getAttribute('name');
-//        $url = $schema->getAttribute('url');
-
         foreach ($schema->attributes as $attrName => $attrNode)
         {
             if ($attrName == 'prefix')
 
     public function create_metadata_element($element)
     {
-//        $namespace_prefix = $element->getAttribute('schema_prefix');
-//        $element_name = $element->getAttribute('element');
         foreach ($element->attributes as $attrName => $attrNode)
         {
             if ($attrName == 'schema_prefix')
                 $element_name = $attrNode->value;
             }
         }
-
-
         $namespace = MetadataDataManager::get_instance()->retrieve_metadata_namespace_by_prefix($namespace_prefix);
 
         if ($namespace)
         }
     }
 
+    public function check_uniqueness($content_object, $type, $id)
+    {
+        //handbook_item and handbook: check uuid to see if item already exists (if exists: don't import -> update
+        $exists_already = false;
+        if (($type == 'handbook') || ($type == 'handbook_item'))
+        {
+            $extended = $content_object->getElementsByTagName('extended')->item(0);
+            $nodes = $extended->childNodes;
+            foreach ($nodes as $node)
+            {
+                if ($node->nodeName == 'uuid')
+                {
+                    $uuid = convert_uudecode($node->nodeValue);
+                }
+                if ($node->nodeName == 'reference_id')
+                {
+                    $reference_id = convert_uudecode($node->nodeValue);
+                }
+            }
+            if ($type == 'handbook_item')
+            {
+                $co = HandbookDataManager::get_instance()->retrieve_handbook_item_data_by_uuid($uuid);
+            }
+            if ($type == 'handbook')
+            {
+                $co = HandbookDataManager::get_instance()->retrieve_handbook_data_by_uuid($uuid);
+            }
+            if ($co != false)
+            {
+                $exists_already = true;
+                $this->log[] = 'item with uid ' . $uuid . ' (' . $id . ')exists already';
+                $this->copies[] = $id;
+                $this->content_object_reference[$id] = $co[Handbook :: PROPERTY_ID];
+                if ($reference_id)
+                {
+                    $this->log[] = 'item with id ' . $reference_id . ' added to list linked to copy (wrapper exists)';
+                    $this->linked_to_copy[] = $reference_id;
+                }
+            }
+        }
+
+        return $exists_already;
+    }
+
+    public function render_metadata($content_object, $lo, $id)
+    {
+        //metadata
+        $metadata = $content_object->getElementsByTagName('content_object_metadata')->item(0);
+        if (is_object($metadata))
+        {
+            $children = $metadata->childNodes;
+            for ($i = 0; $i < $children->length; $i++)
+            {
+                $co_metadata = $children->item($i);
+                if ($co_metadata->nodeName == "#text")
+                    continue;
+                if ($co_metadata->hasAttributes())
+                {
+                    foreach ($co_metadata->attributes as $attrName => $attrNode)
+                    {
+                        if ($attrName == 'name')
+                        {
+                            $property = $attrNode->value;
+                        }
+                        elseif ($attrName == 'value')
+                        {
+                            $value = $attrNode->value;
+                        }
+                    }
+                    list($namespace_prefix, $element_name) = explode(':', $property);
+                    $namespace = MetadataDataManager::get_instance()->retrieve_metadata_namespace_by_prefix($namespace_prefix);
+                    if ($namespace)
+                    {
+                        $ns_id = $namespace->get_id();
+                        $property_type = MetadataDataManager::get_instance()->retrieve_metadata_property_type_by_ns_name($ns_id, $element_name);
+                        if ($property_type)
+                        {
+                            $mpv = new ContentObjectMetadataPropertyValue();
+                            $mpv->set_content_object_id($lo->get_id());
+                            $mpv->set_property_type_id($property_type->get_id());
+                            $mpv->set_value($value);
+                            $success = $mpv->create();
+                            if ($success)
+                            {
+                                $this->log[] = '<b> metadata ' . $property . '=' . $value . ' added to item with id ' . $lo->get_id() . '/' . $id . '</b>';
+                            }
+                            else
+                            {
+                                //problem: metadata_property_value not created
+                                $this->log[] = 'Problem! metadata ' . $property . '=' . $value . ' was not added to item with id ' . $lo->get_id() . '/' . $id;
+                            }
+                        }
+                        else
+                        {
+                            //problem: property was not imported
+                            $this->log[] = 'Problem! metadata ' . $property . '=' . $value . ' was not added to item with id ' . $lo->get_id() . '/' . $id . ' because property does not exist in namespace with id ' . $namespace_id;
+                        }
+                    }
+                    else
+                    {
+                        //problem: namespace was not imported
+                        $this->log[] = 'Problem! metadata ' . $property . '=' . $value . ' was not added to item with id ' . $lo->get_id() . '/' . $id . ' because namespace ' . $namespace_prefix . ' does not exist';
+                    }
+                }
+            }
+        }
+    }
+
     public function create_content_object($content_object)
     {
         $exists_already = false;
-
         $id = $content_object->getAttribute('id');
         if (isset($this->content_object_reference[$id]))
             return;
             {
                 $category = null;
             }
-
             $object_number = $general->getElementsByTagName('object_number')->item(0)->nodeValue;
 
-            //handbook_item and handbook: check uuid to see if item already exists (if exists: don't import -> update
-            if (($type == 'handbook') || ($type == 'handbook_item'))
+            $exists_already = $this->check_uniqueness($content_object, $type, $id);
+
+            //CREATE CONTENT OBJECT
+            if (!$exists_already && !in_array($id, $this->linked_to_copy) && !in_array($id, $this->not_in_scope))
             {
-                $extended = $content_object->getElementsByTagName('extended')->item(0);
-                $nodes = $extended->childNodes;
-                foreach ($nodes as $node)
+                $this->create_object($content_object, $id, $type, $title, $description, $comment, $created, $modified, $object_number, $category);
+            }
+            else
+            {
+                //TODO: provide update possibility
+                $this->log[] = 'item with id ' . $id . ' copy or linked to copy or not in scope';
+                if ($this->mode == self::MODE_NEW)
                 {
-                    if ($node->nodeName == 'uuid')
+                    //DO NOTHING
+                }
+                else if ($this->mode == self::MODE_EXTEND)
+                {
+                    //CREATE OBJECT IF IT IS LINKED TO COPY
+                    if (in_array($id, $this->linked_to_copy) && !in_array($id, $this->not_in_scope))
                     {
-                        $uuid = convert_uudecode($node->nodeValue);
-                    }
-                    if ($node->nodeName == 'reference_id')
-                    {
-                        $reference_id = convert_uudecode($node->nodeValue);
+                        //TODO: check if co not in system & create
+                        $this->log[] = 'item with id ' . $id . ' is linked to a copy. check if it is already in system';
                     }
                 }
-
-                if ($type == 'handbook_item')
+                else if ($this->mode == self::MODE_FULL)
                 {
-                    $co = HandbookDataManager::get_instance()->retrieve_handbook_item_data_by_uuid($uuid);
-                }
-                if ($type == 'handbook')
-                {
-                    $co = HandbookDataManager::get_instance()->retrieve_handbook_data_by_uuid($uuid);
-                }
-                if ($co != false)
-                {
-                    $exists_already = true;
-                    $this->log[] = 'item with uid ' . $uuid . ' (' . $id . ')exists already';
-                    $this->copies[] = $id;
-                    if ($reference_id)
+                    //CREATE OBJECT IF IT IS LINKED TO COPY OR UPDATE DATA OF COPY
+                    if (!in_array($id, $this->not_in_scope))
                     {
-                        $this->log[] = 'item with id ' . $reference_id . ' added to list linked to copy (wrapper exists)';
-                        $this->linked_to_copy['children'][] = $reference_id;
+                        //TODO: update or create
+                        $this->log[] = 'item with id ' . $id . ' will be updated or created';
                     }
                 }
             }
 
-            if (!$exists_already && !in_array($id, $this->linked_to_copy['children']))
+            //ADD CONTEXT LINKS
+            $this->render_context_links($content_object, $id);
+
+            //ADD COMPLEX CHILDREN IF ANY
+            $this->render_complex_children($content_object, $id);
+        }
+    }
+
+    public function render_context_links($content_object, $id)
+    {
+        $links = $content_object->getElementsByTagName('linked_items')->item(0);
+        if (is_object($links))
+        {
+            $children = $links->childNodes;
+            for ($i = 0; $i < $children->length; $i++)
             {
-                $this->log[] = '<b>item with title ' . $title . ' and id ' . $id . ' will be created</b>';
-                $lo = ContentObject :: factory($type, array(ContentObject :: PROPERTY_STATE => ContentObject :: STATE_NORMAL));
-
-                if (!$lo)
+                $context_link = $co_metadata = $children->item($i);
+                if ($context_link->nodeName == "#text")
+                    continue;
+                if ($context_link->hasAttributes())
                 {
-                    return null;
-                }
-
-                $lo->set_title($title);
-                $lo->set_description($description);
-                $lo->set_comment($comment);
-                $lo->set_creation_date($created);
-                $lo->set_modification_date($modified);
-                $lo->set_owner_id($this->get_user()->get_id());
-
-                $object_number_exists = array_key_exists($object_number, $this->object_numbers);
-                if ($object_number_exists)
-                {
-                    $lo->set_object_number($this->object_numbers[$object_number]);
-                }
-
-                if ($category == 'category0' || !$category)
-                {
-                    $lo->set_parent_id($this->get_category());
-                }
-                else
-                {
-                    $lo->set_parent_id($this->categories[$category]);
-                }
-                //extended
-                $extended = $content_object->getElementsByTagName('extended')->item(0);
-                if ($extended->hasChildNodes())
-                {
-                    $nodes = $extended->childNodes;
-                    $additionalProperties = array();
-
-                    foreach ($nodes as $node)
+                    foreach ($context_link->attributes as $attrName => $attrNode)
                     {
-                        if ($node->nodeName == "#text" || $node->nodeName == 'id' || $node->nodeName == 'category')
-                            continue;
-
-                        $prop_names = $lo->get_additional_property_names();
-
-                        if (in_array($node->nodeName, $prop_names))
+                        if ($attrName == 'idref')
                         {
-                            $additionalProperties[$node->nodeName] = convert_uudecode($node->nodeValue);
+                            $idref = $attrNode->value;
+                        }
+                        elseif ($attrName == 'metadata_link')
+                        {
+                            $metadata_link = $attrNode->value;
                         }
                     }
-                    $additionalProperties = $this->import_extra_properties($type, $additionalProperties, $lo);
-                    $lo->set_additional_properties($additionalProperties);
-                }
-                if ($type == Document :: get_type_name() && !$lo->get_path())
-                {
-                    return;
-                }
-                if ($object_number_exists)
-                {
-                    $lo->version();
-                }
-                else
-                {
-                    $lo->create_all();
-                    $this->object_numbers[$object_number] = $lo->get_object_number();
-                }
-                if (in_array($type, RepositoryDataManager :: get_active_helper_types()))
-                {
-                    $this->references[$lo->get_id()] = $additionalProperties['reference_id'];
-                }
-                if ($type == HotspotQuestion :: get_type_name())
-                {
-                    $this->hotspot_questions[$lo->get_id()] = $lo->get_image();
-                }
-                $this->content_object_reference[$id] = $lo->get_id();
-
-                //metadata
-                $metadata = $content_object->getElementsByTagName('content_object_metadata')->item(0);
-                if (is_object($metadata))
-                {
-                    $children = $metadata->childNodes;
-                    for ($i = 0; $i < $children->length; $i++)
+                    list($namespace_prefix, $element_name) = explode(':', $metadata_link);
+                    if (!$exists_already && !in_array($id, $this->linked_to_copy) && !in_array($id, $this->not_in_scope))
                     {
-                        $co_metadata = $children->item($i);
-                        if ($co_metadata->nodeName == "#text")
-                            continue;
-                        if ($co_metadata->hasAttributes())
-                        {
-
-                            foreach ($co_metadata->attributes as $attrName => $attrNode)
-                            {
-                                if ($attrName == 'name')
-                                {
-                                    $property = $attrNode->value;
-                                }
-                                elseif ($attrName == 'value')
-                                {
-                                    $value = $attrNode->value;
-                                }
-                            }
-                            list($namespace_prefix, $element_name) = explode(':', $property);
-//                        var_dump('exploded ' .$namespace_prefix . ' ' . $element_name);
-
-                            $namespace = MetadataDataManager::get_instance()->retrieve_metadata_namespace_by_prefix($namespace_prefix);
-
-                            if ($namespace)
-                            {
-                                $ns_id = $namespace->get_id();
-
-                                $property = MetadataDataManager::get_instance()->retrieve_metadata_property_type_by_ns_name($ns_id, $element_name);
-                                if ($property)
-                                {
-                                    $mpv = new ContentObjectMetadataPropertyValue();
-                                    $mpv->set_content_object_id($lo->get_id());
-                                    $mpv->set_property_type_id($property->get_id());
-                                    $mpv->set_value($value);
-                                    $success = $mpv->create();
-                                    if ($success)
-                                    {
-                                        $this->log[] = '<b> metadata ' . $element_name . '=' . $value . ' added to item with id ' . $lo->get_id() . '/' . $id . '</b>';
-                                    }
-                                    else
-                                    {
-                                        //problem: metadata_property_value not created
-                                        $this->log[] = 'Problem! metadata ' . $element_name . '=' . $value . ' was not added to item with id ' . $lo->get_id() . '/' . $id;
-                                    }
-                                }
-                                else
-                                {
-                                    //problem: property was not imported
-                                    $this->log[] = 'Problem! metadata ' . $element_name . '=' . $value . ' was not added to item with id ' . $lo->get_id() . '/' . $id . ' because property does not exist in namespace with id ' . $namespace_id;
-                                }
-                            }
-                            else
-                            {
-                                //problem: namespace was not imported
-                                $this->log[] = 'Problem! metadata ' . $element_name . '=' . $value . ' was not added to item with id ' . $lo->get_id() . '/' . $id . ' because namespace ' . $namespace_prefix . ' does not exist';
-                            }
-                        }
+                        //store original id - alternative id - metadata id
+                        $this->context_links[] = array(self::LINK_ORIGINAL => $id, self::LINK_ALTERNATIVE => $idref, self::LINK_METADATA => $metadata_link);
+                    }
+                    else
+                    {
+                        //store original id - alternative id - metadata id
+                        $this->context_links[] = array(self::LINK_ORIGINAL => $id, self::LINK_ALTERNATIVE => $idref, self::LINK_METADATA => $metadata_link);
+                        $this->linked_to_copy[] = $idref;
                     }
                 }
             }
+        }
+    }
+
+    public function render_attachements($content_object, $id)
+    {
+        // Attachments
+        $attachments = $content_object->getElementsByTagName('attachments')->item(0);
+        if (is_object($attachments))
+        {
+            $children = $attachments->childNodes;
+            if ($children)
+            {
+                for ($i = 0; $i < $children->length; $i++)
+                {
+                    $attachment = $children->item($i);
+                    if ($attachment->nodeName == "#text")
+                        continue;
+
+                    $idref = $attachment->getAttribute('idref');
+                    $type = $attachment->getAttribute('type');
+                    $this->lo_attachments[$id][] = array('idref' => $idref, 'type' => $type);
+                }
+            }
+        }
+    }
+
+    public function render_includes($content_object, $id)
+    {
+        // Includes
+        $includes = $content_object->getElementsByTagName('includes')->item(0);
+        if (is_object($includes))
+        {
+            $children = $includes->childNodes;
+
+            if ($children)
+            {
+                for ($i = 0; $i < $children->length; $i++)
+                {
+                    $include = $children->item($i);
+                    if ($include->nodeName == "#text")
+                        continue;
+
+                    $idref = $include->getAttribute('idref');
+                    $this->lo_includes[$id][] = $idref;
+                }
+            }
+        }
+    }
+
+    public function create_object($content_object, $id, $type, $title, $description, $comment, $created, $modified, $object_number, $category)
+    {
+        if ($this->option_strict || $this->option_limited)
+        {
+            //TODO: extra checks to see if content_object is in scope
+            //first get metadata for co
+            //if strict: check if dc:publisher & dc:language are set
+            //if limited: check is metadata reqs are met
+        }
+        if (!in_array($id, $this->not_in_scope))
+        {
+            $this->log[] = '<b>item with title ' . $title . ' and id ' . $id . ' will be created</b>';
+            $lo = ContentObject :: factory($type, array(ContentObject :: PROPERTY_STATE => ContentObject :: STATE_NORMAL));
+            if (!$lo)
+            {
+                return null;
+            }
+            $lo->set_title($title);
+            $lo->set_description($description);
+            $lo->set_comment($comment);
+            $lo->set_creation_date($created);
+            $lo->set_modification_date($modified);
+            $lo->set_owner_id($this->get_user()->get_id());
+            $object_number_exists = array_key_exists($object_number, $this->object_numbers);
+            if ($object_number_exists)
+            {
+                $lo->set_object_number($this->object_numbers[$object_number]);
+            }
+            if ($category == 'category0' || !$category)
+            {
+                $lo->set_parent_id($this->get_category());
+            }
             else
             {
-                $this->log[] = 'item with id ' . $id . ' linked to copy';
+                $lo->set_parent_id($this->categories[$category]);
             }
 
-            //contextlinks
-            $links = $content_object->getElementsByTagName('linked_items')->item(0);
-            if (is_object($links))
+            //extended
+            $extended = $content_object->getElementsByTagName('extended')->item(0);
+            if ($extended->hasChildNodes())
             {
-                $children = $links->childNodes;
-                for ($i = 0; $i < $children->length; $i++)
+                $nodes = $extended->childNodes;
+                $additionalProperties = array();
+                foreach ($nodes as $node)
                 {
-                    $context_link = $co_metadata = $children->item($i);
+                    if ($node->nodeName == "#text" || $node->nodeName == 'id' || $node->nodeName == 'category')
+                        continue;
+                    $prop_names = $lo->get_additional_property_names();
+                    if (in_array($node->nodeName, $prop_names))
+                    {
+                        $additionalProperties[$node->nodeName] = convert_uudecode($node->nodeValue);
+                    }
+                }
+                $additionalProperties = $this->import_extra_properties($type, $additionalProperties, $lo);
+                $lo->set_additional_properties($additionalProperties);
+            }
+            if ($type == Document :: get_type_name() && !$lo->get_path())
+            {
+                return;
+            }
+            if ($object_number_exists)
+            {
+                $lo->version();
+            }
+            else
+            {
+                $lo->create_all();
+                $this->object_numbers[$object_number] = $lo->get_object_number();
+            }
+            if (in_array($type, RepositoryDataManager :: get_active_helper_types()))
+            {
+                $this->references[$lo->get_id()] = $additionalProperties['reference_id'];
+            }
+            if ($type == HotspotQuestion :: get_type_name())
+            {
+                $this->hotspot_questions[$lo->get_id()] = $lo->get_image();
+            }
+            $this->content_object_reference[$id] = $lo->get_id();
 
-                    if ($context_link->nodeName == "#text")
-                        continue;
+            $this->render_metadata($content_object, $lo, $id);
+            $this->render_includes($content_object, $id);
+            $this->render_attachements($content_object, $id);
+        }
+    }
 
-                    if ($context_link->hasAttributes())
+    public function render_complex_children($content_object, $id)
+    {
+        // Complex children
+        $subitems = $content_object->getElementsByTagName('sub_items')->item(0);
+        if (is_object($subitems))
+        {
+            $children = $subitems->childNodes;
+            for ($i = 0; $i < $children->length; $i++)
+            {
+                $subitem = $children->item($i);
+                if ($subitem->nodeName == "#text")
+                    continue;
+                if ($subitem->hasAttributes())
+                {
+                    $properties = array();
+                    foreach ($subitem->attributes as $attrName => $attrNode)
                     {
-                        foreach ($context_link->attributes as $attrName => $attrNode)
+                        if ($attrName == 'idref')
                         {
-                            if ($attrName == 'idref')
-                            {
-                                $idref = $attrNode->value;
-                            }
-                            elseif ($attrName == 'metadata_link')
-                            {
-                                $metadata_link = $attrNode->value;
-                            }
+                            $idref = $attrNode->value;
                         }
-
-                        list($namespace_prefix, $element_name) = explode(':', $metadata_link);
-
-                        if (!$exists_already && !in_array($id, $this->linked_to_copy['children']))
+                        elseif ($attrName == 'id')
                         {
-                            //store original id - alternative id - metadata id
-                            $this->context_links[] = array($id, $idref, $metadata_link);
+                            $my_id = $attrNode->value;
                         }
                         else
                         {
-                            $this->linked_to_copy['children'][] = $idref;
+                            $properties[$attrName] = $attrNode->value;
                         }
                     }
-                }
-            }
 
-            // Complex children
-            $subitems = $content_object->getElementsByTagName('sub_items')->item(0);
-            if (is_object($subitems))
-            {
-                $children = $subitems->childNodes;
-                for ($i = 0; $i < $children->length; $i++)
-                {
-                    $subitem = $children->item($i);
-                    if ($subitem->nodeName == "#text")
-                        continue;
+                    $this->lo_subitems[$id][] = array('id' => $my_id, 'idref' => $idref, 'properties' => $properties);
 
-                    if ($subitem->hasAttributes())
+                    if (!$exists_already && !in_array($id, $this->linked_to_copy))
                     {
-                        $properties = array();
-
-                        foreach ($subitem->attributes as $attrName => $attrNode)
-                        {
-                            if ($attrName == 'idref')
-                            {
-                                $idref = $attrNode->value;
-                            }
-                            elseif ($attrName == 'id')
-                            {
-                                $my_id = $attrNode->value;
-                            }
-                            else
-                            {
-                                $properties[$attrName] = $attrNode->value;
-                            }
-                        }
-
-
+                        $this->log[] = 'item with id ' . $idref . ' added to list of subitems';
                         $this->lo_subitems[$id][] = array('id' => $my_id, 'idref' => $idref, 'properties' => $properties);
-
-                        if (!$exists_already && !in_array($id, $this->linked_to_copy['children']))
-                        {
-                            $this->log[] = 'item with id ' . $idref . ' added to list of subitems';
-                            $this->lo_subitems[$id][] = array('id' => $my_id, 'idref' => $idref, 'properties' => $properties);
-                        }
-                        else
-                        {
-                            $this->log[] = 'item with id ' . $idref . ' added to list linked to copy';
-                            $this->linked_to_copy['children'][] = $idref;
-                        }
+                    }
+                    else
+                    {
+                        $this->log[] = 'item with id ' . $idref . ' added to list linked to copy';
+                        $this->linked_to_copy[] = $idref;
+                        //TODO: update functionality?
                     }
                 }
             }
-
-            if (!$exists_already && !in_array($id, $this->linked_to_copy['children']))
-            {
-                // Attachments
-                $attachments = $content_object->getElementsByTagName('attachments')->item(0);
-                if (is_object($attachments))
-                {
-                    $children = $attachments->childNodes;
-                    if ($children)
-                    {
-                        for ($i = 0; $i < $children->length; $i++)
-                        {
-                            $attachment = $children->item($i);
-                            if ($attachment->nodeName == "#text")
-                                continue;
-
-                            $idref = $attachment->getAttribute('idref');
-                            $type = $attachment->getAttribute('type');
-                            $this->lo_attachments[$id][] = array('idref' => $idref, 'type' => $type);
-                        }
-                    }
-                }
-
-                // Includes
-                $includes = $content_object->getElementsByTagName('includes')->item(0);
-                if (is_object($includes))
-                {
-                    $children = $includes->childNodes;
-
-                    if ($children)
-                    {
-                        for ($i = 0; $i < $children->length; $i++)
-                        {
-                            $include = $children->item($i);
-                            if ($include->nodeName == "#text")
-                                continue;
-
-                            $idref = $include->getAttribute('idref');
-                            $this->lo_includes[$id][] = $idref;
-                        }
-                    }
-                }
-
-
-         
-            }
         }
     }
 
     {
         if (!$this->lo_subitems)
         {
+            $this->log[] = 'no complex wrappers to be created';
             return;
         }
 
             if (!$real_parent_id)
                 continue;
 
-            foreach ($children as $child)
+            if (!in_array($parent_id, $this->copies) && !in_array($parent_id, $this->linked_to_copy))
             {
-                $real_child_id = $this->content_object_reference[$child['idref']];
+                foreach ($children as $child)
+                {
+                    $real_child_id = $this->content_object_reference[$child['idref']];
 
-                if (!$real_child_id)
-                    continue;
+                    if (!$real_child_id)
+                        continue;
 
-                $childlo = $this->rdm->retrieve_content_object($real_child_id);
+                    $childlo = $this->rdm->retrieve_content_object($real_child_id);
 
-                $cloi = ComplexContentObjectItem :: factory($childlo->get_type());
+                    $cloi = ComplexContentObjectItem :: factory($childlo->get_type());
 
-                $cloi->set_ref($childlo->get_id());
-                $cloi->set_user_id($this->get_user()->get_id());
-                $cloi->set_parent($real_parent_id);
-                $cloi->set_display_order(RepositoryDataManager :: get_instance()->select_next_display_order($real_parent_id));
-                $cloi->set_additional_properties($child['properties']);
-                $cloi->create();
+                    $cloi->set_ref($childlo->get_id());
+                    $cloi->set_user_id($this->get_user()->get_id());
+                    $cloi->set_parent($real_parent_id);
+                    $cloi->set_display_order(RepositoryDataManager :: get_instance()->select_next_display_order($real_parent_id));
+                    $cloi->set_additional_properties($child['properties']);
+                    $cloi->create();
 
-                if ($childlo->get_type() == LearningPathItem :: get_type_name())
-                {
-                    $this->learning_path_item_wrappers[] = $cloi;
+                    $this->log[] = '<b>wrapper created to link ' . $parent_id . ' and ' . $child['idref'] . '</b>';
+
+                    if ($childlo->get_type() == LearningPathItem :: get_type_name())
+                    {
+                        $this->learning_path_item_wrappers[] = $cloi;
+                    }
+
+                    $this->wrapper_reference[$child['id']] = $cloi->get_id();
                 }
-
-                $this->wrapper_reference[$child['id']] = $cloi->get_id();
+            }
+            else
+            {
+                $this->log[] = 'wrapper to link ' . $parent_id . ' and ' . $child['idref'] . 'not created because the parent is a copy or linked to a copy';
             }
         }
     }
 
             foreach ($children as $child)
             {
-                if ($this->content_object_reference[$child])
+                                        if ($this->content_object_reference[$child])
                     $lo->include_content_object($this->content_object_reference[$child]);
             }
 
             $lo = $this->rdm->retrieve_content_object($lo_id);
             $lo->set_reference($real_reference);
             $lo->update();
+            $this->log[] = '<b> change reference to ' .$reference. ' in real id '. $real_reference . ' in content-object ' . $lo_id. '</b>';
         }
     }
 

application/survey/php/lib/forms/survey_publication_mailer_form.class.php

 use group\GroupDataManager;
 use user\UserDataManager;
 
+ini_set("memory_limit", "-1");
+ini_set("max_execution_time", "0");
+
 class SurveyPublicationMailerForm extends FormValidator
 {
 

application/survey/php/lib/survey_manager/component/old_mailer.class.php

 use common\libraries\path;
 use common\libraries\Mail;
 
+ini_set("memory_limit", "-1");
+ini_set("max_execution_time", "0");
+
 class SurveyManagerOldMailerComponent extends SurveyManager
 {
     private $invitees;
         $users[SurveyParticipantTracker :: STATUS_NOTSTARTED] = $not_started_count;
         $users[SurveyParticipantTracker :: STATUS_FINISHED] = $finished_count;
 //        $users[SurveyPublicationMailerForm :: USERS_NOT_SELECTED_COUNT] = $this->not_selected_user_count;
+        
+        
+        
         $form = new SurveyPublicationMailerForm($this, $this->get_user(), $users, $this->get_url(array(
                 self :: PARAM_PUBLICATION_ID => $this->publication_id)));
         
         $mail->set_reply($reply);
         
         //         Check whether it was sent successfully
-         if ($mail->send() === FALSE);
-        if (true)
+        if ($mail->send() === FALSE)
         {
             $this->mail_send = false;
             $args[SurveyParticipantMailTracker :: PROPERTY_STATUS] = SurveyParticipantMailTracker :: STATUS_MAIL_NOT_SEND;

application/weblcms/php/blocks/type/course_catalog.class.php

+<?php
+
+namespace application\weblcms;
+
+use common\libraries\WebApplication;
+use common\libraries\Redirect;
+use common\libraries\Application;
+use common\libraries\CoreApplication;
+use common\libraries\Request;
+use common\libraries\EqualityCondition;
+use common\libraries\AndCondition;
+use common\libraries\OrCondition;
+use common\libraries\Translation;
+use common\libraries\StringUtilities;
+use common\libraries\SimpleTemplate;
+
+require_once CoreApplication :: get_application_class_path('weblcms') . 'lib/course/course_category_menu.class.php';
+require_once CoreApplication :: get_application_class_path('weblcms') . 'lib/course/course_category_catalog_menu.class.php';
+require_once CoreApplication :: get_application_class_path('weblcms') . 'lib/weblcms_manager/component/course_browser/course_browser_table.class.php';
+require_once CoreApplication :: get_application_class_path('weblcms') . 'lib/weblcms_manager/component/catalog_course_browser/catalog_course_browser_table.class.php';
+
+/**
+ * Block that display the list of all opened courses
+ *
+ * @copyright (c) 2011 University of Geneva
+ * @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
+ * @author lopprecht
+ */
+class WeblcmsCourseCatalog extends WeblcmsBlock {
+
+    /**
+     * Note, with several widgets on the frontpage we may have name clashes for generic terms such as category.
+     * For this reason we use 'course_category_id' instead of something more generic such as 'category.
+     */
+    const PARAM_COURSE_CATEGORY_ID = 'course_category';
+
+
+    function as_html() {
+        $html = array();
+        $html[] = $this->display_header();
+        $html[] = $this->display_content();
+        $html[] = $this->display_footer();
+        return implode(StringUtilities::NEW_LINE, $html);
+    }
+
+    function display_content(){
+        $html = array();
+        $html[] = '<div style="padding-top:5px; padding-bottom:15px;font-weight:bold; font-size:15px;">';
+        $html[] = '{$CRUMBS}';
+        $html[] = '</div>';
+        $html[] = '<div style="float: left; width: 20%;"><br/>';
+        $html[] = '{$CATEGORY}';
+        $html[] = '</div>';
+        $html[] = '<div style="float: right; width: 80%; text-align: left">';
+        $html[] = '{$COURSE}';
+        $html[] = '</div>';
+
+        $category_menu = $this->get_category_menu();
+        $CRUMBS = array(array('title' => Translation::get('Home'), 'url' => $this->get_url()));
+        $CRUMBS = array_merge($CRUMBS, $category_menu->get_breadcrumbs());
+        $CRUMBS = SimpleTemplate::all('<span><a href="{$url}">{$title}</a></span>', $CRUMBS, ' > ');
+
+        $CATEGORY = $category_menu->render_as_tree();
+        $table = new CatalogCourseBrowserTable($this, $parameters, $this->get_condition());
+        
+        $COURSE = $table->as_html();
+
+        return SimpleTemplate::ex($html, get_defined_vars());
+    }
+
+    private $_category_menu = null;
+    function get_category_menu(){
+        if($this->_category_menu){
+            return $this->_category_menu;
+        }
+
+        $category = Request::get(self::PARAM_COURSE_CATEGORY_ID);
+        return $this->_category_menu = new CourseCategoryCatalogMenu($category);
+    }
+
+    function get_condition() {
+        $category = Request::get(self::PARAM_COURSE_CATEGORY_ID);
+        $condition = $category ? new EqualityCondition(Course :: PROPERTY_CATEGORY, $category) : null;
+
+        $visibility_conditions = array();
+        $visibility_and_conditions[] = new EqualityCondition(CourseSettings :: PROPERTY_VISIBILITY, 1, CourseSettings :: get_table_name());
+        $visibility_and_conditions[] = new EqualityCondition(CourseSettings :: PROPERTY_ACCESS, 1, CourseSettings :: get_table_name());
+
+        //$visibility_or_conditions[] = new EqualityCondition(CourseType :: PROPERTY_ACTIVE, 1, CourseType :: get_table_name());
+        //typeless courses are always active. Condition below needed because typeless is not defined in database (no typeless row in CourseType table, so no active property)
+        //$visibility_or_conditions[] = new EqualityCondition(Course :: PROPERTY_COURSE_TYPE_ID, '0', Course :: get_table_name());
+        //$visibility_and_conditions[] = new OrCondition($visibility_or_conditions);
+
+        $visibility_condition = new AndCondition($visibility_and_conditions);
+
+        $result = empty($condition) ? $visibility_condition : new AndCondition($condition, $visibility_condition);
+
+        return $result;
+    }
+
+    function count_courses() {
+        $store = Course::get_data_manager();
+        $result = $store->count_courses($this->get_condition());
+        return $result;
+    }
+
+    function retrieve_courses() {
+        $store = Course::get_data_manager();
+        $result = $store->retrieve_courses($this->get_condition());
+        return $result;
+    }
+
+    function get_course_subscription_url($course) {
+        $params[WeblcmsManager::PARAM_APPLICATION] = WeblcmsManager::APPLICATION_NAME;
+        $params[WeblcmsManager :: PARAM_ACTION] = WeblcmsManager :: ACTION_SUBSCRIBE;
+        $params[WeblcmsManager :: PARAM_COURSE] = $course->get_id();
+        return Redirect::get_link(WeblcmsManager::APPLICATION_NAME, $params);
+    }
+
+    function get_course_viewing_url($course) {
+        $params[WeblcmsManager::PARAM_APPLICATION] = WeblcmsManager::APPLICATION_NAME;
+        $params[WeblcmsManager :: PARAM_ACTION] = WeblcmsManager :: ACTION_VIEW_COURSE;
+        $params[WeblcmsManager :: PARAM_COURSE] = $course->get_id();
+        return Redirect::get_link(WeblcmsManager::APPLICATION_NAME, $params);
+    }
+
+    function get_course_editing_url($course) {
+        return '';
+    }
+
+    function get_course_deleting_url($course) {
+        return '';
+    }
+
+    function get_course_changing_course_type_url($course) {
+        return '';
+    }
+
+    function get_course_maintenance_url() {
+        return '';
+    }
+
+    function get_reporting_url() {
+        return '';
+    }
+
+    function is_subscribed($course, $user = null) {
+        $user = $user ? $user : $this->get_user();
+        $wdm = WeblcmsDataManager :: get_instance();
+        return $wdm->is_subscribed($course, $user);
+    }
+
+}
+
+?>

application/weblcms/php/blocks/type/course_menu.class.php

+<?php
+
+namespace application\weblcms;
+
+use repository\ContentObject;
+use common\libraries\SubselectCondition;
+use repository\RepositoryDataManager;
+use common\libraries\WebApplication;
+use common\libraries\ObjectTableOrder;
+use common\libraries\AndCondition;
+use common\libraries\EqualityCondition;
+use common\libraries\Path;
+use common\libraries\Translation;
+use repository\content_object\announcement\Announcement;
+use common\libraries\StringUtilities;
+use common\libraries\Theme;
+use common\libraries\Application;
+use common\libraries\PlatformSetting;
+use common\libraries\RssIconGenerator;
+use common\libraries\Redirect;
+use common\libraries\Session;
+use common\libraries\SimpleTemplate;
+
+require_once WebApplication :: get_application_class_path('weblcms') . 'blocks/weblcms_block.class.php';
+require_once WebApplication :: get_application_class_path('weblcms') . 'lib/weblcms_manager/component/home.class.php';
+
+/**
+ * Block that displays main course's actions available in the main course menu. That is create course, register/unregister to course, etc. Do not display less common actions such as manage categories.
+ *
+ * @copyright (c) 2011 University of Geneva
+ * @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
+ * @author lopprecht
+ */
+class WeblcmsCourseMenu extends WeblcmsBlock {
+
+    function is_teacher() {
+        return $this->get_user()->is_teacher() && (Session::get('studentview') != 'studentenview');
+    }
+
+    function as_html() {
+        $html = array();
+        $html[] = $this->display_header();
+        $html[] = $this->display_content();
+        $html[] = $this->display_footer();
+
+        return implode(StringUtilities::NEW_LINE, $html);
+    }
+
+    function display_content() {
+        $html = array();
+        $html[] = '<div class="tool_menu">';
+        $html[] = '<ul>';
+        $html[] = '{$ADMIN_MENU}';
+        $html[] = '{$USER_MENU}';
+        $html[] = '</ul>';
+        $html[] = '</div>';
+
+        $template = '<li class="tool_list_menu" style="background-image: url({$IMG})"><a style="top: -3px; position: relative;" href="{$HREF}">{$TEXT}</a></li>';
+
+        $ADMIN_MENU = $this->display_admin_menu($template);
+        $USER_MENU = SimpleTemplate::all($template, $this->get_edit_course_menu());
+
+        return SimpleTemplate::ex($html, get_defined_vars());
+    }
+
+    function display_admin_menu($template) {
+        $result = array();
+        if ($this->get_user()->is_platform_admin()) {
+            $menu = $this->get_platform_admin_menu();
+            $result[] = SimpleTemplate::all($template, $menu);
+            $result[] = '<div style="margin: 10px 0 10px 0; border-bottom: 1px dotted #4271B5; height: 0px;"></div>';
+        } else {
+            if ($menu = $this->get_create_course_menu()) {
+                $result[] = SimpleTemplate::all($template, $menu);
+            }
+        }
+        return implode(StringUtilities::NEW_LINE, $result);
+    }
+
+    function get_create_course_menu() {
+        if (!$this->is_teacher()) {
+            return '';
+        }
+
+        $result = array();
+        $wdm = WeblcmsDataManager :: get_instance();
+
+        $count_direct = count($wdm->retrieve_course_types_by_user_right($this->get_user(), CourseTypeGroupCreationRight :: CREATE_DIRECT));
+        if (PlatformSetting :: get('allow_course_creation_without_coursetype', 'weblcms')) {
+            $count_direct++;
+        }
+        if ($count_direct) {
+            $HREF = $this->get_course_action_url(WeblcmsManager :: ACTION_CREATE_COURSE);
+            $TEXT = htmlspecialchars(Translation :: get('CourseCreate'));
+            $IMG = Theme :: get_common_image_path() . 'action_create.png';
+            $result[] = compact('HREF', 'TEXT', 'IMG');
+        }
+
+        $count_request = count($wdm->retrieve_course_types_by_user_right($this->get_user(), CourseTypeGroupCreationRight :: CREATE_REQUEST));
+        if ($count_request) {
+            $HREF = $this->get_course_action_url(WeblcmsManager :: ACTION_COURSE_CREATE_REQUEST_CREATOR);
+            $TEXT = htmlspecialchars(Translation :: get('CourseRequest'));
+            $IMG = Theme :: get_common_image_path() . 'action_create.png';
+            $result[] = compact('HREF', 'TEXT', 'IMG');
+        }
+
+        return $result;
+    }
+
+    function get_edit_course_menu() {
+        $result = array();
+
+        $HREF = $this->get_course_action_url(WeblcmsManager :: ACTION_MANAGER_SUBSCRIBE);
+        $TEXT = htmlspecialchars(Translation :: get('CourseSubscribe'));
+        $IMG = Theme :: get_common_image_path() . 'action_subscribe.png';
+        $result[] = compact('HREF', 'TEXT', 'IMG');
+
+        $HREF = $this->get_course_action_url(WeblcmsManager :: ACTION_MANAGER_UNSUBSCRIBE);
+        $TEXT = htmlspecialchars(Translation :: get('CourseUnsubscribe'));