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))))));
 }
 /**
  * The callback function for module links
  */
 private function module_callback($matches)
 {
     $whole = $matches[0];
     $name = $matches[2];
     $module = Madule::getByName($name);
     if ($module) {
         $ret = "<a href=\"/module/show/{$module->getId()}\">Module: {$name}</a>";
     } else {
         $ret = $name;
     }
     return $ret;
 }
예제 #3
0
 public function executeUpdate($request)
 {
     $this->prepareUpdate();
     if ($this->getRequest()->getMethod() == sfRequest::POST) {
         $this->form->bind($request->getParameter('madule'), $request->getFiles('madule'));
         if ($this->form->isValid()) {
             $module = Madule::update($this->form->getValues(), $this->getUser()->getUser());
             $this->redirect('/module/read?id=' . $module->getId());
         }
     }
 }
예제 #4
0
 public static function update($values, $user)
 {
     $id = $values['id'];
     if ($id) {
         $q = new Doctrine_Query();
         $q = $q->select('m.*')->from('Madule m');
         $q = $q->addWhere('id = ?', array($id));
         if (!$user->getRole() == User::ADMIN) {
             $q = $q->addWhere('user_id = ?', array($user->getId()));
         }
         $module = $q->fetchOne();
     } else {
         $module = new Madule();
     }
     if ($module) {
         $module->setName($values['name']);
         $module->setDescription($values['description']);
         $module->setSourceUrl($values['source_url']);
         if (!$module->getUserId()) {
             $module->setUserId($user->getId());
         }
         $module->setApplicationId($values['application_id']);
         $module->setApproved(false);
         $module->save();
         $folderpath = $module->getFolderPath();
         if (!is_dir($folderpath)) {
             mkdir($folderpath);
         }
         $screenshot = $values['screenshot'];
         if ($screenshot) {
             $screenshotpath = $folderpath . $module->getId() . $screenshot->getOriginalName();
             $screenshot->save($screenshotpath);
             $smallThumb = new Thumbnail($screenshotpath);
             if ($smallThumb->getCurrentWidth() > 150 || $smallThumb->getCurrentHeight() > 150) {
                 $smallThumb->resize(150, 150);
             }
             $smallThumb->show(100, $folderpath . 'smallthumb.png');
             $bigThumb = new Thumbnail($screenshotpath);
             if ($bigThumb->getCurrentWidth() > 500 || $bigThumb->getCurrentHeight() > 500) {
                 $bigThumb->resize(500, 500);
             }
             $bigThumb->show(100, $folderpath . 'bigthumb.png');
             $screenshot = new Thumbnail($screenshotpath);
             $screenshot->show(100, $folderpath . 'screenshot.png');
             unlink($screenshotpath);
         }
         return $module;
     }
     return null;
 }
예제 #5
0
 public function executeUpdate($request)
 {
     $object = $this->getRequestParameter('object');
     $user = User::getByApiKey($request->getParameter('login_id'), $request->getParameter('api_key'));
     if (!$user) {
         $output = '<rsp stat="fail"><err code="2" msg="login_id and api_key do not match" /></rsp>';
     } elseif ($object == 'application') {
         $form = new ApplicationForm();
         $form->bind(array('id' => $request->getParameter('id'), 'name' => $request->getParameter('name'), 'description' => $request->getParameter('description'), 'source_url' => $request->getParameter('source_url')));
         if ($form->isValid()) {
             $application = Application::update($form->getValues(), $user);
             if ($application) {
                 $output = '<rsp stat="ok">' . $application->getXML() . '</rsp>';
             } else {
                 $output = '<rsp stat="fail"><err code="4" msg="Unable to update application." /></rsp>';
             }
         } else {
             $output = '<rsp stat="fail"><err code="4" msg="' . $form->getErrorSchema() . '" /></rsp>';
         }
     } elseif ($object == 'comment') {
         $form = new CommentForm();
         $application_id = $module_id = $theme_id = null;
         if ($request->getParameter('application_id')) {
             $application_id = $request->getParameter('application_id');
         }
         if ($request->getParameter('module_id')) {
             $module_id = $request->getParameter('module_id');
         }
         if ($request->getParameter('theme_id')) {
             $theme_id = $request->getParameter('theme_id');
         }
         $form->bind(array('comment' => $request->getParameter('comment'), 'application_id' => $application_id, 'module_id' => $module_id, 'theme_id' => $theme_id));
         if ($form->isValid()) {
             $comment = Comment::update($form->getValues(), $user);
             $output = '<rsp stat="ok">' . $comment->getXML() . '</rsp>';
         } else {
             $output = '<rsp stat="fail"><err code="3" msg="' . $form->getErrorSchema() . '" /></rsp>';
         }
     } elseif ($object == 'module') {
         $form = new ModuleForm();
         $form->bind(array('id' => $request->getParameter('id'), 'name' => $request->getParameter('name'), 'description' => $request->getParameter('description'), 'source_url' => $request->getParameter('source_url'), 'application_id' => $request->getParameter('application_id')));
         if ($form->isValid()) {
             $module = Madule::update($form->getValues(), $user);
             if ($module) {
                 $output = '<rsp stat="ok">' . $module->getXML() . '</rsp>';
             } else {
                 $output = '<rsp stat="fail"><err code="4" msg="Unable to update module." /></rsp>';
             }
         } else {
             $output = '<rsp stat="fail"><err code="4" msg="' . $form->getErrorSchema() . '" /></rsp>';
         }
     } elseif ($object == 'theme') {
         $form = new ThemeForm();
         $form->bind(array('id' => $request->getParameter('id'), 'name' => $request->getParameter('name'), 'description' => $request->getParameter('description')), $request->getFiles());
         if ($form->isValid()) {
             $theme = Theme::update($form->getValues(), $user);
             if ($theme) {
                 $output = '<rsp stat="ok">' . $theme->getXML() . '</rsp>';
             } else {
                 $output = '<rsp stat="fail"><err code="5" msg="Unable to update theme." /></rsp>';
             }
         } else {
             $output = '<rsp stat="fail"><err code="5" msg="' . $form->getErrorSchema() . '" /></rsp>';
         }
     } elseif ($object == 'theme_group') {
         $output = '<rsp stat="fail"><err code="6" msg="This object is not supported for update" /></rsp>';
     } elseif ($object == 'user') {
         $form = new UserForm();
         $form->bind(array('id' => $request->getParameter('id'), 'name' => $request->getParameter('name'), 'password' => $request->getParameter('password'), 'password2' => $request->getParameter('password'), 'email' => $request->getParameter('email'), 'role' => null));
         if ($form->isValid()) {
             $update_user = User::update($form->getValues(), $user);
             if ($update_user) {
                 $output = '<rsp stat="ok">' . $update_user->getXML() . '</rsp>';
             } else {
                 $output = '<rsp stat="fail"><err code="7" msg="Unable to update user." /></rsp>';
             }
         } else {
             $output = '<rsp stat="fail"><err code="7" msg="' . $form->getErrorSchema() . '" /></rsp>';
         }
     }
     $this->output = $output;
     $this->setTemplate('index');
 }