We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17422
    • 225 Posts
    i upgrade to 2.0.5

    and ALL WORK

    :-) hihihih
      • 4172
      • 5,888 Posts
      thats nice.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 17422
        • 225 Posts
        a last question :

        how use custom table in a snippet ?

          • 17422
          • 225 Posts
          Hi,

          i try to use my custom table in snippet
          i to do this :
          $prefix = "modx_DbCustom_";
          $packageName = "salleConcert";
          $tablename = "salleConcert";
          $packagepath = $modx->getOption('core_path').'components/'.$packageName.'/';  
          $modelpath = $packagepath.'model/';
          $modx->addPackage($packageName,$modelpath,$prefix);
          $classname = $modx->$xdbedit->getClassName($tablename);
          $c = $modx->newQuery($classname);
          $dept='59';  
          $c->where(array($classname.'.dept' => $dept));
          $count = $modx->getCount($classname,$c);
          
          return 'Total'.$count; 


          but i have a problem with this line :
          $classname = $modx->$xdbedit->getClassName($tablename);

          how to do for retrieve the table ?




            • 17422
            • 225 Posts
            I found :

            in the snippet :
            $prefix = "modx_DbCustom_";
            $packageName = "salleConcert";
            $tablename = "salleConcert";
            $packagepath = $modx->getOption(’core_path’).’components/’.$packageName.’/’;
            $modelpath = $packagepath.’model/’;
            $schemapath = $modelpath.’schema/’;
            $schemafile = $schemapath.$packageName.’.mysql.schema.xml’;
            $manager= $modx->getManager();
            $generator= $manager->getGenerator();

            $modx->addPackage($packageName,$modelpath,$prefix);
            $classname = $generator->getClassName($tablename);
            $c = $modx->newQuery($classname);

            $dept=’59’;
            $c->where(array($classname.’.dept’ => $dept));
            $count = $modx->getCount($classname);
            return ’Total’.$count;​

              • 4172
              • 5,888 Posts
              you can try something like that:

              <?php
              
              
              $output = '';
              
              /* get default properties */
              
              $classname = $modx->getOption('classname',$scriptProperties,'News');
              $tpl = $modx->getOption('tpl',$scriptProperties,'news_item');
              $outerTpl = $modx->getOption('outerTpl',$scriptProperties,'news_outer');
              $noResults = $modx->getOption('noResults',$scriptProperties,'');
              
              $altRowCss = $modx->getOption('altRowCss',$scriptProperties,'quip-comment-alt');
              $dateFormat = $modx->getOption('dateFormat',$scriptProperties,'%b %d, %Y at %I:%M %p');
              
              $sortBy = $modx->getOption('sortBy',$scriptProperties,'id');
              $sortByAlias = $modx->getOption('sortByAlias',$scriptProperties,$classname);
              $sortDir = $modx->getOption('sortDir',$scriptProperties,'DESC');
              $limit = $modx->getOption('limit',$scriptProperties,25);
              $offset = $modx->getOption('offset',$scriptProperties,0);
              $totalVar = $modx->getOption('totalVar',$scriptProperties,'total');
              $orderBy = $modx->getOption('orderBy',$scriptProperties,'');
              
              $dept = $modx->getOption('dept',$scriptProperties,'');
              
              
              $c = $modx->newQuery($classname);
              
              /*
              $c->where(array(
                  'published' => 1,
              ));
              	
              $c->where(array(
                  'deleted' => 0,
              ));	
              */
              
              if (!empty($dept)){
              	$c->where(array($classname.'.dept' => $dept));
              }
              
              
              $count = $modx->getCount($classname,$c);
              $modx->setPlaceholder($totalVar, $count);
              $placeholders['total'] = $count;
              
              
              if (!empty($orderBy)) {
              $c->sortby($orderBy,'');
              $sortBy='';
              }
              
              if (!empty($sortBy)) {
              $c->sortby('`'.$sortByAlias.'`.`'.$sortBy.'`',$sortDir);
              }
              
              if (!empty($limit)) $c->limit($limit, $offset);
              //$c->prepare();echo $c->toSql();
              $objects = $modx->getCollection($classname,$c);
              
              
              /* iterate */
              
              $placeholders['items'] = '';
              $alt = false;
              
              if ($count > 0){
                  foreach ($objects as $object){
                      $objectArray = $object->toArray();
              		//echo '<pre>'.print_r($objectArray,1).'</pre>';
                      if ($alt)
                      {
                          $objectArray['alt'] = $altRowCss;
                      }
                      //$objectArray['createdon_format'] = strftime($dateFormat, strtotime($object->get('createdon')));
              
              		$placeholders['items'] .= $modx->getChunk($tpl, $objectArray);
                     
              		$alt = !$alt;
              		
                      //echo '<pre>'.print_r($objectArray,1).'</pre>';
                  }
                  $modx->toPlaceholders($placeholders, 'items');
              	//echo '<pre>'.print_r($placeholders,1).'</pre>';
                  if ($modx->getOption('useWrapper', $scriptProperties, true)){
                      $output = $modx->getChunk($outerTpl, $placeholders);
                  }
                  else $output = $placeholders['items'];
              
              
              }
              else{
              	$output=$noResults;
              }	
              
              return $output;
              
              
              ?>
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 17422
                • 225 Posts
                Hi Bruno,

                i don’t understand these lines :

                $modx->toPlaceholders($placeholders, ’items’);
                if ($modx->getOption(’useWrapper’, $scriptProperties, true)){
                $output = $modx->getChunk($outerTpl, $placeholders);
                }
                else $output = $placeholders[’items’];
                }


                just before these lines i have a good result with

                return $placeholders[’items’]


                  • 4172
                  • 5,888 Posts
                  you can have an outer-tpl (wrapper) with

                  [[+items]]

                  in it.

                  or use
                  &useWrapper=`0`
                  in your snippet-call for outputting without wrapper.

                  and, oh.. I forgot return $output, because I include that part(modded version) with my snippet.
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 17422
                    • 225 Posts
                    ok,

                    thansk a lot Bruno for all, i love xdbedit smiley

                    now i play with this smiley
                      • 17422
                      • 225 Posts
                      Hi Bruno,

                      i try to use xdbedit with this querying for show a doubloon in my table

                      in the file getlist i do this :

                      $rows=array();
                      if (!empty($showDoub)){
                      $stmt= $modx->query("SELECT *, COMPTEUR FROM modx_DbCustom_salleConcert t1, (SELECT nom, ville, COUNT( * ) AS COMPTEUR FROM modx_DbCustom_salleConcert GROUP BY nom HAVING COUNT( * ) >1 ) t2 WHERE t1.nom = t2.nom and t1.ville = t2.ville order by t1.nom ASC");
                      //$modx->log(modX::LOG_LEVEL_ERROR, "{$stmt} bugggg");
                      //return ;
                      
                      foreach ($stmt->fetchAll(PDO::FETCH_COLUMN, 1) as $row) {
                              $rows[]=$row->toArray();
                      
                          }
                      }else {
                      
                          $collection = $modx->getCollection($classname, $c);
                          $rows=array();
                          foreach ($collection as $row){
                              $rows[]=$row->toArray();
                          }
                      }
                      



                      i’m sure for myt requete, but i have no result and no bug
                      have just : loading ....