From: Gustavo Martin Morcuende Date: Tue, 22 May 2012 20:06:29 +0000 (+0200) Subject: Web page for users: link to general categories. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=abc7ef74b57f5e29bb84672f6a694bf548126cd3;p=mobi%2F.git Web page for users: link to general categories. --- diff --git a/apps/userfront/modules/category/actions/actions.class.php b/apps/userfront/modules/category/actions/actions.class.php index aedc677..3a2fecc 100644 --- a/apps/userfront/modules/category/actions/actions.class.php +++ b/apps/userfront/modules/category/actions/actions.class.php @@ -77,4 +77,64 @@ class categoryActions extends sfActions $this->redirect('category/edit?id='.$general_category->getId()); } } + + public function executeChoose($request) + { + //Get user Id + $userId = $this->getUser()->getGuardUser()->getId(); + + //Get data from user + $checked = $request->getParameter('checked'); + + //We retrieve a Doctrine_Collection + $userBaskets = UserBasketTable::getInstance()->findByUserId($userId); + + + //Using Doctrine_Collection_Iterator + $iterator = $userBaskets->getIterator(); + while ($userBasket = $iterator->current()) + { + if (!empty($checked)) + { + foreach ($checked as $index => $value) + { + if ($userBasket->getGeneralCategId() == $value) + { + unset($checked[$index]); + $iterator->next(); + continue 2; + } + } + } + $userBaskets->remove($iterator->key()); + $iterator->next(); + } + + if (!empty($checked)) + { + foreach ($checked as $index => $value) + { + //Never trust in data coming from users... Performance vs security. + $generalCategory = GeneralCategoryTable::getInstance()->findOneById($value); + if ($generalCategory != null) + { + $userBasket = new UserBasket(); + $userBasket->general_categ_id = $generalCategory->getId(); + $userBasket->user_id = $userId; + $userBaskets->add($userBasket); + } + } + } + + //The Doctrine_Collection should just insert/remove in the database in this point (never before) + //This feature is really nice (if it works as intended) I have no time for checking out its behaviour... + $userBaskets->save(); + + //set content type HTTP field with the right value (we are going to use a JSON response) + $this->getResponse()->setContentType('application/json'); + + //Bypass completely the view layer and set the response code directly from this action. + //In this way the user may know if the data were updated + return $this->renderText(json_encode($checked)); + } } diff --git a/apps/userfront/modules/category/templates/indexSuccess.php b/apps/userfront/modules/category/templates/indexSuccess.php index 7475768..228997b 100644 --- a/apps/userfront/modules/category/templates/indexSuccess.php +++ b/apps/userfront/modules/category/templates/indexSuccess.php @@ -7,13 +7,15 @@ }); @@ -23,8 +25,7 @@ - - + @@ -38,7 +39,7 @@ } ?>> - getUserBaskets() as $userBasket): ?> getUserId() == $userId): ?> checked @@ -51,4 +52,4 @@ - + diff --git a/lib/model/doctrine/GeneralCategoryTable.class.php b/lib/model/doctrine/GeneralCategoryTable.class.php index 864b0ae..70019dd 100644 --- a/lib/model/doctrine/GeneralCategoryTable.class.php +++ b/lib/model/doctrine/GeneralCategoryTable.class.php @@ -25,6 +25,7 @@ class GeneralCategoryTable extends Doctrine_Table */ public function getGeneralCategoriesByLftQuery() { - return $this->createQuery('gc')->orderBy('gc.lft'); + return $this->createQuery('gc')->where('gc.id != 1') + ->orderBy('gc.lft'); } } diff --git a/web/css/inadminpanel/niceforms-default.css b/web/css/inadminpanel/niceforms-default.css index 7d8f64c..3be17d9 100644 --- a/web/css/inadminpanel/niceforms-default.css +++ b/web/css/inadminpanel/niceforms-default.css @@ -37,6 +37,7 @@ line-height:32px; .NFCheck {cursor:pointer; position:absolute;width:20px; margin:0px 0 0 0; height:20px; border:1px solid transparent; background:url(img/checkbox.gif) no-repeat 0 0; z-index:2;} /*Buttons*/ .NFButton {width:auto; height:34px; padding:0 15px; font-weight:bold; background:url(/images/inadminpanel/img/button.gif) repeat-x 0 0; cursor:pointer; border:none;color:#FFFFFF; text-shadow:1px 1px #45add8;vertical-align:middle;} +.NFButtonToRight {width:auto; height:34px; padding:0 15px; font-weight:bold; background:url(/images/inadminpanel/img/button.gif) repeat-x 0 0; cursor:pointer; border:none;color:#FFFFFF; text-shadow:1px 1px #45add8;vertical-align:middle; float:right} .NFButtonLeft, .NFButtonRight {width:10px; height:34px; vertical-align:middle;} .NFButtonLeft {background:url(/images/inadminpanel/img/button-left.gif) no-repeat 0 0;} .NFButtonRight {background:url(/images/inadminpanel/img/button-right.gif) no-repeat 0 0;}