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;
 }
 public function configure()
 {
     $module_options = Madule::getAsOptions();
     $themeGroup_options = ThemeGroup::getAsOptions(null, $this->defaults['module_id']);
     $this->setWidgets(array('module_id' => new sfWidgetFormSelect(array('choices' => $module_options)), 'theme_group_id' => new sfWidgetFormSelect(array('choices' => $themeGroup_options))));
     $this->widgetSchema->setLabels(array('module_id' => 'Module', 'theme_group_id' => 'Theme Group'));
     $this->widgetSchema->setNameFormat('moduleThemeGroup[%s]');
     $formatter = new exchangeWidgetFormSchemaFormatter($this->getWidgetSchema());
     $this->getWidgetSchema()->addFormFormatter('exchange', $formatter);
     $this->getWidgetSchema()->setFormFormatterName('exchange');
     $this->setValidatorSchema(new sfValidatorSchema(array('module_id' => new sfValidatorChoice(array('choices' => array_keys($module_options))), 'theme_group_id' => new sfValidatorChoice(array('choices' => array_keys($themeGroup_options))))));
 }
Exemplo n.º 3
0
 public function addThemeGroup($name)
 {
     try {
         $name = trim($name);
         $q = new Doctrine_Query();
         $themeThemeGroup = $q->select('tg.*')->from('ThemeThemeGroup tg, tg.ThemeGroup t')->addWhere('tg.theme_id = ? and t.name = ?', array($this->getId(), $name))->fetchOne();
         if (!$themeThemeGroup) {
             $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();
             }
             $themeThemeGroup = new ThemeThemeGroup();
             $themeThemeGroup->setThemeGroupId($themeGroup->getId());
             $themeThemeGroup->setThemeId($this->getId());
             $themeThemeGroup->save();
         }
         return $themeThemeGroup;
     } catch (Exception $e) {
     }
     return null;
 }
Exemplo n.º 4
0
 public function addThemeGroup($name)
 {
     $name = trim($name);
     $q = new Doctrine_Query();
     $maduleThemeGroup = $q->select('mt.*')->from('MaduleThemeGroup mt, mt.ThemeGroup t')->addWhere('mt.madule_id = ? and t.name = ?', array($this->getId(), $name))->fetchOne();
     if (!$maduleThemeGroup) {
         $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();
         }
         $maduleThemeGroup = new MaduleThemeGroup();
         $maduleThemeGroup->setThemeGroupId($themeGroup->getId());
         $maduleThemeGroup->setMaduleId($this->getId());
         $maduleThemeGroup->save();
     }
     return $maduleThemeGroup;
 }
 /**
  * Retrieves the singleton instance of the feature
  * @return ThemeGroup unique instance
  */
 public static function get_instance()
 {
     if (self::$instance != null) {
         return self::$instance;
     }
     $c = get_called_class();
     self::$instance = new $c();
     return self::$instance;
 }
