diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..422e619 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true + +[*.php] +indent_style = tab +indent_size = 2 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 836713a..9437702 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +api/vendor/ + # OS generated files .DS_Store .DS_Store? @@ -15,4 +17,4 @@ bower_components .sass-cache *.css.map build/ -dist/ +dist/ \ No newline at end of file diff --git a/README.md b/README.md index c417374..55ec010 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,41 @@ Rules Engine and API for Feeding America / Foodbank Project. PHP and MySQL. +## API + +Everything is located in the `/api` directory. You will need [composer](https://getcomposer.org/) installed. + +The entire API runs from `index.php`. This way everything routes to http://foodbankurl.com/api/. + +Propel was used to generate the ORM. The ORM lives under: + +``` +/api + /generated-classes # All of the main ORM classes used in our application. + /generated-conf # Configuration for the ORM + /generated-sql # Explicit creation queries for our DB structure. +``` + +The Routing is handled through the `routes` folder, and are [Slim](http://www.slimframework.com/) routes. + +### Development + +``` +cd api +composer install +php -S localhost:8000 +``` + +A `Foodbank.postman_collection.json` file has been added. You can import this to Postman to test routes. + +### Helpful URLs + +[Propel ORM Calls](http://propelorm.org/documentation/03-basic-crud.html) + +[PHPMyAdmin](http://www.develop.digitalmediauconn.org/phpmyadmin/) + +[Routing with Slim](http://www.slimframework.com/docs/objects/router.html#how-to-create-routes) + ## Contact [Joel Salisbury](mailto:joel@uconn.edu) - Faculty Advisor diff --git a/api/.htaccess b/api/.htaccess new file mode 100644 index 0000000..11b28de --- /dev/null +++ b/api/.htaccess @@ -0,0 +1,4 @@ +RewriteEngine On +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^ index.php [QSA,L] \ No newline at end of file diff --git a/api/Foodbank.postman_collection.json b/api/Foodbank.postman_collection.json new file mode 100644 index 0000000..8a9179b --- /dev/null +++ b/api/Foodbank.postman_collection.json @@ -0,0 +1,25 @@ +{ + "variables": [], + "info": { + "name": "Foodbank", + "_postman_id": "a8e172cf-8f6b-3abf-a0ee-90832eecb2bf", + "description": "", + "schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json" + }, + "item": [ + { + "name": "GET All Categories", + "request": { + "url": "http://localhost:8000/category/all", + "method": "GET", + "header": [], + "body": { + "mode": "formdata", + "formdata": [] + }, + "description": "" + }, + "response": [] + } + ] +} \ No newline at end of file diff --git a/api/composer.json b/api/composer.json new file mode 100644 index 0000000..2b1a290 --- /dev/null +++ b/api/composer.json @@ -0,0 +1,14 @@ +{ + "name": "brian/foodbank", + "type": "project", + "authors": [ + { + "name": "briankelleher", + "email": "bkelleher4@gmail.com" + } + ], + "require": { + "propel/propel": "~2.0@dev", + "slim/slim": "~3.0" + } +} diff --git a/api/composer.lock b/api/composer.lock new file mode 100644 index 0000000..4cf48b4 --- /dev/null +++ b/api/composer.lock @@ -0,0 +1,883 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "content-hash": "bcabdd706f796d0db77a591eea6cbe9b", + "packages": [ + { + "name": "container-interop/container-interop", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/container-interop/container-interop.git", + "reference": "fc08354828f8fd3245f77a66b9e23a6bca48297e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/container-interop/container-interop/zipball/fc08354828f8fd3245f77a66b9e23a6bca48297e", + "reference": "fc08354828f8fd3245f77a66b9e23a6bca48297e", + "shasum": "" + }, + "type": "library", + "autoload": { + "psr-4": { + "Interop\\Container\\": "src/Interop/Container/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Promoting the interoperability of container objects (DIC, SL, etc.)", + "time": "2014-12-30T15:22:37+00:00" + }, + { + "name": "nikic/fast-route", + "version": "v1.0.1", + "source": { + "type": "git", + "url": "https://github.com/nikic/FastRoute.git", + "reference": "8ea928195fa9b907f0d6e48312d323c1a13cc2af" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/FastRoute/zipball/8ea928195fa9b907f0d6e48312d323c1a13cc2af", + "reference": "8ea928195fa9b907f0d6e48312d323c1a13cc2af", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "FastRoute\\": "src/" + }, + "files": [ + "src/functions.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov", + "email": "nikic@php.net" + } + ], + "description": "Fast request router for PHP", + "keywords": [ + "router", + "routing" + ], + "time": "2016-06-12T19:08:51+00:00" + }, + { + "name": "pimple/pimple", + "version": "v3.0.2", + "source": { + "type": "git", + "url": "https://github.com/silexphp/Pimple.git", + "reference": "a30f7d6e57565a2e1a316e1baf2a483f788b258a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/silexphp/Pimple/zipball/a30f7d6e57565a2e1a316e1baf2a483f788b258a", + "reference": "a30f7d6e57565a2e1a316e1baf2a483f788b258a", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Pimple": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Pimple, a simple Dependency Injection Container", + "homepage": "http://pimple.sensiolabs.org", + "keywords": [ + "container", + "dependency injection" + ], + "time": "2015-09-11T15:10:35+00:00" + }, + { + "name": "propel/propel", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/propelorm/Propel2.git", + "reference": "58d57adc9509e47af757b00458d83c24b273fbfa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/propelorm/Propel2/zipball/58d57adc9509e47af757b00458d83c24b273fbfa", + "reference": "58d57adc9509e47af757b00458d83c24b273fbfa", + "shasum": "" + }, + "require": { + "php": ">=5.5", + "psr/log": "~1.0", + "symfony/config": "~2.3||~3.0", + "symfony/console": "~2.3||~3.0", + "symfony/filesystem": "~2.3||~3.0", + "symfony/finder": "~2.3||~3.0", + "symfony/validator": "~2.3||~3.0", + "symfony/yaml": "~2.3||~3.0" + }, + "require-dev": { + "behat/behat": "~2.4", + "monolog/monolog": "~1.3", + "phpunit/phpunit": "~4.0||~5.0" + }, + "suggest": { + "monolog/monolog": "The recommended logging library to use with Propel." + }, + "bin": [ + "bin/propel" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "psr-0": { + "Propel": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "William Durand", + "email": "william.durand1@gmail.com" + } + ], + "description": "Propel2 is an open-source Object-Relational Mapping (ORM) for PHP 5.5 and up.", + "homepage": "http://www.propelorm.org/", + "keywords": [ + "Active Record", + "orm", + "persistence" + ], + "time": "2016-10-15 23:21:13" + }, + { + "name": "psr/http-message", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2016-08-06T14:39:51+00:00" + }, + { + "name": "psr/log", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2016-10-10T12:19:37+00:00" + }, + { + "name": "slim/slim", + "version": "3.5.0", + "source": { + "type": "git", + "url": "https://github.com/slimphp/Slim.git", + "reference": "184352bc1913d7ba552ab4131d62f4730ddb0893" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/slimphp/Slim/zipball/184352bc1913d7ba552ab4131d62f4730ddb0893", + "reference": "184352bc1913d7ba552ab4131d62f4730ddb0893", + "shasum": "" + }, + "require": { + "container-interop/container-interop": "^1.1", + "nikic/fast-route": "^1.0", + "php": ">=5.5.0", + "pimple/pimple": "^3.0", + "psr/http-message": "^1.0" + }, + "provide": { + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0", + "squizlabs/php_codesniffer": "^2.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Slim\\": "Slim" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Rob Allen", + "email": "rob@akrabat.com", + "homepage": "http://akrabat.com" + }, + { + "name": "Josh Lockhart", + "email": "hello@joshlockhart.com", + "homepage": "https://joshlockhart.com" + }, + { + "name": "Gabriel Manricks", + "email": "gmanricks@me.com", + "homepage": "http://gabrielmanricks.com" + }, + { + "name": "Andrew Smith", + "email": "a.smith@silentworks.co.uk", + "homepage": "http://silentworks.co.uk" + } + ], + "description": "Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs", + "homepage": "http://slimframework.com", + "keywords": [ + "api", + "framework", + "micro", + "router" + ], + "time": "2016-07-26T15:12:13+00:00" + }, + { + "name": "symfony/config", + "version": "v3.1.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/config.git", + "reference": "949e7e846743a7f9e46dc50eb639d5fde1f53341" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/config/zipball/949e7e846743a7f9e46dc50eb639d5fde1f53341", + "reference": "949e7e846743a7f9e46dc50eb639d5fde1f53341", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "symfony/filesystem": "~2.8|~3.0" + }, + "suggest": { + "symfony/yaml": "To use the yaml reference dumper" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Config\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Config Component", + "homepage": "https://symfony.com", + "time": "2016-09-25T08:27:07+00:00" + }, + { + "name": "symfony/console", + "version": "v3.1.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/console.git", + "reference": "c99da1119ae61e15de0e4829196b9fba6f73d065" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/console/zipball/c99da1119ae61e15de0e4829196b9fba6f73d065", + "reference": "c99da1119ae61e15de0e4829196b9fba6f73d065", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "symfony/debug": "~2.8|~3.0", + "symfony/polyfill-mbstring": "~1.0" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/event-dispatcher": "~2.8|~3.0", + "symfony/process": "~2.8|~3.0" + }, + "suggest": { + "psr/log": "For using the console logger", + "symfony/event-dispatcher": "", + "symfony/process": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Console\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Console Component", + "homepage": "https://symfony.com", + "time": "2016-10-06T01:44:51+00:00" + }, + { + "name": "symfony/debug", + "version": "v3.1.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/debug.git", + "reference": "e2b3f74a67fc928adc3c1b9027f73e1bc01190a8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/debug/zipball/e2b3f74a67fc928adc3c1b9027f73e1bc01190a8", + "reference": "e2b3f74a67fc928adc3c1b9027f73e1bc01190a8", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "psr/log": "~1.0" + }, + "conflict": { + "symfony/http-kernel": ">=2.3,<2.3.24|~2.4.0|>=2.5,<2.5.9|>=2.6,<2.6.2" + }, + "require-dev": { + "symfony/class-loader": "~2.8|~3.0", + "symfony/http-kernel": "~2.8|~3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Debug\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Debug Component", + "homepage": "https://symfony.com", + "time": "2016-09-06T11:02:40+00:00" + }, + { + "name": "symfony/filesystem", + "version": "v3.1.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/filesystem.git", + "reference": "0565b61bf098cb4dc09f4f103f033138ae4f42c6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/0565b61bf098cb4dc09f4f103f033138ae4f42c6", + "reference": "0565b61bf098cb4dc09f4f103f033138ae4f42c6", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Filesystem\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Filesystem Component", + "homepage": "https://symfony.com", + "time": "2016-10-18T04:30:12+00:00" + }, + { + "name": "symfony/finder", + "version": "v3.1.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/finder.git", + "reference": "205b5ffbb518a98ba2ae60a52656c4a31ab00c6f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/finder/zipball/205b5ffbb518a98ba2ae60a52656c4a31ab00c6f", + "reference": "205b5ffbb518a98ba2ae60a52656c4a31ab00c6f", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Finder\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Finder Component", + "homepage": "https://symfony.com", + "time": "2016-09-28T00:11:12+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.2.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "dff51f72b0706335131b00a7f49606168c582594" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/dff51f72b0706335131b00a7f49606168c582594", + "reference": "dff51f72b0706335131b00a7f49606168c582594", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "time": "2016-05-18T14:26:46+00:00" + }, + { + "name": "symfony/translation", + "version": "v3.1.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/translation.git", + "reference": "ff1285087397d2f64041b35e591f3025881c90cd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/translation/zipball/ff1285087397d2f64041b35e591f3025881c90cd", + "reference": "ff1285087397d2f64041b35e591f3025881c90cd", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "symfony/config": "<2.8" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~2.8|~3.0", + "symfony/intl": "~2.8|~3.0", + "symfony/yaml": "~2.8|~3.0" + }, + "suggest": { + "psr/log": "To use logging capability in translator", + "symfony/config": "", + "symfony/yaml": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Translation\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Translation Component", + "homepage": "https://symfony.com", + "time": "2016-10-18T04:30:12+00:00" + }, + { + "name": "symfony/validator", + "version": "v3.1.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/validator.git", + "reference": "709dffa9193ee2b88e1fb1760cc0ba5780f1a8b2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/validator/zipball/709dffa9193ee2b88e1fb1760cc0ba5780f1a8b2", + "reference": "709dffa9193ee2b88e1fb1760cc0ba5780f1a8b2", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "symfony/polyfill-mbstring": "~1.0", + "symfony/translation": "~2.8|~3.0" + }, + "require-dev": { + "doctrine/annotations": "~1.0", + "doctrine/cache": "~1.0", + "egulias/email-validator": "~1.2,>=1.2.1", + "symfony/cache": "~3.1", + "symfony/config": "~2.8|~3.0", + "symfony/expression-language": "~2.8|~3.0", + "symfony/http-foundation": "~2.8|~3.0", + "symfony/intl": "~2.8|~3.0", + "symfony/yaml": "~2.8|~3.0" + }, + "suggest": { + "doctrine/annotations": "For using the annotation mapping. You will also need doctrine/cache.", + "doctrine/cache": "For using the default cached annotation reader and metadata cache.", + "egulias/email-validator": "Strict (RFC compliant) email validation", + "psr/cache-implementation": "For using the metadata cache.", + "symfony/config": "", + "symfony/expression-language": "For using the Expression validator", + "symfony/http-foundation": "", + "symfony/intl": "", + "symfony/property-access": "For using the Expression validator", + "symfony/yaml": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Validator\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Validator Component", + "homepage": "https://symfony.com", + "time": "2016-10-19T22:38:53+00:00" + }, + { + "name": "symfony/yaml", + "version": "v3.1.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/yaml.git", + "reference": "7ff51b06c6c3d5cc6686df69004a42c69df09e27" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/yaml/zipball/7ff51b06c6c3d5cc6686df69004a42c69df09e27", + "reference": "7ff51b06c6c3d5cc6686df69004a42c69df09e27", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Yaml Component", + "homepage": "https://symfony.com", + "time": "2016-10-24T18:41:13+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": { + "propel/propel": 20 + }, + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/api/config.php b/api/config.php new file mode 100644 index 0000000..c07ab83 --- /dev/null +++ b/api/config.php @@ -0,0 +1,4 @@ +modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another Category instance. If + * obj is an instance of Category, delegates to + * equals(Category). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + if (!$obj instanceof static) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return $this|Category The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + $cls = new \ReflectionClass($this); + $propertyNames = []; + $serializableProperties = array_diff($cls->getProperties(), $cls->getProperties(\ReflectionProperty::IS_STATIC)); + + foreach($serializableProperties as $property) { + $propertyNames[] = $property->getName(); + } + + return $propertyNames; + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * Get the [name] column value. + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return $this|\Category The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[CategoryTableMap::COL_ID] = true; + } + + return $this; + } // setId() + + /** + * Set the value of [name] column. + * + * @param string $v new value + * @return $this|\Category The current object (for fluent API support) + */ + public function setName($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->name !== $v) { + $this->name = $v; + $this->modifiedColumns[CategoryTableMap::COL_NAME] = true; + } + + return $this; + } // setName() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : CategoryTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : CategoryTableMap::translateFieldName('Name', TableMap::TYPE_PHPNAME, $indexType)]; + $this->name = (null !== $col) ? (string) $col : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 2; // 2 = CategoryTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException(sprintf('Error populating %s object', '\\Category'), 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(CategoryTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildCategoryQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->collCategoryRankNutrients = null; + + $this->collFoods = null; + + $this->collSubcategories = null; + + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see Category::setDeleted() + * @see Category::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(CategoryTableMap::DATABASE_NAME); + } + + $con->transaction(function () use ($con) { + $deleteQuery = ChildCategoryQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $this->setDeleted(true); + } + }); + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(CategoryTableMap::DATABASE_NAME); + } + + return $con->transaction(function () use ($con) { + $ret = $this->preSave($con); + $isInsert = $this->isNew(); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + } else { + $ret = $ret && $this->preUpdate($con); + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + CategoryTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + + return $affectedRows; + }); + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + $affectedRows += 1; + } else { + $affectedRows += $this->doUpdate($con); + } + $this->resetModified(); + } + + if ($this->categoryRankNutrientsScheduledForDeletion !== null) { + if (!$this->categoryRankNutrientsScheduledForDeletion->isEmpty()) { + \CategoryRankNutrientQuery::create() + ->filterByPrimaryKeys($this->categoryRankNutrientsScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); + $this->categoryRankNutrientsScheduledForDeletion = null; + } + } + + if ($this->collCategoryRankNutrients !== null) { + foreach ($this->collCategoryRankNutrients as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + + if ($this->foodsScheduledForDeletion !== null) { + if (!$this->foodsScheduledForDeletion->isEmpty()) { + foreach ($this->foodsScheduledForDeletion as $food) { + // need to save related object because we set the relation to null + $food->save($con); + } + $this->foodsScheduledForDeletion = null; + } + } + + if ($this->collFoods !== null) { + foreach ($this->collFoods as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + + if ($this->subcategoriesScheduledForDeletion !== null) { + if (!$this->subcategoriesScheduledForDeletion->isEmpty()) { + foreach ($this->subcategoriesScheduledForDeletion as $subcategory) { + // need to save related object because we set the relation to null + $subcategory->save($con); + } + $this->subcategoriesScheduledForDeletion = null; + } + } + + if ($this->collSubcategories !== null) { + foreach ($this->collSubcategories as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + $this->modifiedColumns[CategoryTableMap::COL_ID] = true; + if (null !== $this->id) { + throw new PropelException('Cannot insert a value for auto-increment primary key (' . CategoryTableMap::COL_ID . ')'); + } + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(CategoryTableMap::COL_ID)) { + $modifiedColumns[':p' . $index++] = 'id'; + } + if ($this->isColumnModified(CategoryTableMap::COL_NAME)) { + $modifiedColumns[':p' . $index++] = 'name'; + } + + $sql = sprintf( + 'INSERT INTO Category (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case 'id': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case 'name': + $stmt->bindValue($identifier, $this->name, PDO::PARAM_STR); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + try { + $pk = $con->lastInsertId(); + } catch (Exception $e) { + throw new PropelException('Unable to get autoincrement id.', 0, $e); + } + $this->setId($pk); + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = CategoryTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getName(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + + if (isset($alreadyDumpedObjects['Category'][$this->hashCode()])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['Category'][$this->hashCode()] = true; + $keys = CategoryTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getName(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->collCategoryRankNutrients) { + + switch ($keyType) { + case TableMap::TYPE_CAMELNAME: + $key = 'categoryRankNutrients'; + break; + case TableMap::TYPE_FIELDNAME: + $key = 'Category_Rank_Nutrients'; + break; + default: + $key = 'CategoryRankNutrients'; + } + + $result[$key] = $this->collCategoryRankNutrients->toArray(null, false, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } + if (null !== $this->collFoods) { + + switch ($keyType) { + case TableMap::TYPE_CAMELNAME: + $key = 'foods'; + break; + case TableMap::TYPE_FIELDNAME: + $key = 'Foods'; + break; + default: + $key = 'Foods'; + } + + $result[$key] = $this->collFoods->toArray(null, false, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } + if (null !== $this->collSubcategories) { + + switch ($keyType) { + case TableMap::TYPE_CAMELNAME: + $key = 'subcategories'; + break; + case TableMap::TYPE_FIELDNAME: + $key = 'Subcategories'; + break; + default: + $key = 'Subcategories'; + } + + $result[$key] = $this->collSubcategories->toArray(null, false, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return $this|\Category + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = CategoryTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return $this|\Category + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setName($value); + break; + } // switch() + + return $this; + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = CategoryTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) { + $this->setId($arr[$keys[0]]); + } + if (array_key_exists($keys[1], $arr)) { + $this->setName($arr[$keys[1]]); + } + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * @param string $keyType The type of keys the array uses. + * + * @return $this|\Category The current object, for fluid interface + */ + public function importFrom($parser, $data, $keyType = TableMap::TYPE_PHPNAME) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), $keyType); + + return $this; + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(CategoryTableMap::DATABASE_NAME); + + if ($this->isColumnModified(CategoryTableMap::COL_ID)) { + $criteria->add(CategoryTableMap::COL_ID, $this->id); + } + if ($this->isColumnModified(CategoryTableMap::COL_NAME)) { + $criteria->add(CategoryTableMap::COL_NAME, $this->name); + } + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @throws LogicException if no primary key is defined + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = ChildCategoryQuery::create(); + $criteria->add(CategoryTableMap::COL_ID, $this->id); + + return $criteria; + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + $validPk = null !== $this->getId(); + + $validPrimaryKeyFKs = 0; + $primaryKeyFKs = []; + + if ($validPk) { + return crc32(json_encode($this->getPrimaryKey(), JSON_UNESCAPED_UNICODE)); + } elseif ($validPrimaryKeyFKs) { + return crc32(json_encode($primaryKeyFKs, JSON_UNESCAPED_UNICODE)); + } + + return spl_object_hash($this); + } + + /** + * Returns the primary key for this object (row). + * @return int + */ + public function getPrimaryKey() + { + return $this->getId(); + } + + /** + * Generic method to set the primary key (id column). + * + * @param int $key Primary key. + * @return void + */ + public function setPrimaryKey($key) + { + $this->setId($key); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + return null === $this->getId(); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \Category (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setName($this->getName()); + + if ($deepCopy) { + // important: temporarily setNew(false) because this affects the behavior of + // the getter/setter methods for fkey referrer objects. + $copyObj->setNew(false); + + foreach ($this->getCategoryRankNutrients() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addCategoryRankNutrient($relObj->copy($deepCopy)); + } + } + + foreach ($this->getFoods() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addFood($relObj->copy($deepCopy)); + } + } + + foreach ($this->getSubcategories() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addSubcategory($relObj->copy($deepCopy)); + } + } + + } // if ($deepCopy) + + if ($makeNew) { + $copyObj->setNew(true); + $copyObj->setId(NULL); // this is a auto-increment column, so set to default value + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \Category Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + + /** + * Initializes a collection based on the name of a relation. + * Avoids crafting an 'init[$relationName]s' method name + * that wouldn't work when StandardEnglishPluralizer is used. + * + * @param string $relationName The name of the relation to initialize + * @return void + */ + public function initRelation($relationName) + { + if ('CategoryRankNutrient' == $relationName) { + return $this->initCategoryRankNutrients(); + } + if ('Food' == $relationName) { + return $this->initFoods(); + } + if ('Subcategory' == $relationName) { + return $this->initSubcategories(); + } + } + + /** + * Clears out the collCategoryRankNutrients collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addCategoryRankNutrients() + */ + public function clearCategoryRankNutrients() + { + $this->collCategoryRankNutrients = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collCategoryRankNutrients collection loaded partially. + */ + public function resetPartialCategoryRankNutrients($v = true) + { + $this->collCategoryRankNutrientsPartial = $v; + } + + /** + * Initializes the collCategoryRankNutrients collection. + * + * By default this just sets the collCategoryRankNutrients collection to an empty array (like clearcollCategoryRankNutrients()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initCategoryRankNutrients($overrideExisting = true) + { + if (null !== $this->collCategoryRankNutrients && !$overrideExisting) { + return; + } + + $collectionClassName = CategoryRankNutrientTableMap::getTableMap()->getCollectionClassName(); + + $this->collCategoryRankNutrients = new $collectionClassName; + $this->collCategoryRankNutrients->setModel('\CategoryRankNutrient'); + } + + /** + * Gets an array of ChildCategoryRankNutrient objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildCategory is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return ObjectCollection|ChildCategoryRankNutrient[] List of ChildCategoryRankNutrient objects + * @throws PropelException + */ + public function getCategoryRankNutrients(Criteria $criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collCategoryRankNutrientsPartial && !$this->isNew(); + if (null === $this->collCategoryRankNutrients || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCategoryRankNutrients) { + // return empty collection + $this->initCategoryRankNutrients(); + } else { + $collCategoryRankNutrients = ChildCategoryRankNutrientQuery::create(null, $criteria) + ->filterByCategory($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collCategoryRankNutrientsPartial && count($collCategoryRankNutrients)) { + $this->initCategoryRankNutrients(false); + + foreach ($collCategoryRankNutrients as $obj) { + if (false == $this->collCategoryRankNutrients->contains($obj)) { + $this->collCategoryRankNutrients->append($obj); + } + } + + $this->collCategoryRankNutrientsPartial = true; + } + + return $collCategoryRankNutrients; + } + + if ($partial && $this->collCategoryRankNutrients) { + foreach ($this->collCategoryRankNutrients as $obj) { + if ($obj->isNew()) { + $collCategoryRankNutrients[] = $obj; + } + } + } + + $this->collCategoryRankNutrients = $collCategoryRankNutrients; + $this->collCategoryRankNutrientsPartial = false; + } + } + + return $this->collCategoryRankNutrients; + } + + /** + * Sets a collection of ChildCategoryRankNutrient objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $categoryRankNutrients A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return $this|ChildCategory The current object (for fluent API support) + */ + public function setCategoryRankNutrients(Collection $categoryRankNutrients, ConnectionInterface $con = null) + { + /** @var ChildCategoryRankNutrient[] $categoryRankNutrientsToDelete */ + $categoryRankNutrientsToDelete = $this->getCategoryRankNutrients(new Criteria(), $con)->diff($categoryRankNutrients); + + + $this->categoryRankNutrientsScheduledForDeletion = $categoryRankNutrientsToDelete; + + foreach ($categoryRankNutrientsToDelete as $categoryRankNutrientRemoved) { + $categoryRankNutrientRemoved->setCategory(null); + } + + $this->collCategoryRankNutrients = null; + foreach ($categoryRankNutrients as $categoryRankNutrient) { + $this->addCategoryRankNutrient($categoryRankNutrient); + } + + $this->collCategoryRankNutrients = $categoryRankNutrients; + $this->collCategoryRankNutrientsPartial = false; + + return $this; + } + + /** + * Returns the number of related CategoryRankNutrient objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related CategoryRankNutrient objects. + * @throws PropelException + */ + public function countCategoryRankNutrients(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collCategoryRankNutrientsPartial && !$this->isNew(); + if (null === $this->collCategoryRankNutrients || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCategoryRankNutrients) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getCategoryRankNutrients()); + } + + $query = ChildCategoryRankNutrientQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByCategory($this) + ->count($con); + } + + return count($this->collCategoryRankNutrients); + } + + /** + * Method called to associate a ChildCategoryRankNutrient object to this object + * through the ChildCategoryRankNutrient foreign key attribute. + * + * @param ChildCategoryRankNutrient $l ChildCategoryRankNutrient + * @return $this|\Category The current object (for fluent API support) + */ + public function addCategoryRankNutrient(ChildCategoryRankNutrient $l) + { + if ($this->collCategoryRankNutrients === null) { + $this->initCategoryRankNutrients(); + $this->collCategoryRankNutrientsPartial = true; + } + + if (!$this->collCategoryRankNutrients->contains($l)) { + $this->doAddCategoryRankNutrient($l); + + if ($this->categoryRankNutrientsScheduledForDeletion and $this->categoryRankNutrientsScheduledForDeletion->contains($l)) { + $this->categoryRankNutrientsScheduledForDeletion->remove($this->categoryRankNutrientsScheduledForDeletion->search($l)); + } + } + + return $this; + } + + /** + * @param ChildCategoryRankNutrient $categoryRankNutrient The ChildCategoryRankNutrient object to add. + */ + protected function doAddCategoryRankNutrient(ChildCategoryRankNutrient $categoryRankNutrient) + { + $this->collCategoryRankNutrients[]= $categoryRankNutrient; + $categoryRankNutrient->setCategory($this); + } + + /** + * @param ChildCategoryRankNutrient $categoryRankNutrient The ChildCategoryRankNutrient object to remove. + * @return $this|ChildCategory The current object (for fluent API support) + */ + public function removeCategoryRankNutrient(ChildCategoryRankNutrient $categoryRankNutrient) + { + if ($this->getCategoryRankNutrients()->contains($categoryRankNutrient)) { + $pos = $this->collCategoryRankNutrients->search($categoryRankNutrient); + $this->collCategoryRankNutrients->remove($pos); + if (null === $this->categoryRankNutrientsScheduledForDeletion) { + $this->categoryRankNutrientsScheduledForDeletion = clone $this->collCategoryRankNutrients; + $this->categoryRankNutrientsScheduledForDeletion->clear(); + } + $this->categoryRankNutrientsScheduledForDeletion[]= clone $categoryRankNutrient; + $categoryRankNutrient->setCategory(null); + } + + return $this; + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Category is new, it will return + * an empty collection; or if this Category has previously + * been saved, it will retrieve related CategoryRankNutrients from storage. + * + * This method is protected by default in order to keep the public + * api reasonable. You can provide public methods for those you + * actually need in Category. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) + * @return ObjectCollection|ChildCategoryRankNutrient[] List of ChildCategoryRankNutrient objects + */ + public function getCategoryRankNutrientsJoinNutrient(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCategoryRankNutrientQuery::create(null, $criteria); + $query->joinWith('Nutrient', $joinBehavior); + + return $this->getCategoryRankNutrients($query, $con); + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Category is new, it will return + * an empty collection; or if this Category has previously + * been saved, it will retrieve related CategoryRankNutrients from storage. + * + * This method is protected by default in order to keep the public + * api reasonable. You can provide public methods for those you + * actually need in Category. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) + * @return ObjectCollection|ChildCategoryRankNutrient[] List of ChildCategoryRankNutrient objects + */ + public function getCategoryRankNutrientsJoinRank(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCategoryRankNutrientQuery::create(null, $criteria); + $query->joinWith('Rank', $joinBehavior); + + return $this->getCategoryRankNutrients($query, $con); + } + + /** + * Clears out the collFoods collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addFoods() + */ + public function clearFoods() + { + $this->collFoods = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collFoods collection loaded partially. + */ + public function resetPartialFoods($v = true) + { + $this->collFoodsPartial = $v; + } + + /** + * Initializes the collFoods collection. + * + * By default this just sets the collFoods collection to an empty array (like clearcollFoods()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initFoods($overrideExisting = true) + { + if (null !== $this->collFoods && !$overrideExisting) { + return; + } + + $collectionClassName = FoodTableMap::getTableMap()->getCollectionClassName(); + + $this->collFoods = new $collectionClassName; + $this->collFoods->setModel('\Food'); + } + + /** + * Gets an array of ChildFood objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildCategory is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return ObjectCollection|ChildFood[] List of ChildFood objects + * @throws PropelException + */ + public function getFoods(Criteria $criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collFoodsPartial && !$this->isNew(); + if (null === $this->collFoods || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collFoods) { + // return empty collection + $this->initFoods(); + } else { + $collFoods = ChildFoodQuery::create(null, $criteria) + ->filterByCategory($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collFoodsPartial && count($collFoods)) { + $this->initFoods(false); + + foreach ($collFoods as $obj) { + if (false == $this->collFoods->contains($obj)) { + $this->collFoods->append($obj); + } + } + + $this->collFoodsPartial = true; + } + + return $collFoods; + } + + if ($partial && $this->collFoods) { + foreach ($this->collFoods as $obj) { + if ($obj->isNew()) { + $collFoods[] = $obj; + } + } + } + + $this->collFoods = $collFoods; + $this->collFoodsPartial = false; + } + } + + return $this->collFoods; + } + + /** + * Sets a collection of ChildFood objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $foods A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return $this|ChildCategory The current object (for fluent API support) + */ + public function setFoods(Collection $foods, ConnectionInterface $con = null) + { + /** @var ChildFood[] $foodsToDelete */ + $foodsToDelete = $this->getFoods(new Criteria(), $con)->diff($foods); + + + $this->foodsScheduledForDeletion = $foodsToDelete; + + foreach ($foodsToDelete as $foodRemoved) { + $foodRemoved->setCategory(null); + } + + $this->collFoods = null; + foreach ($foods as $food) { + $this->addFood($food); + } + + $this->collFoods = $foods; + $this->collFoodsPartial = false; + + return $this; + } + + /** + * Returns the number of related Food objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related Food objects. + * @throws PropelException + */ + public function countFoods(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collFoodsPartial && !$this->isNew(); + if (null === $this->collFoods || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collFoods) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getFoods()); + } + + $query = ChildFoodQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByCategory($this) + ->count($con); + } + + return count($this->collFoods); + } + + /** + * Method called to associate a ChildFood object to this object + * through the ChildFood foreign key attribute. + * + * @param ChildFood $l ChildFood + * @return $this|\Category The current object (for fluent API support) + */ + public function addFood(ChildFood $l) + { + if ($this->collFoods === null) { + $this->initFoods(); + $this->collFoodsPartial = true; + } + + if (!$this->collFoods->contains($l)) { + $this->doAddFood($l); + + if ($this->foodsScheduledForDeletion and $this->foodsScheduledForDeletion->contains($l)) { + $this->foodsScheduledForDeletion->remove($this->foodsScheduledForDeletion->search($l)); + } + } + + return $this; + } + + /** + * @param ChildFood $food The ChildFood object to add. + */ + protected function doAddFood(ChildFood $food) + { + $this->collFoods[]= $food; + $food->setCategory($this); + } + + /** + * @param ChildFood $food The ChildFood object to remove. + * @return $this|ChildCategory The current object (for fluent API support) + */ + public function removeFood(ChildFood $food) + { + if ($this->getFoods()->contains($food)) { + $pos = $this->collFoods->search($food); + $this->collFoods->remove($pos); + if (null === $this->foodsScheduledForDeletion) { + $this->foodsScheduledForDeletion = clone $this->collFoods; + $this->foodsScheduledForDeletion->clear(); + } + $this->foodsScheduledForDeletion[]= $food; + $food->setCategory(null); + } + + return $this; + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Category is new, it will return + * an empty collection; or if this Category has previously + * been saved, it will retrieve related Foods from storage. + * + * This method is protected by default in order to keep the public + * api reasonable. You can provide public methods for those you + * actually need in Category. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) + * @return ObjectCollection|ChildFood[] List of ChildFood objects + */ + public function getFoodsJoinRank(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildFoodQuery::create(null, $criteria); + $query->joinWith('Rank', $joinBehavior); + + return $this->getFoods($query, $con); + } + + /** + * Clears out the collSubcategories collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addSubcategories() + */ + public function clearSubcategories() + { + $this->collSubcategories = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collSubcategories collection loaded partially. + */ + public function resetPartialSubcategories($v = true) + { + $this->collSubcategoriesPartial = $v; + } + + /** + * Initializes the collSubcategories collection. + * + * By default this just sets the collSubcategories collection to an empty array (like clearcollSubcategories()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initSubcategories($overrideExisting = true) + { + if (null !== $this->collSubcategories && !$overrideExisting) { + return; + } + + $collectionClassName = SubcategoryTableMap::getTableMap()->getCollectionClassName(); + + $this->collSubcategories = new $collectionClassName; + $this->collSubcategories->setModel('\Subcategory'); + } + + /** + * Gets an array of ChildSubcategory objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildCategory is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return ObjectCollection|ChildSubcategory[] List of ChildSubcategory objects + * @throws PropelException + */ + public function getSubcategories(Criteria $criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collSubcategoriesPartial && !$this->isNew(); + if (null === $this->collSubcategories || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collSubcategories) { + // return empty collection + $this->initSubcategories(); + } else { + $collSubcategories = ChildSubcategoryQuery::create(null, $criteria) + ->filterByCategory($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collSubcategoriesPartial && count($collSubcategories)) { + $this->initSubcategories(false); + + foreach ($collSubcategories as $obj) { + if (false == $this->collSubcategories->contains($obj)) { + $this->collSubcategories->append($obj); + } + } + + $this->collSubcategoriesPartial = true; + } + + return $collSubcategories; + } + + if ($partial && $this->collSubcategories) { + foreach ($this->collSubcategories as $obj) { + if ($obj->isNew()) { + $collSubcategories[] = $obj; + } + } + } + + $this->collSubcategories = $collSubcategories; + $this->collSubcategoriesPartial = false; + } + } + + return $this->collSubcategories; + } + + /** + * Sets a collection of ChildSubcategory objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $subcategories A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return $this|ChildCategory The current object (for fluent API support) + */ + public function setSubcategories(Collection $subcategories, ConnectionInterface $con = null) + { + /** @var ChildSubcategory[] $subcategoriesToDelete */ + $subcategoriesToDelete = $this->getSubcategories(new Criteria(), $con)->diff($subcategories); + + + $this->subcategoriesScheduledForDeletion = $subcategoriesToDelete; + + foreach ($subcategoriesToDelete as $subcategoryRemoved) { + $subcategoryRemoved->setCategory(null); + } + + $this->collSubcategories = null; + foreach ($subcategories as $subcategory) { + $this->addSubcategory($subcategory); + } + + $this->collSubcategories = $subcategories; + $this->collSubcategoriesPartial = false; + + return $this; + } + + /** + * Returns the number of related Subcategory objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related Subcategory objects. + * @throws PropelException + */ + public function countSubcategories(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collSubcategoriesPartial && !$this->isNew(); + if (null === $this->collSubcategories || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collSubcategories) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getSubcategories()); + } + + $query = ChildSubcategoryQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByCategory($this) + ->count($con); + } + + return count($this->collSubcategories); + } + + /** + * Method called to associate a ChildSubcategory object to this object + * through the ChildSubcategory foreign key attribute. + * + * @param ChildSubcategory $l ChildSubcategory + * @return $this|\Category The current object (for fluent API support) + */ + public function addSubcategory(ChildSubcategory $l) + { + if ($this->collSubcategories === null) { + $this->initSubcategories(); + $this->collSubcategoriesPartial = true; + } + + if (!$this->collSubcategories->contains($l)) { + $this->doAddSubcategory($l); + + if ($this->subcategoriesScheduledForDeletion and $this->subcategoriesScheduledForDeletion->contains($l)) { + $this->subcategoriesScheduledForDeletion->remove($this->subcategoriesScheduledForDeletion->search($l)); + } + } + + return $this; + } + + /** + * @param ChildSubcategory $subcategory The ChildSubcategory object to add. + */ + protected function doAddSubcategory(ChildSubcategory $subcategory) + { + $this->collSubcategories[]= $subcategory; + $subcategory->setCategory($this); + } + + /** + * @param ChildSubcategory $subcategory The ChildSubcategory object to remove. + * @return $this|ChildCategory The current object (for fluent API support) + */ + public function removeSubcategory(ChildSubcategory $subcategory) + { + if ($this->getSubcategories()->contains($subcategory)) { + $pos = $this->collSubcategories->search($subcategory); + $this->collSubcategories->remove($pos); + if (null === $this->subcategoriesScheduledForDeletion) { + $this->subcategoriesScheduledForDeletion = clone $this->collSubcategories; + $this->subcategoriesScheduledForDeletion->clear(); + } + $this->subcategoriesScheduledForDeletion[]= $subcategory; + $subcategory->setCategory(null); + } + + return $this; + } + + /** + * Clears the current object, sets all attributes to their default values and removes + * outgoing references as well as back-references (from other objects to this one. Results probably in a database + * change of those foreign objects when you call `save` there). + */ + public function clear() + { + $this->id = null; + $this->name = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references and back-references to other model objects or collections of model objects. + * + * This method is used to reset all php object references (not the actual reference in the database). + * Necessary for object serialisation. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + if ($this->collCategoryRankNutrients) { + foreach ($this->collCategoryRankNutrients as $o) { + $o->clearAllReferences($deep); + } + } + if ($this->collFoods) { + foreach ($this->collFoods as $o) { + $o->clearAllReferences($deep); + } + } + if ($this->collSubcategories) { + foreach ($this->collSubcategories as $o) { + $o->clearAllReferences($deep); + } + } + } // if ($deep) + + $this->collCategoryRankNutrients = null; + $this->collFoods = null; + $this->collSubcategories = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(CategoryTableMap::DEFAULT_STRING_FORMAT); + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + if (is_callable('parent::preSave')) { + return parent::preSave($con); + } + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + if (is_callable('parent::postSave')) { + parent::postSave($con); + } + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + if (is_callable('parent::preInsert')) { + return parent::preInsert($con); + } + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + if (is_callable('parent::postInsert')) { + parent::postInsert($con); + } + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + if (is_callable('parent::preUpdate')) { + return parent::preUpdate($con); + } + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + if (is_callable('parent::postUpdate')) { + parent::postUpdate($con); + } + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + if (is_callable('parent::preDelete')) { + return parent::preDelete($con); + } + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + if (is_callable('parent::postDelete')) { + parent::postDelete($con); + } + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/api/generated-classes/Base/CategoryQuery.php b/api/generated-classes/Base/CategoryQuery.php new file mode 100644 index 0000000..c5bd5b4 --- /dev/null +++ b/api/generated-classes/Base/CategoryQuery.php @@ -0,0 +1,634 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(12, $con); + * + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildCategory|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, ConnectionInterface $con = null) + { + if ($key === null) { + return null; + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(CategoryTableMap::DATABASE_NAME); + } + + $this->basePreSelect($con); + + if ( + $this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins + ) { + return $this->findPkComplex($key, $con); + } + + if ((null !== ($obj = CategoryTableMap::getInstanceFromPool(null === $key || is_scalar($key) || is_callable([$key, '__toString']) ? (string) $key : $key)))) { + // the object is already in the instance pool + return $obj; + } + + return $this->findPkSimple($key, $con); + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @throws \Propel\Runtime\Exception\PropelException + * + * @return ChildCategory A model object, or null if the key is not found + */ + protected function findPkSimple($key, ConnectionInterface $con) + { + $sql = 'SELECT id, name FROM Category WHERE id = :p0'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key, PDO::PARAM_INT); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + /** @var ChildCategory $obj */ + $obj = new ChildCategory(); + $obj->hydrate($row); + CategoryTableMap::addInstanceToPool($obj, null === $key || is_scalar($key) || is_callable([$key, '__toString']) ? (string) $key : $key); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildCategory|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, ConnectionInterface $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(12, 56, 832), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return $this|ChildCategoryQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + + return $this->addUsingAlias(CategoryTableMap::COL_ID, $key, Criteria::EQUAL); + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return $this|ChildCategoryQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + + return $this->addUsingAlias(CategoryTableMap::COL_ID, $keys, Criteria::IN); + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return $this|ChildCategoryQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(CategoryTableMap::COL_ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(CategoryTableMap::COL_ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CategoryTableMap::COL_ID, $id, $comparison); + } + + /** + * Filter the query on the name column + * + * Example usage: + * + * $query->filterByName('fooValue'); // WHERE name = 'fooValue' + * $query->filterByName('%fooValue%', Criteria::LIKE); // WHERE name LIKE '%fooValue%' + * + * + * @param string $name The value to use as filter. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return $this|ChildCategoryQuery The current query, for fluid interface + */ + public function filterByName($name = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($name)) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CategoryTableMap::COL_NAME, $name, $comparison); + } + + /** + * Filter the query by a related \CategoryRankNutrient object + * + * @param \CategoryRankNutrient|ObjectCollection $categoryRankNutrient the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCategoryQuery The current query, for fluid interface + */ + public function filterByCategoryRankNutrient($categoryRankNutrient, $comparison = null) + { + if ($categoryRankNutrient instanceof \CategoryRankNutrient) { + return $this + ->addUsingAlias(CategoryTableMap::COL_ID, $categoryRankNutrient->getCategoryId(), $comparison); + } elseif ($categoryRankNutrient instanceof ObjectCollection) { + return $this + ->useCategoryRankNutrientQuery() + ->filterByPrimaryKeys($categoryRankNutrient->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByCategoryRankNutrient() only accepts arguments of type \CategoryRankNutrient or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the CategoryRankNutrient relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return $this|ChildCategoryQuery The current query, for fluid interface + */ + public function joinCategoryRankNutrient($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('CategoryRankNutrient'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'CategoryRankNutrient'); + } + + return $this; + } + + /** + * Use the CategoryRankNutrient relation CategoryRankNutrient object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \CategoryRankNutrientQuery A secondary query class using the current class as primary query + */ + public function useCategoryRankNutrientQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinCategoryRankNutrient($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'CategoryRankNutrient', '\CategoryRankNutrientQuery'); + } + + /** + * Filter the query by a related \Food object + * + * @param \Food|ObjectCollection $food the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCategoryQuery The current query, for fluid interface + */ + public function filterByFood($food, $comparison = null) + { + if ($food instanceof \Food) { + return $this + ->addUsingAlias(CategoryTableMap::COL_ID, $food->getCategoryId(), $comparison); + } elseif ($food instanceof ObjectCollection) { + return $this + ->useFoodQuery() + ->filterByPrimaryKeys($food->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByFood() only accepts arguments of type \Food or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Food relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return $this|ChildCategoryQuery The current query, for fluid interface + */ + public function joinFood($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Food'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Food'); + } + + return $this; + } + + /** + * Use the Food relation Food object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \FoodQuery A secondary query class using the current class as primary query + */ + public function useFoodQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinFood($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Food', '\FoodQuery'); + } + + /** + * Filter the query by a related \Subcategory object + * + * @param \Subcategory|ObjectCollection $subcategory the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildCategoryQuery The current query, for fluid interface + */ + public function filterBySubcategory($subcategory, $comparison = null) + { + if ($subcategory instanceof \Subcategory) { + return $this + ->addUsingAlias(CategoryTableMap::COL_ID, $subcategory->getCategoryId(), $comparison); + } elseif ($subcategory instanceof ObjectCollection) { + return $this + ->useSubcategoryQuery() + ->filterByPrimaryKeys($subcategory->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterBySubcategory() only accepts arguments of type \Subcategory or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Subcategory relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return $this|ChildCategoryQuery The current query, for fluid interface + */ + public function joinSubcategory($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Subcategory'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Subcategory'); + } + + return $this; + } + + /** + * Use the Subcategory relation Subcategory object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \SubcategoryQuery A secondary query class using the current class as primary query + */ + public function useSubcategoryQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinSubcategory($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Subcategory', '\SubcategoryQuery'); + } + + /** + * Exclude object from result + * + * @param ChildCategory $category Object to remove from the list of results + * + * @return $this|ChildCategoryQuery The current query, for fluid interface + */ + public function prune($category = null) + { + if ($category) { + $this->addUsingAlias(CategoryTableMap::COL_ID, $category->getId(), Criteria::NOT_EQUAL); + } + + return $this; + } + + /** + * Deletes all rows from the Category table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(CategoryTableMap::DATABASE_NAME); + } + + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + return $con->transaction(function () use ($con) { + $affectedRows = 0; // initialize var to track total num of affected rows + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + CategoryTableMap::clearInstancePool(); + CategoryTableMap::clearRelatedInstancePool(); + + return $affectedRows; + }); + } + + /** + * Performs a DELETE on the database based on the current ModelCriteria + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(CategoryTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(CategoryTableMap::DATABASE_NAME); + + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + return $con->transaction(function () use ($con, $criteria) { + $affectedRows = 0; // initialize var to track total num of affected rows + + CategoryTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + CategoryTableMap::clearRelatedInstancePool(); + + return $affectedRows; + }); + } + +} // CategoryQuery diff --git a/api/generated-classes/Base/CategoryRankNutrient.php b/api/generated-classes/Base/CategoryRankNutrient.php new file mode 100644 index 0000000..3bec93d --- /dev/null +++ b/api/generated-classes/Base/CategoryRankNutrient.php @@ -0,0 +1,1744 @@ +modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another CategoryRankNutrient instance. If + * obj is an instance of CategoryRankNutrient, delegates to + * equals(CategoryRankNutrient). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + if (!$obj instanceof static) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return $this|CategoryRankNutrient The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + $cls = new \ReflectionClass($this); + $propertyNames = []; + $serializableProperties = array_diff($cls->getProperties(), $cls->getProperties(\ReflectionProperty::IS_STATIC)); + + foreach($serializableProperties as $property) { + $propertyNames[] = $property->getName(); + } + + return $propertyNames; + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * Get the [units] column value. + * + * @return string + */ + public function getUnits() + { + return $this->units; + } + + /** + * Get the [threshold] column value. + * + * @return double + */ + public function getThreshold() + { + return $this->threshold; + } + + /** + * Get the [operator] column value. + * + * @return string + */ + public function getOperator() + { + return $this->operator; + } + + /** + * Get the [category_id] column value. + * + * @return int + */ + public function getCategoryId() + { + return $this->category_id; + } + + /** + * Get the [rank_id] column value. + * + * @return int + */ + public function getRankId() + { + return $this->rank_id; + } + + /** + * Get the [nutrient_id] column value. + * + * @return int + */ + public function getNutrientId() + { + return $this->nutrient_id; + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return $this|\CategoryRankNutrient The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[CategoryRankNutrientTableMap::COL_ID] = true; + } + + return $this; + } // setId() + + /** + * Set the value of [units] column. + * + * @param string $v new value + * @return $this|\CategoryRankNutrient The current object (for fluent API support) + */ + public function setUnits($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->units !== $v) { + $this->units = $v; + $this->modifiedColumns[CategoryRankNutrientTableMap::COL_UNITS] = true; + } + + return $this; + } // setUnits() + + /** + * Set the value of [threshold] column. + * + * @param double $v new value + * @return $this|\CategoryRankNutrient The current object (for fluent API support) + */ + public function setThreshold($v) + { + if ($v !== null) { + $v = (double) $v; + } + + if ($this->threshold !== $v) { + $this->threshold = $v; + $this->modifiedColumns[CategoryRankNutrientTableMap::COL_THRESHOLD] = true; + } + + return $this; + } // setThreshold() + + /** + * Set the value of [operator] column. + * + * @param string $v new value + * @return $this|\CategoryRankNutrient The current object (for fluent API support) + */ + public function setOperator($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->operator !== $v) { + $this->operator = $v; + $this->modifiedColumns[CategoryRankNutrientTableMap::COL_OPERATOR] = true; + } + + return $this; + } // setOperator() + + /** + * Set the value of [category_id] column. + * + * @param int $v new value + * @return $this|\CategoryRankNutrient The current object (for fluent API support) + */ + public function setCategoryId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->category_id !== $v) { + $this->category_id = $v; + $this->modifiedColumns[CategoryRankNutrientTableMap::COL_CATEGORY_ID] = true; + } + + if ($this->aCategory !== null && $this->aCategory->getId() !== $v) { + $this->aCategory = null; + } + + return $this; + } // setCategoryId() + + /** + * Set the value of [rank_id] column. + * + * @param int $v new value + * @return $this|\CategoryRankNutrient The current object (for fluent API support) + */ + public function setRankId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->rank_id !== $v) { + $this->rank_id = $v; + $this->modifiedColumns[CategoryRankNutrientTableMap::COL_RANK_ID] = true; + } + + if ($this->aRank !== null && $this->aRank->getId() !== $v) { + $this->aRank = null; + } + + return $this; + } // setRankId() + + /** + * Set the value of [nutrient_id] column. + * + * @param int $v new value + * @return $this|\CategoryRankNutrient The current object (for fluent API support) + */ + public function setNutrientId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->nutrient_id !== $v) { + $this->nutrient_id = $v; + $this->modifiedColumns[CategoryRankNutrientTableMap::COL_NUTRIENT_ID] = true; + } + + if ($this->aNutrient !== null && $this->aNutrient->getId() !== $v) { + $this->aNutrient = null; + } + + return $this; + } // setNutrientId() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : CategoryRankNutrientTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : CategoryRankNutrientTableMap::translateFieldName('Units', TableMap::TYPE_PHPNAME, $indexType)]; + $this->units = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : CategoryRankNutrientTableMap::translateFieldName('Threshold', TableMap::TYPE_PHPNAME, $indexType)]; + $this->threshold = (null !== $col) ? (double) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : CategoryRankNutrientTableMap::translateFieldName('Operator', TableMap::TYPE_PHPNAME, $indexType)]; + $this->operator = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : CategoryRankNutrientTableMap::translateFieldName('CategoryId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->category_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : CategoryRankNutrientTableMap::translateFieldName('RankId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->rank_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : CategoryRankNutrientTableMap::translateFieldName('NutrientId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->nutrient_id = (null !== $col) ? (int) $col : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 7; // 7 = CategoryRankNutrientTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException(sprintf('Error populating %s object', '\\CategoryRankNutrient'), 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + if ($this->aCategory !== null && $this->category_id !== $this->aCategory->getId()) { + $this->aCategory = null; + } + if ($this->aRank !== null && $this->rank_id !== $this->aRank->getId()) { + $this->aRank = null; + } + if ($this->aNutrient !== null && $this->nutrient_id !== $this->aNutrient->getId()) { + $this->aNutrient = null; + } + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(CategoryRankNutrientTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildCategoryRankNutrientQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->aNutrient = null; + $this->aCategory = null; + $this->aRank = null; + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see CategoryRankNutrient::setDeleted() + * @see CategoryRankNutrient::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(CategoryRankNutrientTableMap::DATABASE_NAME); + } + + $con->transaction(function () use ($con) { + $deleteQuery = ChildCategoryRankNutrientQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $this->setDeleted(true); + } + }); + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(CategoryRankNutrientTableMap::DATABASE_NAME); + } + + return $con->transaction(function () use ($con) { + $ret = $this->preSave($con); + $isInsert = $this->isNew(); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + } else { + $ret = $ret && $this->preUpdate($con); + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + CategoryRankNutrientTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + + return $affectedRows; + }); + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + // We call the save method on the following object(s) if they + // were passed to this object by their corresponding set + // method. This object relates to these object(s) by a + // foreign key reference. + + if ($this->aNutrient !== null) { + if ($this->aNutrient->isModified() || $this->aNutrient->isNew()) { + $affectedRows += $this->aNutrient->save($con); + } + $this->setNutrient($this->aNutrient); + } + + if ($this->aCategory !== null) { + if ($this->aCategory->isModified() || $this->aCategory->isNew()) { + $affectedRows += $this->aCategory->save($con); + } + $this->setCategory($this->aCategory); + } + + if ($this->aRank !== null) { + if ($this->aRank->isModified() || $this->aRank->isNew()) { + $affectedRows += $this->aRank->save($con); + } + $this->setRank($this->aRank); + } + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + $affectedRows += 1; + } else { + $affectedRows += $this->doUpdate($con); + } + $this->resetModified(); + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + $this->modifiedColumns[CategoryRankNutrientTableMap::COL_ID] = true; + if (null !== $this->id) { + throw new PropelException('Cannot insert a value for auto-increment primary key (' . CategoryRankNutrientTableMap::COL_ID . ')'); + } + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(CategoryRankNutrientTableMap::COL_ID)) { + $modifiedColumns[':p' . $index++] = 'id'; + } + if ($this->isColumnModified(CategoryRankNutrientTableMap::COL_UNITS)) { + $modifiedColumns[':p' . $index++] = 'units'; + } + if ($this->isColumnModified(CategoryRankNutrientTableMap::COL_THRESHOLD)) { + $modifiedColumns[':p' . $index++] = 'threshold'; + } + if ($this->isColumnModified(CategoryRankNutrientTableMap::COL_OPERATOR)) { + $modifiedColumns[':p' . $index++] = 'operator'; + } + if ($this->isColumnModified(CategoryRankNutrientTableMap::COL_CATEGORY_ID)) { + $modifiedColumns[':p' . $index++] = 'category_id'; + } + if ($this->isColumnModified(CategoryRankNutrientTableMap::COL_RANK_ID)) { + $modifiedColumns[':p' . $index++] = 'rank_id'; + } + if ($this->isColumnModified(CategoryRankNutrientTableMap::COL_NUTRIENT_ID)) { + $modifiedColumns[':p' . $index++] = 'nutrient_id'; + } + + $sql = sprintf( + 'INSERT INTO Category_Rank_Nutrient (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case 'id': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case 'units': + $stmt->bindValue($identifier, $this->units, PDO::PARAM_STR); + break; + case 'threshold': + $stmt->bindValue($identifier, $this->threshold, PDO::PARAM_STR); + break; + case 'operator': + $stmt->bindValue($identifier, $this->operator, PDO::PARAM_STR); + break; + case 'category_id': + $stmt->bindValue($identifier, $this->category_id, PDO::PARAM_INT); + break; + case 'rank_id': + $stmt->bindValue($identifier, $this->rank_id, PDO::PARAM_INT); + break; + case 'nutrient_id': + $stmt->bindValue($identifier, $this->nutrient_id, PDO::PARAM_INT); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + try { + $pk = $con->lastInsertId(); + } catch (Exception $e) { + throw new PropelException('Unable to get autoincrement id.', 0, $e); + } + $this->setId($pk); + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = CategoryRankNutrientTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getUnits(); + break; + case 2: + return $this->getThreshold(); + break; + case 3: + return $this->getOperator(); + break; + case 4: + return $this->getCategoryId(); + break; + case 5: + return $this->getRankId(); + break; + case 6: + return $this->getNutrientId(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + + if (isset($alreadyDumpedObjects['CategoryRankNutrient'][$this->hashCode()])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['CategoryRankNutrient'][$this->hashCode()] = true; + $keys = CategoryRankNutrientTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getUnits(), + $keys[2] => $this->getThreshold(), + $keys[3] => $this->getOperator(), + $keys[4] => $this->getCategoryId(), + $keys[5] => $this->getRankId(), + $keys[6] => $this->getNutrientId(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aNutrient) { + + switch ($keyType) { + case TableMap::TYPE_CAMELNAME: + $key = 'nutrient'; + break; + case TableMap::TYPE_FIELDNAME: + $key = 'Nutrient'; + break; + default: + $key = 'Nutrient'; + } + + $result[$key] = $this->aNutrient->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + if (null !== $this->aCategory) { + + switch ($keyType) { + case TableMap::TYPE_CAMELNAME: + $key = 'category'; + break; + case TableMap::TYPE_FIELDNAME: + $key = 'Category'; + break; + default: + $key = 'Category'; + } + + $result[$key] = $this->aCategory->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + if (null !== $this->aRank) { + + switch ($keyType) { + case TableMap::TYPE_CAMELNAME: + $key = 'rank'; + break; + case TableMap::TYPE_FIELDNAME: + $key = 'Rank'; + break; + default: + $key = 'Rank'; + } + + $result[$key] = $this->aRank->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return $this|\CategoryRankNutrient + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = CategoryRankNutrientTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return $this|\CategoryRankNutrient + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setUnits($value); + break; + case 2: + $this->setThreshold($value); + break; + case 3: + $this->setOperator($value); + break; + case 4: + $this->setCategoryId($value); + break; + case 5: + $this->setRankId($value); + break; + case 6: + $this->setNutrientId($value); + break; + } // switch() + + return $this; + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = CategoryRankNutrientTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) { + $this->setId($arr[$keys[0]]); + } + if (array_key_exists($keys[1], $arr)) { + $this->setUnits($arr[$keys[1]]); + } + if (array_key_exists($keys[2], $arr)) { + $this->setThreshold($arr[$keys[2]]); + } + if (array_key_exists($keys[3], $arr)) { + $this->setOperator($arr[$keys[3]]); + } + if (array_key_exists($keys[4], $arr)) { + $this->setCategoryId($arr[$keys[4]]); + } + if (array_key_exists($keys[5], $arr)) { + $this->setRankId($arr[$keys[5]]); + } + if (array_key_exists($keys[6], $arr)) { + $this->setNutrientId($arr[$keys[6]]); + } + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * @param string $keyType The type of keys the array uses. + * + * @return $this|\CategoryRankNutrient The current object, for fluid interface + */ + public function importFrom($parser, $data, $keyType = TableMap::TYPE_PHPNAME) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), $keyType); + + return $this; + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(CategoryRankNutrientTableMap::DATABASE_NAME); + + if ($this->isColumnModified(CategoryRankNutrientTableMap::COL_ID)) { + $criteria->add(CategoryRankNutrientTableMap::COL_ID, $this->id); + } + if ($this->isColumnModified(CategoryRankNutrientTableMap::COL_UNITS)) { + $criteria->add(CategoryRankNutrientTableMap::COL_UNITS, $this->units); + } + if ($this->isColumnModified(CategoryRankNutrientTableMap::COL_THRESHOLD)) { + $criteria->add(CategoryRankNutrientTableMap::COL_THRESHOLD, $this->threshold); + } + if ($this->isColumnModified(CategoryRankNutrientTableMap::COL_OPERATOR)) { + $criteria->add(CategoryRankNutrientTableMap::COL_OPERATOR, $this->operator); + } + if ($this->isColumnModified(CategoryRankNutrientTableMap::COL_CATEGORY_ID)) { + $criteria->add(CategoryRankNutrientTableMap::COL_CATEGORY_ID, $this->category_id); + } + if ($this->isColumnModified(CategoryRankNutrientTableMap::COL_RANK_ID)) { + $criteria->add(CategoryRankNutrientTableMap::COL_RANK_ID, $this->rank_id); + } + if ($this->isColumnModified(CategoryRankNutrientTableMap::COL_NUTRIENT_ID)) { + $criteria->add(CategoryRankNutrientTableMap::COL_NUTRIENT_ID, $this->nutrient_id); + } + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @throws LogicException if no primary key is defined + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = ChildCategoryRankNutrientQuery::create(); + $criteria->add(CategoryRankNutrientTableMap::COL_ID, $this->id); + + return $criteria; + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + $validPk = null !== $this->getId(); + + $validPrimaryKeyFKs = 0; + $primaryKeyFKs = []; + + if ($validPk) { + return crc32(json_encode($this->getPrimaryKey(), JSON_UNESCAPED_UNICODE)); + } elseif ($validPrimaryKeyFKs) { + return crc32(json_encode($primaryKeyFKs, JSON_UNESCAPED_UNICODE)); + } + + return spl_object_hash($this); + } + + /** + * Returns the primary key for this object (row). + * @return int + */ + public function getPrimaryKey() + { + return $this->getId(); + } + + /** + * Generic method to set the primary key (id column). + * + * @param int $key Primary key. + * @return void + */ + public function setPrimaryKey($key) + { + $this->setId($key); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + return null === $this->getId(); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \CategoryRankNutrient (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setUnits($this->getUnits()); + $copyObj->setThreshold($this->getThreshold()); + $copyObj->setOperator($this->getOperator()); + $copyObj->setCategoryId($this->getCategoryId()); + $copyObj->setRankId($this->getRankId()); + $copyObj->setNutrientId($this->getNutrientId()); + if ($makeNew) { + $copyObj->setNew(true); + $copyObj->setId(NULL); // this is a auto-increment column, so set to default value + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \CategoryRankNutrient Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + /** + * Declares an association between this object and a ChildNutrient object. + * + * @param ChildNutrient $v + * @return $this|\CategoryRankNutrient The current object (for fluent API support) + * @throws PropelException + */ + public function setNutrient(ChildNutrient $v = null) + { + if ($v === null) { + $this->setNutrientId(NULL); + } else { + $this->setNutrientId($v->getId()); + } + + $this->aNutrient = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildNutrient object, it will not be re-added. + if ($v !== null) { + $v->addCategoryRankNutrient($this); + } + + + return $this; + } + + + /** + * Get the associated ChildNutrient object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildNutrient The associated ChildNutrient object. + * @throws PropelException + */ + public function getNutrient(ConnectionInterface $con = null) + { + if ($this->aNutrient === null && ($this->nutrient_id !== null)) { + $this->aNutrient = ChildNutrientQuery::create()->findPk($this->nutrient_id, $con); + /* The following can be used additionally to + guarantee the related object contains a reference + to this object. This level of coupling may, however, be + undesirable since it could result in an only partially populated collection + in the referenced object. + $this->aNutrient->addCategoryRankNutrients($this); + */ + } + + return $this->aNutrient; + } + + /** + * Declares an association between this object and a ChildCategory object. + * + * @param ChildCategory $v + * @return $this|\CategoryRankNutrient The current object (for fluent API support) + * @throws PropelException + */ + public function setCategory(ChildCategory $v = null) + { + if ($v === null) { + $this->setCategoryId(NULL); + } else { + $this->setCategoryId($v->getId()); + } + + $this->aCategory = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildCategory object, it will not be re-added. + if ($v !== null) { + $v->addCategoryRankNutrient($this); + } + + + return $this; + } + + + /** + * Get the associated ChildCategory object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildCategory The associated ChildCategory object. + * @throws PropelException + */ + public function getCategory(ConnectionInterface $con = null) + { + if ($this->aCategory === null && ($this->category_id !== null)) { + $this->aCategory = ChildCategoryQuery::create()->findPk($this->category_id, $con); + /* The following can be used additionally to + guarantee the related object contains a reference + to this object. This level of coupling may, however, be + undesirable since it could result in an only partially populated collection + in the referenced object. + $this->aCategory->addCategoryRankNutrients($this); + */ + } + + return $this->aCategory; + } + + /** + * Declares an association between this object and a ChildRank object. + * + * @param ChildRank $v + * @return $this|\CategoryRankNutrient The current object (for fluent API support) + * @throws PropelException + */ + public function setRank(ChildRank $v = null) + { + if ($v === null) { + $this->setRankId(NULL); + } else { + $this->setRankId($v->getId()); + } + + $this->aRank = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildRank object, it will not be re-added. + if ($v !== null) { + $v->addCategoryRankNutrient($this); + } + + + return $this; + } + + + /** + * Get the associated ChildRank object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildRank The associated ChildRank object. + * @throws PropelException + */ + public function getRank(ConnectionInterface $con = null) + { + if ($this->aRank === null && ($this->rank_id !== null)) { + $this->aRank = ChildRankQuery::create()->findPk($this->rank_id, $con); + /* The following can be used additionally to + guarantee the related object contains a reference + to this object. This level of coupling may, however, be + undesirable since it could result in an only partially populated collection + in the referenced object. + $this->aRank->addCategoryRankNutrients($this); + */ + } + + return $this->aRank; + } + + /** + * Clears the current object, sets all attributes to their default values and removes + * outgoing references as well as back-references (from other objects to this one. Results probably in a database + * change of those foreign objects when you call `save` there). + */ + public function clear() + { + if (null !== $this->aNutrient) { + $this->aNutrient->removeCategoryRankNutrient($this); + } + if (null !== $this->aCategory) { + $this->aCategory->removeCategoryRankNutrient($this); + } + if (null !== $this->aRank) { + $this->aRank->removeCategoryRankNutrient($this); + } + $this->id = null; + $this->units = null; + $this->threshold = null; + $this->operator = null; + $this->category_id = null; + $this->rank_id = null; + $this->nutrient_id = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references and back-references to other model objects or collections of model objects. + * + * This method is used to reset all php object references (not the actual reference in the database). + * Necessary for object serialisation. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + } // if ($deep) + + $this->aNutrient = null; + $this->aCategory = null; + $this->aRank = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(CategoryRankNutrientTableMap::DEFAULT_STRING_FORMAT); + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + if (is_callable('parent::preSave')) { + return parent::preSave($con); + } + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + if (is_callable('parent::postSave')) { + parent::postSave($con); + } + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + if (is_callable('parent::preInsert')) { + return parent::preInsert($con); + } + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + if (is_callable('parent::postInsert')) { + parent::postInsert($con); + } + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + if (is_callable('parent::preUpdate')) { + return parent::preUpdate($con); + } + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + if (is_callable('parent::postUpdate')) { + parent::postUpdate($con); + } + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + if (is_callable('parent::preDelete')) { + return parent::preDelete($con); + } + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + if (is_callable('parent::postDelete')) { + parent::postDelete($con); + } + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/api/generated-classes/Base/CategoryRankNutrientQuery.php b/api/generated-classes/Base/CategoryRankNutrientQuery.php new file mode 100644 index 0000000..832818e --- /dev/null +++ b/api/generated-classes/Base/CategoryRankNutrientQuery.php @@ -0,0 +1,866 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(12, $con); + * + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildCategoryRankNutrient|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, ConnectionInterface $con = null) + { + if ($key === null) { + return null; + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(CategoryRankNutrientTableMap::DATABASE_NAME); + } + + $this->basePreSelect($con); + + if ( + $this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins + ) { + return $this->findPkComplex($key, $con); + } + + if ((null !== ($obj = CategoryRankNutrientTableMap::getInstanceFromPool(null === $key || is_scalar($key) || is_callable([$key, '__toString']) ? (string) $key : $key)))) { + // the object is already in the instance pool + return $obj; + } + + return $this->findPkSimple($key, $con); + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @throws \Propel\Runtime\Exception\PropelException + * + * @return ChildCategoryRankNutrient A model object, or null if the key is not found + */ + protected function findPkSimple($key, ConnectionInterface $con) + { + $sql = 'SELECT id, units, threshold, operator, category_id, rank_id, nutrient_id FROM Category_Rank_Nutrient WHERE id = :p0'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key, PDO::PARAM_INT); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + /** @var ChildCategoryRankNutrient $obj */ + $obj = new ChildCategoryRankNutrient(); + $obj->hydrate($row); + CategoryRankNutrientTableMap::addInstanceToPool($obj, null === $key || is_scalar($key) || is_callable([$key, '__toString']) ? (string) $key : $key); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildCategoryRankNutrient|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, ConnectionInterface $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(12, 56, 832), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return $this|ChildCategoryRankNutrientQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + + return $this->addUsingAlias(CategoryRankNutrientTableMap::COL_ID, $key, Criteria::EQUAL); + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return $this|ChildCategoryRankNutrientQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + + return $this->addUsingAlias(CategoryRankNutrientTableMap::COL_ID, $keys, Criteria::IN); + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return $this|ChildCategoryRankNutrientQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(CategoryRankNutrientTableMap::COL_ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(CategoryRankNutrientTableMap::COL_ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CategoryRankNutrientTableMap::COL_ID, $id, $comparison); + } + + /** + * Filter the query on the units column + * + * Example usage: + * + * $query->filterByUnits('fooValue'); // WHERE units = 'fooValue' + * $query->filterByUnits('%fooValue%', Criteria::LIKE); // WHERE units LIKE '%fooValue%' + * + * + * @param string $units The value to use as filter. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return $this|ChildCategoryRankNutrientQuery The current query, for fluid interface + */ + public function filterByUnits($units = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($units)) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CategoryRankNutrientTableMap::COL_UNITS, $units, $comparison); + } + + /** + * Filter the query on the threshold column + * + * Example usage: + * + * $query->filterByThreshold(1234); // WHERE threshold = 1234 + * $query->filterByThreshold(array(12, 34)); // WHERE threshold IN (12, 34) + * $query->filterByThreshold(array('min' => 12)); // WHERE threshold > 12 + * + * + * @param mixed $threshold The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return $this|ChildCategoryRankNutrientQuery The current query, for fluid interface + */ + public function filterByThreshold($threshold = null, $comparison = null) + { + if (is_array($threshold)) { + $useMinMax = false; + if (isset($threshold['min'])) { + $this->addUsingAlias(CategoryRankNutrientTableMap::COL_THRESHOLD, $threshold['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($threshold['max'])) { + $this->addUsingAlias(CategoryRankNutrientTableMap::COL_THRESHOLD, $threshold['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CategoryRankNutrientTableMap::COL_THRESHOLD, $threshold, $comparison); + } + + /** + * Filter the query on the operator column + * + * Example usage: + * + * $query->filterByOperator('fooValue'); // WHERE operator = 'fooValue' + * $query->filterByOperator('%fooValue%', Criteria::LIKE); // WHERE operator LIKE '%fooValue%' + * + * + * @param string $operator The value to use as filter. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return $this|ChildCategoryRankNutrientQuery The current query, for fluid interface + */ + public function filterByOperator($operator = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($operator)) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CategoryRankNutrientTableMap::COL_OPERATOR, $operator, $comparison); + } + + /** + * Filter the query on the category_id column + * + * Example usage: + * + * $query->filterByCategoryId(1234); // WHERE category_id = 1234 + * $query->filterByCategoryId(array(12, 34)); // WHERE category_id IN (12, 34) + * $query->filterByCategoryId(array('min' => 12)); // WHERE category_id > 12 + * + * + * @see filterByCategory() + * + * @param mixed $categoryId The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return $this|ChildCategoryRankNutrientQuery The current query, for fluid interface + */ + public function filterByCategoryId($categoryId = null, $comparison = null) + { + if (is_array($categoryId)) { + $useMinMax = false; + if (isset($categoryId['min'])) { + $this->addUsingAlias(CategoryRankNutrientTableMap::COL_CATEGORY_ID, $categoryId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($categoryId['max'])) { + $this->addUsingAlias(CategoryRankNutrientTableMap::COL_CATEGORY_ID, $categoryId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CategoryRankNutrientTableMap::COL_CATEGORY_ID, $categoryId, $comparison); + } + + /** + * Filter the query on the rank_id column + * + * Example usage: + * + * $query->filterByRankId(1234); // WHERE rank_id = 1234 + * $query->filterByRankId(array(12, 34)); // WHERE rank_id IN (12, 34) + * $query->filterByRankId(array('min' => 12)); // WHERE rank_id > 12 + * + * + * @see filterByRank() + * + * @param mixed $rankId The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return $this|ChildCategoryRankNutrientQuery The current query, for fluid interface + */ + public function filterByRankId($rankId = null, $comparison = null) + { + if (is_array($rankId)) { + $useMinMax = false; + if (isset($rankId['min'])) { + $this->addUsingAlias(CategoryRankNutrientTableMap::COL_RANK_ID, $rankId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($rankId['max'])) { + $this->addUsingAlias(CategoryRankNutrientTableMap::COL_RANK_ID, $rankId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CategoryRankNutrientTableMap::COL_RANK_ID, $rankId, $comparison); + } + + /** + * Filter the query on the nutrient_id column + * + * Example usage: + * + * $query->filterByNutrientId(1234); // WHERE nutrient_id = 1234 + * $query->filterByNutrientId(array(12, 34)); // WHERE nutrient_id IN (12, 34) + * $query->filterByNutrientId(array('min' => 12)); // WHERE nutrient_id > 12 + * + * + * @see filterByNutrient() + * + * @param mixed $nutrientId The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return $this|ChildCategoryRankNutrientQuery The current query, for fluid interface + */ + public function filterByNutrientId($nutrientId = null, $comparison = null) + { + if (is_array($nutrientId)) { + $useMinMax = false; + if (isset($nutrientId['min'])) { + $this->addUsingAlias(CategoryRankNutrientTableMap::COL_NUTRIENT_ID, $nutrientId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($nutrientId['max'])) { + $this->addUsingAlias(CategoryRankNutrientTableMap::COL_NUTRIENT_ID, $nutrientId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(CategoryRankNutrientTableMap::COL_NUTRIENT_ID, $nutrientId, $comparison); + } + + /** + * Filter the query by a related \Nutrient object + * + * @param \Nutrient|ObjectCollection $nutrient The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @throws \Propel\Runtime\Exception\PropelException + * + * @return ChildCategoryRankNutrientQuery The current query, for fluid interface + */ + public function filterByNutrient($nutrient, $comparison = null) + { + if ($nutrient instanceof \Nutrient) { + return $this + ->addUsingAlias(CategoryRankNutrientTableMap::COL_NUTRIENT_ID, $nutrient->getId(), $comparison); + } elseif ($nutrient instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(CategoryRankNutrientTableMap::COL_NUTRIENT_ID, $nutrient->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByNutrient() only accepts arguments of type \Nutrient or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Nutrient relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return $this|ChildCategoryRankNutrientQuery The current query, for fluid interface + */ + public function joinNutrient($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Nutrient'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Nutrient'); + } + + return $this; + } + + /** + * Use the Nutrient relation Nutrient object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \NutrientQuery A secondary query class using the current class as primary query + */ + public function useNutrientQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinNutrient($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Nutrient', '\NutrientQuery'); + } + + /** + * Filter the query by a related \Category object + * + * @param \Category|ObjectCollection $category The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @throws \Propel\Runtime\Exception\PropelException + * + * @return ChildCategoryRankNutrientQuery The current query, for fluid interface + */ + public function filterByCategory($category, $comparison = null) + { + if ($category instanceof \Category) { + return $this + ->addUsingAlias(CategoryRankNutrientTableMap::COL_CATEGORY_ID, $category->getId(), $comparison); + } elseif ($category instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(CategoryRankNutrientTableMap::COL_CATEGORY_ID, $category->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByCategory() only accepts arguments of type \Category or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Category relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return $this|ChildCategoryRankNutrientQuery The current query, for fluid interface + */ + public function joinCategory($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Category'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Category'); + } + + return $this; + } + + /** + * Use the Category relation Category object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \CategoryQuery A secondary query class using the current class as primary query + */ + public function useCategoryQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinCategory($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Category', '\CategoryQuery'); + } + + /** + * Filter the query by a related \Rank object + * + * @param \Rank|ObjectCollection $rank The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @throws \Propel\Runtime\Exception\PropelException + * + * @return ChildCategoryRankNutrientQuery The current query, for fluid interface + */ + public function filterByRank($rank, $comparison = null) + { + if ($rank instanceof \Rank) { + return $this + ->addUsingAlias(CategoryRankNutrientTableMap::COL_RANK_ID, $rank->getId(), $comparison); + } elseif ($rank instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(CategoryRankNutrientTableMap::COL_RANK_ID, $rank->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByRank() only accepts arguments of type \Rank or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Rank relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return $this|ChildCategoryRankNutrientQuery The current query, for fluid interface + */ + public function joinRank($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Rank'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Rank'); + } + + return $this; + } + + /** + * Use the Rank relation Rank object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \RankQuery A secondary query class using the current class as primary query + */ + public function useRankQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinRank($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Rank', '\RankQuery'); + } + + /** + * Exclude object from result + * + * @param ChildCategoryRankNutrient $categoryRankNutrient Object to remove from the list of results + * + * @return $this|ChildCategoryRankNutrientQuery The current query, for fluid interface + */ + public function prune($categoryRankNutrient = null) + { + if ($categoryRankNutrient) { + $this->addUsingAlias(CategoryRankNutrientTableMap::COL_ID, $categoryRankNutrient->getId(), Criteria::NOT_EQUAL); + } + + return $this; + } + + /** + * Deletes all rows from the Category_Rank_Nutrient table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(CategoryRankNutrientTableMap::DATABASE_NAME); + } + + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + return $con->transaction(function () use ($con) { + $affectedRows = 0; // initialize var to track total num of affected rows + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + CategoryRankNutrientTableMap::clearInstancePool(); + CategoryRankNutrientTableMap::clearRelatedInstancePool(); + + return $affectedRows; + }); + } + + /** + * Performs a DELETE on the database based on the current ModelCriteria + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(CategoryRankNutrientTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(CategoryRankNutrientTableMap::DATABASE_NAME); + + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + return $con->transaction(function () use ($con, $criteria) { + $affectedRows = 0; // initialize var to track total num of affected rows + + CategoryRankNutrientTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + CategoryRankNutrientTableMap::clearRelatedInstancePool(); + + return $affectedRows; + }); + } + +} // CategoryRankNutrientQuery diff --git a/api/generated-classes/Base/Food.php b/api/generated-classes/Base/Food.php new file mode 100644 index 0000000..38bb5bc --- /dev/null +++ b/api/generated-classes/Base/Food.php @@ -0,0 +1,1530 @@ +modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another Food instance. If + * obj is an instance of Food, delegates to + * equals(Food). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + if (!$obj instanceof static) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return $this|Food The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + $cls = new \ReflectionClass($this); + $propertyNames = []; + $serializableProperties = array_diff($cls->getProperties(), $cls->getProperties(\ReflectionProperty::IS_STATIC)); + + foreach($serializableProperties as $property) { + $propertyNames[] = $property->getName(); + } + + return $propertyNames; + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * Get the [name] column value. + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Get the [barcode] column value. + * + * @return int + */ + public function getBarcode() + { + return $this->barcode; + } + + /** + * Get the [rank_id] column value. + * + * @return int + */ + public function getRankId() + { + return $this->rank_id; + } + + /** + * Get the [category_id] column value. + * + * @return int + */ + public function getCategoryId() + { + return $this->category_id; + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return $this|\Food The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[FoodTableMap::COL_ID] = true; + } + + return $this; + } // setId() + + /** + * Set the value of [name] column. + * + * @param string $v new value + * @return $this|\Food The current object (for fluent API support) + */ + public function setName($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->name !== $v) { + $this->name = $v; + $this->modifiedColumns[FoodTableMap::COL_NAME] = true; + } + + return $this; + } // setName() + + /** + * Set the value of [barcode] column. + * + * @param int $v new value + * @return $this|\Food The current object (for fluent API support) + */ + public function setBarcode($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->barcode !== $v) { + $this->barcode = $v; + $this->modifiedColumns[FoodTableMap::COL_BARCODE] = true; + } + + return $this; + } // setBarcode() + + /** + * Set the value of [rank_id] column. + * + * @param int $v new value + * @return $this|\Food The current object (for fluent API support) + */ + public function setRankId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->rank_id !== $v) { + $this->rank_id = $v; + $this->modifiedColumns[FoodTableMap::COL_RANK_ID] = true; + } + + if ($this->aRank !== null && $this->aRank->getId() !== $v) { + $this->aRank = null; + } + + return $this; + } // setRankId() + + /** + * Set the value of [category_id] column. + * + * @param int $v new value + * @return $this|\Food The current object (for fluent API support) + */ + public function setCategoryId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->category_id !== $v) { + $this->category_id = $v; + $this->modifiedColumns[FoodTableMap::COL_CATEGORY_ID] = true; + } + + if ($this->aCategory !== null && $this->aCategory->getId() !== $v) { + $this->aCategory = null; + } + + return $this; + } // setCategoryId() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : FoodTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : FoodTableMap::translateFieldName('Name', TableMap::TYPE_PHPNAME, $indexType)]; + $this->name = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : FoodTableMap::translateFieldName('Barcode', TableMap::TYPE_PHPNAME, $indexType)]; + $this->barcode = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : FoodTableMap::translateFieldName('RankId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->rank_id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : FoodTableMap::translateFieldName('CategoryId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->category_id = (null !== $col) ? (int) $col : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 5; // 5 = FoodTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException(sprintf('Error populating %s object', '\\Food'), 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + if ($this->aRank !== null && $this->rank_id !== $this->aRank->getId()) { + $this->aRank = null; + } + if ($this->aCategory !== null && $this->category_id !== $this->aCategory->getId()) { + $this->aCategory = null; + } + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(FoodTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildFoodQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->aCategory = null; + $this->aRank = null; + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see Food::setDeleted() + * @see Food::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(FoodTableMap::DATABASE_NAME); + } + + $con->transaction(function () use ($con) { + $deleteQuery = ChildFoodQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $this->setDeleted(true); + } + }); + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(FoodTableMap::DATABASE_NAME); + } + + return $con->transaction(function () use ($con) { + $ret = $this->preSave($con); + $isInsert = $this->isNew(); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + } else { + $ret = $ret && $this->preUpdate($con); + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + FoodTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + + return $affectedRows; + }); + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + // We call the save method on the following object(s) if they + // were passed to this object by their corresponding set + // method. This object relates to these object(s) by a + // foreign key reference. + + if ($this->aCategory !== null) { + if ($this->aCategory->isModified() || $this->aCategory->isNew()) { + $affectedRows += $this->aCategory->save($con); + } + $this->setCategory($this->aCategory); + } + + if ($this->aRank !== null) { + if ($this->aRank->isModified() || $this->aRank->isNew()) { + $affectedRows += $this->aRank->save($con); + } + $this->setRank($this->aRank); + } + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + $affectedRows += 1; + } else { + $affectedRows += $this->doUpdate($con); + } + $this->resetModified(); + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + $this->modifiedColumns[FoodTableMap::COL_ID] = true; + if (null !== $this->id) { + throw new PropelException('Cannot insert a value for auto-increment primary key (' . FoodTableMap::COL_ID . ')'); + } + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(FoodTableMap::COL_ID)) { + $modifiedColumns[':p' . $index++] = 'id'; + } + if ($this->isColumnModified(FoodTableMap::COL_NAME)) { + $modifiedColumns[':p' . $index++] = 'name'; + } + if ($this->isColumnModified(FoodTableMap::COL_BARCODE)) { + $modifiedColumns[':p' . $index++] = 'barcode'; + } + if ($this->isColumnModified(FoodTableMap::COL_RANK_ID)) { + $modifiedColumns[':p' . $index++] = 'rank_id'; + } + if ($this->isColumnModified(FoodTableMap::COL_CATEGORY_ID)) { + $modifiedColumns[':p' . $index++] = 'category_id'; + } + + $sql = sprintf( + 'INSERT INTO Food (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case 'id': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case 'name': + $stmt->bindValue($identifier, $this->name, PDO::PARAM_STR); + break; + case 'barcode': + $stmt->bindValue($identifier, $this->barcode, PDO::PARAM_INT); + break; + case 'rank_id': + $stmt->bindValue($identifier, $this->rank_id, PDO::PARAM_INT); + break; + case 'category_id': + $stmt->bindValue($identifier, $this->category_id, PDO::PARAM_INT); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + try { + $pk = $con->lastInsertId(); + } catch (Exception $e) { + throw new PropelException('Unable to get autoincrement id.', 0, $e); + } + $this->setId($pk); + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = FoodTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getName(); + break; + case 2: + return $this->getBarcode(); + break; + case 3: + return $this->getRankId(); + break; + case 4: + return $this->getCategoryId(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + + if (isset($alreadyDumpedObjects['Food'][$this->hashCode()])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['Food'][$this->hashCode()] = true; + $keys = FoodTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getName(), + $keys[2] => $this->getBarcode(), + $keys[3] => $this->getRankId(), + $keys[4] => $this->getCategoryId(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aCategory) { + + switch ($keyType) { + case TableMap::TYPE_CAMELNAME: + $key = 'category'; + break; + case TableMap::TYPE_FIELDNAME: + $key = 'Category'; + break; + default: + $key = 'Category'; + } + + $result[$key] = $this->aCategory->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + if (null !== $this->aRank) { + + switch ($keyType) { + case TableMap::TYPE_CAMELNAME: + $key = 'rank'; + break; + case TableMap::TYPE_FIELDNAME: + $key = 'Rank'; + break; + default: + $key = 'Rank'; + } + + $result[$key] = $this->aRank->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return $this|\Food + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = FoodTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return $this|\Food + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setName($value); + break; + case 2: + $this->setBarcode($value); + break; + case 3: + $this->setRankId($value); + break; + case 4: + $this->setCategoryId($value); + break; + } // switch() + + return $this; + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = FoodTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) { + $this->setId($arr[$keys[0]]); + } + if (array_key_exists($keys[1], $arr)) { + $this->setName($arr[$keys[1]]); + } + if (array_key_exists($keys[2], $arr)) { + $this->setBarcode($arr[$keys[2]]); + } + if (array_key_exists($keys[3], $arr)) { + $this->setRankId($arr[$keys[3]]); + } + if (array_key_exists($keys[4], $arr)) { + $this->setCategoryId($arr[$keys[4]]); + } + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * @param string $keyType The type of keys the array uses. + * + * @return $this|\Food The current object, for fluid interface + */ + public function importFrom($parser, $data, $keyType = TableMap::TYPE_PHPNAME) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), $keyType); + + return $this; + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(FoodTableMap::DATABASE_NAME); + + if ($this->isColumnModified(FoodTableMap::COL_ID)) { + $criteria->add(FoodTableMap::COL_ID, $this->id); + } + if ($this->isColumnModified(FoodTableMap::COL_NAME)) { + $criteria->add(FoodTableMap::COL_NAME, $this->name); + } + if ($this->isColumnModified(FoodTableMap::COL_BARCODE)) { + $criteria->add(FoodTableMap::COL_BARCODE, $this->barcode); + } + if ($this->isColumnModified(FoodTableMap::COL_RANK_ID)) { + $criteria->add(FoodTableMap::COL_RANK_ID, $this->rank_id); + } + if ($this->isColumnModified(FoodTableMap::COL_CATEGORY_ID)) { + $criteria->add(FoodTableMap::COL_CATEGORY_ID, $this->category_id); + } + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @throws LogicException if no primary key is defined + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = ChildFoodQuery::create(); + $criteria->add(FoodTableMap::COL_ID, $this->id); + + return $criteria; + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + $validPk = null !== $this->getId(); + + $validPrimaryKeyFKs = 0; + $primaryKeyFKs = []; + + if ($validPk) { + return crc32(json_encode($this->getPrimaryKey(), JSON_UNESCAPED_UNICODE)); + } elseif ($validPrimaryKeyFKs) { + return crc32(json_encode($primaryKeyFKs, JSON_UNESCAPED_UNICODE)); + } + + return spl_object_hash($this); + } + + /** + * Returns the primary key for this object (row). + * @return int + */ + public function getPrimaryKey() + { + return $this->getId(); + } + + /** + * Generic method to set the primary key (id column). + * + * @param int $key Primary key. + * @return void + */ + public function setPrimaryKey($key) + { + $this->setId($key); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + return null === $this->getId(); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \Food (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setName($this->getName()); + $copyObj->setBarcode($this->getBarcode()); + $copyObj->setRankId($this->getRankId()); + $copyObj->setCategoryId($this->getCategoryId()); + if ($makeNew) { + $copyObj->setNew(true); + $copyObj->setId(NULL); // this is a auto-increment column, so set to default value + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \Food Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + /** + * Declares an association between this object and a ChildCategory object. + * + * @param ChildCategory $v + * @return $this|\Food The current object (for fluent API support) + * @throws PropelException + */ + public function setCategory(ChildCategory $v = null) + { + if ($v === null) { + $this->setCategoryId(NULL); + } else { + $this->setCategoryId($v->getId()); + } + + $this->aCategory = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildCategory object, it will not be re-added. + if ($v !== null) { + $v->addFood($this); + } + + + return $this; + } + + + /** + * Get the associated ChildCategory object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildCategory The associated ChildCategory object. + * @throws PropelException + */ + public function getCategory(ConnectionInterface $con = null) + { + if ($this->aCategory === null && ($this->category_id !== null)) { + $this->aCategory = ChildCategoryQuery::create()->findPk($this->category_id, $con); + /* The following can be used additionally to + guarantee the related object contains a reference + to this object. This level of coupling may, however, be + undesirable since it could result in an only partially populated collection + in the referenced object. + $this->aCategory->addFoods($this); + */ + } + + return $this->aCategory; + } + + /** + * Declares an association between this object and a ChildRank object. + * + * @param ChildRank $v + * @return $this|\Food The current object (for fluent API support) + * @throws PropelException + */ + public function setRank(ChildRank $v = null) + { + if ($v === null) { + $this->setRankId(NULL); + } else { + $this->setRankId($v->getId()); + } + + $this->aRank = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildRank object, it will not be re-added. + if ($v !== null) { + $v->addFood($this); + } + + + return $this; + } + + + /** + * Get the associated ChildRank object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildRank The associated ChildRank object. + * @throws PropelException + */ + public function getRank(ConnectionInterface $con = null) + { + if ($this->aRank === null && ($this->rank_id !== null)) { + $this->aRank = ChildRankQuery::create()->findPk($this->rank_id, $con); + /* The following can be used additionally to + guarantee the related object contains a reference + to this object. This level of coupling may, however, be + undesirable since it could result in an only partially populated collection + in the referenced object. + $this->aRank->addFoods($this); + */ + } + + return $this->aRank; + } + + /** + * Clears the current object, sets all attributes to their default values and removes + * outgoing references as well as back-references (from other objects to this one. Results probably in a database + * change of those foreign objects when you call `save` there). + */ + public function clear() + { + if (null !== $this->aCategory) { + $this->aCategory->removeFood($this); + } + if (null !== $this->aRank) { + $this->aRank->removeFood($this); + } + $this->id = null; + $this->name = null; + $this->barcode = null; + $this->rank_id = null; + $this->category_id = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references and back-references to other model objects or collections of model objects. + * + * This method is used to reset all php object references (not the actual reference in the database). + * Necessary for object serialisation. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + } // if ($deep) + + $this->aCategory = null; + $this->aRank = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(FoodTableMap::DEFAULT_STRING_FORMAT); + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + if (is_callable('parent::preSave')) { + return parent::preSave($con); + } + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + if (is_callable('parent::postSave')) { + parent::postSave($con); + } + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + if (is_callable('parent::preInsert')) { + return parent::preInsert($con); + } + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + if (is_callable('parent::postInsert')) { + parent::postInsert($con); + } + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + if (is_callable('parent::preUpdate')) { + return parent::preUpdate($con); + } + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + if (is_callable('parent::postUpdate')) { + parent::postUpdate($con); + } + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + if (is_callable('parent::preDelete')) { + return parent::preDelete($con); + } + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + if (is_callable('parent::postDelete')) { + parent::postDelete($con); + } + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/api/generated-classes/Base/FoodQuery.php b/api/generated-classes/Base/FoodQuery.php new file mode 100644 index 0000000..19211a4 --- /dev/null +++ b/api/generated-classes/Base/FoodQuery.php @@ -0,0 +1,701 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(12, $con); + * + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildFood|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, ConnectionInterface $con = null) + { + if ($key === null) { + return null; + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(FoodTableMap::DATABASE_NAME); + } + + $this->basePreSelect($con); + + if ( + $this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins + ) { + return $this->findPkComplex($key, $con); + } + + if ((null !== ($obj = FoodTableMap::getInstanceFromPool(null === $key || is_scalar($key) || is_callable([$key, '__toString']) ? (string) $key : $key)))) { + // the object is already in the instance pool + return $obj; + } + + return $this->findPkSimple($key, $con); + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @throws \Propel\Runtime\Exception\PropelException + * + * @return ChildFood A model object, or null if the key is not found + */ + protected function findPkSimple($key, ConnectionInterface $con) + { + $sql = 'SELECT id, name, barcode, rank_id, category_id FROM Food WHERE id = :p0'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key, PDO::PARAM_INT); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + /** @var ChildFood $obj */ + $obj = new ChildFood(); + $obj->hydrate($row); + FoodTableMap::addInstanceToPool($obj, null === $key || is_scalar($key) || is_callable([$key, '__toString']) ? (string) $key : $key); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildFood|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, ConnectionInterface $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(12, 56, 832), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return $this|ChildFoodQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + + return $this->addUsingAlias(FoodTableMap::COL_ID, $key, Criteria::EQUAL); + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return $this|ChildFoodQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + + return $this->addUsingAlias(FoodTableMap::COL_ID, $keys, Criteria::IN); + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return $this|ChildFoodQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(FoodTableMap::COL_ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(FoodTableMap::COL_ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(FoodTableMap::COL_ID, $id, $comparison); + } + + /** + * Filter the query on the name column + * + * Example usage: + * + * $query->filterByName('fooValue'); // WHERE name = 'fooValue' + * $query->filterByName('%fooValue%', Criteria::LIKE); // WHERE name LIKE '%fooValue%' + * + * + * @param string $name The value to use as filter. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return $this|ChildFoodQuery The current query, for fluid interface + */ + public function filterByName($name = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($name)) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(FoodTableMap::COL_NAME, $name, $comparison); + } + + /** + * Filter the query on the barcode column + * + * Example usage: + * + * $query->filterByBarcode(1234); // WHERE barcode = 1234 + * $query->filterByBarcode(array(12, 34)); // WHERE barcode IN (12, 34) + * $query->filterByBarcode(array('min' => 12)); // WHERE barcode > 12 + * + * + * @param mixed $barcode The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return $this|ChildFoodQuery The current query, for fluid interface + */ + public function filterByBarcode($barcode = null, $comparison = null) + { + if (is_array($barcode)) { + $useMinMax = false; + if (isset($barcode['min'])) { + $this->addUsingAlias(FoodTableMap::COL_BARCODE, $barcode['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($barcode['max'])) { + $this->addUsingAlias(FoodTableMap::COL_BARCODE, $barcode['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(FoodTableMap::COL_BARCODE, $barcode, $comparison); + } + + /** + * Filter the query on the rank_id column + * + * Example usage: + * + * $query->filterByRankId(1234); // WHERE rank_id = 1234 + * $query->filterByRankId(array(12, 34)); // WHERE rank_id IN (12, 34) + * $query->filterByRankId(array('min' => 12)); // WHERE rank_id > 12 + * + * + * @see filterByRank() + * + * @param mixed $rankId The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return $this|ChildFoodQuery The current query, for fluid interface + */ + public function filterByRankId($rankId = null, $comparison = null) + { + if (is_array($rankId)) { + $useMinMax = false; + if (isset($rankId['min'])) { + $this->addUsingAlias(FoodTableMap::COL_RANK_ID, $rankId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($rankId['max'])) { + $this->addUsingAlias(FoodTableMap::COL_RANK_ID, $rankId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(FoodTableMap::COL_RANK_ID, $rankId, $comparison); + } + + /** + * Filter the query on the category_id column + * + * Example usage: + * + * $query->filterByCategoryId(1234); // WHERE category_id = 1234 + * $query->filterByCategoryId(array(12, 34)); // WHERE category_id IN (12, 34) + * $query->filterByCategoryId(array('min' => 12)); // WHERE category_id > 12 + * + * + * @see filterByCategory() + * + * @param mixed $categoryId The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return $this|ChildFoodQuery The current query, for fluid interface + */ + public function filterByCategoryId($categoryId = null, $comparison = null) + { + if (is_array($categoryId)) { + $useMinMax = false; + if (isset($categoryId['min'])) { + $this->addUsingAlias(FoodTableMap::COL_CATEGORY_ID, $categoryId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($categoryId['max'])) { + $this->addUsingAlias(FoodTableMap::COL_CATEGORY_ID, $categoryId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(FoodTableMap::COL_CATEGORY_ID, $categoryId, $comparison); + } + + /** + * Filter the query by a related \Category object + * + * @param \Category|ObjectCollection $category The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @throws \Propel\Runtime\Exception\PropelException + * + * @return ChildFoodQuery The current query, for fluid interface + */ + public function filterByCategory($category, $comparison = null) + { + if ($category instanceof \Category) { + return $this + ->addUsingAlias(FoodTableMap::COL_CATEGORY_ID, $category->getId(), $comparison); + } elseif ($category instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(FoodTableMap::COL_CATEGORY_ID, $category->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByCategory() only accepts arguments of type \Category or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Category relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return $this|ChildFoodQuery The current query, for fluid interface + */ + public function joinCategory($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Category'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Category'); + } + + return $this; + } + + /** + * Use the Category relation Category object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \CategoryQuery A secondary query class using the current class as primary query + */ + public function useCategoryQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinCategory($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Category', '\CategoryQuery'); + } + + /** + * Filter the query by a related \Rank object + * + * @param \Rank|ObjectCollection $rank The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @throws \Propel\Runtime\Exception\PropelException + * + * @return ChildFoodQuery The current query, for fluid interface + */ + public function filterByRank($rank, $comparison = null) + { + if ($rank instanceof \Rank) { + return $this + ->addUsingAlias(FoodTableMap::COL_RANK_ID, $rank->getId(), $comparison); + } elseif ($rank instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(FoodTableMap::COL_RANK_ID, $rank->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByRank() only accepts arguments of type \Rank or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Rank relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return $this|ChildFoodQuery The current query, for fluid interface + */ + public function joinRank($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Rank'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Rank'); + } + + return $this; + } + + /** + * Use the Rank relation Rank object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \RankQuery A secondary query class using the current class as primary query + */ + public function useRankQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinRank($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Rank', '\RankQuery'); + } + + /** + * Exclude object from result + * + * @param ChildFood $food Object to remove from the list of results + * + * @return $this|ChildFoodQuery The current query, for fluid interface + */ + public function prune($food = null) + { + if ($food) { + $this->addUsingAlias(FoodTableMap::COL_ID, $food->getId(), Criteria::NOT_EQUAL); + } + + return $this; + } + + /** + * Deletes all rows from the Food table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(FoodTableMap::DATABASE_NAME); + } + + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + return $con->transaction(function () use ($con) { + $affectedRows = 0; // initialize var to track total num of affected rows + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + FoodTableMap::clearInstancePool(); + FoodTableMap::clearRelatedInstancePool(); + + return $affectedRows; + }); + } + + /** + * Performs a DELETE on the database based on the current ModelCriteria + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(FoodTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(FoodTableMap::DATABASE_NAME); + + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + return $con->transaction(function () use ($con, $criteria) { + $affectedRows = 0; // initialize var to track total num of affected rows + + FoodTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + FoodTableMap::clearRelatedInstancePool(); + + return $affectedRows; + }); + } + +} // FoodQuery diff --git a/api/generated-classes/Base/Nutrient.php b/api/generated-classes/Base/Nutrient.php new file mode 100644 index 0000000..581a3c1 --- /dev/null +++ b/api/generated-classes/Base/Nutrient.php @@ -0,0 +1,1520 @@ +modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another Nutrient instance. If + * obj is an instance of Nutrient, delegates to + * equals(Nutrient). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + if (!$obj instanceof static) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return $this|Nutrient The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + $cls = new \ReflectionClass($this); + $propertyNames = []; + $serializableProperties = array_diff($cls->getProperties(), $cls->getProperties(\ReflectionProperty::IS_STATIC)); + + foreach($serializableProperties as $property) { + $propertyNames[] = $property->getName(); + } + + return $propertyNames; + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * Get the [name] column value. + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return $this|\Nutrient The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[NutrientTableMap::COL_ID] = true; + } + + return $this; + } // setId() + + /** + * Set the value of [name] column. + * + * @param string $v new value + * @return $this|\Nutrient The current object (for fluent API support) + */ + public function setName($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->name !== $v) { + $this->name = $v; + $this->modifiedColumns[NutrientTableMap::COL_NAME] = true; + } + + return $this; + } // setName() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : NutrientTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : NutrientTableMap::translateFieldName('Name', TableMap::TYPE_PHPNAME, $indexType)]; + $this->name = (null !== $col) ? (string) $col : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 2; // 2 = NutrientTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException(sprintf('Error populating %s object', '\\Nutrient'), 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(NutrientTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildNutrientQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->collCategoryRankNutrients = null; + + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see Nutrient::setDeleted() + * @see Nutrient::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(NutrientTableMap::DATABASE_NAME); + } + + $con->transaction(function () use ($con) { + $deleteQuery = ChildNutrientQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $this->setDeleted(true); + } + }); + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(NutrientTableMap::DATABASE_NAME); + } + + return $con->transaction(function () use ($con) { + $ret = $this->preSave($con); + $isInsert = $this->isNew(); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + } else { + $ret = $ret && $this->preUpdate($con); + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + NutrientTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + + return $affectedRows; + }); + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + $affectedRows += 1; + } else { + $affectedRows += $this->doUpdate($con); + } + $this->resetModified(); + } + + if ($this->categoryRankNutrientsScheduledForDeletion !== null) { + if (!$this->categoryRankNutrientsScheduledForDeletion->isEmpty()) { + \CategoryRankNutrientQuery::create() + ->filterByPrimaryKeys($this->categoryRankNutrientsScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); + $this->categoryRankNutrientsScheduledForDeletion = null; + } + } + + if ($this->collCategoryRankNutrients !== null) { + foreach ($this->collCategoryRankNutrients as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + $this->modifiedColumns[NutrientTableMap::COL_ID] = true; + if (null !== $this->id) { + throw new PropelException('Cannot insert a value for auto-increment primary key (' . NutrientTableMap::COL_ID . ')'); + } + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(NutrientTableMap::COL_ID)) { + $modifiedColumns[':p' . $index++] = 'id'; + } + if ($this->isColumnModified(NutrientTableMap::COL_NAME)) { + $modifiedColumns[':p' . $index++] = 'name'; + } + + $sql = sprintf( + 'INSERT INTO Nutrient (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case 'id': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case 'name': + $stmt->bindValue($identifier, $this->name, PDO::PARAM_STR); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + try { + $pk = $con->lastInsertId(); + } catch (Exception $e) { + throw new PropelException('Unable to get autoincrement id.', 0, $e); + } + $this->setId($pk); + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = NutrientTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getName(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + + if (isset($alreadyDumpedObjects['Nutrient'][$this->hashCode()])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['Nutrient'][$this->hashCode()] = true; + $keys = NutrientTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getName(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->collCategoryRankNutrients) { + + switch ($keyType) { + case TableMap::TYPE_CAMELNAME: + $key = 'categoryRankNutrients'; + break; + case TableMap::TYPE_FIELDNAME: + $key = 'Category_Rank_Nutrients'; + break; + default: + $key = 'CategoryRankNutrients'; + } + + $result[$key] = $this->collCategoryRankNutrients->toArray(null, false, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return $this|\Nutrient + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = NutrientTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return $this|\Nutrient + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setName($value); + break; + } // switch() + + return $this; + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = NutrientTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) { + $this->setId($arr[$keys[0]]); + } + if (array_key_exists($keys[1], $arr)) { + $this->setName($arr[$keys[1]]); + } + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * @param string $keyType The type of keys the array uses. + * + * @return $this|\Nutrient The current object, for fluid interface + */ + public function importFrom($parser, $data, $keyType = TableMap::TYPE_PHPNAME) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), $keyType); + + return $this; + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(NutrientTableMap::DATABASE_NAME); + + if ($this->isColumnModified(NutrientTableMap::COL_ID)) { + $criteria->add(NutrientTableMap::COL_ID, $this->id); + } + if ($this->isColumnModified(NutrientTableMap::COL_NAME)) { + $criteria->add(NutrientTableMap::COL_NAME, $this->name); + } + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @throws LogicException if no primary key is defined + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = ChildNutrientQuery::create(); + $criteria->add(NutrientTableMap::COL_ID, $this->id); + + return $criteria; + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + $validPk = null !== $this->getId(); + + $validPrimaryKeyFKs = 0; + $primaryKeyFKs = []; + + if ($validPk) { + return crc32(json_encode($this->getPrimaryKey(), JSON_UNESCAPED_UNICODE)); + } elseif ($validPrimaryKeyFKs) { + return crc32(json_encode($primaryKeyFKs, JSON_UNESCAPED_UNICODE)); + } + + return spl_object_hash($this); + } + + /** + * Returns the primary key for this object (row). + * @return int + */ + public function getPrimaryKey() + { + return $this->getId(); + } + + /** + * Generic method to set the primary key (id column). + * + * @param int $key Primary key. + * @return void + */ + public function setPrimaryKey($key) + { + $this->setId($key); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + return null === $this->getId(); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \Nutrient (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setName($this->getName()); + + if ($deepCopy) { + // important: temporarily setNew(false) because this affects the behavior of + // the getter/setter methods for fkey referrer objects. + $copyObj->setNew(false); + + foreach ($this->getCategoryRankNutrients() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addCategoryRankNutrient($relObj->copy($deepCopy)); + } + } + + } // if ($deepCopy) + + if ($makeNew) { + $copyObj->setNew(true); + $copyObj->setId(NULL); // this is a auto-increment column, so set to default value + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \Nutrient Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + + /** + * Initializes a collection based on the name of a relation. + * Avoids crafting an 'init[$relationName]s' method name + * that wouldn't work when StandardEnglishPluralizer is used. + * + * @param string $relationName The name of the relation to initialize + * @return void + */ + public function initRelation($relationName) + { + if ('CategoryRankNutrient' == $relationName) { + return $this->initCategoryRankNutrients(); + } + } + + /** + * Clears out the collCategoryRankNutrients collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addCategoryRankNutrients() + */ + public function clearCategoryRankNutrients() + { + $this->collCategoryRankNutrients = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collCategoryRankNutrients collection loaded partially. + */ + public function resetPartialCategoryRankNutrients($v = true) + { + $this->collCategoryRankNutrientsPartial = $v; + } + + /** + * Initializes the collCategoryRankNutrients collection. + * + * By default this just sets the collCategoryRankNutrients collection to an empty array (like clearcollCategoryRankNutrients()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initCategoryRankNutrients($overrideExisting = true) + { + if (null !== $this->collCategoryRankNutrients && !$overrideExisting) { + return; + } + + $collectionClassName = CategoryRankNutrientTableMap::getTableMap()->getCollectionClassName(); + + $this->collCategoryRankNutrients = new $collectionClassName; + $this->collCategoryRankNutrients->setModel('\CategoryRankNutrient'); + } + + /** + * Gets an array of ChildCategoryRankNutrient objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildNutrient is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return ObjectCollection|ChildCategoryRankNutrient[] List of ChildCategoryRankNutrient objects + * @throws PropelException + */ + public function getCategoryRankNutrients(Criteria $criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collCategoryRankNutrientsPartial && !$this->isNew(); + if (null === $this->collCategoryRankNutrients || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCategoryRankNutrients) { + // return empty collection + $this->initCategoryRankNutrients(); + } else { + $collCategoryRankNutrients = ChildCategoryRankNutrientQuery::create(null, $criteria) + ->filterByNutrient($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collCategoryRankNutrientsPartial && count($collCategoryRankNutrients)) { + $this->initCategoryRankNutrients(false); + + foreach ($collCategoryRankNutrients as $obj) { + if (false == $this->collCategoryRankNutrients->contains($obj)) { + $this->collCategoryRankNutrients->append($obj); + } + } + + $this->collCategoryRankNutrientsPartial = true; + } + + return $collCategoryRankNutrients; + } + + if ($partial && $this->collCategoryRankNutrients) { + foreach ($this->collCategoryRankNutrients as $obj) { + if ($obj->isNew()) { + $collCategoryRankNutrients[] = $obj; + } + } + } + + $this->collCategoryRankNutrients = $collCategoryRankNutrients; + $this->collCategoryRankNutrientsPartial = false; + } + } + + return $this->collCategoryRankNutrients; + } + + /** + * Sets a collection of ChildCategoryRankNutrient objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $categoryRankNutrients A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return $this|ChildNutrient The current object (for fluent API support) + */ + public function setCategoryRankNutrients(Collection $categoryRankNutrients, ConnectionInterface $con = null) + { + /** @var ChildCategoryRankNutrient[] $categoryRankNutrientsToDelete */ + $categoryRankNutrientsToDelete = $this->getCategoryRankNutrients(new Criteria(), $con)->diff($categoryRankNutrients); + + + $this->categoryRankNutrientsScheduledForDeletion = $categoryRankNutrientsToDelete; + + foreach ($categoryRankNutrientsToDelete as $categoryRankNutrientRemoved) { + $categoryRankNutrientRemoved->setNutrient(null); + } + + $this->collCategoryRankNutrients = null; + foreach ($categoryRankNutrients as $categoryRankNutrient) { + $this->addCategoryRankNutrient($categoryRankNutrient); + } + + $this->collCategoryRankNutrients = $categoryRankNutrients; + $this->collCategoryRankNutrientsPartial = false; + + return $this; + } + + /** + * Returns the number of related CategoryRankNutrient objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related CategoryRankNutrient objects. + * @throws PropelException + */ + public function countCategoryRankNutrients(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collCategoryRankNutrientsPartial && !$this->isNew(); + if (null === $this->collCategoryRankNutrients || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCategoryRankNutrients) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getCategoryRankNutrients()); + } + + $query = ChildCategoryRankNutrientQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByNutrient($this) + ->count($con); + } + + return count($this->collCategoryRankNutrients); + } + + /** + * Method called to associate a ChildCategoryRankNutrient object to this object + * through the ChildCategoryRankNutrient foreign key attribute. + * + * @param ChildCategoryRankNutrient $l ChildCategoryRankNutrient + * @return $this|\Nutrient The current object (for fluent API support) + */ + public function addCategoryRankNutrient(ChildCategoryRankNutrient $l) + { + if ($this->collCategoryRankNutrients === null) { + $this->initCategoryRankNutrients(); + $this->collCategoryRankNutrientsPartial = true; + } + + if (!$this->collCategoryRankNutrients->contains($l)) { + $this->doAddCategoryRankNutrient($l); + + if ($this->categoryRankNutrientsScheduledForDeletion and $this->categoryRankNutrientsScheduledForDeletion->contains($l)) { + $this->categoryRankNutrientsScheduledForDeletion->remove($this->categoryRankNutrientsScheduledForDeletion->search($l)); + } + } + + return $this; + } + + /** + * @param ChildCategoryRankNutrient $categoryRankNutrient The ChildCategoryRankNutrient object to add. + */ + protected function doAddCategoryRankNutrient(ChildCategoryRankNutrient $categoryRankNutrient) + { + $this->collCategoryRankNutrients[]= $categoryRankNutrient; + $categoryRankNutrient->setNutrient($this); + } + + /** + * @param ChildCategoryRankNutrient $categoryRankNutrient The ChildCategoryRankNutrient object to remove. + * @return $this|ChildNutrient The current object (for fluent API support) + */ + public function removeCategoryRankNutrient(ChildCategoryRankNutrient $categoryRankNutrient) + { + if ($this->getCategoryRankNutrients()->contains($categoryRankNutrient)) { + $pos = $this->collCategoryRankNutrients->search($categoryRankNutrient); + $this->collCategoryRankNutrients->remove($pos); + if (null === $this->categoryRankNutrientsScheduledForDeletion) { + $this->categoryRankNutrientsScheduledForDeletion = clone $this->collCategoryRankNutrients; + $this->categoryRankNutrientsScheduledForDeletion->clear(); + } + $this->categoryRankNutrientsScheduledForDeletion[]= clone $categoryRankNutrient; + $categoryRankNutrient->setNutrient(null); + } + + return $this; + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Nutrient is new, it will return + * an empty collection; or if this Nutrient has previously + * been saved, it will retrieve related CategoryRankNutrients from storage. + * + * This method is protected by default in order to keep the public + * api reasonable. You can provide public methods for those you + * actually need in Nutrient. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) + * @return ObjectCollection|ChildCategoryRankNutrient[] List of ChildCategoryRankNutrient objects + */ + public function getCategoryRankNutrientsJoinCategory(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCategoryRankNutrientQuery::create(null, $criteria); + $query->joinWith('Category', $joinBehavior); + + return $this->getCategoryRankNutrients($query, $con); + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Nutrient is new, it will return + * an empty collection; or if this Nutrient has previously + * been saved, it will retrieve related CategoryRankNutrients from storage. + * + * This method is protected by default in order to keep the public + * api reasonable. You can provide public methods for those you + * actually need in Nutrient. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) + * @return ObjectCollection|ChildCategoryRankNutrient[] List of ChildCategoryRankNutrient objects + */ + public function getCategoryRankNutrientsJoinRank(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCategoryRankNutrientQuery::create(null, $criteria); + $query->joinWith('Rank', $joinBehavior); + + return $this->getCategoryRankNutrients($query, $con); + } + + /** + * Clears the current object, sets all attributes to their default values and removes + * outgoing references as well as back-references (from other objects to this one. Results probably in a database + * change of those foreign objects when you call `save` there). + */ + public function clear() + { + $this->id = null; + $this->name = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references and back-references to other model objects or collections of model objects. + * + * This method is used to reset all php object references (not the actual reference in the database). + * Necessary for object serialisation. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + if ($this->collCategoryRankNutrients) { + foreach ($this->collCategoryRankNutrients as $o) { + $o->clearAllReferences($deep); + } + } + } // if ($deep) + + $this->collCategoryRankNutrients = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(NutrientTableMap::DEFAULT_STRING_FORMAT); + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + if (is_callable('parent::preSave')) { + return parent::preSave($con); + } + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + if (is_callable('parent::postSave')) { + parent::postSave($con); + } + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + if (is_callable('parent::preInsert')) { + return parent::preInsert($con); + } + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + if (is_callable('parent::postInsert')) { + parent::postInsert($con); + } + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + if (is_callable('parent::preUpdate')) { + return parent::preUpdate($con); + } + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + if (is_callable('parent::postUpdate')) { + parent::postUpdate($con); + } + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + if (is_callable('parent::preDelete')) { + return parent::preDelete($con); + } + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + if (is_callable('parent::postDelete')) { + parent::postDelete($con); + } + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/api/generated-classes/Base/NutrientQuery.php b/api/generated-classes/Base/NutrientQuery.php new file mode 100644 index 0000000..a5b8c1e --- /dev/null +++ b/api/generated-classes/Base/NutrientQuery.php @@ -0,0 +1,468 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(12, $con); + * + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildNutrient|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, ConnectionInterface $con = null) + { + if ($key === null) { + return null; + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(NutrientTableMap::DATABASE_NAME); + } + + $this->basePreSelect($con); + + if ( + $this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins + ) { + return $this->findPkComplex($key, $con); + } + + if ((null !== ($obj = NutrientTableMap::getInstanceFromPool(null === $key || is_scalar($key) || is_callable([$key, '__toString']) ? (string) $key : $key)))) { + // the object is already in the instance pool + return $obj; + } + + return $this->findPkSimple($key, $con); + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @throws \Propel\Runtime\Exception\PropelException + * + * @return ChildNutrient A model object, or null if the key is not found + */ + protected function findPkSimple($key, ConnectionInterface $con) + { + $sql = 'SELECT id, name FROM Nutrient WHERE id = :p0'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key, PDO::PARAM_INT); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + /** @var ChildNutrient $obj */ + $obj = new ChildNutrient(); + $obj->hydrate($row); + NutrientTableMap::addInstanceToPool($obj, null === $key || is_scalar($key) || is_callable([$key, '__toString']) ? (string) $key : $key); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildNutrient|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, ConnectionInterface $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(12, 56, 832), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return $this|ChildNutrientQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + + return $this->addUsingAlias(NutrientTableMap::COL_ID, $key, Criteria::EQUAL); + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return $this|ChildNutrientQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + + return $this->addUsingAlias(NutrientTableMap::COL_ID, $keys, Criteria::IN); + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return $this|ChildNutrientQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(NutrientTableMap::COL_ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(NutrientTableMap::COL_ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(NutrientTableMap::COL_ID, $id, $comparison); + } + + /** + * Filter the query on the name column + * + * Example usage: + * + * $query->filterByName('fooValue'); // WHERE name = 'fooValue' + * $query->filterByName('%fooValue%', Criteria::LIKE); // WHERE name LIKE '%fooValue%' + * + * + * @param string $name The value to use as filter. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return $this|ChildNutrientQuery The current query, for fluid interface + */ + public function filterByName($name = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($name)) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(NutrientTableMap::COL_NAME, $name, $comparison); + } + + /** + * Filter the query by a related \CategoryRankNutrient object + * + * @param \CategoryRankNutrient|ObjectCollection $categoryRankNutrient the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildNutrientQuery The current query, for fluid interface + */ + public function filterByCategoryRankNutrient($categoryRankNutrient, $comparison = null) + { + if ($categoryRankNutrient instanceof \CategoryRankNutrient) { + return $this + ->addUsingAlias(NutrientTableMap::COL_ID, $categoryRankNutrient->getNutrientId(), $comparison); + } elseif ($categoryRankNutrient instanceof ObjectCollection) { + return $this + ->useCategoryRankNutrientQuery() + ->filterByPrimaryKeys($categoryRankNutrient->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByCategoryRankNutrient() only accepts arguments of type \CategoryRankNutrient or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the CategoryRankNutrient relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return $this|ChildNutrientQuery The current query, for fluid interface + */ + public function joinCategoryRankNutrient($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('CategoryRankNutrient'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'CategoryRankNutrient'); + } + + return $this; + } + + /** + * Use the CategoryRankNutrient relation CategoryRankNutrient object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \CategoryRankNutrientQuery A secondary query class using the current class as primary query + */ + public function useCategoryRankNutrientQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinCategoryRankNutrient($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'CategoryRankNutrient', '\CategoryRankNutrientQuery'); + } + + /** + * Exclude object from result + * + * @param ChildNutrient $nutrient Object to remove from the list of results + * + * @return $this|ChildNutrientQuery The current query, for fluid interface + */ + public function prune($nutrient = null) + { + if ($nutrient) { + $this->addUsingAlias(NutrientTableMap::COL_ID, $nutrient->getId(), Criteria::NOT_EQUAL); + } + + return $this; + } + + /** + * Deletes all rows from the Nutrient table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(NutrientTableMap::DATABASE_NAME); + } + + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + return $con->transaction(function () use ($con) { + $affectedRows = 0; // initialize var to track total num of affected rows + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + NutrientTableMap::clearInstancePool(); + NutrientTableMap::clearRelatedInstancePool(); + + return $affectedRows; + }); + } + + /** + * Performs a DELETE on the database based on the current ModelCriteria + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(NutrientTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(NutrientTableMap::DATABASE_NAME); + + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + return $con->transaction(function () use ($con, $criteria) { + $affectedRows = 0; // initialize var to track total num of affected rows + + NutrientTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + NutrientTableMap::clearRelatedInstancePool(); + + return $affectedRows; + }); + } + +} // NutrientQuery diff --git a/api/generated-classes/Base/Rank.php b/api/generated-classes/Base/Rank.php new file mode 100644 index 0000000..164de22 --- /dev/null +++ b/api/generated-classes/Base/Rank.php @@ -0,0 +1,1835 @@ +modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another Rank instance. If + * obj is an instance of Rank, delegates to + * equals(Rank). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + if (!$obj instanceof static) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return $this|Rank The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + $cls = new \ReflectionClass($this); + $propertyNames = []; + $serializableProperties = array_diff($cls->getProperties(), $cls->getProperties(\ReflectionProperty::IS_STATIC)); + + foreach($serializableProperties as $property) { + $propertyNames[] = $property->getName(); + } + + return $propertyNames; + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * Get the [name] column value. + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return $this|\Rank The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[RankTableMap::COL_ID] = true; + } + + return $this; + } // setId() + + /** + * Set the value of [name] column. + * + * @param string $v new value + * @return $this|\Rank The current object (for fluent API support) + */ + public function setName($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->name !== $v) { + $this->name = $v; + $this->modifiedColumns[RankTableMap::COL_NAME] = true; + } + + return $this; + } // setName() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : RankTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : RankTableMap::translateFieldName('Name', TableMap::TYPE_PHPNAME, $indexType)]; + $this->name = (null !== $col) ? (string) $col : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 2; // 2 = RankTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException(sprintf('Error populating %s object', '\\Rank'), 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(RankTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildRankQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->collCategoryRankNutrients = null; + + $this->collFoods = null; + + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see Rank::setDeleted() + * @see Rank::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(RankTableMap::DATABASE_NAME); + } + + $con->transaction(function () use ($con) { + $deleteQuery = ChildRankQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $this->setDeleted(true); + } + }); + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(RankTableMap::DATABASE_NAME); + } + + return $con->transaction(function () use ($con) { + $ret = $this->preSave($con); + $isInsert = $this->isNew(); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + } else { + $ret = $ret && $this->preUpdate($con); + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + RankTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + + return $affectedRows; + }); + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + $affectedRows += 1; + } else { + $affectedRows += $this->doUpdate($con); + } + $this->resetModified(); + } + + if ($this->categoryRankNutrientsScheduledForDeletion !== null) { + if (!$this->categoryRankNutrientsScheduledForDeletion->isEmpty()) { + \CategoryRankNutrientQuery::create() + ->filterByPrimaryKeys($this->categoryRankNutrientsScheduledForDeletion->getPrimaryKeys(false)) + ->delete($con); + $this->categoryRankNutrientsScheduledForDeletion = null; + } + } + + if ($this->collCategoryRankNutrients !== null) { + foreach ($this->collCategoryRankNutrients as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + + if ($this->foodsScheduledForDeletion !== null) { + if (!$this->foodsScheduledForDeletion->isEmpty()) { + foreach ($this->foodsScheduledForDeletion as $food) { + // need to save related object because we set the relation to null + $food->save($con); + } + $this->foodsScheduledForDeletion = null; + } + } + + if ($this->collFoods !== null) { + foreach ($this->collFoods as $referrerFK) { + if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) { + $affectedRows += $referrerFK->save($con); + } + } + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + $this->modifiedColumns[RankTableMap::COL_ID] = true; + if (null !== $this->id) { + throw new PropelException('Cannot insert a value for auto-increment primary key (' . RankTableMap::COL_ID . ')'); + } + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(RankTableMap::COL_ID)) { + $modifiedColumns[':p' . $index++] = 'id'; + } + if ($this->isColumnModified(RankTableMap::COL_NAME)) { + $modifiedColumns[':p' . $index++] = 'name'; + } + + $sql = sprintf( + 'INSERT INTO Rank (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case 'id': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case 'name': + $stmt->bindValue($identifier, $this->name, PDO::PARAM_STR); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + try { + $pk = $con->lastInsertId(); + } catch (Exception $e) { + throw new PropelException('Unable to get autoincrement id.', 0, $e); + } + $this->setId($pk); + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = RankTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getName(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + + if (isset($alreadyDumpedObjects['Rank'][$this->hashCode()])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['Rank'][$this->hashCode()] = true; + $keys = RankTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getName(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->collCategoryRankNutrients) { + + switch ($keyType) { + case TableMap::TYPE_CAMELNAME: + $key = 'categoryRankNutrients'; + break; + case TableMap::TYPE_FIELDNAME: + $key = 'Category_Rank_Nutrients'; + break; + default: + $key = 'CategoryRankNutrients'; + } + + $result[$key] = $this->collCategoryRankNutrients->toArray(null, false, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } + if (null !== $this->collFoods) { + + switch ($keyType) { + case TableMap::TYPE_CAMELNAME: + $key = 'foods'; + break; + case TableMap::TYPE_FIELDNAME: + $key = 'Foods'; + break; + default: + $key = 'Foods'; + } + + $result[$key] = $this->collFoods->toArray(null, false, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return $this|\Rank + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = RankTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return $this|\Rank + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setName($value); + break; + } // switch() + + return $this; + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = RankTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) { + $this->setId($arr[$keys[0]]); + } + if (array_key_exists($keys[1], $arr)) { + $this->setName($arr[$keys[1]]); + } + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * @param string $keyType The type of keys the array uses. + * + * @return $this|\Rank The current object, for fluid interface + */ + public function importFrom($parser, $data, $keyType = TableMap::TYPE_PHPNAME) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), $keyType); + + return $this; + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(RankTableMap::DATABASE_NAME); + + if ($this->isColumnModified(RankTableMap::COL_ID)) { + $criteria->add(RankTableMap::COL_ID, $this->id); + } + if ($this->isColumnModified(RankTableMap::COL_NAME)) { + $criteria->add(RankTableMap::COL_NAME, $this->name); + } + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @throws LogicException if no primary key is defined + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = ChildRankQuery::create(); + $criteria->add(RankTableMap::COL_ID, $this->id); + + return $criteria; + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + $validPk = null !== $this->getId(); + + $validPrimaryKeyFKs = 0; + $primaryKeyFKs = []; + + if ($validPk) { + return crc32(json_encode($this->getPrimaryKey(), JSON_UNESCAPED_UNICODE)); + } elseif ($validPrimaryKeyFKs) { + return crc32(json_encode($primaryKeyFKs, JSON_UNESCAPED_UNICODE)); + } + + return spl_object_hash($this); + } + + /** + * Returns the primary key for this object (row). + * @return int + */ + public function getPrimaryKey() + { + return $this->getId(); + } + + /** + * Generic method to set the primary key (id column). + * + * @param int $key Primary key. + * @return void + */ + public function setPrimaryKey($key) + { + $this->setId($key); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + return null === $this->getId(); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \Rank (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setName($this->getName()); + + if ($deepCopy) { + // important: temporarily setNew(false) because this affects the behavior of + // the getter/setter methods for fkey referrer objects. + $copyObj->setNew(false); + + foreach ($this->getCategoryRankNutrients() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addCategoryRankNutrient($relObj->copy($deepCopy)); + } + } + + foreach ($this->getFoods() as $relObj) { + if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves + $copyObj->addFood($relObj->copy($deepCopy)); + } + } + + } // if ($deepCopy) + + if ($makeNew) { + $copyObj->setNew(true); + $copyObj->setId(NULL); // this is a auto-increment column, so set to default value + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \Rank Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + + /** + * Initializes a collection based on the name of a relation. + * Avoids crafting an 'init[$relationName]s' method name + * that wouldn't work when StandardEnglishPluralizer is used. + * + * @param string $relationName The name of the relation to initialize + * @return void + */ + public function initRelation($relationName) + { + if ('CategoryRankNutrient' == $relationName) { + return $this->initCategoryRankNutrients(); + } + if ('Food' == $relationName) { + return $this->initFoods(); + } + } + + /** + * Clears out the collCategoryRankNutrients collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addCategoryRankNutrients() + */ + public function clearCategoryRankNutrients() + { + $this->collCategoryRankNutrients = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collCategoryRankNutrients collection loaded partially. + */ + public function resetPartialCategoryRankNutrients($v = true) + { + $this->collCategoryRankNutrientsPartial = $v; + } + + /** + * Initializes the collCategoryRankNutrients collection. + * + * By default this just sets the collCategoryRankNutrients collection to an empty array (like clearcollCategoryRankNutrients()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initCategoryRankNutrients($overrideExisting = true) + { + if (null !== $this->collCategoryRankNutrients && !$overrideExisting) { + return; + } + + $collectionClassName = CategoryRankNutrientTableMap::getTableMap()->getCollectionClassName(); + + $this->collCategoryRankNutrients = new $collectionClassName; + $this->collCategoryRankNutrients->setModel('\CategoryRankNutrient'); + } + + /** + * Gets an array of ChildCategoryRankNutrient objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildRank is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return ObjectCollection|ChildCategoryRankNutrient[] List of ChildCategoryRankNutrient objects + * @throws PropelException + */ + public function getCategoryRankNutrients(Criteria $criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collCategoryRankNutrientsPartial && !$this->isNew(); + if (null === $this->collCategoryRankNutrients || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCategoryRankNutrients) { + // return empty collection + $this->initCategoryRankNutrients(); + } else { + $collCategoryRankNutrients = ChildCategoryRankNutrientQuery::create(null, $criteria) + ->filterByRank($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collCategoryRankNutrientsPartial && count($collCategoryRankNutrients)) { + $this->initCategoryRankNutrients(false); + + foreach ($collCategoryRankNutrients as $obj) { + if (false == $this->collCategoryRankNutrients->contains($obj)) { + $this->collCategoryRankNutrients->append($obj); + } + } + + $this->collCategoryRankNutrientsPartial = true; + } + + return $collCategoryRankNutrients; + } + + if ($partial && $this->collCategoryRankNutrients) { + foreach ($this->collCategoryRankNutrients as $obj) { + if ($obj->isNew()) { + $collCategoryRankNutrients[] = $obj; + } + } + } + + $this->collCategoryRankNutrients = $collCategoryRankNutrients; + $this->collCategoryRankNutrientsPartial = false; + } + } + + return $this->collCategoryRankNutrients; + } + + /** + * Sets a collection of ChildCategoryRankNutrient objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $categoryRankNutrients A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return $this|ChildRank The current object (for fluent API support) + */ + public function setCategoryRankNutrients(Collection $categoryRankNutrients, ConnectionInterface $con = null) + { + /** @var ChildCategoryRankNutrient[] $categoryRankNutrientsToDelete */ + $categoryRankNutrientsToDelete = $this->getCategoryRankNutrients(new Criteria(), $con)->diff($categoryRankNutrients); + + + $this->categoryRankNutrientsScheduledForDeletion = $categoryRankNutrientsToDelete; + + foreach ($categoryRankNutrientsToDelete as $categoryRankNutrientRemoved) { + $categoryRankNutrientRemoved->setRank(null); + } + + $this->collCategoryRankNutrients = null; + foreach ($categoryRankNutrients as $categoryRankNutrient) { + $this->addCategoryRankNutrient($categoryRankNutrient); + } + + $this->collCategoryRankNutrients = $categoryRankNutrients; + $this->collCategoryRankNutrientsPartial = false; + + return $this; + } + + /** + * Returns the number of related CategoryRankNutrient objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related CategoryRankNutrient objects. + * @throws PropelException + */ + public function countCategoryRankNutrients(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collCategoryRankNutrientsPartial && !$this->isNew(); + if (null === $this->collCategoryRankNutrients || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collCategoryRankNutrients) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getCategoryRankNutrients()); + } + + $query = ChildCategoryRankNutrientQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByRank($this) + ->count($con); + } + + return count($this->collCategoryRankNutrients); + } + + /** + * Method called to associate a ChildCategoryRankNutrient object to this object + * through the ChildCategoryRankNutrient foreign key attribute. + * + * @param ChildCategoryRankNutrient $l ChildCategoryRankNutrient + * @return $this|\Rank The current object (for fluent API support) + */ + public function addCategoryRankNutrient(ChildCategoryRankNutrient $l) + { + if ($this->collCategoryRankNutrients === null) { + $this->initCategoryRankNutrients(); + $this->collCategoryRankNutrientsPartial = true; + } + + if (!$this->collCategoryRankNutrients->contains($l)) { + $this->doAddCategoryRankNutrient($l); + + if ($this->categoryRankNutrientsScheduledForDeletion and $this->categoryRankNutrientsScheduledForDeletion->contains($l)) { + $this->categoryRankNutrientsScheduledForDeletion->remove($this->categoryRankNutrientsScheduledForDeletion->search($l)); + } + } + + return $this; + } + + /** + * @param ChildCategoryRankNutrient $categoryRankNutrient The ChildCategoryRankNutrient object to add. + */ + protected function doAddCategoryRankNutrient(ChildCategoryRankNutrient $categoryRankNutrient) + { + $this->collCategoryRankNutrients[]= $categoryRankNutrient; + $categoryRankNutrient->setRank($this); + } + + /** + * @param ChildCategoryRankNutrient $categoryRankNutrient The ChildCategoryRankNutrient object to remove. + * @return $this|ChildRank The current object (for fluent API support) + */ + public function removeCategoryRankNutrient(ChildCategoryRankNutrient $categoryRankNutrient) + { + if ($this->getCategoryRankNutrients()->contains($categoryRankNutrient)) { + $pos = $this->collCategoryRankNutrients->search($categoryRankNutrient); + $this->collCategoryRankNutrients->remove($pos); + if (null === $this->categoryRankNutrientsScheduledForDeletion) { + $this->categoryRankNutrientsScheduledForDeletion = clone $this->collCategoryRankNutrients; + $this->categoryRankNutrientsScheduledForDeletion->clear(); + } + $this->categoryRankNutrientsScheduledForDeletion[]= clone $categoryRankNutrient; + $categoryRankNutrient->setRank(null); + } + + return $this; + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Rank is new, it will return + * an empty collection; or if this Rank has previously + * been saved, it will retrieve related CategoryRankNutrients from storage. + * + * This method is protected by default in order to keep the public + * api reasonable. You can provide public methods for those you + * actually need in Rank. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) + * @return ObjectCollection|ChildCategoryRankNutrient[] List of ChildCategoryRankNutrient objects + */ + public function getCategoryRankNutrientsJoinNutrient(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCategoryRankNutrientQuery::create(null, $criteria); + $query->joinWith('Nutrient', $joinBehavior); + + return $this->getCategoryRankNutrients($query, $con); + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Rank is new, it will return + * an empty collection; or if this Rank has previously + * been saved, it will retrieve related CategoryRankNutrients from storage. + * + * This method is protected by default in order to keep the public + * api reasonable. You can provide public methods for those you + * actually need in Rank. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) + * @return ObjectCollection|ChildCategoryRankNutrient[] List of ChildCategoryRankNutrient objects + */ + public function getCategoryRankNutrientsJoinCategory(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildCategoryRankNutrientQuery::create(null, $criteria); + $query->joinWith('Category', $joinBehavior); + + return $this->getCategoryRankNutrients($query, $con); + } + + /** + * Clears out the collFoods collection + * + * This does not modify the database; however, it will remove any associated objects, causing + * them to be refetched by subsequent calls to accessor method. + * + * @return void + * @see addFoods() + */ + public function clearFoods() + { + $this->collFoods = null; // important to set this to NULL since that means it is uninitialized + } + + /** + * Reset is the collFoods collection loaded partially. + */ + public function resetPartialFoods($v = true) + { + $this->collFoodsPartial = $v; + } + + /** + * Initializes the collFoods collection. + * + * By default this just sets the collFoods collection to an empty array (like clearcollFoods()); + * however, you may wish to override this method in your stub class to provide setting appropriate + * to your application -- for example, setting the initial array to the values stored in database. + * + * @param boolean $overrideExisting If set to true, the method call initializes + * the collection even if it is not empty + * + * @return void + */ + public function initFoods($overrideExisting = true) + { + if (null !== $this->collFoods && !$overrideExisting) { + return; + } + + $collectionClassName = FoodTableMap::getTableMap()->getCollectionClassName(); + + $this->collFoods = new $collectionClassName; + $this->collFoods->setModel('\Food'); + } + + /** + * Gets an array of ChildFood objects which contain a foreign key that references this object. + * + * If the $criteria is not null, it is used to always fetch the results from the database. + * Otherwise the results are fetched from the database the first time, then cached. + * Next time the same method is called without $criteria, the cached collection is returned. + * If this ChildRank is new, it will return + * an empty collection or the current collection; the criteria is ignored on a new object. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @return ObjectCollection|ChildFood[] List of ChildFood objects + * @throws PropelException + */ + public function getFoods(Criteria $criteria = null, ConnectionInterface $con = null) + { + $partial = $this->collFoodsPartial && !$this->isNew(); + if (null === $this->collFoods || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collFoods) { + // return empty collection + $this->initFoods(); + } else { + $collFoods = ChildFoodQuery::create(null, $criteria) + ->filterByRank($this) + ->find($con); + + if (null !== $criteria) { + if (false !== $this->collFoodsPartial && count($collFoods)) { + $this->initFoods(false); + + foreach ($collFoods as $obj) { + if (false == $this->collFoods->contains($obj)) { + $this->collFoods->append($obj); + } + } + + $this->collFoodsPartial = true; + } + + return $collFoods; + } + + if ($partial && $this->collFoods) { + foreach ($this->collFoods as $obj) { + if ($obj->isNew()) { + $collFoods[] = $obj; + } + } + } + + $this->collFoods = $collFoods; + $this->collFoodsPartial = false; + } + } + + return $this->collFoods; + } + + /** + * Sets a collection of ChildFood objects related by a one-to-many relationship + * to the current object. + * It will also schedule objects for deletion based on a diff between old objects (aka persisted) + * and new objects from the given Propel collection. + * + * @param Collection $foods A Propel collection. + * @param ConnectionInterface $con Optional connection object + * @return $this|ChildRank The current object (for fluent API support) + */ + public function setFoods(Collection $foods, ConnectionInterface $con = null) + { + /** @var ChildFood[] $foodsToDelete */ + $foodsToDelete = $this->getFoods(new Criteria(), $con)->diff($foods); + + + $this->foodsScheduledForDeletion = $foodsToDelete; + + foreach ($foodsToDelete as $foodRemoved) { + $foodRemoved->setRank(null); + } + + $this->collFoods = null; + foreach ($foods as $food) { + $this->addFood($food); + } + + $this->collFoods = $foods; + $this->collFoodsPartial = false; + + return $this; + } + + /** + * Returns the number of related Food objects. + * + * @param Criteria $criteria + * @param boolean $distinct + * @param ConnectionInterface $con + * @return int Count of related Food objects. + * @throws PropelException + */ + public function countFoods(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null) + { + $partial = $this->collFoodsPartial && !$this->isNew(); + if (null === $this->collFoods || null !== $criteria || $partial) { + if ($this->isNew() && null === $this->collFoods) { + return 0; + } + + if ($partial && !$criteria) { + return count($this->getFoods()); + } + + $query = ChildFoodQuery::create(null, $criteria); + if ($distinct) { + $query->distinct(); + } + + return $query + ->filterByRank($this) + ->count($con); + } + + return count($this->collFoods); + } + + /** + * Method called to associate a ChildFood object to this object + * through the ChildFood foreign key attribute. + * + * @param ChildFood $l ChildFood + * @return $this|\Rank The current object (for fluent API support) + */ + public function addFood(ChildFood $l) + { + if ($this->collFoods === null) { + $this->initFoods(); + $this->collFoodsPartial = true; + } + + if (!$this->collFoods->contains($l)) { + $this->doAddFood($l); + + if ($this->foodsScheduledForDeletion and $this->foodsScheduledForDeletion->contains($l)) { + $this->foodsScheduledForDeletion->remove($this->foodsScheduledForDeletion->search($l)); + } + } + + return $this; + } + + /** + * @param ChildFood $food The ChildFood object to add. + */ + protected function doAddFood(ChildFood $food) + { + $this->collFoods[]= $food; + $food->setRank($this); + } + + /** + * @param ChildFood $food The ChildFood object to remove. + * @return $this|ChildRank The current object (for fluent API support) + */ + public function removeFood(ChildFood $food) + { + if ($this->getFoods()->contains($food)) { + $pos = $this->collFoods->search($food); + $this->collFoods->remove($pos); + if (null === $this->foodsScheduledForDeletion) { + $this->foodsScheduledForDeletion = clone $this->collFoods; + $this->foodsScheduledForDeletion->clear(); + } + $this->foodsScheduledForDeletion[]= $food; + $food->setRank(null); + } + + return $this; + } + + + /** + * If this collection has already been initialized with + * an identical criteria, it returns the collection. + * Otherwise if this Rank is new, it will return + * an empty collection; or if this Rank has previously + * been saved, it will retrieve related Foods from storage. + * + * This method is protected by default in order to keep the public + * api reasonable. You can provide public methods for those you + * actually need in Rank. + * + * @param Criteria $criteria optional Criteria object to narrow the query + * @param ConnectionInterface $con optional connection object + * @param string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN) + * @return ObjectCollection|ChildFood[] List of ChildFood objects + */ + public function getFoodsJoinCategory(Criteria $criteria = null, ConnectionInterface $con = null, $joinBehavior = Criteria::LEFT_JOIN) + { + $query = ChildFoodQuery::create(null, $criteria); + $query->joinWith('Category', $joinBehavior); + + return $this->getFoods($query, $con); + } + + /** + * Clears the current object, sets all attributes to their default values and removes + * outgoing references as well as back-references (from other objects to this one. Results probably in a database + * change of those foreign objects when you call `save` there). + */ + public function clear() + { + $this->id = null; + $this->name = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references and back-references to other model objects or collections of model objects. + * + * This method is used to reset all php object references (not the actual reference in the database). + * Necessary for object serialisation. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + if ($this->collCategoryRankNutrients) { + foreach ($this->collCategoryRankNutrients as $o) { + $o->clearAllReferences($deep); + } + } + if ($this->collFoods) { + foreach ($this->collFoods as $o) { + $o->clearAllReferences($deep); + } + } + } // if ($deep) + + $this->collCategoryRankNutrients = null; + $this->collFoods = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(RankTableMap::DEFAULT_STRING_FORMAT); + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + if (is_callable('parent::preSave')) { + return parent::preSave($con); + } + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + if (is_callable('parent::postSave')) { + parent::postSave($con); + } + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + if (is_callable('parent::preInsert')) { + return parent::preInsert($con); + } + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + if (is_callable('parent::postInsert')) { + parent::postInsert($con); + } + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + if (is_callable('parent::preUpdate')) { + return parent::preUpdate($con); + } + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + if (is_callable('parent::postUpdate')) { + parent::postUpdate($con); + } + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + if (is_callable('parent::preDelete')) { + return parent::preDelete($con); + } + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + if (is_callable('parent::postDelete')) { + parent::postDelete($con); + } + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/api/generated-classes/Base/RankQuery.php b/api/generated-classes/Base/RankQuery.php new file mode 100644 index 0000000..9f3d376 --- /dev/null +++ b/api/generated-classes/Base/RankQuery.php @@ -0,0 +1,551 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(12, $con); + * + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildRank|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, ConnectionInterface $con = null) + { + if ($key === null) { + return null; + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(RankTableMap::DATABASE_NAME); + } + + $this->basePreSelect($con); + + if ( + $this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins + ) { + return $this->findPkComplex($key, $con); + } + + if ((null !== ($obj = RankTableMap::getInstanceFromPool(null === $key || is_scalar($key) || is_callable([$key, '__toString']) ? (string) $key : $key)))) { + // the object is already in the instance pool + return $obj; + } + + return $this->findPkSimple($key, $con); + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @throws \Propel\Runtime\Exception\PropelException + * + * @return ChildRank A model object, or null if the key is not found + */ + protected function findPkSimple($key, ConnectionInterface $con) + { + $sql = 'SELECT id, name FROM Rank WHERE id = :p0'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key, PDO::PARAM_INT); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + /** @var ChildRank $obj */ + $obj = new ChildRank(); + $obj->hydrate($row); + RankTableMap::addInstanceToPool($obj, null === $key || is_scalar($key) || is_callable([$key, '__toString']) ? (string) $key : $key); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildRank|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, ConnectionInterface $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(12, 56, 832), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return $this|ChildRankQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + + return $this->addUsingAlias(RankTableMap::COL_ID, $key, Criteria::EQUAL); + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return $this|ChildRankQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + + return $this->addUsingAlias(RankTableMap::COL_ID, $keys, Criteria::IN); + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return $this|ChildRankQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(RankTableMap::COL_ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(RankTableMap::COL_ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(RankTableMap::COL_ID, $id, $comparison); + } + + /** + * Filter the query on the name column + * + * Example usage: + * + * $query->filterByName('fooValue'); // WHERE name = 'fooValue' + * $query->filterByName('%fooValue%', Criteria::LIKE); // WHERE name LIKE '%fooValue%' + * + * + * @param string $name The value to use as filter. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return $this|ChildRankQuery The current query, for fluid interface + */ + public function filterByName($name = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($name)) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(RankTableMap::COL_NAME, $name, $comparison); + } + + /** + * Filter the query by a related \CategoryRankNutrient object + * + * @param \CategoryRankNutrient|ObjectCollection $categoryRankNutrient the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildRankQuery The current query, for fluid interface + */ + public function filterByCategoryRankNutrient($categoryRankNutrient, $comparison = null) + { + if ($categoryRankNutrient instanceof \CategoryRankNutrient) { + return $this + ->addUsingAlias(RankTableMap::COL_ID, $categoryRankNutrient->getRankId(), $comparison); + } elseif ($categoryRankNutrient instanceof ObjectCollection) { + return $this + ->useCategoryRankNutrientQuery() + ->filterByPrimaryKeys($categoryRankNutrient->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByCategoryRankNutrient() only accepts arguments of type \CategoryRankNutrient or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the CategoryRankNutrient relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return $this|ChildRankQuery The current query, for fluid interface + */ + public function joinCategoryRankNutrient($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('CategoryRankNutrient'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'CategoryRankNutrient'); + } + + return $this; + } + + /** + * Use the CategoryRankNutrient relation CategoryRankNutrient object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \CategoryRankNutrientQuery A secondary query class using the current class as primary query + */ + public function useCategoryRankNutrientQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) + { + return $this + ->joinCategoryRankNutrient($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'CategoryRankNutrient', '\CategoryRankNutrientQuery'); + } + + /** + * Filter the query by a related \Food object + * + * @param \Food|ObjectCollection $food the related object to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return ChildRankQuery The current query, for fluid interface + */ + public function filterByFood($food, $comparison = null) + { + if ($food instanceof \Food) { + return $this + ->addUsingAlias(RankTableMap::COL_ID, $food->getRankId(), $comparison); + } elseif ($food instanceof ObjectCollection) { + return $this + ->useFoodQuery() + ->filterByPrimaryKeys($food->getPrimaryKeys()) + ->endUse(); + } else { + throw new PropelException('filterByFood() only accepts arguments of type \Food or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Food relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return $this|ChildRankQuery The current query, for fluid interface + */ + public function joinFood($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Food'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Food'); + } + + return $this; + } + + /** + * Use the Food relation Food object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \FoodQuery A secondary query class using the current class as primary query + */ + public function useFoodQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinFood($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Food', '\FoodQuery'); + } + + /** + * Exclude object from result + * + * @param ChildRank $rank Object to remove from the list of results + * + * @return $this|ChildRankQuery The current query, for fluid interface + */ + public function prune($rank = null) + { + if ($rank) { + $this->addUsingAlias(RankTableMap::COL_ID, $rank->getId(), Criteria::NOT_EQUAL); + } + + return $this; + } + + /** + * Deletes all rows from the Rank table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(RankTableMap::DATABASE_NAME); + } + + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + return $con->transaction(function () use ($con) { + $affectedRows = 0; // initialize var to track total num of affected rows + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + RankTableMap::clearInstancePool(); + RankTableMap::clearRelatedInstancePool(); + + return $affectedRows; + }); + } + + /** + * Performs a DELETE on the database based on the current ModelCriteria + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(RankTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(RankTableMap::DATABASE_NAME); + + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + return $con->transaction(function () use ($con, $criteria) { + $affectedRows = 0; // initialize var to track total num of affected rows + + RankTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + RankTableMap::clearRelatedInstancePool(); + + return $affectedRows; + }); + } + +} // RankQuery diff --git a/api/generated-classes/Base/Subcategory.php b/api/generated-classes/Base/Subcategory.php new file mode 100644 index 0000000..c6a7ba1 --- /dev/null +++ b/api/generated-classes/Base/Subcategory.php @@ -0,0 +1,1316 @@ +modifiedColumns; + } + + /** + * Has specified column been modified? + * + * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID + * @return boolean True if $col has been modified. + */ + public function isColumnModified($col) + { + return $this->modifiedColumns && isset($this->modifiedColumns[$col]); + } + + /** + * Get the columns that have been modified in this object. + * @return array A unique list of the modified column names for this object. + */ + public function getModifiedColumns() + { + return $this->modifiedColumns ? array_keys($this->modifiedColumns) : []; + } + + /** + * Returns whether the object has ever been saved. This will + * be false, if the object was retrieved from storage or was created + * and then saved. + * + * @return boolean true, if the object has never been persisted. + */ + public function isNew() + { + return $this->new; + } + + /** + * Setter for the isNew attribute. This method will be called + * by Propel-generated children and objects. + * + * @param boolean $b the state of the object. + */ + public function setNew($b) + { + $this->new = (boolean) $b; + } + + /** + * Whether this object has been deleted. + * @return boolean The deleted state of this object. + */ + public function isDeleted() + { + return $this->deleted; + } + + /** + * Specify whether this object has been deleted. + * @param boolean $b The deleted state of this object. + * @return void + */ + public function setDeleted($b) + { + $this->deleted = (boolean) $b; + } + + /** + * Sets the modified state for the object to be false. + * @param string $col If supplied, only the specified column is reset. + * @return void + */ + public function resetModified($col = null) + { + if (null !== $col) { + if (isset($this->modifiedColumns[$col])) { + unset($this->modifiedColumns[$col]); + } + } else { + $this->modifiedColumns = array(); + } + } + + /** + * Compares this with another Subcategory instance. If + * obj is an instance of Subcategory, delegates to + * equals(Subcategory). Otherwise, returns false. + * + * @param mixed $obj The object to compare to. + * @return boolean Whether equal to the object specified. + */ + public function equals($obj) + { + if (!$obj instanceof static) { + return false; + } + + if ($this === $obj) { + return true; + } + + if (null === $this->getPrimaryKey() || null === $obj->getPrimaryKey()) { + return false; + } + + return $this->getPrimaryKey() === $obj->getPrimaryKey(); + } + + /** + * Get the associative array of the virtual columns in this object + * + * @return array + */ + public function getVirtualColumns() + { + return $this->virtualColumns; + } + + /** + * Checks the existence of a virtual column in this object + * + * @param string $name The virtual column name + * @return boolean + */ + public function hasVirtualColumn($name) + { + return array_key_exists($name, $this->virtualColumns); + } + + /** + * Get the value of a virtual column in this object + * + * @param string $name The virtual column name + * @return mixed + * + * @throws PropelException + */ + public function getVirtualColumn($name) + { + if (!$this->hasVirtualColumn($name)) { + throw new PropelException(sprintf('Cannot get value of inexistent virtual column %s.', $name)); + } + + return $this->virtualColumns[$name]; + } + + /** + * Set the value of a virtual column in this object + * + * @param string $name The virtual column name + * @param mixed $value The value to give to the virtual column + * + * @return $this|Subcategory The current object, for fluid interface + */ + public function setVirtualColumn($name, $value) + { + $this->virtualColumns[$name] = $value; + + return $this; + } + + /** + * Logs a message using Propel::log(). + * + * @param string $msg + * @param int $priority One of the Propel::LOG_* logging levels + * @return boolean + */ + protected function log($msg, $priority = Propel::LOG_INFO) + { + return Propel::log(get_class($this) . ': ' . $msg, $priority); + } + + /** + * Export the current object properties to a string, using a given parser format + * + * $book = BookQuery::create()->findPk(9012); + * echo $book->exportTo('JSON'); + * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. + * @return string The exported data + */ + public function exportTo($parser, $includeLazyLoadColumns = true) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true)); + } + + /** + * Clean up internal collections prior to serializing + * Avoids recursive loops that turn into segmentation faults when serializing + */ + public function __sleep() + { + $this->clearAllReferences(); + + $cls = new \ReflectionClass($this); + $propertyNames = []; + $serializableProperties = array_diff($cls->getProperties(), $cls->getProperties(\ReflectionProperty::IS_STATIC)); + + foreach($serializableProperties as $property) { + $propertyNames[] = $property->getName(); + } + + return $propertyNames; + } + + /** + * Get the [id] column value. + * + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * Get the [name] column value. + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Get the [category_id] column value. + * + * @return int + */ + public function getCategoryId() + { + return $this->category_id; + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return $this|\Subcategory The current object (for fluent API support) + */ + public function setId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[SubcategoryTableMap::COL_ID] = true; + } + + return $this; + } // setId() + + /** + * Set the value of [name] column. + * + * @param string $v new value + * @return $this|\Subcategory The current object (for fluent API support) + */ + public function setName($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->name !== $v) { + $this->name = $v; + $this->modifiedColumns[SubcategoryTableMap::COL_NAME] = true; + } + + return $this; + } // setName() + + /** + * Set the value of [category_id] column. + * + * @param int $v new value + * @return $this|\Subcategory The current object (for fluent API support) + */ + public function setCategoryId($v) + { + if ($v !== null) { + $v = (int) $v; + } + + if ($this->category_id !== $v) { + $this->category_id = $v; + $this->modifiedColumns[SubcategoryTableMap::COL_CATEGORY_ID] = true; + } + + if ($this->aCategory !== null && $this->aCategory->getId() !== $v) { + $this->aCategory = null; + } + + return $this; + } // setCategoryId() + + /** + * Indicates whether the columns in this object are only set to default values. + * + * This method can be used in conjunction with isModified() to indicate whether an object is both + * modified _and_ has some values set which are non-default. + * + * @return boolean Whether the columns in this object are only been set with default values. + */ + public function hasOnlyDefaultValues() + { + // otherwise, everything was equal, so return TRUE + return true; + } // hasOnlyDefaultValues() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (0-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param array $row The row returned by DataFetcher->fetch(). + * @param int $startcol 0-based offset column which indicates which restultset column to start with. + * @param boolean $rehydrate Whether this object is being re-hydrated from the database. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) + { + try { + + $col = $row[TableMap::TYPE_NUM == $indexType ? 0 + $startcol : SubcategoryTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + $this->id = (null !== $col) ? (int) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : SubcategoryTableMap::translateFieldName('Name', TableMap::TYPE_PHPNAME, $indexType)]; + $this->name = (null !== $col) ? (string) $col : null; + + $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : SubcategoryTableMap::translateFieldName('CategoryId', TableMap::TYPE_PHPNAME, $indexType)]; + $this->category_id = (null !== $col) ? (int) $col : null; + $this->resetModified(); + + $this->setNew(false); + + if ($rehydrate) { + $this->ensureConsistency(); + } + + return $startcol + 3; // 3 = SubcategoryTableMap::NUM_HYDRATE_COLUMNS. + + } catch (Exception $e) { + throw new PropelException(sprintf('Error populating %s object', '\\Subcategory'), 0, $e); + } + } + + /** + * Checks and repairs the internal consistency of the object. + * + * This method is executed after an already-instantiated object is re-hydrated + * from the database. It exists to check any foreign keys to make sure that + * the objects related to the current object are correct based on foreign key. + * + * You can override this method in the stub class, but you should always invoke + * the base method from the overridden method (i.e. parent::ensureConsistency()), + * in case your model changes. + * + * @throws PropelException + */ + public function ensureConsistency() + { + if ($this->aCategory !== null && $this->category_id !== $this->aCategory->getId()) { + $this->aCategory = null; + } + } // ensureConsistency + + /** + * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. + * + * This will only work if the object has been saved and has a valid primary key set. + * + * @param boolean $deep (optional) Whether to also de-associated any related objects. + * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. + * @return void + * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db + */ + public function reload($deep = false, ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("Cannot reload a deleted object."); + } + + if ($this->isNew()) { + throw new PropelException("Cannot reload an unsaved object."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(SubcategoryTableMap::DATABASE_NAME); + } + + // We don't need to alter the object instance pool; we're just modifying this instance + // already in the pool. + + $dataFetcher = ChildSubcategoryQuery::create(null, $this->buildPkeyCriteria())->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con); + $row = $dataFetcher->fetch(); + $dataFetcher->close(); + if (!$row) { + throw new PropelException('Cannot find matching row in the database to reload object values.'); + } + $this->hydrate($row, 0, true, $dataFetcher->getIndexType()); // rehydrate + + if ($deep) { // also de-associate any related objects? + + $this->aCategory = null; + } // if (deep) + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param ConnectionInterface $con + * @return void + * @throws PropelException + * @see Subcategory::setDeleted() + * @see Subcategory::isDeleted() + */ + public function delete(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(SubcategoryTableMap::DATABASE_NAME); + } + + $con->transaction(function () use ($con) { + $deleteQuery = ChildSubcategoryQuery::create() + ->filterByPrimaryKey($this->getPrimaryKey()); + $ret = $this->preDelete($con); + if ($ret) { + $deleteQuery->delete($con); + $this->postDelete($con); + $this->setDeleted(true); + } + }); + } + + /** + * Persists this object to the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All modified related objects will also be persisted in the doSave() + * method. This method wraps all precipitate database operations in a + * single transaction. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see doSave() + */ + public function save(ConnectionInterface $con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getWriteConnection(SubcategoryTableMap::DATABASE_NAME); + } + + return $con->transaction(function () use ($con) { + $ret = $this->preSave($con); + $isInsert = $this->isNew(); + if ($isInsert) { + $ret = $ret && $this->preInsert($con); + } else { + $ret = $ret && $this->preUpdate($con); + } + if ($ret) { + $affectedRows = $this->doSave($con); + if ($isInsert) { + $this->postInsert($con); + } else { + $this->postUpdate($con); + } + $this->postSave($con); + SubcategoryTableMap::addInstanceToPool($this); + } else { + $affectedRows = 0; + } + + return $affectedRows; + }); + } + + /** + * Performs the work of inserting or updating the row in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param ConnectionInterface $con + * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. + * @throws PropelException + * @see save() + */ + protected function doSave(ConnectionInterface $con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + // We call the save method on the following object(s) if they + // were passed to this object by their corresponding set + // method. This object relates to these object(s) by a + // foreign key reference. + + if ($this->aCategory !== null) { + if ($this->aCategory->isModified() || $this->aCategory->isNew()) { + $affectedRows += $this->aCategory->save($con); + } + $this->setCategory($this->aCategory); + } + + if ($this->isNew() || $this->isModified()) { + // persist changes + if ($this->isNew()) { + $this->doInsert($con); + $affectedRows += 1; + } else { + $affectedRows += $this->doUpdate($con); + } + $this->resetModified(); + } + + $this->alreadyInSave = false; + + } + + return $affectedRows; + } // doSave() + + /** + * Insert the row in the database. + * + * @param ConnectionInterface $con + * + * @throws PropelException + * @see doSave() + */ + protected function doInsert(ConnectionInterface $con) + { + $modifiedColumns = array(); + $index = 0; + + $this->modifiedColumns[SubcategoryTableMap::COL_ID] = true; + if (null !== $this->id) { + throw new PropelException('Cannot insert a value for auto-increment primary key (' . SubcategoryTableMap::COL_ID . ')'); + } + + // check the columns in natural order for more readable SQL queries + if ($this->isColumnModified(SubcategoryTableMap::COL_ID)) { + $modifiedColumns[':p' . $index++] = 'id'; + } + if ($this->isColumnModified(SubcategoryTableMap::COL_NAME)) { + $modifiedColumns[':p' . $index++] = 'name'; + } + if ($this->isColumnModified(SubcategoryTableMap::COL_CATEGORY_ID)) { + $modifiedColumns[':p' . $index++] = 'category_id'; + } + + $sql = sprintf( + 'INSERT INTO Subcategory (%s) VALUES (%s)', + implode(', ', $modifiedColumns), + implode(', ', array_keys($modifiedColumns)) + ); + + try { + $stmt = $con->prepare($sql); + foreach ($modifiedColumns as $identifier => $columnName) { + switch ($columnName) { + case 'id': + $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); + break; + case 'name': + $stmt->bindValue($identifier, $this->name, PDO::PARAM_STR); + break; + case 'category_id': + $stmt->bindValue($identifier, $this->category_id, PDO::PARAM_INT); + break; + } + } + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e); + } + + try { + $pk = $con->lastInsertId(); + } catch (Exception $e) { + throw new PropelException('Unable to get autoincrement id.', 0, $e); + } + $this->setId($pk); + + $this->setNew(false); + } + + /** + * Update the row in the database. + * + * @param ConnectionInterface $con + * + * @return Integer Number of updated rows + * @see doSave() + */ + protected function doUpdate(ConnectionInterface $con) + { + $selectCriteria = $this->buildPkeyCriteria(); + $valuesCriteria = $this->buildCriteria(); + + return $selectCriteria->doUpdate($valuesCriteria, $con); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return mixed Value of field. + */ + public function getByName($name, $type = TableMap::TYPE_PHPNAME) + { + $pos = SubcategoryTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + $field = $this->getByPosition($pos); + + return $field; + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch ($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getName(); + break; + case 2: + return $this->getCategoryId(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. + * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion + * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. + * + * @return array an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) + { + + if (isset($alreadyDumpedObjects['Subcategory'][$this->hashCode()])) { + return '*RECURSION*'; + } + $alreadyDumpedObjects['Subcategory'][$this->hashCode()] = true; + $keys = SubcategoryTableMap::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getName(), + $keys[2] => $this->getCategoryId(), + ); + $virtualColumns = $this->virtualColumns; + foreach ($virtualColumns as $key => $virtualColumn) { + $result[$key] = $virtualColumn; + } + + if ($includeForeignObjects) { + if (null !== $this->aCategory) { + + switch ($keyType) { + case TableMap::TYPE_CAMELNAME: + $key = 'category'; + break; + case TableMap::TYPE_FIELDNAME: + $key = 'Category'; + break; + default: + $key = 'Category'; + } + + $result[$key] = $this->aCategory->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true); + } + } + + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * Defaults to TableMap::TYPE_PHPNAME. + * @return $this|\Subcategory + */ + public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) + { + $pos = SubcategoryTableMap::translateFieldName($name, $type, TableMap::TYPE_NUM); + + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return $this|\Subcategory + */ + public function setByPosition($pos, $value) + { + switch ($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setName($value); + break; + case 2: + $this->setCategoryId($value); + break; + } // switch() + + return $this; + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) + { + $keys = SubcategoryTableMap::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) { + $this->setId($arr[$keys[0]]); + } + if (array_key_exists($keys[1], $arr)) { + $this->setName($arr[$keys[1]]); + } + if (array_key_exists($keys[2], $arr)) { + $this->setCategoryId($arr[$keys[2]]); + } + } + + /** + * Populate the current object from a string, using a given parser format + * + * $book = new Book(); + * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); + * + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * The default key type is the column's TableMap::TYPE_PHPNAME. + * + * @param mixed $parser A AbstractParser instance, + * or a format name ('XML', 'YAML', 'JSON', 'CSV') + * @param string $data The source data to import from + * @param string $keyType The type of keys the array uses. + * + * @return $this|\Subcategory The current object, for fluid interface + */ + public function importFrom($parser, $data, $keyType = TableMap::TYPE_PHPNAME) + { + if (!$parser instanceof AbstractParser) { + $parser = AbstractParser::getParser($parser); + } + + $this->fromArray($parser->toArray($data), $keyType); + + return $this; + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(SubcategoryTableMap::DATABASE_NAME); + + if ($this->isColumnModified(SubcategoryTableMap::COL_ID)) { + $criteria->add(SubcategoryTableMap::COL_ID, $this->id); + } + if ($this->isColumnModified(SubcategoryTableMap::COL_NAME)) { + $criteria->add(SubcategoryTableMap::COL_NAME, $this->name); + } + if ($this->isColumnModified(SubcategoryTableMap::COL_CATEGORY_ID)) { + $criteria->add(SubcategoryTableMap::COL_CATEGORY_ID, $this->category_id); + } + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @throws LogicException if no primary key is defined + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = ChildSubcategoryQuery::create(); + $criteria->add(SubcategoryTableMap::COL_ID, $this->id); + + return $criteria; + } + + /** + * If the primary key is not null, return the hashcode of the + * primary key. Otherwise, return the hash code of the object. + * + * @return int Hashcode + */ + public function hashCode() + { + $validPk = null !== $this->getId(); + + $validPrimaryKeyFKs = 0; + $primaryKeyFKs = []; + + if ($validPk) { + return crc32(json_encode($this->getPrimaryKey(), JSON_UNESCAPED_UNICODE)); + } elseif ($validPrimaryKeyFKs) { + return crc32(json_encode($primaryKeyFKs, JSON_UNESCAPED_UNICODE)); + } + + return spl_object_hash($this); + } + + /** + * Returns the primary key for this object (row). + * @return int + */ + public function getPrimaryKey() + { + return $this->getId(); + } + + /** + * Generic method to set the primary key (id column). + * + * @param int $key Primary key. + * @return void + */ + public function setPrimaryKey($key) + { + $this->setId($key); + } + + /** + * Returns true if the primary key for this object is null. + * @return boolean + */ + public function isPrimaryKeyNull() + { + return null === $this->getId(); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of \Subcategory (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false, $makeNew = true) + { + $copyObj->setName($this->getName()); + $copyObj->setCategoryId($this->getCategoryId()); + if ($makeNew) { + $copyObj->setNew(true); + $copyObj->setId(NULL); // this is a auto-increment column, so set to default value + } + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return \Subcategory Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + + return $copyObj; + } + + /** + * Declares an association between this object and a ChildCategory object. + * + * @param ChildCategory $v + * @return $this|\Subcategory The current object (for fluent API support) + * @throws PropelException + */ + public function setCategory(ChildCategory $v = null) + { + if ($v === null) { + $this->setCategoryId(NULL); + } else { + $this->setCategoryId($v->getId()); + } + + $this->aCategory = $v; + + // Add binding for other direction of this n:n relationship. + // If this object has already been added to the ChildCategory object, it will not be re-added. + if ($v !== null) { + $v->addSubcategory($this); + } + + + return $this; + } + + + /** + * Get the associated ChildCategory object + * + * @param ConnectionInterface $con Optional Connection object. + * @return ChildCategory The associated ChildCategory object. + * @throws PropelException + */ + public function getCategory(ConnectionInterface $con = null) + { + if ($this->aCategory === null && ($this->category_id !== null)) { + $this->aCategory = ChildCategoryQuery::create()->findPk($this->category_id, $con); + /* The following can be used additionally to + guarantee the related object contains a reference + to this object. This level of coupling may, however, be + undesirable since it could result in an only partially populated collection + in the referenced object. + $this->aCategory->addSubcategories($this); + */ + } + + return $this->aCategory; + } + + /** + * Clears the current object, sets all attributes to their default values and removes + * outgoing references as well as back-references (from other objects to this one. Results probably in a database + * change of those foreign objects when you call `save` there). + */ + public function clear() + { + if (null !== $this->aCategory) { + $this->aCategory->removeSubcategory($this); + } + $this->id = null; + $this->name = null; + $this->category_id = null; + $this->alreadyInSave = false; + $this->clearAllReferences(); + $this->resetModified(); + $this->setNew(true); + $this->setDeleted(false); + } + + /** + * Resets all references and back-references to other model objects or collections of model objects. + * + * This method is used to reset all php object references (not the actual reference in the database). + * Necessary for object serialisation. + * + * @param boolean $deep Whether to also clear the references on all referrer objects. + */ + public function clearAllReferences($deep = false) + { + if ($deep) { + } // if ($deep) + + $this->aCategory = null; + } + + /** + * Return the string representation of this object + * + * @return string + */ + public function __toString() + { + return (string) $this->exportTo(SubcategoryTableMap::DEFAULT_STRING_FORMAT); + } + + /** + * Code to be run before persisting the object + * @param ConnectionInterface $con + * @return boolean + */ + public function preSave(ConnectionInterface $con = null) + { + if (is_callable('parent::preSave')) { + return parent::preSave($con); + } + return true; + } + + /** + * Code to be run after persisting the object + * @param ConnectionInterface $con + */ + public function postSave(ConnectionInterface $con = null) + { + if (is_callable('parent::postSave')) { + parent::postSave($con); + } + } + + /** + * Code to be run before inserting to database + * @param ConnectionInterface $con + * @return boolean + */ + public function preInsert(ConnectionInterface $con = null) + { + if (is_callable('parent::preInsert')) { + return parent::preInsert($con); + } + return true; + } + + /** + * Code to be run after inserting to database + * @param ConnectionInterface $con + */ + public function postInsert(ConnectionInterface $con = null) + { + if (is_callable('parent::postInsert')) { + parent::postInsert($con); + } + } + + /** + * Code to be run before updating the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preUpdate(ConnectionInterface $con = null) + { + if (is_callable('parent::preUpdate')) { + return parent::preUpdate($con); + } + return true; + } + + /** + * Code to be run after updating the object in database + * @param ConnectionInterface $con + */ + public function postUpdate(ConnectionInterface $con = null) + { + if (is_callable('parent::postUpdate')) { + parent::postUpdate($con); + } + } + + /** + * Code to be run before deleting the object in database + * @param ConnectionInterface $con + * @return boolean + */ + public function preDelete(ConnectionInterface $con = null) + { + if (is_callable('parent::preDelete')) { + return parent::preDelete($con); + } + return true; + } + + /** + * Code to be run after deleting the object in database + * @param ConnectionInterface $con + */ + public function postDelete(ConnectionInterface $con = null) + { + if (is_callable('parent::postDelete')) { + parent::postDelete($con); + } + } + + + /** + * Derived method to catches calls to undefined methods. + * + * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). + * Allows to define default __call() behavior if you overwrite __call() + * + * @param string $name + * @param mixed $params + * + * @return array|string + */ + public function __call($name, $params) + { + if (0 === strpos($name, 'get')) { + $virtualColumn = substr($name, 3); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + + $virtualColumn = lcfirst($virtualColumn); + if ($this->hasVirtualColumn($virtualColumn)) { + return $this->getVirtualColumn($virtualColumn); + } + } + + if (0 === strpos($name, 'from')) { + $format = substr($name, 4); + + return $this->importFrom($format, reset($params)); + } + + if (0 === strpos($name, 'to')) { + $format = substr($name, 2); + $includeLazyLoadColumns = isset($params[0]) ? $params[0] : true; + + return $this->exportTo($format, $includeLazyLoadColumns); + } + + throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $name)); + } + +} diff --git a/api/generated-classes/Base/SubcategoryQuery.php b/api/generated-classes/Base/SubcategoryQuery.php new file mode 100644 index 0000000..e5ff830 --- /dev/null +++ b/api/generated-classes/Base/SubcategoryQuery.php @@ -0,0 +1,520 @@ +setModelAlias($modelAlias); + } + if ($criteria instanceof Criteria) { + $query->mergeWith($criteria); + } + + return $query; + } + + /** + * Find object by primary key. + * Propel uses the instance pool to skip the database if the object exists. + * Go fast if the query is untouched. + * + * + * $obj = $c->findPk(12, $con); + * + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ChildSubcategory|array|mixed the result, formatted by the current formatter + */ + public function findPk($key, ConnectionInterface $con = null) + { + if ($key === null) { + return null; + } + + if ($con === null) { + $con = Propel::getServiceContainer()->getReadConnection(SubcategoryTableMap::DATABASE_NAME); + } + + $this->basePreSelect($con); + + if ( + $this->formatter || $this->modelAlias || $this->with || $this->select + || $this->selectColumns || $this->asColumns || $this->selectModifiers + || $this->map || $this->having || $this->joins + ) { + return $this->findPkComplex($key, $con); + } + + if ((null !== ($obj = SubcategoryTableMap::getInstanceFromPool(null === $key || is_scalar($key) || is_callable([$key, '__toString']) ? (string) $key : $key)))) { + // the object is already in the instance pool + return $obj; + } + + return $this->findPkSimple($key, $con); + } + + /** + * Find object by primary key using raw SQL to go fast. + * Bypass doSelect() and the object formatter by using generated code. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @throws \Propel\Runtime\Exception\PropelException + * + * @return ChildSubcategory A model object, or null if the key is not found + */ + protected function findPkSimple($key, ConnectionInterface $con) + { + $sql = 'SELECT id, name, category_id FROM Subcategory WHERE id = :p0'; + try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':p0', $key, PDO::PARAM_INT); + $stmt->execute(); + } catch (Exception $e) { + Propel::log($e->getMessage(), Propel::LOG_ERR); + throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e); + } + $obj = null; + if ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + /** @var ChildSubcategory $obj */ + $obj = new ChildSubcategory(); + $obj->hydrate($row); + SubcategoryTableMap::addInstanceToPool($obj, null === $key || is_scalar($key) || is_callable([$key, '__toString']) ? (string) $key : $key); + } + $stmt->closeCursor(); + + return $obj; + } + + /** + * Find object by primary key. + * + * @param mixed $key Primary key to use for the query + * @param ConnectionInterface $con A connection object + * + * @return ChildSubcategory|array|mixed the result, formatted by the current formatter + */ + protected function findPkComplex($key, ConnectionInterface $con) + { + // As the query uses a PK condition, no limit(1) is necessary. + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKey($key) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); + } + + /** + * Find objects by primary key + * + * $objs = $c->findPks(array(12, 56, 832), $con); + * + * @param array $keys Primary keys to use for the query + * @param ConnectionInterface $con an optional connection object + * + * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter + */ + public function findPks($keys, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); + } + $this->basePreSelect($con); + $criteria = $this->isKeepQuery() ? clone $this : $this; + $dataFetcher = $criteria + ->filterByPrimaryKeys($keys) + ->doSelect($con); + + return $criteria->getFormatter()->init($criteria)->format($dataFetcher); + } + + /** + * Filter the query by primary key + * + * @param mixed $key Primary key to use for the query + * + * @return $this|ChildSubcategoryQuery The current query, for fluid interface + */ + public function filterByPrimaryKey($key) + { + + return $this->addUsingAlias(SubcategoryTableMap::COL_ID, $key, Criteria::EQUAL); + } + + /** + * Filter the query by a list of primary keys + * + * @param array $keys The list of primary key to use for the query + * + * @return $this|ChildSubcategoryQuery The current query, for fluid interface + */ + public function filterByPrimaryKeys($keys) + { + + return $this->addUsingAlias(SubcategoryTableMap::COL_ID, $keys, Criteria::IN); + } + + /** + * Filter the query on the id column + * + * Example usage: + * + * $query->filterById(1234); // WHERE id = 1234 + * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) + * $query->filterById(array('min' => 12)); // WHERE id > 12 + * + * + * @param mixed $id The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return $this|ChildSubcategoryQuery The current query, for fluid interface + */ + public function filterById($id = null, $comparison = null) + { + if (is_array($id)) { + $useMinMax = false; + if (isset($id['min'])) { + $this->addUsingAlias(SubcategoryTableMap::COL_ID, $id['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($id['max'])) { + $this->addUsingAlias(SubcategoryTableMap::COL_ID, $id['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(SubcategoryTableMap::COL_ID, $id, $comparison); + } + + /** + * Filter the query on the name column + * + * Example usage: + * + * $query->filterByName('fooValue'); // WHERE name = 'fooValue' + * $query->filterByName('%fooValue%', Criteria::LIKE); // WHERE name LIKE '%fooValue%' + * + * + * @param string $name The value to use as filter. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return $this|ChildSubcategoryQuery The current query, for fluid interface + */ + public function filterByName($name = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($name)) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(SubcategoryTableMap::COL_NAME, $name, $comparison); + } + + /** + * Filter the query on the category_id column + * + * Example usage: + * + * $query->filterByCategoryId(1234); // WHERE category_id = 1234 + * $query->filterByCategoryId(array(12, 34)); // WHERE category_id IN (12, 34) + * $query->filterByCategoryId(array('min' => 12)); // WHERE category_id > 12 + * + * + * @see filterByCategory() + * + * @param mixed $categoryId The value to use as filter. + * Use scalar values for equality. + * Use array values for in_array() equivalent. + * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return $this|ChildSubcategoryQuery The current query, for fluid interface + */ + public function filterByCategoryId($categoryId = null, $comparison = null) + { + if (is_array($categoryId)) { + $useMinMax = false; + if (isset($categoryId['min'])) { + $this->addUsingAlias(SubcategoryTableMap::COL_CATEGORY_ID, $categoryId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($categoryId['max'])) { + $this->addUsingAlias(SubcategoryTableMap::COL_CATEGORY_ID, $categoryId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { + $comparison = Criteria::IN; + } + } + + return $this->addUsingAlias(SubcategoryTableMap::COL_CATEGORY_ID, $categoryId, $comparison); + } + + /** + * Filter the query by a related \Category object + * + * @param \Category|ObjectCollection $category The related object(s) to use as filter + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @throws \Propel\Runtime\Exception\PropelException + * + * @return ChildSubcategoryQuery The current query, for fluid interface + */ + public function filterByCategory($category, $comparison = null) + { + if ($category instanceof \Category) { + return $this + ->addUsingAlias(SubcategoryTableMap::COL_CATEGORY_ID, $category->getId(), $comparison); + } elseif ($category instanceof ObjectCollection) { + if (null === $comparison) { + $comparison = Criteria::IN; + } + + return $this + ->addUsingAlias(SubcategoryTableMap::COL_CATEGORY_ID, $category->toKeyValue('PrimaryKey', 'Id'), $comparison); + } else { + throw new PropelException('filterByCategory() only accepts arguments of type \Category or Collection'); + } + } + + /** + * Adds a JOIN clause to the query using the Category relation + * + * @param string $relationAlias optional alias for the relation + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return $this|ChildSubcategoryQuery The current query, for fluid interface + */ + public function joinCategory($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + $tableMap = $this->getTableMap(); + $relationMap = $tableMap->getRelation('Category'); + + // create a ModelJoin object for this join + $join = new ModelJoin(); + $join->setJoinType($joinType); + $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias); + if ($previousJoin = $this->getPreviousJoin()) { + $join->setPreviousJoin($previousJoin); + } + + // add the ModelJoin to the current object + if ($relationAlias) { + $this->addAlias($relationAlias, $relationMap->getRightTable()->getName()); + $this->addJoinObject($join, $relationAlias); + } else { + $this->addJoinObject($join, 'Category'); + } + + return $this; + } + + /** + * Use the Category relation Category object + * + * @see useQuery() + * + * @param string $relationAlias optional alias for the relation, + * to be used as main alias in the secondary query + * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' + * + * @return \CategoryQuery A secondary query class using the current class as primary query + */ + public function useCategoryQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) + { + return $this + ->joinCategory($relationAlias, $joinType) + ->useQuery($relationAlias ? $relationAlias : 'Category', '\CategoryQuery'); + } + + /** + * Exclude object from result + * + * @param ChildSubcategory $subcategory Object to remove from the list of results + * + * @return $this|ChildSubcategoryQuery The current query, for fluid interface + */ + public function prune($subcategory = null) + { + if ($subcategory) { + $this->addUsingAlias(SubcategoryTableMap::COL_ID, $subcategory->getId(), Criteria::NOT_EQUAL); + } + + return $this; + } + + /** + * Deletes all rows from the Subcategory table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public function doDeleteAll(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(SubcategoryTableMap::DATABASE_NAME); + } + + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + return $con->transaction(function () use ($con) { + $affectedRows = 0; // initialize var to track total num of affected rows + $affectedRows += parent::doDeleteAll($con); + // Because this db requires some delete cascade/set null emulation, we have to + // clear the cached instance *after* the emulation has happened (since + // instances get re-added by the select statement contained therein). + SubcategoryTableMap::clearInstancePool(); + SubcategoryTableMap::clearRelatedInstancePool(); + + return $affectedRows; + }); + } + + /** + * Performs a DELETE on the database based on the current ModelCriteria + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public function delete(ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(SubcategoryTableMap::DATABASE_NAME); + } + + $criteria = $this; + + // Set the correct dbName + $criteria->setDbName(SubcategoryTableMap::DATABASE_NAME); + + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + return $con->transaction(function () use ($con, $criteria) { + $affectedRows = 0; // initialize var to track total num of affected rows + + SubcategoryTableMap::removeInstanceFromPool($criteria); + + $affectedRows += ModelCriteria::delete($con); + SubcategoryTableMap::clearRelatedInstancePool(); + + return $affectedRows; + }); + } + +} // SubcategoryQuery diff --git a/api/generated-classes/Category.php b/api/generated-classes/Category.php new file mode 100644 index 0000000..90c4ffb --- /dev/null +++ b/api/generated-classes/Category.php @@ -0,0 +1,18 @@ + array('Id', 'Units', 'Threshold', 'Operator', 'CategoryId', 'RankId', 'NutrientId', ), + self::TYPE_CAMELNAME => array('id', 'units', 'threshold', 'operator', 'categoryId', 'rankId', 'nutrientId', ), + self::TYPE_COLNAME => array(CategoryRankNutrientTableMap::COL_ID, CategoryRankNutrientTableMap::COL_UNITS, CategoryRankNutrientTableMap::COL_THRESHOLD, CategoryRankNutrientTableMap::COL_OPERATOR, CategoryRankNutrientTableMap::COL_CATEGORY_ID, CategoryRankNutrientTableMap::COL_RANK_ID, CategoryRankNutrientTableMap::COL_NUTRIENT_ID, ), + self::TYPE_FIELDNAME => array('id', 'units', 'threshold', 'operator', 'category_id', 'rank_id', 'nutrient_id', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'Units' => 1, 'Threshold' => 2, 'Operator' => 3, 'CategoryId' => 4, 'RankId' => 5, 'NutrientId' => 6, ), + self::TYPE_CAMELNAME => array('id' => 0, 'units' => 1, 'threshold' => 2, 'operator' => 3, 'categoryId' => 4, 'rankId' => 5, 'nutrientId' => 6, ), + self::TYPE_COLNAME => array(CategoryRankNutrientTableMap::COL_ID => 0, CategoryRankNutrientTableMap::COL_UNITS => 1, CategoryRankNutrientTableMap::COL_THRESHOLD => 2, CategoryRankNutrientTableMap::COL_OPERATOR => 3, CategoryRankNutrientTableMap::COL_CATEGORY_ID => 4, CategoryRankNutrientTableMap::COL_RANK_ID => 5, CategoryRankNutrientTableMap::COL_NUTRIENT_ID => 6, ), + self::TYPE_FIELDNAME => array('id' => 0, 'units' => 1, 'threshold' => 2, 'operator' => 3, 'category_id' => 4, 'rank_id' => 5, 'nutrient_id' => 6, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('Category_Rank_Nutrient'); + $this->setPhpName('CategoryRankNutrient'); + $this->setIdentifierQuoting(false); + $this->setClassName('\\CategoryRankNutrient'); + $this->setPackage(''); + $this->setUseIdGenerator(true); + // columns + $this->addPrimaryKey('id', 'Id', 'INTEGER', true, null, null); + $this->addColumn('units', 'Units', 'VARCHAR', false, 128, null); + $this->addColumn('threshold', 'Threshold', 'FLOAT', true, null, null); + $this->addColumn('operator', 'Operator', 'VARCHAR', true, 10, null); + $this->addForeignKey('category_id', 'CategoryId', 'INTEGER', 'Category', 'id', true, null, null); + $this->addForeignKey('rank_id', 'RankId', 'INTEGER', 'Rank', 'id', true, null, null); + $this->addForeignKey('nutrient_id', 'NutrientId', 'INTEGER', 'Nutrient', 'id', true, null, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('Nutrient', '\\Nutrient', RelationMap::MANY_TO_ONE, array ( + 0 => + array ( + 0 => ':nutrient_id', + 1 => ':id', + ), +), 'CASCADE', 'CASCADE', null, false); + $this->addRelation('Category', '\\Category', RelationMap::MANY_TO_ONE, array ( + 0 => + array ( + 0 => ':category_id', + 1 => ':id', + ), +), 'CASCADE', 'CASCADE', null, false); + $this->addRelation('Rank', '\\Rank', RelationMap::MANY_TO_ONE, array ( + 0 => + array ( + 0 => ':rank_id', + 1 => ':id', + ), +), 'CASCADE', 'CASCADE', null, false); + } // buildRelations() + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return string The primary key hash of the row + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return null === $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] || is_scalar($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]) || is_callable([$row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)], '__toString']) ? (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] : $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + return (int) $row[ + $indexType == TableMap::TYPE_NUM + ? 0 + $offset + : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) + ]; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? CategoryRankNutrientTableMap::CLASS_DEFAULT : CategoryRankNutrientTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (CategoryRankNutrient object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = CategoryRankNutrientTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = CategoryRankNutrientTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + CategoryRankNutrientTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = CategoryRankNutrientTableMap::OM_CLASS; + /** @var CategoryRankNutrient $obj */ + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + CategoryRankNutrientTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = CategoryRankNutrientTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = CategoryRankNutrientTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + /** @var CategoryRankNutrient $obj */ + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + CategoryRankNutrientTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(CategoryRankNutrientTableMap::COL_ID); + $criteria->addSelectColumn(CategoryRankNutrientTableMap::COL_UNITS); + $criteria->addSelectColumn(CategoryRankNutrientTableMap::COL_THRESHOLD); + $criteria->addSelectColumn(CategoryRankNutrientTableMap::COL_OPERATOR); + $criteria->addSelectColumn(CategoryRankNutrientTableMap::COL_CATEGORY_ID); + $criteria->addSelectColumn(CategoryRankNutrientTableMap::COL_RANK_ID); + $criteria->addSelectColumn(CategoryRankNutrientTableMap::COL_NUTRIENT_ID); + } else { + $criteria->addSelectColumn($alias . '.id'); + $criteria->addSelectColumn($alias . '.units'); + $criteria->addSelectColumn($alias . '.threshold'); + $criteria->addSelectColumn($alias . '.operator'); + $criteria->addSelectColumn($alias . '.category_id'); + $criteria->addSelectColumn($alias . '.rank_id'); + $criteria->addSelectColumn($alias . '.nutrient_id'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(CategoryRankNutrientTableMap::DATABASE_NAME)->getTable(CategoryRankNutrientTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(CategoryRankNutrientTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(CategoryRankNutrientTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new CategoryRankNutrientTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a CategoryRankNutrient or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or CategoryRankNutrient object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(CategoryRankNutrientTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \CategoryRankNutrient) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(CategoryRankNutrientTableMap::DATABASE_NAME); + $criteria->add(CategoryRankNutrientTableMap::COL_ID, (array) $values, Criteria::IN); + } + + $query = CategoryRankNutrientQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { + CategoryRankNutrientTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { + CategoryRankNutrientTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the Category_Rank_Nutrient table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return CategoryRankNutrientQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a CategoryRankNutrient or Criteria object. + * + * @param mixed $criteria Criteria or CategoryRankNutrient object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(CategoryRankNutrientTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from CategoryRankNutrient object + } + + if ($criteria->containsKey(CategoryRankNutrientTableMap::COL_ID) && $criteria->keyContainsValue(CategoryRankNutrientTableMap::COL_ID) ) { + throw new PropelException('Cannot insert a value for auto-increment primary key ('.CategoryRankNutrientTableMap::COL_ID.')'); + } + + + // Set the correct dbName + $query = CategoryRankNutrientQuery::create()->mergeWith($criteria); + + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + return $con->transaction(function () use ($con, $query) { + return $query->doInsert($con); + }); + } + +} // CategoryRankNutrientTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +CategoryRankNutrientTableMap::buildTableMap(); diff --git a/api/generated-classes/Map/CategoryTableMap.php b/api/generated-classes/Map/CategoryTableMap.php new file mode 100644 index 0000000..70d22ba --- /dev/null +++ b/api/generated-classes/Map/CategoryTableMap.php @@ -0,0 +1,440 @@ + array('Id', 'Name', ), + self::TYPE_CAMELNAME => array('id', 'name', ), + self::TYPE_COLNAME => array(CategoryTableMap::COL_ID, CategoryTableMap::COL_NAME, ), + self::TYPE_FIELDNAME => array('id', 'name', ), + self::TYPE_NUM => array(0, 1, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'Name' => 1, ), + self::TYPE_CAMELNAME => array('id' => 0, 'name' => 1, ), + self::TYPE_COLNAME => array(CategoryTableMap::COL_ID => 0, CategoryTableMap::COL_NAME => 1, ), + self::TYPE_FIELDNAME => array('id' => 0, 'name' => 1, ), + self::TYPE_NUM => array(0, 1, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('Category'); + $this->setPhpName('Category'); + $this->setIdentifierQuoting(false); + $this->setClassName('\\Category'); + $this->setPackage(''); + $this->setUseIdGenerator(true); + // columns + $this->addPrimaryKey('id', 'Id', 'INTEGER', true, null, null); + $this->addColumn('name', 'Name', 'VARCHAR', true, 128, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('CategoryRankNutrient', '\\CategoryRankNutrient', RelationMap::ONE_TO_MANY, array ( + 0 => + array ( + 0 => ':category_id', + 1 => ':id', + ), +), 'CASCADE', 'CASCADE', 'CategoryRankNutrients', false); + $this->addRelation('Food', '\\Food', RelationMap::ONE_TO_MANY, array ( + 0 => + array ( + 0 => ':category_id', + 1 => ':id', + ), +), 'SET NULL', 'CASCADE', 'Foods', false); + $this->addRelation('Subcategory', '\\Subcategory', RelationMap::ONE_TO_MANY, array ( + 0 => + array ( + 0 => ':category_id', + 1 => ':id', + ), +), 'SET NULL', 'CASCADE', 'Subcategories', false); + } // buildRelations() + /** + * Method to invalidate the instance pool of all tables related to Category * by a foreign key with ON DELETE CASCADE + */ + public static function clearRelatedInstancePool() + { + // Invalidate objects in related instance pools, + // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule. + CategoryRankNutrientTableMap::clearInstancePool(); + FoodTableMap::clearInstancePool(); + SubcategoryTableMap::clearInstancePool(); + } + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return string The primary key hash of the row + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return null === $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] || is_scalar($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]) || is_callable([$row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)], '__toString']) ? (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] : $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + return (int) $row[ + $indexType == TableMap::TYPE_NUM + ? 0 + $offset + : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) + ]; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? CategoryTableMap::CLASS_DEFAULT : CategoryTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (Category object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = CategoryTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = CategoryTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + CategoryTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = CategoryTableMap::OM_CLASS; + /** @var Category $obj */ + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + CategoryTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = CategoryTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = CategoryTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + /** @var Category $obj */ + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + CategoryTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(CategoryTableMap::COL_ID); + $criteria->addSelectColumn(CategoryTableMap::COL_NAME); + } else { + $criteria->addSelectColumn($alias . '.id'); + $criteria->addSelectColumn($alias . '.name'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(CategoryTableMap::DATABASE_NAME)->getTable(CategoryTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(CategoryTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(CategoryTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new CategoryTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a Category or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or Category object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(CategoryTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \Category) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(CategoryTableMap::DATABASE_NAME); + $criteria->add(CategoryTableMap::COL_ID, (array) $values, Criteria::IN); + } + + $query = CategoryQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { + CategoryTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { + CategoryTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the Category table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return CategoryQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a Category or Criteria object. + * + * @param mixed $criteria Criteria or Category object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(CategoryTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from Category object + } + + if ($criteria->containsKey(CategoryTableMap::COL_ID) && $criteria->keyContainsValue(CategoryTableMap::COL_ID) ) { + throw new PropelException('Cannot insert a value for auto-increment primary key ('.CategoryTableMap::COL_ID.')'); + } + + + // Set the correct dbName + $query = CategoryQuery::create()->mergeWith($criteria); + + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + return $con->transaction(function () use ($con, $query) { + return $query->doInsert($con); + }); + } + +} // CategoryTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +CategoryTableMap::buildTableMap(); diff --git a/api/generated-classes/Map/FoodTableMap.php b/api/generated-classes/Map/FoodTableMap.php new file mode 100644 index 0000000..cb0c787 --- /dev/null +++ b/api/generated-classes/Map/FoodTableMap.php @@ -0,0 +1,446 @@ + array('Id', 'Name', 'Barcode', 'RankId', 'CategoryId', ), + self::TYPE_CAMELNAME => array('id', 'name', 'barcode', 'rankId', 'categoryId', ), + self::TYPE_COLNAME => array(FoodTableMap::COL_ID, FoodTableMap::COL_NAME, FoodTableMap::COL_BARCODE, FoodTableMap::COL_RANK_ID, FoodTableMap::COL_CATEGORY_ID, ), + self::TYPE_FIELDNAME => array('id', 'name', 'barcode', 'rank_id', 'category_id', ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'Name' => 1, 'Barcode' => 2, 'RankId' => 3, 'CategoryId' => 4, ), + self::TYPE_CAMELNAME => array('id' => 0, 'name' => 1, 'barcode' => 2, 'rankId' => 3, 'categoryId' => 4, ), + self::TYPE_COLNAME => array(FoodTableMap::COL_ID => 0, FoodTableMap::COL_NAME => 1, FoodTableMap::COL_BARCODE => 2, FoodTableMap::COL_RANK_ID => 3, FoodTableMap::COL_CATEGORY_ID => 4, ), + self::TYPE_FIELDNAME => array('id' => 0, 'name' => 1, 'barcode' => 2, 'rank_id' => 3, 'category_id' => 4, ), + self::TYPE_NUM => array(0, 1, 2, 3, 4, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('Food'); + $this->setPhpName('Food'); + $this->setIdentifierQuoting(false); + $this->setClassName('\\Food'); + $this->setPackage(''); + $this->setUseIdGenerator(true); + // columns + $this->addPrimaryKey('id', 'Id', 'INTEGER', true, null, null); + $this->addColumn('name', 'Name', 'VARCHAR', true, 255, null); + $this->addColumn('barcode', 'Barcode', 'INTEGER', true, null, null); + $this->addForeignKey('rank_id', 'RankId', 'INTEGER', 'Rank', 'id', false, null, null); + $this->addForeignKey('category_id', 'CategoryId', 'INTEGER', 'Category', 'id', false, null, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('Category', '\\Category', RelationMap::MANY_TO_ONE, array ( + 0 => + array ( + 0 => ':category_id', + 1 => ':id', + ), +), 'SET NULL', 'CASCADE', null, false); + $this->addRelation('Rank', '\\Rank', RelationMap::MANY_TO_ONE, array ( + 0 => + array ( + 0 => ':rank_id', + 1 => ':id', + ), +), 'SET NULL', 'CASCADE', null, false); + } // buildRelations() + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return string The primary key hash of the row + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return null === $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] || is_scalar($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]) || is_callable([$row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)], '__toString']) ? (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] : $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + return (int) $row[ + $indexType == TableMap::TYPE_NUM + ? 0 + $offset + : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) + ]; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? FoodTableMap::CLASS_DEFAULT : FoodTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (Food object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = FoodTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = FoodTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + FoodTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = FoodTableMap::OM_CLASS; + /** @var Food $obj */ + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + FoodTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = FoodTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = FoodTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + /** @var Food $obj */ + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + FoodTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(FoodTableMap::COL_ID); + $criteria->addSelectColumn(FoodTableMap::COL_NAME); + $criteria->addSelectColumn(FoodTableMap::COL_BARCODE); + $criteria->addSelectColumn(FoodTableMap::COL_RANK_ID); + $criteria->addSelectColumn(FoodTableMap::COL_CATEGORY_ID); + } else { + $criteria->addSelectColumn($alias . '.id'); + $criteria->addSelectColumn($alias . '.name'); + $criteria->addSelectColumn($alias . '.barcode'); + $criteria->addSelectColumn($alias . '.rank_id'); + $criteria->addSelectColumn($alias . '.category_id'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(FoodTableMap::DATABASE_NAME)->getTable(FoodTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(FoodTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(FoodTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new FoodTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a Food or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or Food object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(FoodTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \Food) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(FoodTableMap::DATABASE_NAME); + $criteria->add(FoodTableMap::COL_ID, (array) $values, Criteria::IN); + } + + $query = FoodQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { + FoodTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { + FoodTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the Food table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return FoodQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a Food or Criteria object. + * + * @param mixed $criteria Criteria or Food object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(FoodTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from Food object + } + + if ($criteria->containsKey(FoodTableMap::COL_ID) && $criteria->keyContainsValue(FoodTableMap::COL_ID) ) { + throw new PropelException('Cannot insert a value for auto-increment primary key ('.FoodTableMap::COL_ID.')'); + } + + + // Set the correct dbName + $query = FoodQuery::create()->mergeWith($criteria); + + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + return $con->transaction(function () use ($con, $query) { + return $query->doInsert($con); + }); + } + +} // FoodTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +FoodTableMap::buildTableMap(); diff --git a/api/generated-classes/Map/NutrientTableMap.php b/api/generated-classes/Map/NutrientTableMap.php new file mode 100644 index 0000000..25adea2 --- /dev/null +++ b/api/generated-classes/Map/NutrientTableMap.php @@ -0,0 +1,424 @@ + array('Id', 'Name', ), + self::TYPE_CAMELNAME => array('id', 'name', ), + self::TYPE_COLNAME => array(NutrientTableMap::COL_ID, NutrientTableMap::COL_NAME, ), + self::TYPE_FIELDNAME => array('id', 'name', ), + self::TYPE_NUM => array(0, 1, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'Name' => 1, ), + self::TYPE_CAMELNAME => array('id' => 0, 'name' => 1, ), + self::TYPE_COLNAME => array(NutrientTableMap::COL_ID => 0, NutrientTableMap::COL_NAME => 1, ), + self::TYPE_FIELDNAME => array('id' => 0, 'name' => 1, ), + self::TYPE_NUM => array(0, 1, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('Nutrient'); + $this->setPhpName('Nutrient'); + $this->setIdentifierQuoting(false); + $this->setClassName('\\Nutrient'); + $this->setPackage(''); + $this->setUseIdGenerator(true); + // columns + $this->addPrimaryKey('id', 'Id', 'INTEGER', true, null, null); + $this->addColumn('name', 'Name', 'VARCHAR', true, 255, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('CategoryRankNutrient', '\\CategoryRankNutrient', RelationMap::ONE_TO_MANY, array ( + 0 => + array ( + 0 => ':nutrient_id', + 1 => ':id', + ), +), 'CASCADE', 'CASCADE', 'CategoryRankNutrients', false); + } // buildRelations() + /** + * Method to invalidate the instance pool of all tables related to Nutrient * by a foreign key with ON DELETE CASCADE + */ + public static function clearRelatedInstancePool() + { + // Invalidate objects in related instance pools, + // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule. + CategoryRankNutrientTableMap::clearInstancePool(); + } + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return string The primary key hash of the row + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return null === $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] || is_scalar($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]) || is_callable([$row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)], '__toString']) ? (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] : $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + return (int) $row[ + $indexType == TableMap::TYPE_NUM + ? 0 + $offset + : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) + ]; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? NutrientTableMap::CLASS_DEFAULT : NutrientTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (Nutrient object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = NutrientTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = NutrientTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + NutrientTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = NutrientTableMap::OM_CLASS; + /** @var Nutrient $obj */ + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + NutrientTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = NutrientTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = NutrientTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + /** @var Nutrient $obj */ + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + NutrientTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(NutrientTableMap::COL_ID); + $criteria->addSelectColumn(NutrientTableMap::COL_NAME); + } else { + $criteria->addSelectColumn($alias . '.id'); + $criteria->addSelectColumn($alias . '.name'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(NutrientTableMap::DATABASE_NAME)->getTable(NutrientTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(NutrientTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(NutrientTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new NutrientTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a Nutrient or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or Nutrient object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(NutrientTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \Nutrient) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(NutrientTableMap::DATABASE_NAME); + $criteria->add(NutrientTableMap::COL_ID, (array) $values, Criteria::IN); + } + + $query = NutrientQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { + NutrientTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { + NutrientTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the Nutrient table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return NutrientQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a Nutrient or Criteria object. + * + * @param mixed $criteria Criteria or Nutrient object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(NutrientTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from Nutrient object + } + + if ($criteria->containsKey(NutrientTableMap::COL_ID) && $criteria->keyContainsValue(NutrientTableMap::COL_ID) ) { + throw new PropelException('Cannot insert a value for auto-increment primary key ('.NutrientTableMap::COL_ID.')'); + } + + + // Set the correct dbName + $query = NutrientQuery::create()->mergeWith($criteria); + + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + return $con->transaction(function () use ($con, $query) { + return $query->doInsert($con); + }); + } + +} // NutrientTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +NutrientTableMap::buildTableMap(); diff --git a/api/generated-classes/Map/RankTableMap.php b/api/generated-classes/Map/RankTableMap.php new file mode 100644 index 0000000..e5a8cea --- /dev/null +++ b/api/generated-classes/Map/RankTableMap.php @@ -0,0 +1,432 @@ + array('Id', 'Name', ), + self::TYPE_CAMELNAME => array('id', 'name', ), + self::TYPE_COLNAME => array(RankTableMap::COL_ID, RankTableMap::COL_NAME, ), + self::TYPE_FIELDNAME => array('id', 'name', ), + self::TYPE_NUM => array(0, 1, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'Name' => 1, ), + self::TYPE_CAMELNAME => array('id' => 0, 'name' => 1, ), + self::TYPE_COLNAME => array(RankTableMap::COL_ID => 0, RankTableMap::COL_NAME => 1, ), + self::TYPE_FIELDNAME => array('id' => 0, 'name' => 1, ), + self::TYPE_NUM => array(0, 1, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('Rank'); + $this->setPhpName('Rank'); + $this->setIdentifierQuoting(false); + $this->setClassName('\\Rank'); + $this->setPackage(''); + $this->setUseIdGenerator(true); + // columns + $this->addPrimaryKey('id', 'Id', 'INTEGER', true, null, null); + $this->addColumn('name', 'Name', 'VARCHAR', true, 128, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('CategoryRankNutrient', '\\CategoryRankNutrient', RelationMap::ONE_TO_MANY, array ( + 0 => + array ( + 0 => ':rank_id', + 1 => ':id', + ), +), 'CASCADE', 'CASCADE', 'CategoryRankNutrients', false); + $this->addRelation('Food', '\\Food', RelationMap::ONE_TO_MANY, array ( + 0 => + array ( + 0 => ':rank_id', + 1 => ':id', + ), +), 'SET NULL', 'CASCADE', 'Foods', false); + } // buildRelations() + /** + * Method to invalidate the instance pool of all tables related to Rank * by a foreign key with ON DELETE CASCADE + */ + public static function clearRelatedInstancePool() + { + // Invalidate objects in related instance pools, + // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule. + CategoryRankNutrientTableMap::clearInstancePool(); + FoodTableMap::clearInstancePool(); + } + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return string The primary key hash of the row + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return null === $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] || is_scalar($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]) || is_callable([$row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)], '__toString']) ? (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] : $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + return (int) $row[ + $indexType == TableMap::TYPE_NUM + ? 0 + $offset + : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) + ]; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? RankTableMap::CLASS_DEFAULT : RankTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (Rank object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = RankTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = RankTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + RankTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = RankTableMap::OM_CLASS; + /** @var Rank $obj */ + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + RankTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = RankTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = RankTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + /** @var Rank $obj */ + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + RankTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(RankTableMap::COL_ID); + $criteria->addSelectColumn(RankTableMap::COL_NAME); + } else { + $criteria->addSelectColumn($alias . '.id'); + $criteria->addSelectColumn($alias . '.name'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(RankTableMap::DATABASE_NAME)->getTable(RankTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(RankTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(RankTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new RankTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a Rank or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or Rank object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(RankTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \Rank) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(RankTableMap::DATABASE_NAME); + $criteria->add(RankTableMap::COL_ID, (array) $values, Criteria::IN); + } + + $query = RankQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { + RankTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { + RankTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the Rank table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return RankQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a Rank or Criteria object. + * + * @param mixed $criteria Criteria or Rank object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(RankTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from Rank object + } + + if ($criteria->containsKey(RankTableMap::COL_ID) && $criteria->keyContainsValue(RankTableMap::COL_ID) ) { + throw new PropelException('Cannot insert a value for auto-increment primary key ('.RankTableMap::COL_ID.')'); + } + + + // Set the correct dbName + $query = RankQuery::create()->mergeWith($criteria); + + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + return $con->transaction(function () use ($con, $query) { + return $query->doInsert($con); + }); + } + +} // RankTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +RankTableMap::buildTableMap(); diff --git a/api/generated-classes/Map/SubcategoryTableMap.php b/api/generated-classes/Map/SubcategoryTableMap.php new file mode 100644 index 0000000..d4b8c2e --- /dev/null +++ b/api/generated-classes/Map/SubcategoryTableMap.php @@ -0,0 +1,423 @@ + array('Id', 'Name', 'CategoryId', ), + self::TYPE_CAMELNAME => array('id', 'name', 'categoryId', ), + self::TYPE_COLNAME => array(SubcategoryTableMap::COL_ID, SubcategoryTableMap::COL_NAME, SubcategoryTableMap::COL_CATEGORY_ID, ), + self::TYPE_FIELDNAME => array('id', 'name', 'category_id', ), + self::TYPE_NUM => array(0, 1, 2, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0 + */ + protected static $fieldKeys = array ( + self::TYPE_PHPNAME => array('Id' => 0, 'Name' => 1, 'CategoryId' => 2, ), + self::TYPE_CAMELNAME => array('id' => 0, 'name' => 1, 'categoryId' => 2, ), + self::TYPE_COLNAME => array(SubcategoryTableMap::COL_ID => 0, SubcategoryTableMap::COL_NAME => 1, SubcategoryTableMap::COL_CATEGORY_ID => 2, ), + self::TYPE_FIELDNAME => array('id' => 0, 'name' => 1, 'category_id' => 2, ), + self::TYPE_NUM => array(0, 1, 2, ) + ); + + /** + * Initialize the table attributes and columns + * Relations are not initialized by this method since they are lazy loaded + * + * @return void + * @throws PropelException + */ + public function initialize() + { + // attributes + $this->setName('Subcategory'); + $this->setPhpName('Subcategory'); + $this->setIdentifierQuoting(false); + $this->setClassName('\\Subcategory'); + $this->setPackage(''); + $this->setUseIdGenerator(true); + // columns + $this->addPrimaryKey('id', 'Id', 'INTEGER', true, null, null); + $this->addColumn('name', 'Name', 'VARCHAR', true, 255, null); + $this->addForeignKey('category_id', 'CategoryId', 'INTEGER', 'Category', 'id', false, null, null); + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('Category', '\\Category', RelationMap::MANY_TO_ONE, array ( + 0 => + array ( + 0 => ':category_id', + 1 => ':id', + ), +), 'SET NULL', 'CASCADE', null, false); + } // buildRelations() + + /** + * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. + * + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, a serialize()d version of the primary key will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return string The primary key hash of the row + */ + public static function getPrimaryKeyHashFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + // If the PK cannot be derived from the row, return NULL. + if ($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] === null) { + return null; + } + + return null === $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] || is_scalar($row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]) || is_callable([$row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)], '__toString']) ? (string) $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)] : $row[TableMap::TYPE_NUM == $indexType ? 0 + $offset : static::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; + } + + /** + * Retrieves the primary key from the DB resultset row + * For tables with a single-column primary key, that simple pkey value will be returned. For tables with + * a multi-column primary key, an array of the primary key columns will be returned. + * + * @param array $row resultset row. + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM + * + * @return mixed The primary key of the row + */ + public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + return (int) $row[ + $indexType == TableMap::TYPE_NUM + ? 0 + $offset + : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) + ]; + } + + /** + * The class that the tableMap will make instances of. + * + * If $withPrefix is true, the returned path + * uses a dot-path notation which is translated into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @param boolean $withPrefix Whether or not to return the path with the class name + * @return string path.to.ClassName + */ + public static function getOMClass($withPrefix = true) + { + return $withPrefix ? SubcategoryTableMap::CLASS_DEFAULT : SubcategoryTableMap::OM_CLASS; + } + + /** + * Populates an object of the default type or an object that inherit from the default. + * + * @param array $row row returned by DataFetcher->fetch(). + * @param int $offset The 0-based offset for reading from the resultset row. + * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). + One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME + * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return array (Subcategory object, last column rank) + */ + public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) + { + $key = SubcategoryTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); + if (null !== ($obj = SubcategoryTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, $offset, true); // rehydrate + $col = $offset + SubcategoryTableMap::NUM_HYDRATE_COLUMNS; + } else { + $cls = SubcategoryTableMap::OM_CLASS; + /** @var Subcategory $obj */ + $obj = new $cls(); + $col = $obj->hydrate($row, $offset, false, $indexType); + SubcategoryTableMap::addInstanceToPool($obj, $key); + } + + return array($obj, $col); + } + + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @param DataFetcherInterface $dataFetcher + * @return array + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(DataFetcherInterface $dataFetcher) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = static::getOMClass(false); + // populate the object(s) + while ($row = $dataFetcher->fetch()) { + $key = SubcategoryTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); + if (null !== ($obj = SubcategoryTableMap::getInstanceFromPool($key))) { + // We no longer rehydrate the object, since this can cause data loss. + // See http://www.propelorm.org/ticket/509 + // $obj->hydrate($row, 0, true); // rehydrate + $results[] = $obj; + } else { + /** @var Subcategory $obj */ + $obj = new $cls(); + $obj->hydrate($row); + $results[] = $obj; + SubcategoryTableMap::addInstanceToPool($obj, $key); + } // if key exists + } + + return $results; + } + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param Criteria $criteria object containing the columns to add. + * @param string $alias optional table alias + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria, $alias = null) + { + if (null === $alias) { + $criteria->addSelectColumn(SubcategoryTableMap::COL_ID); + $criteria->addSelectColumn(SubcategoryTableMap::COL_NAME); + $criteria->addSelectColumn(SubcategoryTableMap::COL_CATEGORY_ID); + } else { + $criteria->addSelectColumn($alias . '.id'); + $criteria->addSelectColumn($alias . '.name'); + $criteria->addSelectColumn($alias . '.category_id'); + } + } + + /** + * Returns the TableMap related to this object. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getServiceContainer()->getDatabaseMap(SubcategoryTableMap::DATABASE_NAME)->getTable(SubcategoryTableMap::TABLE_NAME); + } + + /** + * Add a TableMap instance to the database for this tableMap class. + */ + public static function buildTableMap() + { + $dbMap = Propel::getServiceContainer()->getDatabaseMap(SubcategoryTableMap::DATABASE_NAME); + if (!$dbMap->hasTable(SubcategoryTableMap::TABLE_NAME)) { + $dbMap->addTableObject(new SubcategoryTableMap()); + } + } + + /** + * Performs a DELETE on the database, given a Subcategory or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or Subcategory object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(SubcategoryTableMap::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + // rename for clarity + $criteria = $values; + } elseif ($values instanceof \Subcategory) { // it's a model object + // create criteria based on pk values + $criteria = $values->buildPkeyCriteria(); + } else { // it's a primary key, or an array of pks + $criteria = new Criteria(SubcategoryTableMap::DATABASE_NAME); + $criteria->add(SubcategoryTableMap::COL_ID, (array) $values, Criteria::IN); + } + + $query = SubcategoryQuery::create()->mergeWith($criteria); + + if ($values instanceof Criteria) { + SubcategoryTableMap::clearInstancePool(); + } elseif (!is_object($values)) { // it's a primary key, or an array of pks + foreach ((array) $values as $singleval) { + SubcategoryTableMap::removeInstanceFromPool($singleval); + } + } + + return $query->delete($con); + } + + /** + * Deletes all rows from the Subcategory table. + * + * @param ConnectionInterface $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll(ConnectionInterface $con = null) + { + return SubcategoryQuery::create()->doDeleteAll($con); + } + + /** + * Performs an INSERT on the database, given a Subcategory or Criteria object. + * + * @param mixed $criteria Criteria or Subcategory object containing data that is used to create the INSERT statement. + * @param ConnectionInterface $con the ConnectionInterface connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($criteria, ConnectionInterface $con = null) + { + if (null === $con) { + $con = Propel::getServiceContainer()->getWriteConnection(SubcategoryTableMap::DATABASE_NAME); + } + + if ($criteria instanceof Criteria) { + $criteria = clone $criteria; // rename for clarity + } else { + $criteria = $criteria->buildCriteria(); // build Criteria from Subcategory object + } + + if ($criteria->containsKey(SubcategoryTableMap::COL_ID) && $criteria->keyContainsValue(SubcategoryTableMap::COL_ID) ) { + throw new PropelException('Cannot insert a value for auto-increment primary key ('.SubcategoryTableMap::COL_ID.')'); + } + + + // Set the correct dbName + $query = SubcategoryQuery::create()->mergeWith($criteria); + + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + return $con->transaction(function () use ($con, $query) { + return $query->doInsert($con); + }); + } + +} // SubcategoryTableMap +// This is the static code needed to register the TableMap for this table with the main Propel class. +// +SubcategoryTableMap::buildTableMap(); diff --git a/api/generated-classes/Nutrient.php b/api/generated-classes/Nutrient.php new file mode 100644 index 0000000..c893930 --- /dev/null +++ b/api/generated-classes/Nutrient.php @@ -0,0 +1,18 @@ +checkVersion('2.0.0-dev'); +$serviceContainer->setAdapterClass('default', 'mysql'); +$manager = new \Propel\Runtime\Connection\ConnectionManagerSingle(); +$manager->setConfiguration(array ( + 'dsn' => 'mysql:host=develop.digitalmediauconn.org;port=3306;dbname=foodbank', + 'user' => 'foodbank', + 'password' => 'foodbank123', + 'settings' => + array ( + 'charset' => 'utf8', + 'queries' => + array ( + ), + ), + 'classname' => '\\Propel\\Runtime\\Connection\\ConnectionWrapper', + 'model_paths' => + array ( + 0 => 'src', + 1 => 'vendor', + ), +)); +$manager->setName('default'); +$serviceContainer->setConnectionManager('default', $manager); +$serviceContainer->setDefaultDatasource('default'); \ No newline at end of file diff --git a/api/generated-sql/default.sql b/api/generated-sql/default.sql new file mode 100644 index 0000000..1dd54e8 --- /dev/null +++ b/api/generated-sql/default.sql @@ -0,0 +1,131 @@ + +# This is a fix for InnoDB in MySQL >= 4.1.x +# It "suspends judgement" for fkey relationships until are tables are set. +SET FOREIGN_KEY_CHECKS = 0; + +-- --------------------------------------------------------------------- +-- Category +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `Category`; + +CREATE TABLE `Category` +( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `name` VARCHAR(128) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- Category_Rank_Nutrient +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `Category_Rank_Nutrient`; + +CREATE TABLE `Category_Rank_Nutrient` +( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `units` VARCHAR(128), + `threshold` FLOAT NOT NULL, + `operator` VARCHAR(10) NOT NULL, + `category_id` INTEGER NOT NULL, + `rank_id` INTEGER NOT NULL, + `nutrient_id` INTEGER NOT NULL, + PRIMARY KEY (`id`), + INDEX `category_id` (`category_id`), + INDEX `rank_id` (`rank_id`), + INDEX `nutrient_id` (`nutrient_id`), + CONSTRAINT `Category_Rank_Nutrient_ibfk_3` + FOREIGN KEY (`nutrient_id`) + REFERENCES `Nutrient` (`id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `Category_Rank_Nutrient_ibfk_1` + FOREIGN KEY (`category_id`) + REFERENCES `Category` (`id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `Category_Rank_Nutrient_ibfk_2` + FOREIGN KEY (`rank_id`) + REFERENCES `Rank` (`id`) + ON UPDATE CASCADE + ON DELETE CASCADE +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- Food +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `Food`; + +CREATE TABLE `Food` +( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `name` VARCHAR(255) NOT NULL, + `barcode` INTEGER NOT NULL, + `rank_id` INTEGER, + `category_id` INTEGER, + PRIMARY KEY (`id`), + UNIQUE INDEX `barcode` (`barcode`), + INDEX `rank_id` (`rank_id`, `category_id`), + INDEX `category_id` (`category_id`), + CONSTRAINT `Food_ibfk_1` + FOREIGN KEY (`category_id`) + REFERENCES `Category` (`id`) + ON UPDATE CASCADE + ON DELETE SET NULL, + CONSTRAINT `Parent Rank ID` + FOREIGN KEY (`rank_id`) + REFERENCES `Rank` (`id`) + ON UPDATE CASCADE + ON DELETE SET NULL +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- Nutrient +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `Nutrient`; + +CREATE TABLE `Nutrient` +( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `name` VARCHAR(255) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- Rank +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `Rank`; + +CREATE TABLE `Rank` +( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `name` VARCHAR(128) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB; + +-- --------------------------------------------------------------------- +-- Subcategory +-- --------------------------------------------------------------------- + +DROP TABLE IF EXISTS `Subcategory`; + +CREATE TABLE `Subcategory` +( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `name` VARCHAR(255) NOT NULL, + `category_id` INTEGER, + PRIMARY KEY (`id`), + INDEX `category_id` (`category_id`), + CONSTRAINT `Parent Category ID` + FOREIGN KEY (`category_id`) + REFERENCES `Category` (`id`) + ON UPDATE CASCADE + ON DELETE SET NULL +) ENGINE=InnoDB; + +# This restores the fkey checks, after having unset them earlier +SET FOREIGN_KEY_CHECKS = 1; diff --git a/api/generated-sql/sqldb.map b/api/generated-sql/sqldb.map new file mode 100644 index 0000000..67bc4d4 --- /dev/null +++ b/api/generated-sql/sqldb.map @@ -0,0 +1,2 @@ +# Sqlfile -> Database map +default.sql=default diff --git a/api/index.php b/api/index.php new file mode 100644 index 0000000..ee8530e --- /dev/null +++ b/api/index.php @@ -0,0 +1,17 @@ +add('', __DIR__ . '/generated-classes/'); // Propel ORM Classes +require './generated-conf/config.php'; // Propel Config +require './config.php'; // Slim Config + +// Init Slim +$app = new \Slim\App($config); + +/** + * Routes + */ +require './routes/category.php'; + +// Run App +$app->run(); \ No newline at end of file diff --git a/api/propel.yml b/api/propel.yml new file mode 100644 index 0000000..c305b3e --- /dev/null +++ b/api/propel.yml @@ -0,0 +1,10 @@ +propel: + database: + connections: + default: + adapter: mysql + dsn: mysql:host=develop.digitalmediauconn.org;port=3306;dbname=foodbank + user: foodbank + password: foodbank123 + settings: + charset: utf8mb4_unicode_ci diff --git a/api/propel.yml.dist b/api/propel.yml.dist new file mode 100644 index 0000000..1a6809d --- /dev/null +++ b/api/propel.yml.dist @@ -0,0 +1,25 @@ +# When you're part of a team, you could want to define a common configuration file and commit it into your VCS. But, of +# course, there can be some properties you don't want to share, e.g. database passwords. Propel helps you and looks for +# a propel.yml.dist file too, merging its properties with propel.yml ones. So you can define shared configuration +# properties in propel.yml.dist, committing it in your VCS, and keep propel.yml as private. The properties loaded from +# propel.yml overwrite the ones with the same name, loaded from propel.yml.dist. +# +# For a complete references see: http://propelorm.org/documentation/reference/configuration-file.html + +propel: + paths: + # The directory where Propel expects to find your `schema.xml` file. + schemaDir: /Users/brian/Documents/Sites/foodbank/api + + # The directory where Propel should output generated object model classes. + phpDir: /Users/brian/Documents/Sites/foodbank/api + +# database: +# connections: +# default: +# adapter: mysql +# dsn: mysql:host=develop.digitalmediauconn.org;port=3306;dbname=foodbank +# user: foodbank +# password: +# settings: +# charset: utf8mb4_unicode_ci diff --git a/api/routes/category.php b/api/routes/category.php new file mode 100644 index 0000000..6a344a0 --- /dev/null +++ b/api/routes/category.php @@ -0,0 +1,25 @@ +get('/category/all', function( $request, $response ) { + $q = new CategoryQuery; + $cats = $q::create()->find(); + $response_json = [ + "status" => [ + "code" => $response->getStatusCode(), + "message" => "OK" + ], + "data" => [] + ]; + foreach( $cats as $cat ) { + $response_json["data"][] = [ + "id" => $cat->getId(), + "name" => $cat->getName() + ]; + } + $response = $response->withJSON($response_json); + return $response; +}); \ No newline at end of file diff --git a/api/schema.xml b/api/schema.xml new file mode 100644 index 0000000..099723a --- /dev/null +++ b/api/schema.xml @@ -0,0 +1,94 @@ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + +
+ + + + + + +
+ + + + + + + + + + + + + +
+
\ No newline at end of file diff --git a/app/pages/login/ctrl.js b/app/pages/login/ctrl.js index d8e34b5..c8daf8f 100644 --- a/app/pages/login/ctrl.js +++ b/app/pages/login/ctrl.js @@ -1,7 +1,40 @@ -app.controller('LoginCtrl', ['$scope', function ($scope) { +app.controller('LoginCtrl', ['$scope', 'loginService', function ($scope, loginService) { $scope.page.title = 'Login'; $scope.page.id = 'login'; $scope.page.yourVar = "globalStuff"; - $scope.var2 = "localStuff"; + $scope.selected = { + username: "", + password: "" + }; + + $scope.loginAttempt = { + username: "", + password: "", + attempt: false, + login: false + }; + + $scope.loginService = loginService; + + $scope.login = function( username, password ) { + $scope.loginAttempt.username = username; + $scope.loginAttempt.password = password; + $scope.loginAttempt.attempt = true; + // Sanitize? Pre-check? + console.log($scope.loginService); + $scope.loginService.login( username, password ).then(function(response) { + console.log(response); + // Mock the fact that this takes longer + setTimeout(function() { + $scope.$apply(function() { + $scope.loginAttempt.login = response.login; + $scope.loginAttempt.attempt = false; + }); + }, 1000); + }, function(error) { + console.error(error); + }); + }; + }]); diff --git a/app/pages/login/example.json b/app/pages/login/example.json new file mode 100644 index 0000000..79fcf88 --- /dev/null +++ b/app/pages/login/example.json @@ -0,0 +1,4 @@ +{ + "message": "ok", + "login": true +} \ No newline at end of file diff --git a/app/pages/login/loginService.js b/app/pages/login/loginService.js new file mode 100644 index 0000000..a415c3e --- /dev/null +++ b/app/pages/login/loginService.js @@ -0,0 +1,11 @@ +app.factory('loginService', ['$http', function($http) { + return { + login: function( username, password ) { + return $http.get('/app/pages/login/example.json').then(function(response) { + return response.data; + }, function(error) { + return error; + }); + } + }; +}]); \ No newline at end of file diff --git a/app/pages/login/view.html b/app/pages/login/view.html index 182622f..4bcccae 100644 --- a/app/pages/login/view.html +++ b/app/pages/login/view.html @@ -1,2 +1,60 @@
-

You've reached pages/login/view.html.

+
+
+
+
+
+
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+
+
+
+
+
+
+
+
+
+ done +
+
+ + +
{{ selected | json }}
+
{{ loginAttempt | json }}
+
+
+
\ No newline at end of file diff --git a/assets/js/bundle.js b/assets/js/bundle.js index 9aa9625..632e994 100644 --- a/assets/js/bundle.js +++ b/assets/js/bundle.js @@ -126,10 +126,55 @@ app.controller('FoodCtrl', ['$scope', function ($scope) { }]); -app.controller('LoginCtrl', ['$scope', function ($scope) { +app.controller('LoginCtrl', ['$scope', 'loginService', function ($scope, loginService) { $scope.page.title = 'Login'; $scope.page.id = 'login'; $scope.page.yourVar = "globalStuff"; - $scope.var2 = "localStuff"; + $scope.selected = { + username: "", + password: "" + }; + + $scope.loginAttempt = { + username: "", + password: "", + attempt: false, + login: false + }; + + $scope.loginService = loginService; + + $scope.login = function( username, password ) { + $scope.loginAttempt.username = username; + $scope.loginAttempt.password = password; + $scope.loginAttempt.attempt = true; + // Sanitize? Pre-check? + console.log($scope.loginService); + $scope.loginService.login( username, password ).then(function(response) { + console.log(response); + // Mock the fact that this takes longer + setTimeout(function() { + $scope.$apply(function() { + $scope.loginAttempt.login = response.login; + $scope.loginAttempt.attempt = false; + }); + }, 1000); + }, function(error) { + console.error(error); + }); + }; + }]); + +app.factory('loginService', ['$http', function($http) { + return { + login: function( username, password ) { + return $http.get('/app/pages/login/example.json').then(function(response) { + return response.data; + }, function(error) { + return error; + }); + } + }; +}]); \ No newline at end of file