We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25663 MODX Staff
    • 12,272 Posts
    Gotta love clients that happily take advantage of years of work on the framework but rationalize that giving back some code to the project for non-business-proprietary functionality makes sense. tongue
      Ryan Thrash, MODX Co-Founder
      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
      • 36571
      • 145 Posts
      @Taff

      The search function has nothing to do with TVs. I tried to implement TV Search (which is excellent, by the way) but found that it did not suit my purposes. So I built a snippet which performs a custom SQL query. I would be glad to post the code here, but my PHP skills are not amazing, so I am sure there are several bugs in it that I simply not noticed. Let me know if you’re interested.

      Shame about the client, but surely you modifications should fall under the GNU GPL, right?

      Section 5(c) Conveying Modified Source Versions
      "You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it."

      Although I am not sure, but I think that thanks to the original license the client can not prevent you from offering this back to the community.

      On the other hand, I may be completely wrong.

      @rthrash

      You will probably know more about this than I do.
        • 25663 MODX Staff
        • 12,272 Posts
        I’m not a lawyer so I don’t know buy your rationale makes sense. Regardless I tend to not get too worked up about stuff like that and figure that Karma will eventually sort things out.
          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
          • 29181
          • 480 Posts
          Your search function sounds very similar to how I implemented mine. Because I’m using a textfield to supply the term to search for, I looked online for any information regarding the risks involved etc...and found http://www.roscripts.com/PHP_search_engine-119.html which is what I based my search function on.

          I’m also not a lawyer, so I’m not sure about the rest either. I hope you understand that I don’t really want to tell them I’m going to release the ( also pretty minor PHP skills ) script contrary to their wishes, not least because they have a lot of say in an on-going project that pays my bills every month.

          I can however talk you through my approach and then if you have any questions about parts of it, I would be pleased to assist where I can.

          Pagination:

          I’m passing a variable called pag in the url, if it’s undefined or non-numeric the script defaults to 0

          I have a variable which defines how many pages to display either side of the current page.

          I then do
          $modx->db->query("SELECT id FROM ".$web_users);


          This could possibly be improved upon for speed? Using mysql_num_rows I now know how many users I have

          As described on the first page I have a this->Pagination which I divide the number of users by, to find out how many pages I am going to have.

          I need to keep note of the current page number too, which is nothing more than the value of "pag" divided by this->Pagination

          If the pageNumber - the number of pages we are displaying is greater than 1 we need to output arrows at the beginning.

          One to jump to the first page of pagination using $modx->documentIdentifier."&pag=0"

          And one to jump to the page before the first one visible. So say for example we are displaying 5 pages and are on page 12, it would link to page 6. This was the biggest nightmare of the entire script.

          $beforePaginationOutput.="<a class=\"jumpToOneless\" title=\"Jump to page ".($pageNumber-$numberDisplayed-1)."\" href=\"index.php?id=".$modx->documentIdentifier."&pag=".(($pageNumber-$numberDisplayed-1)*$this->Pagination-$this->Pagination)."\"><</a> ";


          The script after pagination works in exactly the same way (but reversed tongue)

          I then loop thru beginning at either 1 (if we arent at a page greater than numberDisplayed) otherwise at pageNumber - numberDisplayed

          for($i=$startIncr;$i<=$pageNumber;$i++){
          			$startPos = $i*$this->Pagination-$this->Pagination;
          			if($startPos !=$positionInList){
          			$output.=" <a href=\"index.php?id=".$modx->documentIdentifier."&pag=".$startPos."\">".$i."</a>";
          			}
          			else{
                                  //We've looped thru right up to the current page. 
                                  //You could also add a here class to the output if you wish
          			$output.=" ".$i;
          			}
          		}
          


          Similar code is then used for after the current page.

          All that is left now, is to query the database to grab the users to display on the current page.

          $fetchUsers = $modx->db->query("SELECT `username` FROM ".$web_users."LIMIT ".$positionInList.",".$this->Pagination);


          All we need to do now is output the data, which is easy using Scottys
          $this->FetchAll($fetchUsers)


          Cheers,
          Taff
            Adrian Lawley: www.adrianlawley.com
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Just because the GPL requires all distribution of derived works to be licensed GPL does not mean that it requires anyone to distribute their derived work. And that is even without exploring the question of whether a snippet or module is actually a "derived work", since they don’t actually incorporate any of the MODx core code but only use public API calls.

            You would definitely need to consult a lawyer before doing anything against the wishes of your employer; your work may well constitute a "work for hire", and in that case you would hold no rights to the work. If that is the case, they could possibly take legal action even in the case of your simply telling someone else what you did and how you did it. Again, you’d need a lawyer to unravel the specifics of your situation.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 29181
              • 480 Posts
              Those were my thoughts too, but they are OK with me outlining the steps I have taken.
                Adrian Lawley: www.adrianlawley.com
                • 36571
                • 145 Posts
                Thanks for the explanation Taff.

                I will give it a go.
                  • 22289
                  • 41 Posts
                  I’ve been throwing together a few simple hacks from various examples to try and make a paginated set of results for an eform2db query that returns a set of contacts that have filled out an eform. I’m about a hair’s breadth from finishing, but wonder if there isn’t some very basic aspect of modX’s ability to deal with php variables passed in URL strings that I’m missing. Here is some paginating code I’ve put together:
                  <?php
                  // Select all records
                  $dbase = 'mydatabase.table';
                  
                  // I'll query this later, but for now it's '51'
                  $docID = "51";
                  
                  
                  //This checks to see if there is a page number. If not, it will set it to page 1
                  if (!(isset($pagenum)))
                  {
                  $pagenum = 1;
                  }
                  
                  //Here we count the number of results
                  $contacts = $modx->db->select('*',$dbase) or die(mysql_error());
                  $rows = mysql_num_rows($contacts);
                  
                  
                  //This is the number of results displayed per page
                  $page_rows = 25;
                  
                  //This tells us the page number of our last page
                  $last = ceil($rows/$page_rows);
                  
                  //this makes sure the page number isn't below one, or more than our maximum pages
                  if ($pagenum < 1)
                  {
                  $pagenum = 1;
                  }
                  elseif ($pagenum > $last)
                  {
                  $pagenum = $last;
                  }
                  
                  //This sets the range to display in our query
                  $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
                  
                  //This is the query again, the same one... the only difference is to add $max into it
                  $contacts_p = mysql_query("SELECT * FROM $dbase $max") or die(mysql_error());
                  
                  		$output= "<ul id=\"contact\">";
                  
                  //This is where you display your query results
                  while($info = mysql_fetch_array( $contacts_p ))
                  {
                  				$id=$info['ID'];
                  				
                  				$firstname=$info['FIRST'];
                  				
                  				$lastname=$info['LAST'];
                  				
                  				
                  				$chunkArr = array(
                  				
                  					'contactid' => $id,
                  					'firstname' => $firstname,
                  					'lastname' => $lastname
                  					
                  				
                  				);
                  
                  // use a chunk to display the results
                  				$output .= $modx->parseChunk('mycontacts', $chunkArr, '[+', '+]');
                  
                  }
                  		$output .= "</ul>";
                  		$output .= "<p>";
                  		// This shows the user what page they are on, and the total number of pages
                  		$output .= " --Page $pagenum of $last-- <p>";
                  
                  
                  // First  check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page.
                  if ($pagenum == 1)
                  {
                  }
                  else
                  {
                  $output .= " <a href='{$_SERVER['PHP_SELF']}?id=$docID&pagenum=1'> <<-First</a> ";
                  $output .= " ";
                  $previous = $pagenum-1;
                  $output .= " <a href='{$_SERVER['PHP_SELF']}?id=$docID&pagenum=$previous'> <-Previous</a> ";
                  }
                  
                  //just a spacer
                  $output .= " ---- ";
                  
                  //This does the same as above, only checking if we are on the last page, and then generating the Next and Last links.
                  
                  // This is where the trouble is- I can set 'pagenum' in the code above, but passing it as a string in a URL does nothing...  it just resets the page at pagenum = 1-  even though the link appears correctly on the page
                  
                  if ($pagenum == $last)
                  {
                  }
                  else {
                  $next = $pagenum+1;
                  $output .= " <a href='{$_SERVER['PHP_SELF']}?id=$docID&pagenum=$next'>Next -></a> ";
                  $output .= " ";
                  $output .= " <a href='{$_SERVER['PHP_SELF']}?id=$docID&pagenum=$last'>Last ->></a> ";
                  }
                  
                  		return $output;
                  ?>
                  

                  I’ve been looking at the ditto snippet and the dittonmain class file as a guide, and see that it relies on a function I’ve unsuccessfully tried to incorporate called buildURL for it’s page number navigation, so I’ll keep looking at that. But if there is some simple fix or something I’m missing wherein the pagenum variable has to be declared in some special way...

                  My next line of thinking would be that this has somethign to do with my use of google friendly URLs,
                  where everything ends in ’.html’ but still, if Ditto can handle it I know that’s not ultimately the problem...
                    • 22289
                    • 41 Posts
                    ah ok... I think all I was missing was this at the beginning...:

                    $pagenum = $_GET['pagenum'];
                      • 29181
                      • 480 Posts
                      I’ve been looking at the ditto snippet and the dittonmain class file as a guide, and see that it relies on a function I’ve unsuccessfully tried to incorporate called buildURL for it’s page number navigation, so I’ll keep looking at that.

                      You may have some success with using makeURL. http://wiki.modxcms.com/index.php/API:makeUrl

                      Taff
                        Adrian Lawley: www.adrianlawley.com