Exemplo n.º 6
0
 public function executeList()
 {
     $rss = $this->getRequestParameter('rss');
     $object = $this->getRequestParameter('object');
     $output = '';
     $title = Tools::get('name');
     $link = Tools::get('url');
     $description = Tools::get('rss_desc');
     $offset = $this->getRequestParameter('offset');
     $limit = $this->getRequestParameter('limit');
     if ($object == 'application') {
         $title .= ' - Applications';
         $user_id = $this->getRequestParameter('user_id');
         if ($this->getRequestParameter('user_name')) {
             $user_id = User::getByName($this->getRequestParameter('user_name'))->getId();
         }
         $q = new Doctrine_Query();
         $q = $q->select('a.*')->from('Application a');
         if ($user_id) {
             $q = $q->addWhere('user_id = ?', array($user_id));
         }
         $q = $q->addWhere('approved = ?', array(true));
         $q = $q->orderby('updated_at desc');
         if ($limit) {
             $q->limit($limit);
         }
         if ($offset) {
             $q->offset($offset);
         }
         $applications = $q->execute();
         if (!$rss) {
             $output .= '<applications count="' . $applications->count() . '">';
         }
         foreach ($applications as $application) {
             $output .= $application->getXML($rss);
         }
         if (!$rss) {
             $output .= '</applications>';
         }
     } elseif ($object == 'comment') {
         $title .= ' - Comments';
         $user_id = $this->getRequestParameter('user_id');
         if ($this->getRequestParameter('user_name')) {
             $user_id = User::getByName($this->getRequestParameter('user_name'))->getId();
         }
         $application_id = $this->getRequestParameter('application_id');
         $module_id = $this->getRequestParameter('module_id');
         $theme_id = $this->getRequestParameter('theme_id');
         $q = new Doctrine_Query();
         $q = $q->select('c.*')->from('Comment c');
         if ($user_id) {
             $q = $q->addWhere('user_id = ?', array($user_id));
         }
         if ($application_id) {
             $q = $q->addWhere('application_id = ?', array($application_id));
         }
         if ($module_id) {
             $q = $q->addWhere('madule_id = ?', array($module_id));
         }
         if ($theme_id) {
             $q = $q->addWhere('theme_id = ?', array($theme_id));
         }
         $q = $q->orderby('updated_at desc');
         if ($limit) {
             $q->limit($limit);
         }
         if ($offset) {
             $q->offset($offset);
         }
         $comments = $q->execute();
         if (!$rss) {
             $output .= '<comments count="' . $comments->count() . '">';
         }
         foreach ($comments as $comment) {
             $output .= $comment->getXML($rss);
         }
         if (!$rss) {
             $output .= '</comments>';
         }
     } elseif ($object == 'module') {
         $title .= ' - Modules';
         $application_id = $this->getRequestParameter('application_id');
         $user_id = $this->getRequestParameter('user_id');
         if ($this->getRequestParameter('user_name')) {
             $user_id = User::getByName($this->getRequestParameter('user_name'))->getId();
         }
         $q = new Doctrine_Query();
         $q = $q->select('m.*')->from('Madule m');
         if ($application_id) {
             $q = $q->addWhere('application_id = ?', array($application_id));
         }
         if ($user_id) {
             $q = $q->addWhere('user_id = ?', array($user_id));
         }
         $q = $q->addWhere('approved = ?', array(true));
         $q = $q->orderby('updated_at desc');
         if ($limit) {
             $q->limit($limit);
         }
         if ($offset) {
             $q->offset($offset);
         }
         $modules = $q->execute();
         if (!$rss) {
             $output .= '<modules count="' . $modules->count() . '">';
         }
         foreach ($modules as $module) {
             $output .= $module->getXML($rss);
         }
         if (!$rss) {
             $output .= '</modules>';
         }
     } elseif ($object == 'theme') {
         $title .= ' - Themes';
         $user_id = $this->getRequestParameter('user_id');
         if ($this->getRequestParameter('user_name')) {
             $user_id = User::getByName($this->getRequestParameter('user_name'))->getId();
         }
         $theme_group_id = $this->getRequestParameter('theme_group_id');
         if ($this->getRequestParameter('theme_group_title')) {
             $theme_group_id = ThemeGroup::getByTitle($this->getRequestParameter('theme_group_title'))->getId();
         }
         if ($this->getRequestParameter('theme_group_name')) {
             $theme_group_id = ThemeGroup::getByName($this->getRequestParameter('theme_group_name'))->getId();
         }
         $application_id = $this->getRequestParameter('application_id');
         $module_id = $this->getRequestParameter('module_id');
         $q = new Doctrine_Query();
         $q = $q->select('t.*')->from('Theme t');
         if ($application_id) {
             $q = $q->addWhere('t.id IN (SELECT ttg.theme_id from ThemeThemeGroup ttg where ttg.theme_group_id IN ' . '(SELECT ag.theme_group_id FROM ApplicationThemeGroup ag where ag.application_id = ?))', array($application_id));
         } elseif ($module_id) {
             $q = $q->addWhere('t.id IN (SELECT ttg.theme_id from ThemeThemeGroup ttg where ttg.theme_group_id IN ' . '(SELECT mg.theme_group_id FROM MaduleThemeGroup mg where mg.madule_id = ?))', array($module_id));
         } elseif ($theme_group_id) {
             $q = $q->innerJoin('t.ThemeThemeGroups ttg')->addWhere('ttg.theme_group_id = ?', array($theme_group_id));
         }
         if ($user_id) {
             $q = $q->addWhere('user_id = ?', array($user_id));
         }
         $q = $q->addWhere('approved = ?', array(true));
         $q = $q->orderby('updated_at desc');
         if ($limit) {
             $q->limit($limit);
         }
         if ($offset) {
             $q->offset($offset);
         }
         $themes = $q->execute();
         if (!$rss) {
             $output .= '<themes count="' . $themes->count() . '">';
         }
         foreach ($themes as $theme) {
             $output .= $theme->getXML($rss);
         }
         if (!$rss) {
             $output .= '</themes>';
         }
     } elseif ($object == 'theme_group') {
         $title .= ' - Theme Groups';
         $theme_id = $this->getRequestParameter('theme_id');
         $q = new Doctrine_Query();
         $q = $q->select('t.*')->from('ThemeGroup t');
         if ($theme_id) {
             $q = $q->innerJoin('t.ThemeThemeGroups ttg')->addWhere('ttg.theme_id = ? and t.known = ?', array($theme_id, true));
         }
         $q = $q->orderby('updated_at desc');
         if ($limit) {
             $q->limit($limit);
         }
         if ($offset) {
             $q->offset($offset);
         }
         $themeGroups = $q->execute();
         if (!$rss) {
             $output .= '<theme_groups count="' . $themeGroups->count() . '">';
         }
         foreach ($themeGroups as $themeGroup) {
             $output .= $themeGroup->getXML($rss);
         }
         if (!$rss) {
             $output .= '</theme_groups>';
         }
     } elseif ($object == 'user') {
         $title .= ' - Users';
         $q = new Doctrine_Query();
         $q = $q->select('u.*')->from('User u')->orderby('updated_at desc');
         if ($limit) {
             $q->limit($limit);
         }
         if ($offset) {
             $q->offset($offset);
         }
         $users = $q->execute();
         if (!$rss) {
             $output .= '<users count="' . $users->count() . '">';
         }
         foreach ($users as $user) {
             $output .= $user->getXML($rss);
         }
         if (!$rss) {
             $output .= '</users>';
         }
     }
     if ($rss) {
         $this->output = '<rss version="2.0">' . '<channel>' . '<title>' . $title . '</title>' . '<link>' . $link . '</link>' . '<description>' . $description . '</description>' . '<generator>' . $title . '</generator>' . $output . '</channel>' . '</rss>';
     } else {
         $this->output = '<rsp stat="ok">' . $output . '</rsp>';
     }
     $this->setTemplate('index');
 }