From 5f9a198d9cf89c7707734e42dc1107a846e903ef Mon Sep 17 00:00:00 2001 From: Nicolas Barbey <223106@supinfo.com> Date: Tue, 27 Jul 2021 15:03:04 +0200 Subject: [PATCH 1/2] Thelia 2.5 compatibility --- Action/CommentAction.php | 25 +- Comment.php | 23 +- Config/config.xml | 12 +- Config/module.xml | 4 +- Config/routing.xml | 15 +- Config/schema.xml | 2 +- Controller/Back/CommentController.php | 74 +- Controller/Front/CommentController.php | 88 +- Form/AddCommentForm.php | 18 +- Form/CommentAbuseForm.php | 6 +- Form/CommentCreationForm.php | 29 +- Form/CommentModificationForm.php | 5 +- Form/ConfigurationForm.php | 19 +- Hook/FrontHook.php | 8 +- Loop/CommentLoop.php | 11 +- Model/Base/Comment.php | 2020 ----------------- Model/Base/CommentQuery.php | 1057 --------- Model/Map/CommentTableMap.php | 528 ----- .../backOffice/default/comment-edit.html | 4 +- .../backOffice/default/configuration.html | 2 +- .../default/include/comments-list.html | 18 +- .../frontOffice/default/ajax-comments.html | 2 +- templates/frontOffice/default/comment.html | 2 +- 23 files changed, 214 insertions(+), 3758 deletions(-) delete mode 100755 Model/Base/Comment.php delete mode 100755 Model/Base/CommentQuery.php delete mode 100755 Model/Map/CommentTableMap.php diff --git a/Action/CommentAction.php b/Action/CommentAction.php index 0fd876c..2ed0d36 100644 --- a/Action/CommentAction.php +++ b/Action/CommentAction.php @@ -42,8 +42,9 @@ use DateTime; use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\ActiveQuery\Join; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\Translation\TranslatorInterface; +use Symfony\Contracts\Translation\TranslatorInterface; use Thelia\Core\Template\ParserInterface; use Thelia\Core\Translation\Translator; use Thelia\Log\Tlog; @@ -81,11 +82,15 @@ class CommentAction implements EventSubscriberInterface /** @var null|MailerFactory */ protected $mailer = null; - public function __construct(TranslatorInterface $translator, ParserInterface $parser, MailerFactory $mailer) + /** @var null|EventDispatcherInterface */ + protected $dispatcher = null; + + public function __construct(TranslatorInterface $translator, ParserInterface $parser, MailerFactory $mailer, EventDispatcherInterface $dispatcher) { $this->translator = $translator; $this->parser = $parser; $this->mailer = $mailer; + $this->dispatcher = $dispatcher; } public function create(CommentCreateEvent $event) @@ -111,7 +116,6 @@ public function create(CommentCreateEvent $event) if (Comment::ACCEPTED === $comment->getStatus()) { $this->dispatchRatingCompute( - $event->getDispatcher(), $comment->getRef(), $comment->getRefId() ); @@ -138,7 +142,6 @@ public function update(CommentUpdateEvent $event) $event->setComment($comment); $this->dispatchRatingCompute( - $event->getDispatcher(), $comment->getRef(), $comment->getRefId() ); @@ -154,7 +157,6 @@ public function delete(CommentDeleteEvent $event) if (Comment::ACCEPTED === $comment->getStatus()) { $this->dispatchRatingCompute( - $event->getDispatcher(), $comment->getRef(), $comment->getRefId() ); @@ -184,7 +186,6 @@ public function statusChange(CommentChangeStatusEvent $event) $event->setComment($comment); $this->dispatchRatingCompute( - $event->getDispatcher(), $comment->getRef(), $comment->getRefId() ); @@ -230,7 +231,7 @@ public function productRatingCompute(CommentComputeRatingEvent $event) * @param string $ref * @param int $refId */ - protected function dispatchRatingCompute($dispatcher, $ref, $refId) + protected function dispatchRatingCompute($ref, $refId) { $ratingEvent = new CommentComputeRatingEvent(); @@ -238,9 +239,9 @@ protected function dispatchRatingCompute($dispatcher, $ref, $refId) ->setRef($ref) ->setRefId($refId); - $dispatcher->dispatch( - CommentEvents::COMMENT_RATING_COMPUTE, - $ratingEvent + $this->dispatcher->dispatch( + $ratingEvent, + CommentEvents::COMMENT_RATING_COMPUTE ); } @@ -292,7 +293,7 @@ public function getDefinition(CommentDefinitionEvent $event) } $eventName = CommentEvents::COMMENT_GET_DEFINITION . "." . $event->getRef(); - $event->getDispatcher()->dispatch($eventName, $event); + $this->dispatcher->dispatch($event, $eventName); // is only customer is authorized to publish if ($config['only_customer'] && null === $event->getCustomer()) { @@ -612,7 +613,7 @@ public function notifyAdminOfNewComment(CommentCreateEvent $event) $comment->getRefId(), $shopLocale ); - $event->getDispatcher()->dispatch(CommentEvents::COMMENT_REFERENCE_GETTER, $getCommentRefEvent); + $this->dispatcher->dispatch($getCommentRefEvent, CommentEvents::COMMENT_REFERENCE_GETTER); $this->mailer->sendEmailToShopManagers( 'new_comment_notification_admin', diff --git a/Comment.php b/Comment.php index e3c74c5..aecaf9a 100755 --- a/Comment.php +++ b/Comment.php @@ -14,6 +14,7 @@ use Comment\Model\CommentQuery; use Propel\Runtime\Connection\ConnectionInterface; +use Symfony\Component\DependencyInjection\Loader\Configurator\ServicesConfigurator; use Thelia\Core\Translation\Translator; use Thelia\Install\Database; use Thelia\Model\ConfigQuery; @@ -57,7 +58,7 @@ class Comment extends BaseModule const CONFIG_NOTIFY_ADMIN_NEW_COMMENT = true; - public function postActivation(ConnectionInterface $con = null) + public function postActivation(ConnectionInterface $con = null): void { // Config if (null === ConfigQuery::read('comment_activated')) { @@ -180,30 +181,38 @@ public static function getConfig() { $config = [ 'activated' => ( - intval(ConfigQuery::read('comment_activated', self::CONFIG_ACTIVATED)) === 1 + (int)ConfigQuery::read('comment_activated', self::CONFIG_ACTIVATED) === 1 ), 'moderate' => ( - intval(ConfigQuery::read('comment_moderate', self::CONFIG_MODERATE)) === 1 + (int)ConfigQuery::read('comment_moderate', self::CONFIG_MODERATE) === 1 ), 'ref_allowed' => explode( ',', ConfigQuery::read('comment_ref_allowed', self::CONFIG_REF_ALLOWED) ), 'only_customer' => ( - intval(ConfigQuery::read('comment_only_customer', self::CONFIG_ONLY_CUSTOMER)) === 1 + (int)ConfigQuery::read('comment_only_customer', self::CONFIG_ONLY_CUSTOMER) === 1 ), 'only_verified' => ( - intval(ConfigQuery::read('comment_only_verified', self::CONFIG_ONLY_VERIFIED)) === 1 + (int)ConfigQuery::read('comment_only_verified', self::CONFIG_ONLY_VERIFIED) === 1 ), 'request_customer_ttl' => ( - intval(ConfigQuery::read('comment_request_customer_ttl', self::CONFIG_REQUEST_CUSTOMMER_TTL)) + (int)ConfigQuery::read('comment_request_customer_ttl', self::CONFIG_REQUEST_CUSTOMMER_TTL) ), 'notify_admin_new_comment' => ( - intval(ConfigQuery::read('comment_notify_admin_new_comment', self::CONFIG_NOTIFY_ADMIN_NEW_COMMENT)) + (int)ConfigQuery::read('comment_notify_admin_new_comment', self::CONFIG_NOTIFY_ADMIN_NEW_COMMENT) === 1 ), ]; return $config; } + + public static function configureServices(ServicesConfigurator $servicesConfigurator): void + { + $servicesConfigurator->load(self::getModuleCode().'\\', __DIR__) + ->exclude([THELIA_MODULE_DIR . ucfirst(self::getModuleCode()). "/I18n/*"]) + ->autowire(true) + ->autoconfigure(true); + } } diff --git a/Config/config.xml b/Config/config.xml index 1e24164..858bf92 100755 --- a/Config/config.xml +++ b/Config/config.xml @@ -9,10 +9,10 @@ -
- - - + + + + @@ -21,7 +21,7 @@ --> - + - + - - Comment\Controller\Back\CommentController::saveConfiguration - + --> - + Comment\Controller\Back\CommentController::defaultAction @@ -52,7 +47,7 @@ Comment\Controller\Back\CommentController::deleteAction - + diff --git a/Config/schema.xml b/Config/schema.xml index e6668bd..489888c 100755 --- a/Config/schema.xml +++ b/Config/schema.xml @@ -1,5 +1,5 @@ - + diff --git a/Controller/Back/CommentController.php b/Controller/Back/CommentController.php index 6bbe290..4b805de 100644 --- a/Controller/Back/CommentController.php +++ b/Controller/Back/CommentController.php @@ -33,17 +33,25 @@ use Comment\Events\CommentUpdateEvent; use Comment\Form\CommentCreationForm; use Comment\Form\CommentModificationForm; +use Comment\Form\ConfigurationForm; use Comment\Model\CommentQuery; use Exception; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\Form\Extension\Core\Type\FormType; use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\HttpFoundation\RequestStack; use Thelia\Controller\Admin\AbstractCrudController; use Thelia\Core\Security\AccessManager; use Thelia\Core\Security\Resource\AdminResources; +use Thelia\Core\Template\ParserContext; +use Thelia\Core\Translation\Translator; use Thelia\Model\ConfigQuery; use Thelia\Model\MetaDataQuery; use Thelia\Tools\URL; +use Symfony\Component\Routing\Annotation\Route; /** + * @Route("/admin/module/comment", name="comment_module") * Class CommentController * @package Comment\Controller\Back * @author Julien Chanséaume @@ -51,8 +59,6 @@ class CommentController extends AbstractCrudController { - protected $currentRouter = "router.comment"; - public function __construct() { parent::__construct( @@ -74,7 +80,7 @@ public function __construct() */ protected function getCreationForm() { - return new CommentCreationForm($this->getRequest()); + return $this->createForm(CommentCreationForm::getName()); } /** @@ -82,7 +88,7 @@ protected function getCreationForm() */ protected function getUpdateForm() { - return new CommentModificationForm($this->getRequest()); + return $this->createForm(CommentModificationForm::getName()); } /** @@ -90,7 +96,7 @@ protected function getUpdateForm() * * @param \Comment\Model\Comment $object */ - protected function hydrateObjectForm($object) + protected function hydrateObjectForm(ParserContext $parserContext, $object) { // Prepare the data that will hydrate the form $data = [ @@ -109,7 +115,7 @@ protected function hydrateObjectForm($object) ]; // Setup the object form - return new CommentModificationForm($this->getRequest(), "form", $data); + return $this->createForm(CommentModificationForm::getName(), FormType::class, $data); } /** @@ -216,7 +222,7 @@ protected function getExistingObject() */ protected function getObjectLabel($object) { - $object->getTitle(); + return $object->getTitle(); } /** @@ -226,7 +232,7 @@ protected function getObjectLabel($object) */ protected function getObjectId($object) { - $object->getId(); + return $object->getId(); } /** @@ -254,14 +260,13 @@ protected function renderEditionTemplate() /** * Must return a RedirectResponse instance - * @return \Symfony\Component\HttpFoundation\RedirectResponse + */ protected function redirectToEditionTemplate() { - return $this->generateRedirectFromRoute( - "admin.comment.comments.update", - [], - ['comment_id' => $this->getRequest()->get('comment_id')] + $commentId = $this->getRequest()->get('comment_id'); + return $this->generateRedirect( + URL::getInstance()->absoluteUrl("/admin/module/comment/update/$commentId") ); } @@ -275,7 +280,10 @@ protected function redirectToListTemplate() } - public function changeStatusAction() + /** + * @Route("/status", name="_status", methods="POST") + */ + public function changeStatusAction(RequestStack $requestStack, EventDispatcherInterface $eventDispatcher) { if (null !== $response = $this->checkAuth([], ['comment'], AccessManager::UPDATE) ) { @@ -286,8 +294,9 @@ public function changeStatusAction() "success" => false, ]; - $id = $this->getRequest()->request->get('id'); - $status = $this->getRequest()->request->get('status'); + $request = $requestStack->getCurrentRequest(); + $id = $request->request->get('id'); + $status = $request->request->get('status'); if (null !== $id && null !== $status) { try { @@ -296,9 +305,9 @@ public function changeStatusAction() ->setId($id) ->setNewStatus($status); - $this->dispatch( - CommentEvents::COMMENT_STATUS_UPDATE, - $event + $eventDispatcher->dispatch( + $event, + CommentEvents::COMMENT_STATUS_UPDATE ); $message = [ @@ -312,12 +321,15 @@ public function changeStatusAction() $message["error"] = $ex->getMessage(); } } else { - $message["error"] = $this->getTranslator()->trans('Missing parameters', [], Comment::MESSAGE_DOMAIN); + $message["error"] = Translator::getInstance()->trans('Missing parameters', [], Comment::MESSAGE_DOMAIN); } return $this->jsonResponse(json_encode($message)); } + /** + * @Route("/activation/{ref}/{refId}", name="_activation", methods="POST") + */ public function activationAction($ref, $refId) { if (null !== $response = $this->checkAuth([], ['comment'], AccessManager::UPDATE) @@ -360,7 +372,10 @@ public function activationAction($ref, $refId) * * @return \Symfony\Component\HttpFoundation\RedirectResponse */ - public function saveConfiguration() + /** + * @Route("/configuration", name="_configuration", methods="POST") + */ + public function saveConfiguration(ParserContext $parserContext) { if (null !== $response = $this->checkAuth([AdminResources::MODULE], ['comment'], AccessManager::UPDATE) @@ -368,7 +383,7 @@ public function saveConfiguration() return $response; } - $form = new \Comment\Form\ConfigurationForm($this->getRequest()); + $form = $this->createForm(ConfigurationForm::getName()); $message = ""; $response = null; @@ -407,8 +422,8 @@ public function saveConfiguration() } if ($message) { $form->setErrorMessage($message); - $this->getParserContext()->addForm($form); - $this->getParserContext()->setGeneralError($message); + $parserContext->addForm($form); + $parserContext->setGeneralError($message); return $this->render( "module-configure", @@ -421,13 +436,16 @@ public function saveConfiguration() ); } - public function requestCustomerCommentAction() + /** + * @Route("/request-customer", name="_request-customer", methods="POST") + */ + public function requestCustomerCommentAction(EventDispatcherInterface $eventDispatcher) { // We do not check auth, as the related route may be invoked from a cron try { - $this->dispatch( - CommentEvents::COMMENT_CUSTOMER_DEMAND, - new CommentCheckOrderEvent() + $eventDispatcher->dispatch( + new CommentCheckOrderEvent(), + CommentEvents::COMMENT_CUSTOMER_DEMAND ); } catch (\Exception $ex) { // Any error diff --git a/Controller/Front/CommentController.php b/Controller/Front/CommentController.php index 4d48332..9afa5fd 100644 --- a/Controller/Front/CommentController.php +++ b/Controller/Front/CommentController.php @@ -30,11 +30,20 @@ use Comment\Events\CommentDeleteEvent; use Comment\Events\CommentEvents; use Comment\Exception\InvalidDefinitionException; +use Comment\Form\AddCommentForm; +use Comment\Form\CommentAbuseForm; use Comment\Model\CommentQuery; use Exception; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\Form\Extension\Core\Type\FormType; +use Symfony\Component\HttpFoundation\RequestStack; use Thelia\Controller\Front\BaseFrontController; +use Thelia\Core\Security\SecurityContext; +use Thelia\Core\Translation\Translator; +use Symfony\Component\Routing\Annotation\Route; /** + * @Route("/comment", name="comment") * Class CommentController * @package Comment\Controller\Admin * @author Michaël Espeche @@ -46,17 +55,23 @@ class CommentController extends BaseFrontController protected $useFallbackTemplate = true; - public function getAction() + /** + * @Route("/get", name="_get", methods="GET") + */ + public function getAction(RequestStack $requestStack, SecurityContext $securityContext, EventDispatcherInterface $dispatcher) { // only ajax $this->checkXmlHttpRequest(); $definition = null; + $request = $requestStack->getCurrentRequest(); try { $definition = $this->getDefinition( - $this->getRequest()->get('ref', null), - $this->getRequest()->get('ref_id', null) + $request->get('ref', null), + $request->get('ref_id', null), + $securityContext, + $dispatcher ); } catch (InvalidDefinitionException $ex) { if ($ex->isSilent()) { @@ -68,20 +83,23 @@ public function getAction() return $this->render( "ajax-comments", [ - 'ref' => $this->getRequest()->get('ref'), - 'ref_id' => $this->getRequest()->get('ref_id'), - 'start' => $this->getRequest()->get('start', 0), - 'count' => $this->getRequest()->get('count', 10), + 'ref' => $request->get('ref'), + 'ref_id' => $request->get('ref_id'), + 'start' => $request->get('start', 0), + 'count' => $request->get('count', 10), ] ); } - public function abuseAction() + /** + * @Route("/abuse", name="_abuse", methods="POST") + */ + public function abuseAction(EventDispatcherInterface $dispatcher) { // only ajax $this->checkXmlHttpRequest(); - $abuseForm = $this->createForm('comment.abuse.form'); + $abuseForm = $this->createForm(CommentAbuseForm::getName()); $messageData = [ "success" => false @@ -95,17 +113,17 @@ public function abuseAction() $event = new CommentAbuseEvent(); $event->setId($comment_id); - $this->dispatch(CommentEvents::COMMENT_ABUSE, $event); + $dispatcher->dispatch($event, CommentEvents::COMMENT_ABUSE); $messageData["success"] = true; - $messageData["message"] = $this->getTranslator()->trans( + $messageData["message"] = Translator::getInstance()->trans( "Your request has been registered. Thank you.", [], Comment::MESSAGE_DOMAIN ); } catch (\Exception $ex) { // all errors - $messageData["message"] = $this->getTranslator()->trans( + $messageData["message"] = Translator::getInstance()->trans( "Your request could not be validated. Try it later", [], Comment::MESSAGE_DOMAIN @@ -116,7 +134,10 @@ public function abuseAction() } - public function createAction() + /** + * @Route("/add", name="_add", methods="POST") + */ + public function createAction(RequestStack $requestStack, EventDispatcherInterface $dispatcher, SecurityContext $securityContext) { // only ajax $this->checkXmlHttpRequest(); @@ -124,12 +145,14 @@ public function createAction() $responseData = []; /** @var CommentDefinitionEvent $definition */ $definition = null; - + $request = $requestStack->getCurrentRequest(); try { - $params = $this->getRequest()->get('admin_add_comment'); + $params = $request->get('admin_add_comment'); $definition = $this->getDefinition( $params['ref'], - $params['ref_id'] + $params['ref_id'], + $securityContext, + $dispatcher ); } catch (InvalidDefinitionException $ex) { if ($ex->isSilent()) { @@ -159,8 +182,8 @@ public function createAction() } $commentForm = $this->createForm( - 'comment.add.form', - 'form', + AddCommentForm::getName(), + FormType::class, [], ['validation_groups' => $validationGroups] ); @@ -183,15 +206,15 @@ public function createAction() $event->setStatus(\Comment\Model\Comment::PENDING); } - $event->setLocale($this->getRequest()->getLocale()); + $event->setLocale($request->getLocale()); - $this->dispatch(CommentEvents::COMMENT_CREATE, $event); + $dispatcher->dispatch($event, CommentEvents::COMMENT_CREATE); if (null !== $event->getComment()) { $responseData = [ "success" => true, "messages" => [ - $this->getTranslator()->trans( + Translator::getInstance()->trans( "Thank you for submitting your comment.", [], Comment::MESSAGE_DOMAIN @@ -209,7 +232,7 @@ public function createAction() $responseData = [ "success" => false, "messages" => [ - $this->getTranslator()->trans( + Translator::getInstance()->trans( "Sorry, an unknown error occurred. Please try again.", [], Comment::MESSAGE_DOMAIN @@ -227,24 +250,27 @@ public function createAction() return $this->jsonResponse(json_encode($responseData)); } - protected function getDefinition($ref, $refId) + protected function getDefinition($ref, $refId, SecurityContext $securityContext, EventDispatcherInterface $dispatcher) { $eventDefinition = new CommentDefinitionEvent(); $eventDefinition ->setRef($ref) ->setRefId($refId) - ->setCustomer($this->getSecurityContext()->getCustomerUser()) + ->setCustomer($securityContext->getCustomerUser()) ->setConfig(Comment::getConfig()); - $this->dispatch( - CommentEvents::COMMENT_GET_DEFINITION, - $eventDefinition + $dispatcher->dispatch( + $eventDefinition, + CommentEvents::COMMENT_GET_DEFINITION ); return $eventDefinition; } - public function deleteAction($commentId) + /** + * @Route("/delete/{commentId}", name="_delete", methods="GET") + */ + public function deleteAction($commentId, SecurityContext $securityContext, EventDispatcherInterface $dispatcher) { // only ajax $this->checkXmlHttpRequest(); @@ -254,7 +280,7 @@ public function deleteAction($commentId) ]; try { - $customer = $this->getSecurityContext()->getCustomerUser(); + $customer = $securityContext->getCustomerUser(); // find the comment $comment = CommentQuery::create()->findPk($commentId); @@ -264,11 +290,11 @@ public function deleteAction($commentId) $event = new CommentDeleteEvent(); $event->setId($commentId); - $this->dispatch(CommentEvents::COMMENT_DELETE, $event); + $dispatcher->dispatch($event, CommentEvents::COMMENT_DELETE); if (null !== $event->getComment()) { $messageData["success"] = true; - $messageData["message"] = $this->getTranslator()->trans( + $messageData["message"] = Translator::getInstance()->trans( "Your comment has been deleted.", [], Comment::MESSAGE_DOMAIN diff --git a/Form/AddCommentForm.php b/Form/AddCommentForm.php index 20afc1b..4bbc5dc 100644 --- a/Form/AddCommentForm.php +++ b/Form/AddCommentForm.php @@ -23,6 +23,8 @@ namespace Comment\Form; use Comment\Comment; +use Symfony\Component\Form\Extension\Core\Type\EmailType; +use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Validator\Constraints\Email; use Symfony\Component\Validator\Constraints\GreaterThan; use Symfony\Component\Validator\Constraints\GreaterThanOrEqual; @@ -40,7 +42,7 @@ protected function trans($id, array $parameters = []) protected function buildForm() { $this->formBuilder - ->add('username', 'text', [ + ->add('username', TextType::class, [ 'constraints' => [ new NotBlank(['groups' => ['anonymous']]) ], @@ -49,7 +51,7 @@ protected function buildForm() 'for' => 'comment_username' ] ]) - ->add('email', 'email', [ + ->add('email', EmailType::class, [ 'constraints' => [ new NotBlank(['groups' => ['anonymous']]), new Email(['groups' => ['anonymous']]) @@ -59,7 +61,7 @@ protected function buildForm() 'for' => 'comment_mail' ] ]) - ->add('title', 'text', [ + ->add('title', TextType::class, [ 'constraints' => [ new NotBlank() ], @@ -68,7 +70,7 @@ protected function buildForm() 'for' => 'title' ] ]) - ->add('content', 'text', [ + ->add('content', TextType::class, [ 'constraints' => [ new NotBlank() ], @@ -77,7 +79,7 @@ protected function buildForm() 'for' => 'content' ] ]) - ->add('ref', 'text', [ + ->add('ref', TextType::class, [ 'constraints' => [ new NotBlank() ], @@ -86,7 +88,7 @@ protected function buildForm() 'for' => 'ref' ] ]) - ->add('ref_id', 'text', [ + ->add('ref_id', TextType::class, [ 'constraints' => [ new GreaterThan(['value' => 0]) ], @@ -95,7 +97,7 @@ protected function buildForm() 'for' => 'ref_id' ] ]) - ->add('rating', 'text', [ + ->add('rating', TextType::class, [ 'constraints' => [ new GreaterThanOrEqual(['value' => 0, 'groups' => ['rating']]), new LessThanOrEqual(['value' => 5, 'groups' => ['rating']]) @@ -112,7 +114,7 @@ protected function getDefinition() { $this->form->get('success_url'); } */ - public function getName() + public static function getName() { return 'admin_add_comment'; } diff --git a/Form/CommentAbuseForm.php b/Form/CommentAbuseForm.php index 2c22ea8..47bf7f0 100644 --- a/Form/CommentAbuseForm.php +++ b/Form/CommentAbuseForm.php @@ -13,6 +13,8 @@ namespace Comment\Form; +use Comment\Comment; +use Comment\Form\Field\CommentIdType; use Thelia\Form\BaseForm; /** @@ -33,7 +35,7 @@ protected function buildForm() ->formBuilder ->add( 'id', - 'comment_id' + CommentIdType::class ); } @@ -41,7 +43,7 @@ protected function buildForm() /** * @return string the name of you form. This name must be unique */ - public function getName() + public static function getName() { return 'comment_abuse'; } diff --git a/Form/CommentCreationForm.php b/Form/CommentCreationForm.php index 653dbea..633f288 100644 --- a/Form/CommentCreationForm.php +++ b/Form/CommentCreationForm.php @@ -14,6 +14,9 @@ namespace Comment\Form; use Comment\Comment; +use Symfony\Component\Form\Extension\Core\Type\EmailType; +use Symfony\Component\Form\Extension\Core\Type\IntegerType; +use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Validator\Constraints\Email; use Symfony\Component\Validator\Constraints\GreaterThanOrEqual; use Symfony\Component\Validator\Constraints\Length; @@ -40,7 +43,7 @@ protected function buildForm() ->formBuilder ->add( 'customer_id', - 'integer', + IntegerType::class, [ 'required' => false, 'label' => $this->trans('Customer'), @@ -49,7 +52,7 @@ protected function buildForm() ] ] ) - ->add('username', 'text', [ + ->add('username', TextType::class, [ 'required' => false, 'constraints' => [ new Length(['min' => 2]) @@ -59,7 +62,7 @@ protected function buildForm() 'for' => 'comment_username' ] ]) - ->add('email', 'email', [ + ->add('email', EmailType::class, [ 'required' => false, 'constraints' => [ new Email() @@ -71,7 +74,7 @@ protected function buildForm() ]) ->add( 'locale', - 'text', + TextType::class, [ 'label' => $this->trans('Locale'), 'label_attr' => [ @@ -79,7 +82,7 @@ protected function buildForm() ] ] ) - ->add('title', 'text', [ + ->add('title', TextType::class, [ 'constraints' => [ new NotBlank() ], @@ -88,7 +91,7 @@ protected function buildForm() 'for' => 'title' ] ]) - ->add('content', 'text', [ + ->add('content', TextType::class, [ 'constraints' => [ new NotBlank() ], @@ -97,7 +100,7 @@ protected function buildForm() 'for' => 'content' ] ]) - ->add('ref', 'text', [ + ->add('ref', TextType::class, [ 'constraints' => [ new NotBlank() ], @@ -106,7 +109,7 @@ protected function buildForm() 'for' => 'ref' ] ]) - ->add('ref_id', 'integer', [ + ->add('ref_id', IntegerType::class, [ 'constraints' => [ new GreaterThanOrEqual(['value' => 0]) ], @@ -115,7 +118,7 @@ protected function buildForm() 'for' => 'ref_id' ] ]) - ->add('rating', 'integer', [ + ->add('rating', IntegerType::class, [ 'required' => false, 'constraints' => [ new GreaterThanOrEqual(['value' => 0]), @@ -128,7 +131,7 @@ protected function buildForm() ]) ->add( 'status', - 'integer', + IntegerType::class, [ 'label' => $this->trans('Status'), 'label_attr' => [ @@ -138,7 +141,7 @@ protected function buildForm() ) ->add( 'verified', - 'integer', + IntegerType::class, [ 'label' => $this->trans('Verified'), 'label_attr' => [ @@ -148,7 +151,7 @@ protected function buildForm() ) ->add( 'abuse', - 'integer', + IntegerType::class, [ 'label' => $this->trans('Abuse'), 'label_attr' => [ @@ -161,7 +164,7 @@ protected function buildForm() /** * @return string the name of you form. This name must be unique */ - public function getName() + public static function getName() { return 'admin_comment_creation'; } diff --git a/Form/CommentModificationForm.php b/Form/CommentModificationForm.php index 21f9c41..4427772 100644 --- a/Form/CommentModificationForm.php +++ b/Form/CommentModificationForm.php @@ -14,6 +14,7 @@ namespace Comment\Form; use Comment\Comment; +use Symfony\Component\Form\Extension\Core\Type\IntegerType; use Symfony\Component\Validator\Constraints\NotBlank; /** @@ -36,7 +37,7 @@ protected function buildForm() ->formBuilder ->add( 'id', - 'integer', + IntegerType::class, [ 'constraints' => [ new NotBlank() @@ -53,7 +54,7 @@ protected function buildForm() /** * @return string the name of you form. This name must be unique */ - public function getName() + public static function getName() { return 'admin_comment_modification'; } diff --git a/Form/ConfigurationForm.php b/Form/ConfigurationForm.php index 17a3015..55b21df 100644 --- a/Form/ConfigurationForm.php +++ b/Form/ConfigurationForm.php @@ -14,6 +14,9 @@ namespace Comment\Form; use Comment\Comment; +use Symfony\Component\Form\Extension\Core\Type\CheckboxType; +use Symfony\Component\Form\Extension\Core\Type\NumberType; +use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Validator\Constraints\NotBlank; use Thelia\Form\BaseForm; @@ -38,7 +41,7 @@ protected function buildForm() $form ->add( "activated", - "checkbox", + CheckboxType::class, [ 'data' => $config['activated'], 'label' => $this->trans("Activated"), @@ -52,7 +55,7 @@ protected function buildForm() ) ->add( "moderate", - "checkbox", + CheckboxType::class, [ 'data' => $config['moderate'], 'label' => $this->trans("Moderate"), @@ -64,7 +67,7 @@ protected function buildForm() ) ->add( "ref_allowed", - "text", + TextType::class, [ 'constraints' => [ new NotBlank() @@ -79,7 +82,7 @@ protected function buildForm() ) ->add( "only_customer", - "checkbox", + CheckboxType::class, [ 'data' => $config['only_customer'], 'label' => $this->trans("Only customer"), @@ -91,7 +94,7 @@ protected function buildForm() ) ->add( "only_verified", - "checkbox", + CheckboxType::class, [ 'data' => $config['only_verified'], 'label' => $this->trans("Only verified"), @@ -105,7 +108,7 @@ protected function buildForm() ) ->add( "request_customer_ttl", - "number", + NumberType::class, [ 'data' => $config['request_customer_ttl'], 'label' => $this->trans("Request customer"), @@ -119,7 +122,7 @@ protected function buildForm() ) ->add( "notify_admin_new_comment", - "checkbox", + CheckboxType::class, [ 'data' => $config['notify_admin_new_comment'], 'label' => $this->trans("Notify store managers on new comment"), @@ -136,7 +139,7 @@ protected function buildForm() /** * @return string the name of you form. This name must be unique */ - public function getName() + public static function getName() { return "comment-configuration-form"; } diff --git a/Hook/FrontHook.php b/Hook/FrontHook.php index faf97d4..ae29a4c 100644 --- a/Hook/FrontHook.php +++ b/Hook/FrontHook.php @@ -76,8 +76,8 @@ protected function showComment(BaseHookRenderEvent $event) try { $this->dispatcher->dispatch( - CommentEvents::COMMENT_GET_DEFINITION, - $eventDefinition + $eventDefinition, + CommentEvents::COMMENT_GET_DEFINITION ); $eventDefinition->setValid(true); } catch (InvalidDefinitionException $ex) { @@ -144,9 +144,9 @@ protected function getParams(BaseHookRenderEvent $event) $refId = $event->getArgument('ref_id'); } else { if ($this->getRequest()->attributes->has('id')) { - $refId = intval($this->getRequest()->attributes->get('id')); + $refId = (int)($this->getRequest()->attributes->get('id')); } elseif ($this->getRequest()->query->has($ref . '_id')) { - $refId = intval($this->getRequest()->query->get($ref . '_id')); + $refId = (int)($this->getRequest()->query->get($ref . '_id')); } } diff --git a/Loop/CommentLoop.php b/Loop/CommentLoop.php index 51131fe..9af1a58 100644 --- a/Loop/CommentLoop.php +++ b/Loop/CommentLoop.php @@ -207,7 +207,8 @@ public function parseResults(LoopResult $loopResult) ->set('RATING', $comment->getRating()) ->set('STATUS', $comment->getStatus()) ->set('VERIFIED', $comment->getVerified()) - ->set('ABUSE', $comment->getAbuse()); + ->set('ABUSE', $comment->getAbuse()) + ->set('CREATED', $comment->getCreatedAt()->format('d/m/Y h:m:s')); if (1 == $this->getLoadRef()) { // dispatch event to get the reference element @@ -231,7 +232,7 @@ public function parseResults(LoopResult $loopResult) * @param string $ref * @param int $refId */ - protected function getReference(LoopResultRow &$loopResultRow, $ref, $refId) + protected function getReference(LoopResultRow $loopResultRow, $ref, $refId) { $key = sprintf('%s:%s', $ref, $refId); $data = [ @@ -244,15 +245,15 @@ protected function getReference(LoopResultRow &$loopResultRow, $ref, $refId) $refLocale = $this->getRefLocale(); if ($refLocale === null) { - $refLocale = $this->request->getLocale(); + $refLocale = $this->requestStack->getCurrentRequest()->getLocale(); } if (!array_key_exists($key, $this->cacheRef)) { $event = new CommentReferenceGetterEvent($ref, $refId, $refLocale); $this->dispatcher->dispatch( - CommentEvents::COMMENT_REFERENCE_GETTER, - $event + $event, + CommentEvents::COMMENT_REFERENCE_GETTER ); $data['REF_OBJECT'] = $event->getObject(); diff --git a/Model/Base/Comment.php b/Model/Base/Comment.php deleted file mode 100755 index 91c0337..0000000 --- a/Model/Base/Comment.php +++ /dev/null @@ -1,2020 +0,0 @@ -status = 0; - } - - /** - * Initializes internal state of Comment\Model\Base\Comment object. - * @see applyDefaults() - */ - public function __construct() - { - $this->applyDefaultValues(); - } - - /** - * Returns whether the object has been modified. - * - * @return boolean True if the object has been modified. - */ - public function isModified() - { - return !!$this->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 Comment instance. If - * obj is an instance of Comment, delegates to - * equals(Comment). Otherwise, returns false. - * - * @param mixed $obj The object to compare to. - * @return boolean Whether equal to the object specified. - */ - public function equals($obj) - { - $thisclazz = get_class($this); - if (!is_object($obj) || !($obj instanceof $thisclazz)) { - return false; - } - - if ($this === $obj) { - return true; - } - - if (null === $this->getPrimaryKey() - || null === $obj->getPrimaryKey()) { - return false; - } - - return $this->getPrimaryKey() === $obj->getPrimaryKey(); - } - - /** - * 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() - { - if (null !== $this->getPrimaryKey()) { - return crc32(serialize($this->getPrimaryKey())); - } - - return crc32(serialize(clone $this)); - } - - /** - * 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 Comment 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); - } - - /** - * 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}'); - * - * - * @param mixed $parser A AbstractParser instance, - * or a format name ('XML', 'YAML', 'JSON', 'CSV') - * @param string $data The source data to import from - * - * @return Comment The current object, for fluid interface - */ - public function importFrom($parser, $data) - { - if (!$parser instanceof AbstractParser) { - $parser = AbstractParser::getParser($parser); - } - - $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME); - - return $this; - } - - /** - * 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(); - - return array_keys(get_object_vars($this)); - } - - /** - * Get the [id] column value. - * - * @return int - */ - public function getId() - { - - return $this->id; - } - - /** - * Get the [username] column value. - * - * @return string - */ - public function getUsername() - { - - return $this->username; - } - - /** - * Get the [customer_id] column value. - * - * @return int - */ - public function getCustomerId() - { - - return $this->customer_id; - } - - /** - * Get the [ref] column value. - * - * @return string - */ - public function getRef() - { - - return $this->ref; - } - - /** - * Get the [ref_id] column value. - * - * @return int - */ - public function getRefId() - { - - return $this->ref_id; - } - - /** - * Get the [email] column value. - * - * @return string - */ - public function getEmail() - { - - return $this->email; - } - - /** - * Get the [title] column value. - * - * @return string - */ - public function getTitle() - { - - return $this->title; - } - - /** - * Get the [content] column value. - * - * @return string - */ - public function getContent() - { - - return $this->content; - } - - /** - * Get the [rating] column value. - * - * @return int - */ - public function getRating() - { - - return $this->rating; - } - - /** - * Get the [status] column value. - * - * @return int - */ - public function getStatus() - { - - return $this->status; - } - - /** - * Get the [verified] column value. - * - * @return int - */ - public function getVerified() - { - - return $this->verified; - } - - /** - * Get the [abuse] column value. - * - * @return int - */ - public function getAbuse() - { - - return $this->abuse; - } - - /** - * Get the [locale] column value. - * - * @return string - */ - public function getLocale() - { - - return $this->locale; - } - - /** - * Get the [optionally formatted] temporal [created_at] column value. - * - * - * @param string $format The date/time format string (either date()-style or strftime()-style). - * If format is NULL, then the raw \DateTime object will be returned. - * - * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 - * - * @throws PropelException - if unable to parse/validate the date/time value. - */ - public function getCreatedAt($format = NULL) - { - if ($format === null) { - return $this->created_at; - } else { - return $this->created_at instanceof \DateTime ? $this->created_at->format($format) : null; - } - } - - /** - * Get the [optionally formatted] temporal [updated_at] column value. - * - * - * @param string $format The date/time format string (either date()-style or strftime()-style). - * If format is NULL, then the raw \DateTime object will be returned. - * - * @return mixed Formatted date/time value as string or \DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 - * - * @throws PropelException - if unable to parse/validate the date/time value. - */ - public function getUpdatedAt($format = NULL) - { - if ($format === null) { - return $this->updated_at; - } else { - return $this->updated_at instanceof \DateTime ? $this->updated_at->format($format) : null; - } - } - - /** - * Set the value of [id] column. - * - * @param int $v new value - * @return \Comment\Model\Comment 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[CommentTableMap::ID] = true; - } - - - return $this; - } // setId() - - /** - * Set the value of [username] column. - * - * @param string $v new value - * @return \Comment\Model\Comment The current object (for fluent API support) - */ - public function setUsername($v) - { - if ($v !== null) { - $v = (string) $v; - } - - if ($this->username !== $v) { - $this->username = $v; - $this->modifiedColumns[CommentTableMap::USERNAME] = true; - } - - - return $this; - } // setUsername() - - /** - * Set the value of [customer_id] column. - * - * @param int $v new value - * @return \Comment\Model\Comment The current object (for fluent API support) - */ - public function setCustomerId($v) - { - if ($v !== null) { - $v = (int) $v; - } - - if ($this->customer_id !== $v) { - $this->customer_id = $v; - $this->modifiedColumns[CommentTableMap::CUSTOMER_ID] = true; - } - - if ($this->aCustomer !== null && $this->aCustomer->getId() !== $v) { - $this->aCustomer = null; - } - - - return $this; - } // setCustomerId() - - /** - * Set the value of [ref] column. - * - * @param string $v new value - * @return \Comment\Model\Comment The current object (for fluent API support) - */ - public function setRef($v) - { - if ($v !== null) { - $v = (string) $v; - } - - if ($this->ref !== $v) { - $this->ref = $v; - $this->modifiedColumns[CommentTableMap::REF] = true; - } - - - return $this; - } // setRef() - - /** - * Set the value of [ref_id] column. - * - * @param int $v new value - * @return \Comment\Model\Comment The current object (for fluent API support) - */ - public function setRefId($v) - { - if ($v !== null) { - $v = (int) $v; - } - - if ($this->ref_id !== $v) { - $this->ref_id = $v; - $this->modifiedColumns[CommentTableMap::REF_ID] = true; - } - - - return $this; - } // setRefId() - - /** - * Set the value of [email] column. - * - * @param string $v new value - * @return \Comment\Model\Comment The current object (for fluent API support) - */ - public function setEmail($v) - { - if ($v !== null) { - $v = (string) $v; - } - - if ($this->email !== $v) { - $this->email = $v; - $this->modifiedColumns[CommentTableMap::EMAIL] = true; - } - - - return $this; - } // setEmail() - - /** - * Set the value of [title] column. - * - * @param string $v new value - * @return \Comment\Model\Comment The current object (for fluent API support) - */ - public function setTitle($v) - { - if ($v !== null) { - $v = (string) $v; - } - - if ($this->title !== $v) { - $this->title = $v; - $this->modifiedColumns[CommentTableMap::TITLE] = true; - } - - - return $this; - } // setTitle() - - /** - * Set the value of [content] column. - * - * @param string $v new value - * @return \Comment\Model\Comment The current object (for fluent API support) - */ - public function setContent($v) - { - if ($v !== null) { - $v = (string) $v; - } - - if ($this->content !== $v) { - $this->content = $v; - $this->modifiedColumns[CommentTableMap::CONTENT] = true; - } - - - return $this; - } // setContent() - - /** - * Set the value of [rating] column. - * - * @param int $v new value - * @return \Comment\Model\Comment The current object (for fluent API support) - */ - public function setRating($v) - { - if ($v !== null) { - $v = (int) $v; - } - - if ($this->rating !== $v) { - $this->rating = $v; - $this->modifiedColumns[CommentTableMap::RATING] = true; - } - - - return $this; - } // setRating() - - /** - * Set the value of [status] column. - * - * @param int $v new value - * @return \Comment\Model\Comment The current object (for fluent API support) - */ - public function setStatus($v) - { - if ($v !== null) { - $v = (int) $v; - } - - if ($this->status !== $v) { - $this->status = $v; - $this->modifiedColumns[CommentTableMap::STATUS] = true; - } - - - return $this; - } // setStatus() - - /** - * Set the value of [verified] column. - * - * @param int $v new value - * @return \Comment\Model\Comment The current object (for fluent API support) - */ - public function setVerified($v) - { - if ($v !== null) { - $v = (int) $v; - } - - if ($this->verified !== $v) { - $this->verified = $v; - $this->modifiedColumns[CommentTableMap::VERIFIED] = true; - } - - - return $this; - } // setVerified() - - /** - * Set the value of [abuse] column. - * - * @param int $v new value - * @return \Comment\Model\Comment The current object (for fluent API support) - */ - public function setAbuse($v) - { - if ($v !== null) { - $v = (int) $v; - } - - if ($this->abuse !== $v) { - $this->abuse = $v; - $this->modifiedColumns[CommentTableMap::ABUSE] = true; - } - - - return $this; - } // setAbuse() - - /** - * Set the value of [locale] column. - * - * @param string $v new value - * @return \Comment\Model\Comment The current object (for fluent API support) - */ - public function setLocale($v) - { - if ($v !== null) { - $v = (string) $v; - } - - if ($this->locale !== $v) { - $this->locale = $v; - $this->modifiedColumns[CommentTableMap::LOCALE] = true; - } - - - return $this; - } // setLocale() - - /** - * Sets the value of [created_at] column to a normalized version of the date/time value specified. - * - * @param mixed $v string, integer (timestamp), or \DateTime value. - * Empty strings are treated as NULL. - * @return \Comment\Model\Comment The current object (for fluent API support) - */ - public function setCreatedAt($v) - { - $dt = PropelDateTime::newInstance($v, null, '\DateTime'); - if ($this->created_at !== null || $dt !== null) { - if ($dt !== $this->created_at) { - $this->created_at = $dt; - $this->modifiedColumns[CommentTableMap::CREATED_AT] = true; - } - } // if either are not null - - - return $this; - } // setCreatedAt() - - /** - * Sets the value of [updated_at] column to a normalized version of the date/time value specified. - * - * @param mixed $v string, integer (timestamp), or \DateTime value. - * Empty strings are treated as NULL. - * @return \Comment\Model\Comment The current object (for fluent API support) - */ - public function setUpdatedAt($v) - { - $dt = PropelDateTime::newInstance($v, null, '\DateTime'); - if ($this->updated_at !== null || $dt !== null) { - if ($dt !== $this->updated_at) { - $this->updated_at = $dt; - $this->modifiedColumns[CommentTableMap::UPDATED_AT] = true; - } - } // if either are not null - - - return $this; - } // setUpdatedAt() - - /** - * 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() - { - if ($this->status !== 0) { - return false; - } - - // 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_STUDLYPHPNAME - * 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 : CommentTableMap::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType)]; - $this->id = (null !== $col) ? (int) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 1 + $startcol : CommentTableMap::translateFieldName('Username', TableMap::TYPE_PHPNAME, $indexType)]; - $this->username = (null !== $col) ? (string) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 2 + $startcol : CommentTableMap::translateFieldName('CustomerId', TableMap::TYPE_PHPNAME, $indexType)]; - $this->customer_id = (null !== $col) ? (int) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : CommentTableMap::translateFieldName('Ref', TableMap::TYPE_PHPNAME, $indexType)]; - $this->ref = (null !== $col) ? (string) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : CommentTableMap::translateFieldName('RefId', TableMap::TYPE_PHPNAME, $indexType)]; - $this->ref_id = (null !== $col) ? (int) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : CommentTableMap::translateFieldName('Email', TableMap::TYPE_PHPNAME, $indexType)]; - $this->email = (null !== $col) ? (string) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : CommentTableMap::translateFieldName('Title', TableMap::TYPE_PHPNAME, $indexType)]; - $this->title = (null !== $col) ? (string) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : CommentTableMap::translateFieldName('Content', TableMap::TYPE_PHPNAME, $indexType)]; - $this->content = (null !== $col) ? (string) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : CommentTableMap::translateFieldName('Rating', TableMap::TYPE_PHPNAME, $indexType)]; - $this->rating = (null !== $col) ? (int) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 9 + $startcol : CommentTableMap::translateFieldName('Status', TableMap::TYPE_PHPNAME, $indexType)]; - $this->status = (null !== $col) ? (int) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 10 + $startcol : CommentTableMap::translateFieldName('Verified', TableMap::TYPE_PHPNAME, $indexType)]; - $this->verified = (null !== $col) ? (int) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 11 + $startcol : CommentTableMap::translateFieldName('Abuse', TableMap::TYPE_PHPNAME, $indexType)]; - $this->abuse = (null !== $col) ? (int) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 12 + $startcol : CommentTableMap::translateFieldName('Locale', TableMap::TYPE_PHPNAME, $indexType)]; - $this->locale = (null !== $col) ? (string) $col : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 13 + $startcol : CommentTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)]; - if ($col === '0000-00-00 00:00:00') { - $col = null; - } - $this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; - - $col = $row[TableMap::TYPE_NUM == $indexType ? 14 + $startcol : CommentTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)]; - if ($col === '0000-00-00 00:00:00') { - $col = null; - } - $this->updated_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null; - $this->resetModified(); - - $this->setNew(false); - - if ($rehydrate) { - $this->ensureConsistency(); - } - - return $startcol + 15; // 15 = CommentTableMap::NUM_HYDRATE_COLUMNS. - - } catch (Exception $e) { - throw new PropelException("Error populating \Comment\Model\Comment object", 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->aCustomer !== null && $this->customer_id !== $this->aCustomer->getId()) { - $this->aCustomer = 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(CommentTableMap::DATABASE_NAME); - } - - // We don't need to alter the object instance pool; we're just modifying this instance - // already in the pool. - - $dataFetcher = ChildCommentQuery::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->aCustomer = null; - } // if (deep) - } - - /** - * Removes this object from datastore and sets delete attribute. - * - * @param ConnectionInterface $con - * @return void - * @throws PropelException - * @see Comment::setDeleted() - * @see Comment::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(CommentTableMap::DATABASE_NAME); - } - - $con->beginTransaction(); - try { - $deleteQuery = ChildCommentQuery::create() - ->filterByPrimaryKey($this->getPrimaryKey()); - $ret = $this->preDelete($con); - if ($ret) { - $deleteQuery->delete($con); - $this->postDelete($con); - $con->commit(); - $this->setDeleted(true); - } else { - $con->commit(); - } - } catch (Exception $e) { - $con->rollBack(); - throw $e; - } - } - - /** - * 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(CommentTableMap::DATABASE_NAME); - } - - $con->beginTransaction(); - $isInsert = $this->isNew(); - try { - $ret = $this->preSave($con); - if ($isInsert) { - $ret = $ret && $this->preInsert($con); - // timestampable behavior - if (!$this->isColumnModified(CommentTableMap::CREATED_AT)) { - $this->setCreatedAt(time()); - } - if (!$this->isColumnModified(CommentTableMap::UPDATED_AT)) { - $this->setUpdatedAt(time()); - } - } else { - $ret = $ret && $this->preUpdate($con); - // timestampable behavior - if ($this->isModified() && !$this->isColumnModified(CommentTableMap::UPDATED_AT)) { - $this->setUpdatedAt(time()); - } - } - if ($ret) { - $affectedRows = $this->doSave($con); - if ($isInsert) { - $this->postInsert($con); - } else { - $this->postUpdate($con); - } - $this->postSave($con); - CommentTableMap::addInstanceToPool($this); - } else { - $affectedRows = 0; - } - $con->commit(); - - return $affectedRows; - } catch (Exception $e) { - $con->rollBack(); - throw $e; - } - } - - /** - * 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->aCustomer !== null) { - if ($this->aCustomer->isModified() || $this->aCustomer->isNew()) { - $affectedRows += $this->aCustomer->save($con); - } - $this->setCustomer($this->aCustomer); - } - - if ($this->isNew() || $this->isModified()) { - // persist changes - if ($this->isNew()) { - $this->doInsert($con); - } else { - $this->doUpdate($con); - } - $affectedRows += 1; - $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[CommentTableMap::ID] = true; - if (null !== $this->id) { - throw new PropelException('Cannot insert a value for auto-increment primary key (' . CommentTableMap::ID . ')'); - } - - // check the columns in natural order for more readable SQL queries - if ($this->isColumnModified(CommentTableMap::ID)) { - $modifiedColumns[':p' . $index++] = 'ID'; - } - if ($this->isColumnModified(CommentTableMap::USERNAME)) { - $modifiedColumns[':p' . $index++] = 'USERNAME'; - } - if ($this->isColumnModified(CommentTableMap::CUSTOMER_ID)) { - $modifiedColumns[':p' . $index++] = 'CUSTOMER_ID'; - } - if ($this->isColumnModified(CommentTableMap::REF)) { - $modifiedColumns[':p' . $index++] = 'REF'; - } - if ($this->isColumnModified(CommentTableMap::REF_ID)) { - $modifiedColumns[':p' . $index++] = 'REF_ID'; - } - if ($this->isColumnModified(CommentTableMap::EMAIL)) { - $modifiedColumns[':p' . $index++] = 'EMAIL'; - } - if ($this->isColumnModified(CommentTableMap::TITLE)) { - $modifiedColumns[':p' . $index++] = 'TITLE'; - } - if ($this->isColumnModified(CommentTableMap::CONTENT)) { - $modifiedColumns[':p' . $index++] = 'CONTENT'; - } - if ($this->isColumnModified(CommentTableMap::RATING)) { - $modifiedColumns[':p' . $index++] = 'RATING'; - } - if ($this->isColumnModified(CommentTableMap::STATUS)) { - $modifiedColumns[':p' . $index++] = 'STATUS'; - } - if ($this->isColumnModified(CommentTableMap::VERIFIED)) { - $modifiedColumns[':p' . $index++] = 'VERIFIED'; - } - if ($this->isColumnModified(CommentTableMap::ABUSE)) { - $modifiedColumns[':p' . $index++] = 'ABUSE'; - } - if ($this->isColumnModified(CommentTableMap::LOCALE)) { - $modifiedColumns[':p' . $index++] = 'LOCALE'; - } - if ($this->isColumnModified(CommentTableMap::CREATED_AT)) { - $modifiedColumns[':p' . $index++] = 'CREATED_AT'; - } - if ($this->isColumnModified(CommentTableMap::UPDATED_AT)) { - $modifiedColumns[':p' . $index++] = 'UPDATED_AT'; - } - - $sql = sprintf( - 'INSERT INTO comment (%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 'USERNAME': - $stmt->bindValue($identifier, $this->username, PDO::PARAM_STR); - break; - case 'CUSTOMER_ID': - $stmt->bindValue($identifier, $this->customer_id, PDO::PARAM_INT); - break; - case 'REF': - $stmt->bindValue($identifier, $this->ref, PDO::PARAM_STR); - break; - case 'REF_ID': - $stmt->bindValue($identifier, $this->ref_id, PDO::PARAM_INT); - break; - case 'EMAIL': - $stmt->bindValue($identifier, $this->email, PDO::PARAM_STR); - break; - case 'TITLE': - $stmt->bindValue($identifier, $this->title, PDO::PARAM_STR); - break; - case 'CONTENT': - $stmt->bindValue($identifier, $this->content, PDO::PARAM_STR); - break; - case 'RATING': - $stmt->bindValue($identifier, $this->rating, PDO::PARAM_INT); - break; - case 'STATUS': - $stmt->bindValue($identifier, $this->status, PDO::PARAM_INT); - break; - case 'VERIFIED': - $stmt->bindValue($identifier, $this->verified, PDO::PARAM_INT); - break; - case 'ABUSE': - $stmt->bindValue($identifier, $this->abuse, PDO::PARAM_INT); - break; - case 'LOCALE': - $stmt->bindValue($identifier, $this->locale, PDO::PARAM_STR); - break; - case 'CREATED_AT': - $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR); - break; - case 'UPDATED_AT': - $stmt->bindValue($identifier, $this->updated_at ? $this->updated_at->format("Y-m-d H:i:s") : null, 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_STUDLYPHPNAME - * 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 = CommentTableMap::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->getUsername(); - break; - case 2: - return $this->getCustomerId(); - break; - case 3: - return $this->getRef(); - break; - case 4: - return $this->getRefId(); - break; - case 5: - return $this->getEmail(); - break; - case 6: - return $this->getTitle(); - break; - case 7: - return $this->getContent(); - break; - case 8: - return $this->getRating(); - break; - case 9: - return $this->getStatus(); - break; - case 10: - return $this->getVerified(); - break; - case 11: - return $this->getAbuse(); - break; - case 12: - return $this->getLocale(); - break; - case 13: - return $this->getCreatedAt(); - break; - case 14: - return $this->getUpdatedAt(); - 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_STUDLYPHPNAME, - * 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['Comment'][$this->getPrimaryKey()])) { - return '*RECURSION*'; - } - $alreadyDumpedObjects['Comment'][$this->getPrimaryKey()] = true; - $keys = CommentTableMap::getFieldNames($keyType); - $result = array( - $keys[0] => $this->getId(), - $keys[1] => $this->getUsername(), - $keys[2] => $this->getCustomerId(), - $keys[3] => $this->getRef(), - $keys[4] => $this->getRefId(), - $keys[5] => $this->getEmail(), - $keys[6] => $this->getTitle(), - $keys[7] => $this->getContent(), - $keys[8] => $this->getRating(), - $keys[9] => $this->getStatus(), - $keys[10] => $this->getVerified(), - $keys[11] => $this->getAbuse(), - $keys[12] => $this->getLocale(), - $keys[13] => $this->getCreatedAt(), - $keys[14] => $this->getUpdatedAt(), - ); - $virtualColumns = $this->virtualColumns; - foreach ($virtualColumns as $key => $virtualColumn) { - $result[$key] = $virtualColumn; - } - - if ($includeForeignObjects) { - if (null !== $this->aCustomer) { - $result['Customer'] = $this->aCustomer->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_STUDLYPHPNAME - * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. - * Defaults to TableMap::TYPE_PHPNAME. - * @return void - */ - public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) - { - $pos = CommentTableMap::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 void - */ - public function setByPosition($pos, $value) - { - switch ($pos) { - case 0: - $this->setId($value); - break; - case 1: - $this->setUsername($value); - break; - case 2: - $this->setCustomerId($value); - break; - case 3: - $this->setRef($value); - break; - case 4: - $this->setRefId($value); - break; - case 5: - $this->setEmail($value); - break; - case 6: - $this->setTitle($value); - break; - case 7: - $this->setContent($value); - break; - case 8: - $this->setRating($value); - break; - case 9: - $this->setStatus($value); - break; - case 10: - $this->setVerified($value); - break; - case 11: - $this->setAbuse($value); - break; - case 12: - $this->setLocale($value); - break; - case 13: - $this->setCreatedAt($value); - break; - case 14: - $this->setUpdatedAt($value); - break; - } // switch() - } - - /** - * 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_STUDLYPHPNAME, - * 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 = CommentTableMap::getFieldNames($keyType); - - if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]); - if (array_key_exists($keys[1], $arr)) $this->setUsername($arr[$keys[1]]); - if (array_key_exists($keys[2], $arr)) $this->setCustomerId($arr[$keys[2]]); - if (array_key_exists($keys[3], $arr)) $this->setRef($arr[$keys[3]]); - if (array_key_exists($keys[4], $arr)) $this->setRefId($arr[$keys[4]]); - if (array_key_exists($keys[5], $arr)) $this->setEmail($arr[$keys[5]]); - if (array_key_exists($keys[6], $arr)) $this->setTitle($arr[$keys[6]]); - if (array_key_exists($keys[7], $arr)) $this->setContent($arr[$keys[7]]); - if (array_key_exists($keys[8], $arr)) $this->setRating($arr[$keys[8]]); - if (array_key_exists($keys[9], $arr)) $this->setStatus($arr[$keys[9]]); - if (array_key_exists($keys[10], $arr)) $this->setVerified($arr[$keys[10]]); - if (array_key_exists($keys[11], $arr)) $this->setAbuse($arr[$keys[11]]); - if (array_key_exists($keys[12], $arr)) $this->setLocale($arr[$keys[12]]); - if (array_key_exists($keys[13], $arr)) $this->setCreatedAt($arr[$keys[13]]); - if (array_key_exists($keys[14], $arr)) $this->setUpdatedAt($arr[$keys[14]]); - } - - /** - * 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(CommentTableMap::DATABASE_NAME); - - if ($this->isColumnModified(CommentTableMap::ID)) $criteria->add(CommentTableMap::ID, $this->id); - if ($this->isColumnModified(CommentTableMap::USERNAME)) $criteria->add(CommentTableMap::USERNAME, $this->username); - if ($this->isColumnModified(CommentTableMap::CUSTOMER_ID)) $criteria->add(CommentTableMap::CUSTOMER_ID, $this->customer_id); - if ($this->isColumnModified(CommentTableMap::REF)) $criteria->add(CommentTableMap::REF, $this->ref); - if ($this->isColumnModified(CommentTableMap::REF_ID)) $criteria->add(CommentTableMap::REF_ID, $this->ref_id); - if ($this->isColumnModified(CommentTableMap::EMAIL)) $criteria->add(CommentTableMap::EMAIL, $this->email); - if ($this->isColumnModified(CommentTableMap::TITLE)) $criteria->add(CommentTableMap::TITLE, $this->title); - if ($this->isColumnModified(CommentTableMap::CONTENT)) $criteria->add(CommentTableMap::CONTENT, $this->content); - if ($this->isColumnModified(CommentTableMap::RATING)) $criteria->add(CommentTableMap::RATING, $this->rating); - if ($this->isColumnModified(CommentTableMap::STATUS)) $criteria->add(CommentTableMap::STATUS, $this->status); - if ($this->isColumnModified(CommentTableMap::VERIFIED)) $criteria->add(CommentTableMap::VERIFIED, $this->verified); - if ($this->isColumnModified(CommentTableMap::ABUSE)) $criteria->add(CommentTableMap::ABUSE, $this->abuse); - if ($this->isColumnModified(CommentTableMap::LOCALE)) $criteria->add(CommentTableMap::LOCALE, $this->locale); - if ($this->isColumnModified(CommentTableMap::CREATED_AT)) $criteria->add(CommentTableMap::CREATED_AT, $this->created_at); - if ($this->isColumnModified(CommentTableMap::UPDATED_AT)) $criteria->add(CommentTableMap::UPDATED_AT, $this->updated_at); - - 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. - * - * @return Criteria The Criteria object containing value(s) for primary key(s). - */ - public function buildPkeyCriteria() - { - $criteria = new Criteria(CommentTableMap::DATABASE_NAME); - $criteria->add(CommentTableMap::ID, $this->id); - - return $criteria; - } - - /** - * 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 \Comment\Model\Comment (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->setUsername($this->getUsername()); - $copyObj->setCustomerId($this->getCustomerId()); - $copyObj->setRef($this->getRef()); - $copyObj->setRefId($this->getRefId()); - $copyObj->setEmail($this->getEmail()); - $copyObj->setTitle($this->getTitle()); - $copyObj->setContent($this->getContent()); - $copyObj->setRating($this->getRating()); - $copyObj->setStatus($this->getStatus()); - $copyObj->setVerified($this->getVerified()); - $copyObj->setAbuse($this->getAbuse()); - $copyObj->setLocale($this->getLocale()); - $copyObj->setCreatedAt($this->getCreatedAt()); - $copyObj->setUpdatedAt($this->getUpdatedAt()); - 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 \Comment\Model\Comment 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 ChildCustomer object. - * - * @param ChildCustomer $v - * @return \Comment\Model\Comment The current object (for fluent API support) - * @throws PropelException - */ - public function setCustomer(ChildCustomer $v = null) - { - if ($v === null) { - $this->setCustomerId(NULL); - } else { - $this->setCustomerId($v->getId()); - } - - $this->aCustomer = $v; - - // Add binding for other direction of this n:n relationship. - // If this object has already been added to the ChildCustomer object, it will not be re-added. - if ($v !== null) { - $v->addComment($this); - } - - - return $this; - } - - - /** - * Get the associated ChildCustomer object - * - * @param ConnectionInterface $con Optional Connection object. - * @return ChildCustomer The associated ChildCustomer object. - * @throws PropelException - */ - public function getCustomer(ConnectionInterface $con = null) - { - if ($this->aCustomer === null && ($this->customer_id !== null)) { - $this->aCustomer = CustomerQuery::create()->findPk($this->customer_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->aCustomer->addComments($this); - */ - } - - return $this->aCustomer; - } - - /** - * Clears the current object and sets all attributes to their default values - */ - public function clear() - { - $this->id = null; - $this->username = null; - $this->customer_id = null; - $this->ref = null; - $this->ref_id = null; - $this->email = null; - $this->title = null; - $this->content = null; - $this->rating = null; - $this->status = null; - $this->verified = null; - $this->abuse = null; - $this->locale = null; - $this->created_at = null; - $this->updated_at = null; - $this->alreadyInSave = false; - $this->clearAllReferences(); - $this->applyDefaultValues(); - $this->resetModified(); - $this->setNew(true); - $this->setDeleted(false); - } - - /** - * Resets all references to other model objects or collections of model objects. - * - * This method is a user-space workaround for PHP's inability to garbage collect - * objects with circular references (even in PHP 5.3). This is currently necessary - * when using Propel in certain daemon or large-volume/high-memory operations. - * - * @param boolean $deep Whether to also clear the references on all referrer objects. - */ - public function clearAllReferences($deep = false) - { - if ($deep) { - } // if ($deep) - - $this->aCustomer = null; - } - - /** - * Return the string representation of this object - * - * @return string - */ - public function __toString() - { - return (string) $this->exportTo(CommentTableMap::DEFAULT_STRING_FORMAT); - } - - // timestampable behavior - - /** - * Mark the current object so that the update date doesn't get updated during next save - * - * @return ChildComment The current object (for fluent API support) - */ - public function keepUpdateDateUnchanged() - { - $this->modifiedColumns[CommentTableMap::UPDATED_AT] = true; - - return $this; - } - - /** - * Code to be run before persisting the object - * @param ConnectionInterface $con - * @return boolean - */ - public function preSave(ConnectionInterface $con = null) - { - return true; - } - - /** - * Code to be run after persisting the object - * @param ConnectionInterface $con - */ - public function postSave(ConnectionInterface $con = null) - { - - } - - /** - * Code to be run before inserting to database - * @param ConnectionInterface $con - * @return boolean - */ - public function preInsert(ConnectionInterface $con = null) - { - return true; - } - - /** - * Code to be run after inserting to database - * @param ConnectionInterface $con - */ - public function postInsert(ConnectionInterface $con = null) - { - - } - - /** - * Code to be run before updating the object in database - * @param ConnectionInterface $con - * @return boolean - */ - public function preUpdate(ConnectionInterface $con = null) - { - return true; - } - - /** - * Code to be run after updating the object in database - * @param ConnectionInterface $con - */ - public function postUpdate(ConnectionInterface $con = null) - { - - } - - /** - * Code to be run before deleting the object in database - * @param ConnectionInterface $con - * @return boolean - */ - public function preDelete(ConnectionInterface $con = null) - { - return true; - } - - /** - * Code to be run after deleting the object in database - * @param ConnectionInterface $con - */ - public function postDelete(ConnectionInterface $con = null) - { - - } - - - /** - * 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/Model/Base/CommentQuery.php b/Model/Base/CommentQuery.php deleted file mode 100755 index 8c3a718..0000000 --- a/Model/Base/CommentQuery.php +++ /dev/null @@ -1,1057 +0,0 @@ -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 ChildComment|array|mixed the result, formatted by the current formatter - */ - public function findPk($key, $con = null) - { - if ($key === null) { - return null; - } - if ((null !== ($obj = CommentTableMap::getInstanceFromPool((string) $key))) && !$this->formatter) { - // the object is already in the instance pool - return $obj; - } - if ($con === null) { - $con = Propel::getServiceContainer()->getReadConnection(CommentTableMap::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); - } else { - 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 - * - * @return ChildComment A model object, or null if the key is not found - */ - protected function findPkSimple($key, $con) - { - $sql = 'SELECT ID, USERNAME, CUSTOMER_ID, REF, REF_ID, EMAIL, TITLE, CONTENT, RATING, STATUS, VERIFIED, ABUSE, LOCALE, CREATED_AT, UPDATED_AT FROM comment 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)) { - $obj = new ChildComment(); - $obj->hydrate($row); - CommentTableMap::addInstanceToPool($obj, (string) $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 ChildComment|array|mixed the result, formatted by the current formatter - */ - protected function findPkComplex($key, $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, $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 ChildCommentQuery The current query, for fluid interface - */ - public function filterByPrimaryKey($key) - { - - return $this->addUsingAlias(CommentTableMap::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 ChildCommentQuery The current query, for fluid interface - */ - public function filterByPrimaryKeys($keys) - { - - return $this->addUsingAlias(CommentTableMap::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 ChildCommentQuery 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(CommentTableMap::ID, $id['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($id['max'])) { - $this->addUsingAlias(CommentTableMap::ID, $id['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(CommentTableMap::ID, $id, $comparison); - } - - /** - * Filter the query on the username column - * - * Example usage: - * - * $query->filterByUsername('fooValue'); // WHERE username = 'fooValue' - * $query->filterByUsername('%fooValue%'); // WHERE username LIKE '%fooValue%' - * - * - * @param string $username The value to use as filter. - * Accepts wildcards (* and % trigger a LIKE) - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildCommentQuery The current query, for fluid interface - */ - public function filterByUsername($username = null, $comparison = null) - { - if (null === $comparison) { - if (is_array($username)) { - $comparison = Criteria::IN; - } elseif (preg_match('/[\%\*]/', $username)) { - $username = str_replace('*', '%', $username); - $comparison = Criteria::LIKE; - } - } - - return $this->addUsingAlias(CommentTableMap::USERNAME, $username, $comparison); - } - - /** - * Filter the query on the customer_id column - * - * Example usage: - * - * $query->filterByCustomerId(1234); // WHERE customer_id = 1234 - * $query->filterByCustomerId(array(12, 34)); // WHERE customer_id IN (12, 34) - * $query->filterByCustomerId(array('min' => 12)); // WHERE customer_id > 12 - * - * - * @see filterByCustomer() - * - * @param mixed $customerId 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 ChildCommentQuery The current query, for fluid interface - */ - public function filterByCustomerId($customerId = null, $comparison = null) - { - if (is_array($customerId)) { - $useMinMax = false; - if (isset($customerId['min'])) { - $this->addUsingAlias(CommentTableMap::CUSTOMER_ID, $customerId['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($customerId['max'])) { - $this->addUsingAlias(CommentTableMap::CUSTOMER_ID, $customerId['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(CommentTableMap::CUSTOMER_ID, $customerId, $comparison); - } - - /** - * Filter the query on the ref column - * - * Example usage: - * - * $query->filterByRef('fooValue'); // WHERE ref = 'fooValue' - * $query->filterByRef('%fooValue%'); // WHERE ref LIKE '%fooValue%' - * - * - * @param string $ref The value to use as filter. - * Accepts wildcards (* and % trigger a LIKE) - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildCommentQuery The current query, for fluid interface - */ - public function filterByRef($ref = null, $comparison = null) - { - if (null === $comparison) { - if (is_array($ref)) { - $comparison = Criteria::IN; - } elseif (preg_match('/[\%\*]/', $ref)) { - $ref = str_replace('*', '%', $ref); - $comparison = Criteria::LIKE; - } - } - - return $this->addUsingAlias(CommentTableMap::REF, $ref, $comparison); - } - - /** - * Filter the query on the ref_id column - * - * Example usage: - * - * $query->filterByRefId(1234); // WHERE ref_id = 1234 - * $query->filterByRefId(array(12, 34)); // WHERE ref_id IN (12, 34) - * $query->filterByRefId(array('min' => 12)); // WHERE ref_id > 12 - * - * - * @param mixed $refId 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 ChildCommentQuery The current query, for fluid interface - */ - public function filterByRefId($refId = null, $comparison = null) - { - if (is_array($refId)) { - $useMinMax = false; - if (isset($refId['min'])) { - $this->addUsingAlias(CommentTableMap::REF_ID, $refId['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($refId['max'])) { - $this->addUsingAlias(CommentTableMap::REF_ID, $refId['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(CommentTableMap::REF_ID, $refId, $comparison); - } - - /** - * Filter the query on the email column - * - * Example usage: - * - * $query->filterByEmail('fooValue'); // WHERE email = 'fooValue' - * $query->filterByEmail('%fooValue%'); // WHERE email LIKE '%fooValue%' - * - * - * @param string $email The value to use as filter. - * Accepts wildcards (* and % trigger a LIKE) - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildCommentQuery The current query, for fluid interface - */ - public function filterByEmail($email = null, $comparison = null) - { - if (null === $comparison) { - if (is_array($email)) { - $comparison = Criteria::IN; - } elseif (preg_match('/[\%\*]/', $email)) { - $email = str_replace('*', '%', $email); - $comparison = Criteria::LIKE; - } - } - - return $this->addUsingAlias(CommentTableMap::EMAIL, $email, $comparison); - } - - /** - * Filter the query on the title column - * - * Example usage: - * - * $query->filterByTitle('fooValue'); // WHERE title = 'fooValue' - * $query->filterByTitle('%fooValue%'); // WHERE title LIKE '%fooValue%' - * - * - * @param string $title The value to use as filter. - * Accepts wildcards (* and % trigger a LIKE) - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildCommentQuery The current query, for fluid interface - */ - public function filterByTitle($title = null, $comparison = null) - { - if (null === $comparison) { - if (is_array($title)) { - $comparison = Criteria::IN; - } elseif (preg_match('/[\%\*]/', $title)) { - $title = str_replace('*', '%', $title); - $comparison = Criteria::LIKE; - } - } - - return $this->addUsingAlias(CommentTableMap::TITLE, $title, $comparison); - } - - /** - * Filter the query on the content column - * - * Example usage: - * - * $query->filterByContent('fooValue'); // WHERE content = 'fooValue' - * $query->filterByContent('%fooValue%'); // WHERE content LIKE '%fooValue%' - * - * - * @param string $content The value to use as filter. - * Accepts wildcards (* and % trigger a LIKE) - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildCommentQuery The current query, for fluid interface - */ - public function filterByContent($content = null, $comparison = null) - { - if (null === $comparison) { - if (is_array($content)) { - $comparison = Criteria::IN; - } elseif (preg_match('/[\%\*]/', $content)) { - $content = str_replace('*', '%', $content); - $comparison = Criteria::LIKE; - } - } - - return $this->addUsingAlias(CommentTableMap::CONTENT, $content, $comparison); - } - - /** - * Filter the query on the rating column - * - * Example usage: - * - * $query->filterByRating(1234); // WHERE rating = 1234 - * $query->filterByRating(array(12, 34)); // WHERE rating IN (12, 34) - * $query->filterByRating(array('min' => 12)); // WHERE rating > 12 - * - * - * @param mixed $rating 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 ChildCommentQuery The current query, for fluid interface - */ - public function filterByRating($rating = null, $comparison = null) - { - if (is_array($rating)) { - $useMinMax = false; - if (isset($rating['min'])) { - $this->addUsingAlias(CommentTableMap::RATING, $rating['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($rating['max'])) { - $this->addUsingAlias(CommentTableMap::RATING, $rating['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(CommentTableMap::RATING, $rating, $comparison); - } - - /** - * Filter the query on the status column - * - * Example usage: - * - * $query->filterByStatus(1234); // WHERE status = 1234 - * $query->filterByStatus(array(12, 34)); // WHERE status IN (12, 34) - * $query->filterByStatus(array('min' => 12)); // WHERE status > 12 - * - * - * @param mixed $status 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 ChildCommentQuery The current query, for fluid interface - */ - public function filterByStatus($status = null, $comparison = null) - { - if (is_array($status)) { - $useMinMax = false; - if (isset($status['min'])) { - $this->addUsingAlias(CommentTableMap::STATUS, $status['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($status['max'])) { - $this->addUsingAlias(CommentTableMap::STATUS, $status['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(CommentTableMap::STATUS, $status, $comparison); - } - - /** - * Filter the query on the verified column - * - * Example usage: - * - * $query->filterByVerified(1234); // WHERE verified = 1234 - * $query->filterByVerified(array(12, 34)); // WHERE verified IN (12, 34) - * $query->filterByVerified(array('min' => 12)); // WHERE verified > 12 - * - * - * @param mixed $verified 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 ChildCommentQuery The current query, for fluid interface - */ - public function filterByVerified($verified = null, $comparison = null) - { - if (is_array($verified)) { - $useMinMax = false; - if (isset($verified['min'])) { - $this->addUsingAlias(CommentTableMap::VERIFIED, $verified['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($verified['max'])) { - $this->addUsingAlias(CommentTableMap::VERIFIED, $verified['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(CommentTableMap::VERIFIED, $verified, $comparison); - } - - /** - * Filter the query on the abuse column - * - * Example usage: - * - * $query->filterByAbuse(1234); // WHERE abuse = 1234 - * $query->filterByAbuse(array(12, 34)); // WHERE abuse IN (12, 34) - * $query->filterByAbuse(array('min' => 12)); // WHERE abuse > 12 - * - * - * @param mixed $abuse 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 ChildCommentQuery The current query, for fluid interface - */ - public function filterByAbuse($abuse = null, $comparison = null) - { - if (is_array($abuse)) { - $useMinMax = false; - if (isset($abuse['min'])) { - $this->addUsingAlias(CommentTableMap::ABUSE, $abuse['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($abuse['max'])) { - $this->addUsingAlias(CommentTableMap::ABUSE, $abuse['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(CommentTableMap::ABUSE, $abuse, $comparison); - } - - /** - * Filter the query on the locale column - * - * Example usage: - * - * $query->filterByLocale('fooValue'); // WHERE locale = 'fooValue' - * $query->filterByLocale('%fooValue%'); // WHERE locale LIKE '%fooValue%' - * - * - * @param string $locale The value to use as filter. - * Accepts wildcards (* and % trigger a LIKE) - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildCommentQuery The current query, for fluid interface - */ - public function filterByLocale($locale = null, $comparison = null) - { - if (null === $comparison) { - if (is_array($locale)) { - $comparison = Criteria::IN; - } elseif (preg_match('/[\%\*]/', $locale)) { - $locale = str_replace('*', '%', $locale); - $comparison = Criteria::LIKE; - } - } - - return $this->addUsingAlias(CommentTableMap::LOCALE, $locale, $comparison); - } - - /** - * Filter the query on the created_at column - * - * Example usage: - * - * $query->filterByCreatedAt('2011-03-14'); // WHERE created_at = '2011-03-14' - * $query->filterByCreatedAt('now'); // WHERE created_at = '2011-03-14' - * $query->filterByCreatedAt(array('max' => 'yesterday')); // WHERE created_at > '2011-03-13' - * - * - * @param mixed $createdAt The value to use as filter. - * Values can be integers (unix timestamps), DateTime objects, or strings. - * Empty strings are treated as NULL. - * 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 ChildCommentQuery The current query, for fluid interface - */ - public function filterByCreatedAt($createdAt = null, $comparison = null) - { - if (is_array($createdAt)) { - $useMinMax = false; - if (isset($createdAt['min'])) { - $this->addUsingAlias(CommentTableMap::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($createdAt['max'])) { - $this->addUsingAlias(CommentTableMap::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(CommentTableMap::CREATED_AT, $createdAt, $comparison); - } - - /** - * Filter the query on the updated_at column - * - * Example usage: - * - * $query->filterByUpdatedAt('2011-03-14'); // WHERE updated_at = '2011-03-14' - * $query->filterByUpdatedAt('now'); // WHERE updated_at = '2011-03-14' - * $query->filterByUpdatedAt(array('max' => 'yesterday')); // WHERE updated_at > '2011-03-13' - * - * - * @param mixed $updatedAt The value to use as filter. - * Values can be integers (unix timestamps), DateTime objects, or strings. - * Empty strings are treated as NULL. - * 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 ChildCommentQuery The current query, for fluid interface - */ - public function filterByUpdatedAt($updatedAt = null, $comparison = null) - { - if (is_array($updatedAt)) { - $useMinMax = false; - if (isset($updatedAt['min'])) { - $this->addUsingAlias(CommentTableMap::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL); - $useMinMax = true; - } - if (isset($updatedAt['max'])) { - $this->addUsingAlias(CommentTableMap::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL); - $useMinMax = true; - } - if ($useMinMax) { - return $this; - } - if (null === $comparison) { - $comparison = Criteria::IN; - } - } - - return $this->addUsingAlias(CommentTableMap::UPDATED_AT, $updatedAt, $comparison); - } - - /** - * Filter the query by a related \Comment\Model\Thelia\Model\Customer object - * - * @param \Comment\Model\Thelia\Model\Customer|ObjectCollection $customer The related object(s) to use as filter - * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL - * - * @return ChildCommentQuery The current query, for fluid interface - */ - public function filterByCustomer($customer, $comparison = null) - { - if ($customer instanceof \Comment\Model\Thelia\Model\Customer) { - return $this - ->addUsingAlias(CommentTableMap::CUSTOMER_ID, $customer->getId(), $comparison); - } elseif ($customer instanceof ObjectCollection) { - if (null === $comparison) { - $comparison = Criteria::IN; - } - - return $this - ->addUsingAlias(CommentTableMap::CUSTOMER_ID, $customer->toKeyValue('PrimaryKey', 'Id'), $comparison); - } else { - throw new PropelException('filterByCustomer() only accepts arguments of type \Comment\Model\Thelia\Model\Customer or Collection'); - } - } - - /** - * Adds a JOIN clause to the query using the Customer relation - * - * @param string $relationAlias optional alias for the relation - * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' - * - * @return ChildCommentQuery The current query, for fluid interface - */ - public function joinCustomer($relationAlias = null, $joinType = Criteria::LEFT_JOIN) - { - $tableMap = $this->getTableMap(); - $relationMap = $tableMap->getRelation('Customer'); - - // 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, 'Customer'); - } - - return $this; - } - - /** - * Use the Customer relation Customer 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 \Comment\Model\Thelia\Model\CustomerQuery A secondary query class using the current class as primary query - */ - public function useCustomerQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) - { - return $this - ->joinCustomer($relationAlias, $joinType) - ->useQuery($relationAlias ? $relationAlias : 'Customer', '\Comment\Model\Thelia\Model\CustomerQuery'); - } - - /** - * Exclude object from result - * - * @param ChildComment $comment Object to remove from the list of results - * - * @return ChildCommentQuery The current query, for fluid interface - */ - public function prune($comment = null) - { - if ($comment) { - $this->addUsingAlias(CommentTableMap::ID, $comment->getId(), Criteria::NOT_EQUAL); - } - - return $this; - } - - /** - * Deletes all rows from the comment 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(CommentTableMap::DATABASE_NAME); - } - $affectedRows = 0; // initialize var to track total num of affected rows - try { - // use transaction because $criteria could contain info - // for more than one table or we could emulating ON DELETE CASCADE, etc. - $con->beginTransaction(); - $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). - CommentTableMap::clearInstancePool(); - CommentTableMap::clearRelatedInstancePool(); - - $con->commit(); - } catch (PropelException $e) { - $con->rollBack(); - throw $e; - } - - return $affectedRows; - } - - /** - * Performs a DELETE on the database, given a ChildComment or Criteria object OR a primary key value. - * - * @param mixed $values Criteria or ChildComment 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 function delete(ConnectionInterface $con = null) - { - if (null === $con) { - $con = Propel::getServiceContainer()->getWriteConnection(CommentTableMap::DATABASE_NAME); - } - - $criteria = $this; - - // Set the correct dbName - $criteria->setDbName(CommentTableMap::DATABASE_NAME); - - $affectedRows = 0; // initialize var to track total num of affected rows - - try { - // use transaction because $criteria could contain info - // for more than one table or we could emulating ON DELETE CASCADE, etc. - $con->beginTransaction(); - - - CommentTableMap::removeInstanceFromPool($criteria); - - $affectedRows += ModelCriteria::delete($con); - CommentTableMap::clearRelatedInstancePool(); - $con->commit(); - - return $affectedRows; - } catch (PropelException $e) { - $con->rollBack(); - throw $e; - } - } - - // timestampable behavior - - /** - * Filter by the latest updated - * - * @param int $nbDays Maximum age of the latest update in days - * - * @return ChildCommentQuery The current query, for fluid interface - */ - public function recentlyUpdated($nbDays = 7) - { - return $this->addUsingAlias(CommentTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); - } - - /** - * Filter by the latest created - * - * @param int $nbDays Maximum age of in days - * - * @return ChildCommentQuery The current query, for fluid interface - */ - public function recentlyCreated($nbDays = 7) - { - return $this->addUsingAlias(CommentTableMap::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL); - } - - /** - * Order by update date desc - * - * @return ChildCommentQuery The current query, for fluid interface - */ - public function lastUpdatedFirst() - { - return $this->addDescendingOrderByColumn(CommentTableMap::UPDATED_AT); - } - - /** - * Order by update date asc - * - * @return ChildCommentQuery The current query, for fluid interface - */ - public function firstUpdatedFirst() - { - return $this->addAscendingOrderByColumn(CommentTableMap::UPDATED_AT); - } - - /** - * Order by create date desc - * - * @return ChildCommentQuery The current query, for fluid interface - */ - public function lastCreatedFirst() - { - return $this->addDescendingOrderByColumn(CommentTableMap::CREATED_AT); - } - - /** - * Order by create date asc - * - * @return ChildCommentQuery The current query, for fluid interface - */ - public function firstCreatedFirst() - { - return $this->addAscendingOrderByColumn(CommentTableMap::CREATED_AT); - } - -} // CommentQuery diff --git a/Model/Map/CommentTableMap.php b/Model/Map/CommentTableMap.php deleted file mode 100755 index 0343259..0000000 --- a/Model/Map/CommentTableMap.php +++ /dev/null @@ -1,528 +0,0 @@ - array('Id', 'Username', 'CustomerId', 'Ref', 'RefId', 'Email', 'Title', 'Content', 'Rating', 'Status', 'Verified', 'Abuse', 'Locale', 'CreatedAt', 'UpdatedAt', ), - self::TYPE_STUDLYPHPNAME => array('id', 'username', 'customerId', 'ref', 'refId', 'email', 'title', 'content', 'rating', 'status', 'verified', 'abuse', 'locale', 'createdAt', 'updatedAt', ), - self::TYPE_COLNAME => array(CommentTableMap::ID, CommentTableMap::USERNAME, CommentTableMap::CUSTOMER_ID, CommentTableMap::REF, CommentTableMap::REF_ID, CommentTableMap::EMAIL, CommentTableMap::TITLE, CommentTableMap::CONTENT, CommentTableMap::RATING, CommentTableMap::STATUS, CommentTableMap::VERIFIED, CommentTableMap::ABUSE, CommentTableMap::LOCALE, CommentTableMap::CREATED_AT, CommentTableMap::UPDATED_AT, ), - self::TYPE_RAW_COLNAME => array('ID', 'USERNAME', 'CUSTOMER_ID', 'REF', 'REF_ID', 'EMAIL', 'TITLE', 'CONTENT', 'RATING', 'STATUS', 'VERIFIED', 'ABUSE', 'LOCALE', 'CREATED_AT', 'UPDATED_AT', ), - self::TYPE_FIELDNAME => array('id', 'username', 'customer_id', 'ref', 'ref_id', 'email', 'title', 'content', 'rating', 'status', 'verified', 'abuse', 'locale', 'created_at', 'updated_at', ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ) - ); - - /** - * 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, 'Username' => 1, 'CustomerId' => 2, 'Ref' => 3, 'RefId' => 4, 'Email' => 5, 'Title' => 6, 'Content' => 7, 'Rating' => 8, 'Status' => 9, 'Verified' => 10, 'Abuse' => 11, 'Locale' => 12, 'CreatedAt' => 13, 'UpdatedAt' => 14, ), - self::TYPE_STUDLYPHPNAME => array('id' => 0, 'username' => 1, 'customerId' => 2, 'ref' => 3, 'refId' => 4, 'email' => 5, 'title' => 6, 'content' => 7, 'rating' => 8, 'status' => 9, 'verified' => 10, 'abuse' => 11, 'locale' => 12, 'createdAt' => 13, 'updatedAt' => 14, ), - self::TYPE_COLNAME => array(CommentTableMap::ID => 0, CommentTableMap::USERNAME => 1, CommentTableMap::CUSTOMER_ID => 2, CommentTableMap::REF => 3, CommentTableMap::REF_ID => 4, CommentTableMap::EMAIL => 5, CommentTableMap::TITLE => 6, CommentTableMap::CONTENT => 7, CommentTableMap::RATING => 8, CommentTableMap::STATUS => 9, CommentTableMap::VERIFIED => 10, CommentTableMap::ABUSE => 11, CommentTableMap::LOCALE => 12, CommentTableMap::CREATED_AT => 13, CommentTableMap::UPDATED_AT => 14, ), - self::TYPE_RAW_COLNAME => array('ID' => 0, 'USERNAME' => 1, 'CUSTOMER_ID' => 2, 'REF' => 3, 'REF_ID' => 4, 'EMAIL' => 5, 'TITLE' => 6, 'CONTENT' => 7, 'RATING' => 8, 'STATUS' => 9, 'VERIFIED' => 10, 'ABUSE' => 11, 'LOCALE' => 12, 'CREATED_AT' => 13, 'UPDATED_AT' => 14, ), - self::TYPE_FIELDNAME => array('id' => 0, 'username' => 1, 'customer_id' => 2, 'ref' => 3, 'ref_id' => 4, 'email' => 5, 'title' => 6, 'content' => 7, 'rating' => 8, 'status' => 9, 'verified' => 10, 'abuse' => 11, 'locale' => 12, 'created_at' => 13, 'updated_at' => 14, ), - self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ) - ); - - /** - * 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('comment'); - $this->setPhpName('Comment'); - $this->setClassName('\\Comment\\Model\\Comment'); - $this->setPackage('Comment.Model'); - $this->setUseIdGenerator(true); - // columns - $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); - $this->addColumn('USERNAME', 'Username', 'VARCHAR', false, 255, null); - $this->addForeignKey('CUSTOMER_ID', 'CustomerId', 'INTEGER', 'customer', 'ID', false, null, null); - $this->addColumn('REF', 'Ref', 'VARCHAR', false, 255, null); - $this->addColumn('REF_ID', 'RefId', 'INTEGER', false, null, null); - $this->addColumn('EMAIL', 'Email', 'VARCHAR', false, 255, null); - $this->addColumn('TITLE', 'Title', 'VARCHAR', false, 255, null); - $this->addColumn('CONTENT', 'Content', 'CLOB', false, null, null); - $this->addColumn('RATING', 'Rating', 'TINYINT', false, null, null); - $this->addColumn('STATUS', 'Status', 'TINYINT', false, null, 0); - $this->addColumn('VERIFIED', 'Verified', 'TINYINT', false, null, null); - $this->addColumn('ABUSE', 'Abuse', 'INTEGER', false, null, null); - $this->addColumn('LOCALE', 'Locale', 'VARCHAR', false, 10, null); - $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); - $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); - } // initialize() - - /** - * Build the RelationMap objects for this table relationships - */ - public function buildRelations() - { - $this->addRelation('Customer', '\\Comment\\Model\\Thelia\\Model\\Customer', RelationMap::MANY_TO_ONE, array('customer_id' => 'id', ), 'CASCADE', 'RESTRICT'); - } // buildRelations() - - /** - * - * Gets the list of behaviors registered for this table - * - * @return array Associative array (name => parameters) of behaviors - */ - public function getBehaviors() - { - return array( - 'timestampable' => array('create_column' => 'created_at', 'update_column' => 'updated_at', ), - ); - } // getBehaviors() - - /** - * 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_STUDLYPHPNAME - * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM - */ - 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 (string) $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_STUDLYPHPNAME - * 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 ? CommentTableMap::CLASS_DEFAULT : CommentTableMap::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_STUDLYPHPNAME - * 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 (Comment object, last column rank) - */ - public static function populateObject($row, $offset = 0, $indexType = TableMap::TYPE_NUM) - { - $key = CommentTableMap::getPrimaryKeyHashFromRow($row, $offset, $indexType); - if (null !== ($obj = CommentTableMap::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 + CommentTableMap::NUM_HYDRATE_COLUMNS; - } else { - $cls = CommentTableMap::OM_CLASS; - $obj = new $cls(); - $col = $obj->hydrate($row, $offset, false, $indexType); - CommentTableMap::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 = CommentTableMap::getPrimaryKeyHashFromRow($row, 0, $dataFetcher->getIndexType()); - if (null !== ($obj = CommentTableMap::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 { - $obj = new $cls(); - $obj->hydrate($row); - $results[] = $obj; - CommentTableMap::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(CommentTableMap::ID); - $criteria->addSelectColumn(CommentTableMap::USERNAME); - $criteria->addSelectColumn(CommentTableMap::CUSTOMER_ID); - $criteria->addSelectColumn(CommentTableMap::REF); - $criteria->addSelectColumn(CommentTableMap::REF_ID); - $criteria->addSelectColumn(CommentTableMap::EMAIL); - $criteria->addSelectColumn(CommentTableMap::TITLE); - $criteria->addSelectColumn(CommentTableMap::CONTENT); - $criteria->addSelectColumn(CommentTableMap::RATING); - $criteria->addSelectColumn(CommentTableMap::STATUS); - $criteria->addSelectColumn(CommentTableMap::VERIFIED); - $criteria->addSelectColumn(CommentTableMap::ABUSE); - $criteria->addSelectColumn(CommentTableMap::LOCALE); - $criteria->addSelectColumn(CommentTableMap::CREATED_AT); - $criteria->addSelectColumn(CommentTableMap::UPDATED_AT); - } else { - $criteria->addSelectColumn($alias . '.ID'); - $criteria->addSelectColumn($alias . '.USERNAME'); - $criteria->addSelectColumn($alias . '.CUSTOMER_ID'); - $criteria->addSelectColumn($alias . '.REF'); - $criteria->addSelectColumn($alias . '.REF_ID'); - $criteria->addSelectColumn($alias . '.EMAIL'); - $criteria->addSelectColumn($alias . '.TITLE'); - $criteria->addSelectColumn($alias . '.CONTENT'); - $criteria->addSelectColumn($alias . '.RATING'); - $criteria->addSelectColumn($alias . '.STATUS'); - $criteria->addSelectColumn($alias . '.VERIFIED'); - $criteria->addSelectColumn($alias . '.ABUSE'); - $criteria->addSelectColumn($alias . '.LOCALE'); - $criteria->addSelectColumn($alias . '.CREATED_AT'); - $criteria->addSelectColumn($alias . '.UPDATED_AT'); - } - } - - /** - * 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(CommentTableMap::DATABASE_NAME)->getTable(CommentTableMap::TABLE_NAME); - } - - /** - * Add a TableMap instance to the database for this tableMap class. - */ - public static function buildTableMap() - { - $dbMap = Propel::getServiceContainer()->getDatabaseMap(CommentTableMap::DATABASE_NAME); - if (!$dbMap->hasTable(CommentTableMap::TABLE_NAME)) { - $dbMap->addTableObject(new CommentTableMap()); - } - } - - /** - * Performs a DELETE on the database, given a Comment or Criteria object OR a primary key value. - * - * @param mixed $values Criteria or Comment 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(CommentTableMap::DATABASE_NAME); - } - - if ($values instanceof Criteria) { - // rename for clarity - $criteria = $values; - } elseif ($values instanceof \Comment\Model\Comment) { // 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(CommentTableMap::DATABASE_NAME); - $criteria->add(CommentTableMap::ID, (array) $values, Criteria::IN); - } - - $query = CommentQuery::create()->mergeWith($criteria); - - if ($values instanceof Criteria) { CommentTableMap::clearInstancePool(); - } elseif (!is_object($values)) { // it's a primary key, or an array of pks - foreach ((array) $values as $singleval) { CommentTableMap::removeInstanceFromPool($singleval); - } - } - - return $query->delete($con); - } - - /** - * Deletes all rows from the comment 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 CommentQuery::create()->doDeleteAll($con); - } - - /** - * Performs an INSERT on the database, given a Comment or Criteria object. - * - * @param mixed $criteria Criteria or Comment 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(CommentTableMap::DATABASE_NAME); - } - - if ($criteria instanceof Criteria) { - $criteria = clone $criteria; // rename for clarity - } else { - $criteria = $criteria->buildCriteria(); // build Criteria from Comment object - } - - if ($criteria->containsKey(CommentTableMap::ID) && $criteria->keyContainsValue(CommentTableMap::ID) ) { - throw new PropelException('Cannot insert a value for auto-increment primary key ('.CommentTableMap::ID.')'); - } - - - // Set the correct dbName - $query = CommentQuery::create()->mergeWith($criteria); - - try { - // use transaction because $criteria could contain info - // for more than one table (I guess, conceivably) - $con->beginTransaction(); - $pk = $query->doInsert($con); - $con->commit(); - } catch (PropelException $e) { - $con->rollBack(); - throw $e; - } - - return $pk; - } - -} // CommentTableMap -// This is the static code needed to register the TableMap for this table with the main Propel class. -// -CommentTableMap::buildTableMap(); diff --git a/templates/backOffice/default/comment-edit.html b/templates/backOffice/default/comment-edit.html index b34333f..b9ea151 100644 --- a/templates/backOffice/default/comment-edit.html +++ b/templates/backOffice/default/comment-edit.html @@ -34,7 +34,7 @@
- {form name="admin.comment.modification.form" blo=1} + {form name="admin_comment_modification_form" blo=1}
{* Be sure to get the comment ID, even if the form could not be validated *} @@ -67,7 +67,7 @@
diff --git a/templates/backOffice/default/configuration.html b/templates/backOffice/default/configuration.html index cde64b7..afec858 100644 --- a/templates/backOffice/default/configuration.html +++ b/templates/backOffice/default/configuration.html @@ -8,7 +8,7 @@
- {form name="comment.configuration.form"} + {form name="comment_configuration_form"} {if $form_error_message}
{$form_error_message}
{/if} diff --git a/templates/backOffice/default/include/comments-list.html b/templates/backOffice/default/include/comments-list.html index 3eca2ef..0ff9738 100644 --- a/templates/backOffice/default/include/comments-list.html +++ b/templates/backOffice/default/include/comments-list.html @@ -1,6 +1,6 @@ {hook name="comments.top" location="comments_top" } -{if $error_message} +{if $error_message|default:null}
@@ -49,7 +49,7 @@ {foreach $comment_status as $status} + {if $status@index == $filter_status|default:null}selected="selected"{/if}>{$status.label} {/foreach}
@@ -74,12 +74,12 @@
{loop type="comment" name="comment.list" - ref=$loop_ref - ref_id=$loop_ref_id - status=$loop_status - order=$loop_order - page=$loop_page - limit=$loop_limit + ref=$loop_ref|default:null + ref_id=$loop_ref_id|default:null + status=$loop_status|default:null + order=$loop_order|default:null + page=$loop_page|default:null + limit=$loop_limit|default:null load_ref="1" backend_context="1"} @@ -254,7 +254,7 @@

{$TITLE}

form_action = {token_url path='/admin/module/comment/delete'} form_content = {$smarty.capture.delete_dialog nofilter} -form_error_message = $error_delete_message +form_error_message = $error_delete_message|default:null }
diff --git a/templates/frontOffice/default/ajax-comments.html b/templates/frontOffice/default/ajax-comments.html index 38edc18..7e287d9 100644 --- a/templates/frontOffice/default/ajax-comments.html +++ b/templates/frontOffice/default/ajax-comments.html @@ -56,7 +56,7 @@

{$TITLE}

  • {intl d="comment.fo.default" l="Delete"}
  • {else}
  • - {form name="comment.abuse.form"} + {form name="comment_abuse_form"} {form_hidden_fields form=$form} {form_field form=$form field="id"} diff --git a/templates/frontOffice/default/comment.html b/templates/frontOffice/default/comment.html index 8fa2c16..14a66d5 100644 --- a/templates/frontOffice/default/comment.html +++ b/templates/frontOffice/default/comment.html @@ -22,7 +22,7 @@ {if $definition->isValid()} - {form name="comment.add.form"} + {form name="comment_add_form"} {form_hidden_fields form=$form} From 921f53b7f6757844df1d729e18b847af69ce930a Mon Sep 17 00:00:00 2001 From: Nicolas Barbey <223106@supinfo.com> Date: Mon, 6 Sep 2021 17:12:40 +0200 Subject: [PATCH 2/2] fix postActivation --- Comment.php | 7 +++---- templates/backOffice/default/tab-content.html | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Comment.php b/Comment.php index aecaf9a..8dcb9d3 100755 --- a/Comment.php +++ b/Comment.php @@ -90,11 +90,10 @@ public function postActivation(ConnectionInterface $con = null): void } // Schema - try { - CommentQuery::create()->findOne(); - } catch (\Exception $ex) { - $database = new Database($con->getWrappedConnection()); + if (!self::getConfigValue('is_initialized', false)) { + $database = new Database($con); $database->insertSql(null, [__DIR__ . DS . 'Config' . DS . 'thelia.sql']); + self::setConfigValue('is_initialized', true); } // Messages diff --git a/templates/backOffice/default/tab-content.html b/templates/backOffice/default/tab-content.html index 8b1c069..4d47320 100644 --- a/templates/backOffice/default/tab-content.html +++ b/templates/backOffice/default/tab-content.html @@ -12,7 +12,7 @@
    -
    +