We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22446
    • 181 Posts
    Bruno,

    I am not very familiar with Migx. I was going through all the documentation and I am uncertain how to set this up. I have migx installed and started to setup a migx TV but I am uncertain where to go from there. Can you assist me through the setup?

    Thank you for your help.

    Quote from: Bruno17 at Dec 10, 2012, 08:50 PM
    wouldn't this be an option:
    Put all urls into a MIGX - TV with this fields:
    url,date,active..... and what you need else

    use this logic:

    1. is there an active item for the current date?
    yes -> goto 7

    no ->
    2. empty all dates and active-states which are older than today
    3. are there more than 7 urls which have empty dates
    no -> goto 6

    yes -> get a random list of all this urls (with an empty date)
    4. search for the latest date
    5. replace all empty dates of the random list with coming dates (later than the latest date found or later than today) and save the result as json-records back to the MIGX-TV

    6. set the item with the current date to active
    7. display the active item with the current date


    1 2012/12/10
    3 2012/12/11
    5 2012/12/12
    9 2012/12/13
    2 2012/12/14
    8 2012/12/15
    6 2012/12/16
    4 2012/12/17
    7 2012/12/18
    ----------------
    17 2012/12/19
    11 2012/12/20
    15 2012/12/21
    10 2012/12/22
    14 2012/12/23
    12 2012/12/24
    16 2012/12/25
    13 2012/12/26
      • 4172
      • 5,888 Posts
      MIGX is installed succesfully?
      http://rtfm.modx.com/display/ADDON/MIGX#MIGX-InstallationInstructions

      Then you are ready to create the input-fields.
      http://rtfm.modx.com/display/ADDON/MIGX.Backend-Usage#MIGX.Backend-Usage-Step3.1FormTabs

      Put this into the formtabs - field of the MIGX - TV:

      [
      {"caption":"Fields", "fields": [
          {"field":"title","caption":"Title"},
          {"field":"description","caption":"Description","inputTVtype":"textarea"},
          {"field":"url","caption":"Url"},
          {"field":"activedate","caption":"Date"},
          {"field":"activated","caption":"Active"}
      ]}
      ]


      and this into the gridcolumns - field:

      [
      {"header": "Title", "width": "50", "sortable": "true", "dataIndex": "title"},
      {"header": "Url", "width": "50", "sortable": "true", "dataIndex": "url"},
      {"header": "Date", "width": "50", "sortable": "true", "dataIndex": "activedate"}
      ]


      that's it for the backend.
      Add your Urls into this MIGX-TV.

      Todo the frontend-stuff we will create a custom-snippet in the next step.
      Let me know, when you are ready for it.


      [ed. note: Bruno17 last edited this post 11 years, 4 months ago.]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 22446
        • 181 Posts
        Bruno17,

        I have successfully installed migx. I have successfully setup the the migx - TV and input the forms tabs information and gridcolumns. All the URL's are added to the migx TV. The only question I have at this point is what should be put in the active form field for each URL?

        Thank you.



        Quote from: Bruno17 at Dec 11, 2012, 05:30 AM
        MIGX is installed succesfully?
        http://rtfm.modx.com/display/ADDON/MIGX#MIGX-InstallationInstructions

        Then you are ready to create the input-fields.
        http://rtfm.modx.com/display/ADDON/MIGX.Backend-Usage#MIGX.Backend-Usage-Step3.1FormTabs

        Put this into the formtabs - field of the MIGX - TV:

        [
        {"caption":"Fields", "fields": [
            {"field":"title","caption":"Title"},
            {"field":"description","caption":"Description","inputTVtype":"textarea"},
            {"field":"url","caption":"Url"},
            {"field":"activedate","caption":"Date","inputTVtype":"date"},
            {"field":"activated","caption":"Active"}
        ]}
        ]


        and this into the gridcolumns - field:

        [
        {"header": "Title", "width": "50", "sortable": "true", "dataIndex": "title"},
        {"header": "Url", "width": "50", "sortable": "true", "dataIndex": "url"},
        {"header": "Date", "width": "50", "sortable": "true", "dataIndex": "activedate"}
        ]


        that's it for the backend.
        Add your Urls into this MIGX-TV.

        Todo the frontend-stuff we will create a custom-snippet in the next step.
        Let me know, when you are ready for it.


          • 4172
          • 5,888 Posts
          active and date should be empty

          they are filled by the snippet.
          Here is the code for the snippet. This should do it so far.

          Call it like that:

          [[!getDayliMIGXrecord? &tvname=`yourTV`&tpl=`yourOutputChunk` &randomize=`1`]]


          This snippet sets some dates, if &randomize=`1` in a randomized order, if necessary, and does output the MIGX-item of the day.
          Once a date is active for the current date, it does nothing else, than reading this record.
          The first time on the other day, it runs the process again (searching for some expired items, if there are some, add some dates... and so on)

          it lets allways the dates of half of the items untouched, so you can be sure, they do not repeat between some days.


          <?php
          
          /**
           * getDayliMIGXrecord
           *
           * Copyright 2009-2011 by Bruno Perner <[email protected]>
           *
           * getDayliMIGXrecord is free software; you can redistribute it and/or modify it
           * under the terms of the GNU General Public License as published by the Free
           * Software Foundation; either version 2 of the License, or (at your option) any
           * later version.
           *
           * getDayliMIGXrecord is distributed in the hope that it will be useful, but WITHOUT ANY
           * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
           * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
           *
           * You should have received a copy of the GNU General Public License along with
           * getDayliMIGXrecord; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
           * Suite 330, Boston, MA 02111-1307 USA
           *
           * @package migx
           */
          /**
           * getDayliMIGXrecord
           *
           * display Items from outputvalue of TV with custom-TV-input-type MIGX or from other JSON-string for MODx Revolution 
           *
           * @version 1.0
           * @author Bruno Perner <[email protected]>
           * @copyright Copyright © 2012
           * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License
           * version 2 or (at your option) any later version.
           * @package migx
           */
          
          /*example: [[!getDayliMIGXrecord? &tvname=`myTV`&tpl=`@CODE:<img src="[[+image]]"/>` &randomize=`1`]]*/
          /* get default properties */
          
          
          $tvname = $modx->getOption('tvname', $scriptProperties, '');
          $tpl = $modx->getOption('tpl', $scriptProperties, '');
          $randomize = $modx->getOption('randomize', $scriptProperties, false);
          $where = $modx->getOption('where', $scriptProperties, '');
          $where = !empty($where) ? $modx->fromJSON($where) : array();
          $sort = $modx->getOption('sort', $scriptProperties, '');
          $sort = !empty($sort) ? $modx->fromJSON($sort) : array();
          $toPlaceholder = $modx->getOption('toPlaceholder', $scriptProperties, false);
          $docid = $modx->getOption('docid', $scriptProperties, (isset($modx->resource) ? $modx->resource->get('id') : 1));
          $processTVs = $modx->getOption('processTVs', $scriptProperties, '1');
          
          $migx = $modx->getService('migx', 'Migx', $modx->getOption('migx.core_path', null, $modx->getOption('core_path') . 'components/migx/') . 'model/migx/', $scriptProperties);
          if (!($migx instanceof Migx))
              return '';
          $migx->working_context = $modx->resource->get('context_key');
          
          if (!empty($tvname)) {
              if ($tv = $modx->getObject('modTemplateVar', array('name' => $tvname))) {
          
                  /*
                  *   get inputProperties
                  */
          
          
                  $properties = $tv->get('input_properties');
                  $properties = isset($properties['formtabs']) ? $properties : $tv->getProperties();
          
                  $migx->config['configs'] = $properties['configs'];
                  $migx->loadConfigs();
                  // get tabs from file or migx-config-table
                  $formtabs = $migx->getTabs();
                  if (empty($formtabs)) {
                      //try to get formtabs and its fields from properties
                      $formtabs = $modx->fromJSON($properties['formtabs']);
                  }
          
                  //$tv->setCacheable(false);
                  //$outputvalue = $tv->renderOutput($docid);
                  $tvresource = $modx->getObject('modTemplateVarResource', array(
                      'tmplvarid' => $tv->get('id'),
                      'contentid' => $docid,
                      ));
          
          
                  $outputvalue = $tvresource->get('value');
                  /*
                  *   get inputTvs 
                  */
                  $inputTvs = array();
                  if (is_array($formtabs)) {
          
                      //multiple different Forms
                      // Note: use same field-names and inputTVs in all forms
                      $inputTvs = $migx->extractInputTvs($formtabs);
                  }
                  $migx->source = $tv->getSource($migx->working_context, false);
          
                  if (empty($outputvalue)) {
                      return '';
                  }
          
                  $items = $modx->fromJSON($outputvalue);
          
          
                  //is there an active item for the current date?
                  $activedate = $modx->getOption('activedate', $scriptProperties, strftime('%Y/%m/%d'));
                  //$activedate = $modx->getOption('activedate', $_GET, strftime('%Y/%m/%d'));
                  $activewhere = array();
                  $activewhere['activedate'] = $activedate;
                  $activewhere['activated'] = '1';
                  $activeitems = $migx->filterItems($activewhere, $items);
          
                  if (count($activeitems) == 0) {
          
                      $activeitems = array();
                      // where filter
                      if (is_array($where) && count($where) > 0) {
                          $items = $migx->filterItems($where, $items);
                      }
          
                      $tempitems = array();
                      $count = count($items);
                      $emptycount = 0;
                      $latestdate = $activedate;
                      $nextdate = strtotime($latestdate);
                      foreach ($items as $item) {
                          //empty all dates and active-states which are older than today
                          if (!empty($item['activedate']) && $item['activedate'] < $activedate) {
                              $item['activated'] = '0';
                              $item['activedate'] = '';
                          }
                          if (empty($item['activedate'])) {
                              $emptycount++;
                          }
                          if ($item['activedate'] > $latestdate) {
                              $latestdate = $item['activedate'];
                              $nextdate = strtotime($latestdate) + (24 * 60 * 60);
                          }
                          if ($item['activedate'] == $activedate) {
                              $item['activated'] = '1';
                              $activeitems[] = $item;
                          }
                          $tempitems[] = $item;
                      }
          
                      //echo '<pre>' . print_r($tempitems, 1) . '</pre>';
          
                      $items = $tempitems;
          
          
                      //are there more than half of all items with empty activedates
          
                      if ($emptycount >= $count / 2) {
          
                          // sort items
                          if (is_array($sort) && count($sort) > 0) {
                              $items = $migx->sortDbResult($items, $sort);
                          }
                          if (count($items) > 0) {
                              //shuffle items
                              if ($randomize) {
                                  shuffle($items);
                              }
                          }
          
                          $tempitems = array();
                          foreach ($items as $item) {
                              if (empty($item['activedate'])) {
                                  $item['activedate'] = strftime('%Y/%m/%d', $nextdate);
                                  $nextdate = $nextdate + (24 * 60 * 60);
                                  if ($item['activedate'] == $activedate) {
                                      $item['activated'] = '1';
                                      $activeitems[] = $item;
                                  }
                              }
          
                              $tempitems[] = $item;
                          }
          
                          $items = $tempitems;
                      }
          
                      //$resource = $modx->getObject('modResource', $docid);
                      //echo $modx->toJson($items);
                      $sort = '[{"sortby":"activedate"}]';
                      $items = $migx->sortDbResult($items, $modx->fromJson($sort));
          
                      //echo '<pre>' . print_r($items, 1) . '</pre>';
          
                      $tv->setValue($docid, $modx->toJson($items));
                      $tv->save();
          
                  }
              }
          
          }
          
          
          $properties = array();
          foreach ($scriptProperties as $property => $value) {
              $properties['property.' . $property] = $value;
          }
          
          $output = '';
          
          foreach ($activeitems as $key => $item) {
          
              $fields = array();
              foreach ($item as $field => $value) {
                  $value = is_array($value) ? implode('||', $value) : $value; //handle arrays (checkboxes, multiselects)
                  if ($processTVs && isset($inputTvs[$field])) {
                      if ($tv = $modx->getObject('modTemplateVar', array('name' => $inputTvs[$field]['inputTV']))) {
          
                      } else {
                          $tv = $modx->newObject('modTemplateVar');
                          $tv->set('type', $inputTvs[$field]['inputTVtype']);
                      }
                      $inputTV = $inputTvs[$field];
          
                      $mTypes = $modx->getOption('manipulatable_url_tv_output_types', null, 'image,file');
                      //don't manipulate any urls here
                      $modx->setOption('manipulatable_url_tv_output_types', '');
                      $tv->set('default_text', $value);
                      $value = $tv->renderOutput($docid);
                      //set option back
                      $modx->setOption('manipulatable_url_tv_output_types', $mTypes);
                      //now manipulate urls
                      if ($mediasource = $migx->getFieldSource($inputTV, $tv)) {
                          $mTypes = explode(',', $mTypes);
                          if (!empty($value) && in_array($tv->get('type'), $mTypes)) {
                              //$value = $mediasource->prepareOutputUrl($value);
                              $value = str_replace('/./', '/', $mediasource->prepareOutputUrl($value));
                          }
                      }
          
                  }
                  $fields[$field] = $value;
          
              }
          
              $rowtpl = $tpl;
              //get changing tpls from field
              if (substr($tpl, 0, 7) == "@FIELD:") {
                  $tplField = substr($tpl, 7);
                  $rowtpl = $fields[$tplField];
              }
          
              if (!isset($template[$rowtpl])) {
                  if (substr($rowtpl, 0, 6) == "@FILE:") {
                      $template[$rowtpl] = file_get_contents($modx->config['base_path'] . substr($rowtpl, 6));
                  } elseif (substr($rowtpl, 0, 6) == "@CODE:") {
                      $template[$rowtpl] = substr($tpl, 6);
                  } elseif ($chunk = $modx->getObject('modChunk', array('name' => $rowtpl), true)) {
                      $template[$rowtpl] = $chunk->getContent();
                  } else {
                      $template[$rowtpl] = false;
                  }
              }
          
              $fields = array_merge($fields, $properties);
          
              if ($template[$rowtpl]) {
                  $chunk = $modx->newObject('modChunk');
                  $chunk->setCacheable(false);
                  $chunk->setContent($template[$rowtpl]);
                  $output .= $chunk->process($fields);
          
              } else {
                  $output .= '<pre>' . print_r($fields, 1) . '</pre>';
          
              }
          
          
          }
          
          
          if (!empty($toPlaceholder)) {
              $modx->setPlaceholder($toPlaceholder, $output);
              return '';
          }
          
          return $output;
          
          
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 22446
            • 181 Posts
            Bruno17,

            Everything works perfectly. Thank you so very much for your help.

            I learned a lot playing around with migx and I can see it being very useful in the future.

            I have one further question. I would like to add one more form tabs and grid column. Can I add those to the current setup you have helped me out with? What I would like to add is a resource ID which with the number that is input would like to that resource page on my website.

            Thank you again.
              • 22446
              • 181 Posts
              Bruno17,

              I was able to get everything working. I added a form tab called pageid and added that into my grid column too in the migx TV I can add the page resource that I would like to link to. In my template I then call out the pageid as a link as as follows

              <a href="[[~[[+pageid]]]]">[[+title]]</a>


              I am so excited that this is working. Thank you again so much for your help.



              Quote from: outdoorsadv at Dec 11, 2012, 08:40 PM
              Bruno17,

              Everything works perfectly. Thank you so very much for your help.

              I learned a lot playing around with migx and I can see it being very useful in the future.

              I have one further question. I would like to add one more form tabs and grid column. Can I add those to the current setup you have helped me out with? What I would like to add is a resource ID which with the number that is input would like to that resource page on my website.

              Thank you again.