Results 1 to 11 of 11

Thread: [solved] Pb to generate a sublist from linked MM

  1. #1
    User
    Join Date
    04-01-10.
    Posts
    292

    Frage [solved] Pb to generate a sublist from linked MM

    Hi everyone,

    I (still) got 2 MM : mm_evenements and mm_rencontres. mm_rencontres is linked to mm_evenements byt select attribute lienRencontreEvenement.
    I got a page with a mm_list of evenements. When clicking, I go to the detail page where I need :
    - the informations of the evenement
    - a list of referenced mm_rencontres records.

    I was told to adapt this example : http://de.contaowiki.org/MetaModels_...ferenced_items . Here is my template code :

    PHP Code:
    <?php 
    function getRencontresParEvenement($strAlias$format='html5')
    {
      
    $objMetaModel MetaModelFactory::byTableName('mm_rencontres'); // my linked mm
      
    $objFilter $objMetaModel->prepareFilter(16, array()); // I created the filter but added no rules
      
    $objFilter->addFilterRule(new MetaModelFilterRuleSearchAttribute($objMetaModel->getAttribute('lienRencontreEvenement'), $strAlias$objMetaModel->getAvailableLanguages()));
      
    $objItems $objMetaModel->findByFilter($objFilter);
      return 
    $objItems->parseAll($format$objMetaModel->getView(20));
    }
    ?>
     
    <div class="evenement_detailview">
      <?php foreach ($this->data as $arrItem): ?> // the problem seems to be here (line 13)
     
      <div class="detailview">
        <h1 class="ce_headline"><?php echo $arrItem['text']['intitule']; ?></h1>
        <p class="description"><?php echo $arrItem['text']['description']; ?></p>
      </div>
     
      <div class="rencontres_liees">
        <h2>Rencontres</h2>
        <?php foreach (getRencontresParEvenement($arrItem['raw']['alias']) as $arrProjects): ?>
      
        <div class="rencontre">
          <h3>
            <a href="{{env::path}}<?php echo $arrProjects['jumpTo']['url']; ?>">
              <?php echo $arrProjects[$this->getFormat()]['intitule']; ?> 
            </a>
          </h3>
          <?php echo $arrProjects[$this->getFormat()]['description']; ?>
        
        </div>
      
      <?php endforeach; ?>
      </div>
     
      <?php endforeach; ?>
    </div>

    But I got this error message :
    Code:
    Warning: Invalid argument supplied for foreach() in templates/ce_metamodel_list_test_evenement.html5 on line 13#0 templates/ce_metamodel_list_test_evenement.html5(13): __error(2, 'Invalid argumen...', '/Users/pro/CLIE...', 13, Array)
    #1 system/modules/core/library/Contao/BaseTemplate.php(88): include('/Users/pro/CLIE...')
    #2 system/modules/core/library/Contao/Template.php(277): Contao\BaseTemplate->parse()
    #3 system/modules/core/classes/FrontendTemplate.php(46): Contao\Template->parse()
    #4 system/modules/core/classes/Hybrid.php(258): Contao\FrontendTemplate->parse()
    #5 composer/vendor/metamodels/core/src/MetaModels/FrontendIntegration/MetaModelHybrid.php(102): Contao\Hybrid->generate()
    #6 composer/vendor/metamodels/core/src/MetaModels/FrontendIntegration/HybridList.php(54): MetaModels\FrontendIntegration\MetaModelHybrid->generate()
    #7 system/modules/core/library/Contao/Controller.php(476): MetaModels\FrontendIntegration\HybridList->generate()
    #8 system/modules/core/modules/ModuleArticle.php(213): Contao\Controller::getContentElement(Object(Contao\ContentModel), 'main')
    #9 system/modules/core/modules/Module.php(283): Contao\ModuleArticle->compile()
    #10 system/modules/core/modules/ModuleArticle.php(67): Contao\Module->generate()
    #11 system/modules/core/library/Contao/Controller.php(409): Contao\ModuleArticle->generate(false)
    #12 system/modules/core/library/Contao/Controller.php(269): Contao\Controller::getArticle(Object(Contao\ArticleModel), false, false, 'main')
    #13 system/modules/core/pages/PageRegular.php(133): Contao\Controller::getFrontendModule('0', 'main')
    #14 system/modules/core/controllers/FrontendIndex.php(267): Contao\PageRegular->generate(Object(Contao\PageModel), true)
    #15 index.php(20): Contao\FrontendIndex->run() #16 {main}
    What is wrong ? Thanks for your help.
    Last edited by charled; 03/10/2016 at 18:39.

  2. #2
    User zonky's Avatar
    Join Date
    11-29-11.
    Location
    Berlin
    Posts
    160

    Default

    may be... you don´t have items?

    you can debug your template like http://metamodels.readthedocs.org/de...templates.html

    PHP Code:

    <?php 
    function getRencontresParEvenement($strAlias$format='html5')
    {
      
    $objMetaModel MetaModelFactory::byTableName('mm_rencontres'); // my linked mm
      
    $objFilter $objMetaModel->prepareFilter(16, array()); // I created the filter but added no rules
      
    $objFilter->addFilterRule(new MetaModelFilterRuleSearchAttribute($objMetaModel->getAttribute('lienRencontreEvenement'), $strAlias$objMetaModel->getAvailableLanguages()));
      
    $objItems $objMetaModel->findByFilter($objFilter);
      return 
    $objItems->parseAll($format$objMetaModel->getView(20));
    }
    ?>

    <?php if (count($this->data)): ?>
     
    <div class="evenement_detailview">
      <?php foreach ($this->data as $arrItem): ?> // the problem seems to be here (line 13)
     
      <div class="detailview">
        <h1 class="ce_headline"><?php echo $arrItem['text']['intitule']; ?></h1>
        <p class="description"><?php echo $arrItem['text']['description']; ?></p>
      </div>
     
      <div class="rencontres_liees">
        <h2>Rencontres</h2>
        <?php foreach (getRencontresParEvenement($arrItem['raw']['alias']) as $arrProjects): ?>
      
        <div class="rencontre">
          <h3>
            <a href="{{env::path}}<?php echo $arrProjects['jumpTo']['url']; ?>">
              <?php echo $arrProjects[$this->getFormat()]['intitule']; ?> 
            </a>
          </h3>
          <?php echo $arrProjects[$this->getFormat()]['description']; ?>
        
        </div>
      
      <?php endforeach; ?>
      </div>
     
      <?php endforeach; ?>
    </div>

    <?php endif; ?>

  3. #3
    User
    Join Date
    04-01-10.
    Posts
    292

    Default

    Hi Zonky,

    Yes I got linked datas.
    So I duplicated metamodel_prerendered as metamodel_prerendered_detail and added debug code and count code.

    But nom I got this error :
    Code:
    Fatal error: Class 'MetaModelFactory' not found in /Users/pro/CLIENTS/LES NOUVELLES HYBRIDES/sites/lnh3dev2/templates/metamodel_prerendered_detail.html5 on line 15
    line 15 is : [code]$objMetaModel = MetaModelFactory::byTableName('mm_rencontres');[/quote]

    Here is my complete code :
    PHP Code:
    <?php
    echo "<!-- DEBUG START \n";
    echo 
    "<pre>\n";
    print_r($this->items->parseAll($this->getFormat(), $this->view));
    echo 
    "</pre>\n";
    echo 
    "\n DEBUG ENDE -->";
    ?>


    <?php $strRendersettings = isset($this->settings)? 'settings' 'view'?>
    <?php 
    if (count($this->data)): ?>


    <?php 
    function getRencontresParEvenement($strAlias$format='html5')
    {
      
    $objMetaModel MetaModelFactory::byTableName('mm_rencontres');
      
    $objFilter $objMetaModel->prepareFilter(16, array());
      
    $objFilter->addFilterRule(new MetaModelFilterRuleSearchAttribute($objMetaModel->getAttribute('lienRencontreEvenement'), $strAlias$objMetaModel->getAvailableLanguages()));
      
    $objItems $objMetaModel->findByFilter($objFilter);
      return 
    $objItems->parseAll($format$objMetaModel->getView(21));
    }
    ?>
     <?php if (count($this->data)): ?> 
     
    <div class="evenement_detailview">
      <?php foreach ($this->data as $arrItem): ?>
     
      <div class="detailview">
        <h1 class="ce_headline"><?php echo $arrItem['text']['intitule']; ?></h1>
        <p class="description"><?php echo $arrItem['text']['description']; ?></p>
      </div>
     
      <div class="rencontres_liees">
        <h2>Rencontres</h2>
        <?php foreach (getRencontresParEvenement($arrItem['raw']['alias']) as $arrRencontres): ?>
      
        <div class="rencontre">
          <h3>
            <a href="{{env::path}}<?php echo $$arrRencontres['jumpTo']['url']; ?>">
              <?php echo $arrRencontres[$this->getFormat()]['intitule']; ?> 
            </a>
          </h3>
          <?php echo $arrRencontres[$this->getFormat()]['description']; ?>
        
        </div>
      
      <?php endforeach; ?>
      </div>
     
      <?php endforeach; ?>
    </div>


    <?php else: ?>
    <p class="info"><?php echo $this->noItemsMsg?></p>
    <?php endif; ?>
    <?php 
    endif; ?>
    Last edited by charled; 03/09/2016 at 15:11.

  4. #4
    User zonky's Avatar
    Join Date
    11-29-11.
    Location
    Berlin
    Posts
    160

    Default

    you must work with this code "Quelltext mit Namespace:"

    like

    PHP Code:
    <?php 
    function getProjectsByCustomer($strAlias$format='html5')
    {
      
    $objMetaModel = \MetaModels\Factory::byTableName('mm_projects');
      
    $objFilter $objMetaModel->prepareFilter(10, array());
      
    $objFilter->addFilterRule(new \MetaModels\Filter\Rules\SearchAttribute($objMetaModel->getAttribute('customer'), $strAlias$objMetaModel->getAvailableLanguages()));
      
    $objItems $objMetaModel->findByFilter($objFilter);
      return 
    $objItems->parseAll($format$objMetaModel->getView(3));
    }
    ?>

  5. #5
    User
    Join Date
    04-01-10.
    Posts
    292

    Default

    Ok. What is the difference between with or without namespace ? What is namespace ?

  6. #6
    User zonky's Avatar
    Join Date
    11-29-11.
    Location
    Berlin
    Posts
    160

    Default

    PHP Code:
    // "old" fashion
    $objMetaModel MetaModelFactory::byTableName('mm_rencontres');

    // the new one
    $objMetaModel = \MetaModels\Factory::byTableName('mm_rencontres'); 
    look at http://metamodels.readthedocs.org/de...etamodels.html

  7. #7
    User
    Join Date
    04-01-10.
    Posts
    292

    Default

    Ok. No more error but Rencontres aren't listed.

    This code produces… nothing. Nothing displayed after line 23<h2>Rencontre avec un auteur</h2>.
    PHP Code:
    […]
    <div class="rencontres_liees">  
        <h2>Rencontre avec un auteur</h2>    
        <?php foreach (getRencontresParEvenement($arrItem['raw']['alias']) as $arrRencontres): ?>      
            <div class="rencontre">         
            <h3><?php echo $arrRencontres[$this->getFormat()]['intitule']; ?> </h3>         
            <p><?php echo $arrRencontres[$this->getFormat()]['description']; ?></p>      
            </div>    
        <?php endforeach; ?>
    </div>
    […]
    HTML result is :
    HTML Code:
    <div class="rencontres_liees">
        <h2>Rencontre avec un auteur</h2>
    </div>
    Last edited by charled; 03/09/2016 at 18:53.

  8. #8
    User zonky's Avatar
    Join Date
    11-29-11.
    Location
    Berlin
    Posts
    160

    Default

    look in your array with print_r(getRencontresParEvenement($arrItem['raw']['alias']))

    PHP Code:
    <?php if (count($this->data)): ?>
     
    <div class="evenement_detailview">
      <?php foreach ($this->data as $arrItem): ?> // the problem seems to be here (line 13)
     
      <div class="detailview">
        <h1 class="ce_headline"><?php echo $arrItem['text']['intitule']; ?></h1>
        <p class="description"><?php echo $arrItem['text']['description']; ?></p>
      </div>
     
      <div class="rencontres_liees">
        <h2>Rencontres</h2>
        <?php print_r(getRencontresParEvenement($arrItem['raw']['alias'])); ?>
      
        <div class="rencontre">
          <h3>
            <a href="{{env::path}}<?php echo $arrProjects['jumpTo']['url']; ?>">
              <?php echo $arrProjects[$this->getFormat()]['intitule']; ?> 
            </a>
          </h3>
          <?php echo $arrProjects[$this->getFormat()]['description']; ?>
        
        </div>
      
      <?php endforeach; ?>
      </div>
     
      <?php endforeach; ?>
    </div>

    <?php endif; ?>

  9. #9
    User
    Join Date
    04-01-10.
    Posts
    292

    Default

    Code:
    Array ( )
    This can't be more empty ;-))

  10. #10
    User zonky's Avatar
    Join Date
    11-29-11.
    Location
    Berlin
    Posts
    160

    Default

    your own function found nothing items...

    pls post your complete new template an we can try to debug your code...

  11. #11
    User
    Join Date
    04-01-10.
    Posts
    292

    Default

    Hi Zonky,

    I've found another way to dot it with a ce_mm_list based on mm_rencontres :
    Code:
    SELECT id FROM mm_rencontres
    WHERE lienRencontreEvenement =(SELECT id FROM mm_evenements
    WHERE alias={{param::get?name=auto_item}})
    AND rencontrePrincipale =1
    adapted from in http://metamodels.readthedocs.org/de...ustom-sql.html (last paragraph).

    I just had to search a little bit the right parameters of the "link" between the two tables so I suppose this could be the same problem in my former code. I have no more time to search for it for the moment but hope I could come back later as I'd like to understand it.

    Thanks.
    Last edited by charled; 03/10/2016 at 18:38.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •