public static function update($values, $user)
 {
     $applicationThemeGroup = new ApplicationThemeGroup();
     $applicationThemeGroup->setApplicationId($values['application_id']);
     $applicationThemeGroup->setThemeGroupId($values['theme_group_id']);
     $applicationThemeGroup->save();
     return $applicationThemeGroup;
 }
 public function executeUpdate($request)
 {
     $this->prepareUpdate();
     if ($this->getRequest()->getMethod() == sfRequest::POST) {
         $this->form->bind($request->getParameter('applicationThemeGroup'));
         if ($this->form->isValid()) {
             $values = $this->form->getValues();
             $applicationThemeGroup = ApplicationThemeGroup::update($this->form->getValues(), $this->getUser()->getUser());
             if ($applicationThemeGroup) {
                 $this->redirect('/application/read?id=' . $applicationThemeGroup->getApplicationId());
             }
         }
         return $this->redirect($this->getRequest()->getReferer());
     }
 }
 public function addThemeGroup($name)
 {
     $name = trim($name);
     $q = new Doctrine_Query();
     $applicationThemeGroup = $q->select('mt.*')->from('ApplicationThemeGroup at, mt.ThemeGroup t')->addWhere('at.application_id = ? and t.name = ?', array($this->getId(), $name))->fetchOne();
     if (!$applicationThemeGroup) {
         $q = new Doctrine_Query();
         $themeGroup = $q->select('t.*')->from('ThemeGroup t')->addWhere('t.name = ?', array($name))->fetchOne();
         if (!$themeGroup) {
             $themeGroup = new ThemeGroup();
             $themeGroup->setName($name);
             $themeGroup->save();
         }
         $applicationThemeGroup = new ApplicationThemeGroup();
         $applicationThemeGroup->setThemeGroupId($themeGroup->getId());
         $applicationThemeGroup->setApplicationId($this->getId());
         $applicationThemeGroup->save();
     }
     return $applicationThemeGroup;
 }