Changeset 11672

Show
Ignore:
Timestamp:
08/22/07 17:45:11 (1 year ago)
Author:
adrenalin
Message:

Changed editing and creating of folders to use
midcom_helper_datamanager2

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/midcom.admin.folder/config/manifest.inc

    r10929 r11672  
    11'name' => 'midcom.admin.folder', 
    22'purecode' => true, 
    3 'version' => '1.2.0beta2', 
     3'version' => '1.2.0beta3', 
    44'state' => 'beta', 
    55'privileges' => array 
  • trunk/midcom/midcom.admin.folder/folder_management.php

    r10928 r11672  
    108108            'create' => array 
    109109            ( 
    110                 'handler' => array('midcom_admin_folder_handler_create', 'create'), 
     110                'handler' => array('midcom_admin_folder_handler_edit', 'edit'), 
    111111                'fixed_args' => array ('create'), 
    112112            ), 
     
    266266     
    267267    /** 
     268     * Static method for populating user interface for editing and creating topics 
     269     *  
     270     * @access static public 
     271     * @return Array Containing a list of components 
     272     */ 
     273    function list_components($parent_component = '', $all = false) 
     274    { 
     275        $list = array(); 
     276         
     277        foreach (midcom_admin_folder_folder_management::get_component_list() as $component => $details) 
     278        { 
     279            // TODO: configuration options for either excluding or including components to the list 
     280            if (   isset($GLOBALS['midcom_config']['component_listing_allowed']) 
     281                && is_array($GLOBALS['midcom_config']['component_listing_allowed']) 
     282                && !in_array($component, $GLOBALS['midcom_config']['component_listing_allowed']) 
     283                && $component !== $parent_component 
     284                && !$all) 
     285            { 
     286                continue; 
     287            } 
     288             
     289            if (   isset($GLOBALS['midcom_config']['component_listing_excluded']) 
     290                && is_array($GLOBALS['midcom_config']['component_listing_excluded']) 
     291                && in_array($component, $GLOBALS['midcom_config']['component_listing_excluded']) 
     292                && $component !== $parent_component 
     293                && !$all) 
     294            { 
     295                continue; 
     296            } 
     297             
     298            $list[$component] = "{$details['name']} ({$component} {$details['version']})"; 
     299        } 
     300         
     301        return $list; 
     302    } 
     303     
     304    /** 
    268305     * Static method for listing available style templates 
    269306     *  
     
    273310    { 
    274311        static $style_array = array(); 
     312         
     313        $style_array[''] = $_MIDCOM->i18n->get_string('default', 'midcom.admin.folder'); 
     314         
     315        // Give an option for creating a new layout template 
     316        $style_array['__create'] = $_MIDCOM->i18n->get_string('new layout template', 'midcom.admin.folder'); 
    275317         
    276318        $qb = midcom_db_style::new_query_builder(); 
     
    281323        { 
    282324            $style_string = "{$prefix}{$style->name}"; 
     325             
     326            // Hide common unwanted material with heuristics 
     327            if (preg_match('/(asgard|aegir|empty|spider|admin site)/i', $style_string)) 
     328            { 
     329                continue; 
     330            } 
     331             
    283332            $style_array[$style_string] = "{$spacer}{$style->name}"; 
    284333            midcom_admin_folder_folder_management::list_styles($style->id, $style_string . '/', $spacer . '  '); 
  • trunk/midcom/midcom.admin.folder/handler/edit.php

    r5239 r11672  
    1616{ 
    1717    /** 
     18     * DM2 schema 
     19     *  
     20     * @access private 
     21     * @var midcom_helper_datamanager2_schema $_schema 
     22     */ 
     23    var $_schemadb; 
     24     
     25    /** 
     26     * DM2 controller instance 
     27     *  
     28     * @access private 
     29     * @var midcom_helper_datamanager2_controller $_controller 
     30     */ 
     31    var $_controller; 
     32     
     33    /** 
     34     * ID of the handler 
     35     *  
     36     * @access private 
     37     */ 
     38    var $_handler_id; 
     39     
     40    /** 
    1841     * Constructor method 
    1942     *  
     
    2447        parent::midcom_baseclasses_components_handler(); 
    2548    } 
    26  
     49     
     50    /** 
     51     * Load the schemadb and other midcom.admin.folder specific stuff 
     52     *  
     53     * @access public 
     54     */ 
     55    function _on_initialize() 
     56    { 
     57        // Load the configuration 
     58        $_MIDCOM->componentloader->load('midcom.admin.folder'); 
     59        $this->_config =& $GLOBALS['midcom_component_data']['midcom.admin.folder']['config']; 
     60    } 
     61     
     62    /** 
     63     * Load either a create controller or an edit (simple) controller or trigger an error message 
     64     *  
     65     * @access private 
     66     */ 
     67    function _load_controller() 
     68    { 
     69        // Get the configured schemas 
     70        $schemadbs = $this->_config->get('schemadbs_folder'); 
     71         
     72        // Check if a custom schema exists 
     73        if (array_key_exists($this->_topic->component, $schemadbs)) 
     74        { 
     75            $schemadb = $schemadbs[$this->_topic->component]; 
     76        } 
     77        else 
     78        { 
     79            if (!array_key_exists('default', $schemadbs)) 
     80            { 
     81                $_MIDCOM->generate_error(MIDCOM_ERRCRIT, 'Configuration error. No default schema for topic has been defined!'); 
     82                // This will exit 
     83            } 
     84             
     85            $schemadb = $schemadbs['default']; 
     86        } 
     87         
     88        $GLOBALS['midcom_admin_folder_mode'] = $this->_handler_id; 
     89         
     90        // Create the schema instance 
     91        $this->_schemadb = midcom_helper_datamanager2_schema::load_database($schemadb); 
     92         
     93        switch ($this->_handler_id) 
     94        { 
     95            case 'edit': 
     96                $this->_controller =& midcom_helper_datamanager2_controller::create('simple'); 
     97                $this->_controller->schemadb =& $this->_schemadb; 
     98                $this->_controller->set_storage($this->_topic); 
     99                break; 
     100             
     101            case 'create': 
     102                $this->_schemadb->default->fields['name']['required'] = 0; 
     103                $this->_controller =& midcom_helper_datamanager2_controller::create('create'); 
     104                $this->_controller->schemadb =& $this->_schemadb; 
     105                $this->_controller->schemaname = 'default'; 
     106                $this->_controller->callback_object =& $this; 
     107                 
     108                // Suggest to create the same type of a folder as the parent is 
     109                $this->_controller->defaults = array 
     110                ( 
     111                    'component' => $this->_topic->component, 
     112                ); 
     113                break; 
     114             
     115            default: 
     116                $_MIDCOM->generate_error(MIDCOM_ERRCRIT, 'Unable to process the request, unknown handler id'); 
     117                // This will exit 
     118        } 
     119         
     120        if (! $this->_controller->initialize()) 
     121        { 
     122            $_MIDCOM->generate_error(MIDCOM_ERRCRIT, "Failed to initialize a DM2 controller instance for article {$this->_event->id}."); 
     123            // This will exit. 
     124        } 
     125         
     126    } 
     127     
     128    /** 
     129     * DM2 creation callback, binds to the current content topic. 
     130     */ 
     131    function & dm2_create_callback (&$controller) 
     132    { 
     133        $this->_new_topic = new midcom_db_topic(); 
     134        $this->_new_topic->up = $this->_topic->id; 
     135         
     136        if (! $this->_new_topic->create()) 
     137        { 
     138            debug_push_class(__CLASS__, __FUNCTION__); 
     139            debug_print_r('We operated on this object:', $this->_new_topic); 
     140            debug_pop(); 
     141            $_MIDCOM->generate_error(MIDCOM_ERRCRIT, 
     142                'Failed to create a new article, cannot continue. Last Midgard error was: '. mgd_errstr()); 
     143            // This will exit. 
     144        } 
     145 
     146        return $this->_new_topic; 
     147    } 
     148 
     149     
    27150    /** 
    28151     * Handler for folder editing. Checks for the permissions and folder integrity. 
     
    36159        $this->_topic->require_do('midcom.admin.folder:topic_management'); 
    37160         
    38         if (array_key_exists('f_cancel', $_REQUEST)) 
    39         { 
    40             $_MIDCOM->relocate(''); 
    41             // This will exit. 
    42         } 
    43  
    44         if (array_key_exists('f_submit', $_REQUEST)) 
    45         { 
    46             if ($this->_process_edit_form()) 
    47             { 
    48                 // Relocate to the renamed topic 
    49                 $_MIDCOM->relocate($_MIDCOM->permalinks->create_permalink($this->_topic->guid)); 
    50                 // This will exit. 
    51             } 
     161        $this->_handler_id = str_replace('____ais-folder-', '', $handler_id); 
     162         
     163        // Load the DM2 controller 
     164        $this->_load_controller(); 
     165         
     166        // Get the content topic prefix 
     167        $prefix = $_MIDCOM->get_context_data(MIDCOM_CONTEXT_ANCHORPREFIX); 
     168         
     169        // Store the old name before editing 
     170        $old_name = $this->_topic->name; 
     171         
     172        switch ($this->_controller->process_form()) 
     173        { 
     174            case 'cancel': 
     175                $_MIDCOM->uimessages->add($this->_l10n->get('midcom.admin.folder'), $this->_l10n->get('cancelled')); 
     176                $_MIDCOM->relocate($prefix); 
     177                break; 
     178             
     179            case 'save': 
     180                if ($this->_handler_id === 'edit') 
     181                { 
     182                    $_MIDCOM->uimessages->add($this->_l10n->get('midcom.admin.folder'), $this->_l10n->get('folder saved')); 
     183                     
     184                    // Get the relocation url 
     185                    $url = preg_replace("/{$old_name}\/\$/", "{$this->_topic->name}/", $prefix); 
     186                } 
     187                else 
     188                { 
     189                    $_MIDCOM->uimessages->add($this->_l10n->get('midcom.admin.folder'), $this->_l10n->get('folder created')); 
     190                     
     191                    // Generate name if it is missing 
     192                    if (!$this->_new_topic->name) 
     193                    { 
     194                        $this->_new_topic->name = midcom_generate_urlname_from_string($this->_new_topic->extra); 
     195                        $this->_new_topic->update(); 
     196                    } 
     197                     
     198                    // Get the relocation url 
     199                    $url = "{$prefix}/{$this->_new_topic->name}/"; 
     200                } 
     201                 
     202                $_MIDCOM->relocate($url); 
     203                // This will exit 
    52204        } 
    53205         
     
    65217        $this->_node_toolbar->hide_item('__ais/folder/edit.html'); 
    66218 
     219        $data['topic'] =& $this->_topic; 
     220        $data['controller'] =& $this->_controller; 
     221         
    67222        // Set page title 
    68         $data['topic'] = $this->_topic; 
    69223        $data['title'] = sprintf($_MIDCOM->i18n->get_string('edit folder %s', 'midcom.admin.folder'), $data['topic']->extra); 
    70224        $_MIDCOM->set_pagetitle($data['title']); 
     
    75229        // Ensure we get the correct styles 
    76230        $_MIDCOM->style->prepend_component_styledir('midcom.admin.folder'); 
     231         
     232        // Serve the correct localization 
     233        $data['l10n'] =& $this->_l10n; 
    77234         
    78235        // Add style sheet 
     
    132289     
    133290    /** 
    134      * Processes the _Edit folder_ page form and updates the folder. 
    135      *  
    136      * @access private 
    137      * @return boolean Indicating success 
    138      */ 
    139     function _process_edit_form() 
    140     { 
    141         if (trim($_REQUEST['f_name']) == '') 
    142         { 
    143             $this->_processing_msg = $_MIDCOM->i18n->get_string('no url name specified', 'midcom.admin.folder'); 
    144             $_MIDCOM->uimessages->add($_MIDCOM->i18n->get_string('create folder', 'midcom.admin.folder'), $this->_processing_msg, 'error'); 
    145              
    146             return false; 
    147         } 
    148         if (trim($_REQUEST['f_title']) == '') 
    149         { 
    150             $this->_processing_msg = $_MIDCOM->i18n->get_string('title is empty', 'midcom.admin.folder'); 
    151             $_MIDCOM->uimessages->add($_MIDCOM->i18n->get_string('create folder', 'midcom.admin.folder'), $this->_processing_msg, 'error'); 
    152             return false; 
    153         } 
    154          
    155         if (mgd_get_topic_by_name($this->_topic->id, $_REQUEST['f_name'])) 
    156         { 
    157             $this->_processing_msg = sprintf($_MIDCOM->i18n->get_string('folder with name %s already exists', 'midcom.admin.folder'), $_REQUEST['f_name']); 
    158             $_MIDCOM->uimessages->add($_MIDCOM->i18n->get_string('create folder', 'midcom.admin.folder'), $this->_processing_msg, 'error'); 
    159             return false; 
    160         } 
    161  
    162         // store form data in topic object 
    163         $this->_topic->name = midcom_generate_urlname_from_string($_REQUEST['f_name']); 
    164         $this->_topic->extra = $_REQUEST['f_title']; 
    165         //$this->_topic->score = $_REQUEST['f_score']; 
    166         //$this->_topic->owner = $_REQUEST['f_owner']; 
    167          
    168         if ($_REQUEST['f_style'] === '__create') 
    169         { 
    170             $this->_topic->require_do('midcom.admin.folder:template_management'); 
    171  
    172             $this->_topic->style = $this->_create_style($this->_topic->name); 
    173              
    174             // Failed to create the new style template 
    175             if ($this->_topic->style === '') 
    176             { 
    177                 return false; 
    178             } 
     291     * Shows the _Edit folder_ page. 
     292     *  
     293     * @access private 
     294     */ 
     295    function _show_edit($handler_id, &$data) 
     296    { 
     297        $styles_all = midcom_admin_folder_folder_management::list_styles(); 
     298         
     299        // Show the style element 
     300        if ($this->_handler_id === 'create') 
     301        { 
     302            $data['page_title'] = sprintf($this->_i18n->get_string("create folder", 'midcom.admin.folder')); 
    179303        } 
    180304        else 
    181305        { 
    182             $this->_topic->style = $_REQUEST['f_style']; 
    183         } 
    184          
    185         // TODO: Move to metadata 
    186         $this->_topic->parameter('midcom.helper.nav', 'navorder', $_REQUEST['f_navorder']); 
    187          
    188         if (   array_key_exists('f_style_inherit', $_REQUEST) 
    189             && $_REQUEST['f_style_inherit'] == 'on') 
    190         { 
    191             $this->_topic->styleInherit = true; 
    192         } 
    193         else 
    194         { 
    195             $this->_topic->styleInherit = false; 
    196         } 
    197  
    198         if (   trim($_REQUEST['f_type']) !== $this->_topic->component 
    199             && $_MIDCOM->auth->admin 
    200             && $_REQUEST['f_type'] !== '') 
    201         { 
    202              $this->_topic->component = $_REQUEST['f_type']; 
    203         } 
    204  
    205  
    206         if (! $this->_topic->update()) 
    207         { 
    208             $this->_processing_msg = 'Could not save Folder: ' . mgd_errstr(); 
    209             return false; 
    210         } 
    211  
    212         $_MIDCOM->cache->invalidate($this->_topic->guid()); 
    213  
    214         return true; 
    215     } 
    216      
    217     /** 
    218      * Shows the _Edit folder_ page. 
    219      *  
    220      * @access private 
    221      */ 
    222     function _show_edit($handler_id, &$data) 
    223     { 
    224         // Get parent component and navorder 
    225         $data['parent_topic'] = $this->_topic->component; 
    226                 
    227         $data['view'] =& $this->_topic; 
    228         $data['style_inherit'] = $this->_topic->styleInherit; 
    229         $data['style'] = $this->_topic->style; 
    230         $data['folder'] =& $this->_topic; 
    231          
    232         // TODO: Move to metadata 
    233         $data['navorder'] = $this->_topic->parameter('midcom.helper.nav', 'navorder'); 
    234          
    235         $data['navorder_list'] = array 
    236         ( 
    237             MIDCOM_NAVORDER_DEFAULT => $_MIDCOM->i18n->get_string('default sort order', 'midcom.admin.folder'), 
    238             MIDCOM_NAVORDER_TOPICSFIRST => $_MIDCOM->i18n->get_string('folders first', 'midcom.admin.folder'), 
    239             MIDCOM_NAVORDER_ARTICLESFIRST => $_MIDCOM->i18n->get_string('pages first', 'midcom.admin.folder'), 
    240             MIDCOM_NAVORDER_SCORE => $_MIDCOM->i18n->get_string('by score', 'midcom.admin.folder'), 
    241         ); 
    242          
    243         $style_default = array 
    244         ( 
    245             '' => $_MIDCOM->i18n->get_string('default', 'midcom.admin.folder'), 
    246         ); 
    247          
    248         if ($this->_topic->can_do('midcom.admin.folder:template_management')) 
    249         { 
    250             $style_default['__create'] = $_MIDCOM->i18n->get_string('new layout template', 'midcom.admin.folder'); 
    251         } 
    252          
    253         $styles_all = midcom_admin_folder_folder_management::list_styles(); 
    254          
    255         $data['styles'] = array_merge($style_default, $styles_all); 
    256          
    257         // Place $view as a super global for the style checker function 
    258         // midcom_admin_content_list_styles_selector2 
    259         $GLOBALS['view'] =& $this->_topic; 
    260          
    261         // Show the style element 
    262         midcom_show_style('midcom-admin-show-edit-folder'); 
     306            $data['page_title'] = sprintf($this->_i18n->get_string("{$this->_handler_id} folder %s", 'midcom.admin.folder'), $this->_topic->extra); 
     307        } 
     308         
     309        midcom_show_style('midcom-admin-show-folder-actions'); 
    263310    } 
    264311} 
  • trunk/midcom/midcom.admin.folder/midcom/interfaces.php

    r5191 r11672  
    1818    { 
    1919        parent::midcom_baseclasses_components_interface(); 
     20         
    2021        $this->_component = 'midcom.admin.folder'; 
    2122        $this->_purecode = true; 
     
    3132        ); 
    3233    } 
    33  
    3434} 
    3535?>