We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17249 ☆ A M B ☆
    • 165 Posts
    Hi Bruno;

    I'm trying to use the multiupload feature on a Custom Package with the following simplified structure for this post:


    <?xml version="1.0" encoding="UTF-8"?>
    <model package="cms" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
    	
    
    	<object class="Content" table="content" extends="xPDOSimpleObject">
    
    		<field key="content_name" dbtype="varchar" precision="200" phptype="string" null="true" />
    		<field key="content_description" dbtype="varchar" precision="512" phptype="string" null="true" />
    		<field key="content_text" dbtype="longtext" phptype="string" null="true" />
    		<field key="deleted" dbtype="int" precision="11" phptype="integer" null="false" default="0" />
    		<field key="published" dbtype="int" precision="11" phptype="integer" null="false" default="1" />
    		<index alias="id" name="id" primary="false" unique="true" type="BTREE" >
    			<column key="id" length="" collation="A" null="false" />
    		</index>
    		
    		<composite alias="ContentPhoto" class="ContentPhoto" local="id" foreign="photo_content_id" cardinality="many" owner="local" />
    	
    	</object>
    	<object class="ContentPhoto" table="content_photo" extends="xPDOSimpleObject">
    
    		<field key="photo_name" dbtype="varchar" precision="255" phptype="string" null="true" />
    		<field key="photo_content_id" dbtype="int" precision="11" phptype="integer" null="true" />
    		<field key="photo_file" dbtype="varchar" precision="20" phptype="string" null="true" />
    		<field key="deleted" dbtype="int" precision="11" phptype="integer" null="false" default="0" />
    		<field key="published" dbtype="int" precision="11" phptype="integer" null="false" default="1" />
    		<index alias="id" name="id" primary="false" unique="true" type="BTREE" >
    			<column key="id" length="" collation="A" null="false" />
    		</index>
    		
    		<aggregate alias="Content" class="Content" local="photo_content_id" foreign="id" cardinality="one" owner="foreign" />		
    		
    	</object>
    
    	
    </model>


    Multiupload tool is intended to work with MODx Resources and MIGx.
    I want to make it work for a custom class called "Content" and using a MIGXdb which stores gallery items as "ContentPhoto" class items in the db.
    Sort of a custom Gallery component.

    The whole project is working like a charm, complete with filters, custom renderChunks in the grids, joined classes, class relationships, etc.
    Except for uploading the files in the wrong folder.
    I need the folder ID to be the 'id' from the table/class Content, but its taking the value from the manager's resource ID '11' all the time.
    I've checked some of the files but still not sure where is the correct place to assign resource_id or object_id or co_id the correct value.

    I think the following lines in the custom processor /core/cms/processors/mgr/default/update.php file has something to do:
    $resource_id = $modx->getOption('resource_id', $scriptProperties, false);
    $resource_id = !empty($co_id) ? $co_id : $resource_id;


    Copied update.php from the default migx/processors/mgr/default/ to my package folder and commented out the code blocks i will not need but still not sure if this is the place where it needs to be changed. Where's the correct place for changing this?

    Please, see attachment for clarification

    This question has been answered by Bruno17. See the first response.

    [ed. note: lithiumlab last edited this post 13 years, 5 months ago.]
      • 4172
      • 5,888 Posts
      At first you will need this fix to get allways the correct co_id:

      https://github.com/Bruno17/MIGX/commit/288bb35dbe5655ca6437f25983a0b486e16aafa9

      other instructions will follow later.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
      • discuss.answer
        • 4172
        • 5,888 Posts
        This is one way, which seems to work:

        1. Create a mediasource for your object-photos with an dynamic path
        path and url:

        [[migxObjectMediaPath? &pathTpl=`assets/res/{id}/`]]


        be sure this snippet is installed 'migxObjectMediaPath':
        <?php
        
        $pathTpl = $modx->getOption('pathTpl', $scriptProperties, '');
        $objectid = $modx->getOption('objectid', $scriptProperties, '');
        $createfolder = $modx->getOption('createFolder', $scriptProperties, '1');
        $path = '';
        $createpath = false;
        
        if (empty($objectid) && $modx->getPlaceholder('objectid')) {
            // placeholder was set by some script on frontend for example
            $objectid = $modx->getPlaceholder('objectid');
        }
        if (empty($objectid)) {
        
            //set Session - var in fields.php - processor
            if (isset($_SESSION['migxWorkingObjectid'])) {
                $objectid = $_SESSION['migxWorkingObjectid'];
                $createpath = !empty($createfolder);
            }
        
        }
        
        
        $path = str_replace('{id}', $objectid, $pathTpl);
        
        $fullpath = $modx->getOption('base_path') . $path;
        
        if ($createpath && !file_exists($fullpath)) {
            mkdir($fullpath, 0755, true);
        }
        
        return $path;
        



        if you want to have multiple file-sizes when uploading images add a mediasource-configuration.

        resizeconfigs:
        [{"x":"300","y":"300","alias":"small"},{"x":"500","y":"500","alias":"middle"},{"x":"800","y":"800","alias":"big"}]
        


        2. Create a (image)-TV with this mediasource for the context 'web'
        I named it 'objectimage'

        3. Create a php-config-file under your packages-folder.
        lets say the package is named 'cms' and the migx-configuration für your images is named 'contentphotos' (the filename needs to start with the name of your migx-configuration)

        core/components/cms/migxconfigs/contentphotos.config.inc.php

        with this content:

        <?php
        
        if (isset($_REQUEST['iframeTpl']) && $_REQUEST['iframeTpl']=='ajaxupload.html'){
            $_REQUEST['resource_id'] = '1';// we need any resource-id of a resource in the correct context, just to get the context
            $_REQUEST['tv_name'] = 'objectimage';// we need a image-tv with the correct mediasource in this context     
        }
        
        


        4. Create a copy of the migx/processors/mgr/default/fields.php
        to
        cms/processors/mgr/default/fields.php

        and change this line:
        $_SESSION['migxWorkingObjectid'] = $object_id;
        

        to:
        $_SESSION['migxWorkingObjectid'] = $modx->getOption('co_id',$_REQUEST,'undefined');
        

        This does update the SESSION-var every time you open the update-window. This way the mediasource-snippet can get the object-id of the currently edited object and the filebrowser can navigate to the correct filepath.

        5. In your form-configuration select for your image-field a inputTVtype of image with the above mediasource for contexts web and mgr





          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 17249 ☆ A M B ☆
          • 165 Posts
          Amazing Bruno!

          I will implement and let you know about the results.
          Forgot to say i'm using migx-2.4.0-beta3 from your github repository

          Found some differences in core/components/migx/templates/mgr/grids/default.grid.tpl but i'll figure it out.
          Thanks a lot for all the help. Really helpful
            • 17249 ☆ A M B ☆
            • 165 Posts
            Quote from: Bruno17 at Apr 30, 2013, 02:10 PM

            4. Create a copy of the migx/processors/mgr/default/fields.php
            to
            cms/processors/mgr/default/fields.php

            and change this line:
            $_SESSION['migxWorkingObjectid'] = $object_id;
            

            to:
            $_SESSION['migxWorkingObjectid'] = $modx--->getOption('co_id',$_REQUEST,'undefined');
            


            I can't find
            $_SESSION['migxWorkingObjectid'] = $object_id;

            in the specified file. Perhaps because i'm using 2.4.0-beta3?
              • 4172
              • 5,888 Posts
              it was added with this commit:

              https://github.com/Bruno17/MIGX/commit/9d91b94eed7af470ce619b9cc31d940221ba958d#L1R52

              just put it before this lines:

              //handle json fields
              $record = $object->toArray();
              
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 17249 ☆ A M B ☆
                • 165 Posts
                I've carefully updated to 2.4.2-beta4 and made the modifications, loved the new small additions since 2.4.0-beta3 btw.

                Nothing comes out from this line. co_id seems empty.
                Double checked all the steps just in case.

                I've made a xPDO::LOG_LEVEL_ERROR on $_SESSION['migxWorkingObjectid'] and $co_id after the following line and comes out empty:

                $_SESSION['migxWorkingObjectid'] = $modx->getOption('co_id',$_REQUEST,'undefined');


                I've noticed it works OK if i change it to $modx->getOption('object_id)',$_REQUEST,'undefined');
                Any drawbacks for doing this?

                Do you recommend to use the same inputTV and its associated MediaSource in the input field content_image for the edit formtab of the ContentPhoto items?
                Tried and it generates the folder with the id of the ContentPhoto item instead of the Content id [ed. note: lithiumlab last edited this post 13 years, 5 months ago.]
                  • 4172
                  • 5,888 Posts
                  I think, should have a look into it by myself. Seems still somewhere a missconfiguration or something not updated correctly.
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 17249 ☆ A M B ☆
                    • 165 Posts
                    Latest package on Github has this modifications in place.
                    Still some work to do to persist the objects in the database but the files and thumbs are being generated in the correct place. [ed. note: lithiumlab last edited this post 13 years, 3 months ago.]
                      • 3866 ☆ A M B ☆
                      • 350 Posts
                      Any chance of those other instructions to follow! I've tried to follow all this but I can't seem to get it to work. I can get as far as upload option but it fails to create directories and then fails to upload.

                      I'm using latest version of MIGX 2.5.2. And would like to be able to upload images for use in a custom table.
                        Helen Warner
                        Number one pixel!
                        Proud to be linked with MODX at Crimson Pixel