2013-11-11

parse.com-php-library - Contributed with a function in Github

We are using parse.com as the server backend in a project. The administration interface is written in PHP so we are using parse.com-php-library to easily integrate with parse.com.
parse.com-php-library is open source and available on GitHub.

Today we needed a function to filter our records on a specific date in the database.
The most obvious way to solve it was to combine a call to whereGreaterThanOrEqualTo() with a call to whereLessThanOrEqualTo(), but it will not work since it will handle it as an OR query.

The solution was to add a new function to parseQuery.php:
public function whereBetweenOrEqualTo($key, $startValue, $endValue){
   if(isset($key) && isset($startValue) && isset($endValue)){
      $this->_query[$key] = array(
         '$gte' => $startValue,
         '$lte' => $endValue
      );
   }        
   else{
      $this->throwError('the $key, $startValue and $endValue parameters must be set when setting a "where" query method');                
   }
}

We could just have added it to our own parseQuery.php and continued to work, but since it is open source and on GitHub it is very easy to contribute to the original project.

  1. Fork the project you would like to contribute to - Go to the project at the GitHub web page and click the Fork button.
  2. Clone the code to your computer. There is an application for GitHub that will handle repositories on GitHub for you which will make cloning, committing and other tasks very easy.
  3. Make changes to the code.
  4. Commit your changes to your local repository. Use the GitHub application to make it easier.
  5. Push your changes to the remote server. It is called Sync in the GitHub application.
Your changes are now in your the repository that you forked. Make a pull request to let the original repository now that you have made some great additions and changes to the code.

  1. Go to your project and click Pull requests and then New pull request.
  2. Follow the instructions to create a pull request for your changes and write an informative comment: "Fixes #117. Query for between or equal to start and end value."
    Hash + issue number will automatically be linked to the issue number.
  3. If the owner of the original repository likes the changes he/she will add them to the repository.