public function render($name, $value = null, $attributes = array(), $errors = array()) { if ($value && is_string($value)) { $value = PetitionText::getHashForId($value); } return parent::render($name, $value, $attributes, $errors); }
public function getChoices() { $petition_texts = Doctrine_Core::getTable('PetitionText')->createQuery('pt')->leftJoin('pt.Language l')->where('pt.petition_id = ?', $this->getOption('petition_id'))->andWhere('pt.status = ? or pt.id = ?', array(PetitionText::STATUS_ACTIVE, $this->getOption('petition_text_id')))->select('pt.id, l.id, l.name')->orderBy('l.order_number')->fetchArray(); $language_choices = array(); foreach ($petition_texts as $petition_text) { $language_choices[PetitionText::getHashForId($petition_text['id'])] = $petition_text['Language']['name']; } return $language_choices; }
protected function doClean($value) { $value = PetitionText::getIdByHash($value); if ($value !== false) { if ($this->getOption('petition_text_id') == $value) { return $value; } if (Doctrine_Core::getTable('PetitionText')->createQuery('pt')->where('pt.petition_id = ?', $this->getOption('petition_id'))->andWhere('pt.status = ?', PetitionText::STATUS_ACTIVE)->andWhere('pt.id = ?', $value)->limit(1)->count()) { return $value; } } throw new sfValidatorError($this, 'invalid'); }
public function executeText(sfWebRequest $request) { $hash = $request->getParameter('hash'); $id = PetitionText::getIdByHash($hash); if ($id === false) { $this->forward404(); } $petition_text = Doctrine_Core::getTable('PetitionText')->createQuery('pt')->where('pt.id = ?', $id)->andWhere('pt.status = ?', PetitionText::STATUS_ACTIVE)->fetchOne(); $result = array(); foreach (array('title', 'target', 'background', 'intro', 'body', 'footer', 'email_subject', 'email_body') as $field) { $result[$field] = $petition_text[$field]; } $this->getResponse()->setContentType('text/javascript'); $this->setLayout(false); $this->setContentTags($petition_text); return $this->renderText(json_encode($result)); }
public function executeTranslationEdit(sfWebRequest $request) { $route_params = $this->getRoute()->getParameters(); $copy = null; if (isset($route_params['new'])) { $petition = PetitionTable::getInstance()->findById($request->getParameter('id'), $this->userIsAdmin()); /* @var $petition Petition */ if (!$petition) { return $this->notFound(); } $translation = new PetitionText(); $translation->setPetition($petition); $copy_id = $request->getGetParameter('copy'); if (is_numeric($copy_id)) { $copy = PetitionTextTable::getInstance()->find($copy_id); /* @var $copy PetitionText */ if ($copy && $copy->getPetitionId() != $petition->getId()) { $copy = null; } } } else { $translation = PetitionTextTable::getInstance()->find($request->getParameter('id')); /* @var $translation PetitionText */ if (!$translation) { return $this->notFound(); } $petition = $translation->getPetition(); if ($petition->getStatus() == Petition::STATUS_DELETED && !$this->userIsAdmin()) { return $this->notFound(); } if (!$this->userIsAdmin() && $petition->getCampaign()->getStatus() == CampaignTable::STATUS_DELETED) { return $this->notFound(); } } if (!$petition->isEditableBy($this->getGuardUser())) { return $this->noAccess(); } $this->form = new TranslationForm($translation, array('copy' => $copy)); if ($request->isMethod('post')) { $this->form->bind($request->getPostParameter($this->form->getName())); if ($this->form->isValid()) { $this->form->save(); if ($request->getPostParameter('go_translation')) { if ($translation->getStatus() == PetitionText::STATUS_ACTIVE) { return $this->ajax()->redirectPostRoute('widget_create', array('id' => $petition->getId()), array('page' => 1, 'lang' => $translation->getId()))->render(); } else { return $this->ajax()->redirectRotue('petition_translations', array('id' => $petition->getId()), array('a' => 1))->render(); } } return $this->ajax()->redirectRotue('petition_translations', array('id' => $petition->getId()))->render(); } return $this->ajax()->form($this->form)->render(); } $this->translation = $translation; $this->petition = $petition; $this->includeMarkdown(); $this->includeHighlight(); }
public function configure() { $this->widgetSchema->setFormFormatterName('bootstrap'); $this->widgetSchema->setNameFormat('translation[%s]'); $petition_text = $this->getObject(); $petition = $petition_text->getPetition(); unset($this['created_at'], $this['updated_at'], $this['petition_id'], $this['object_version'], $this['email_targets'], $this['widget_id']); $this->setWidget('title', new sfWidgetFormInput(array(), array('size' => 90, 'class' => 'large'))); $this->setWidget('target', new sfWidgetFormTextarea(array(), array('cols' => 90, 'rows' => 3, 'class' => 'markdown'))); $this->getWidgetSchema()->setHelp('target', 'Keep this short, this area is not scrollable.'); $this->getValidator('target')->setOption('required', false)->setOption('trim', true); $this->setWidget('background', new sfWidgetFormTextarea(array(), array('cols' => 90, 'rows' => 5, 'class' => 'markdown'))); $this->setWidget('landing_url', new sfWidgetFormInput(array('label' => 'Email Validation Landingpage - auto forwarding to external page'), array('size' => 90, 'class' => 'add_popover large', 'data-content' => 'Enter URL of external landing page, including \'http://\'. Leave empty for standard landing page'))); $this->setValidator('landing_url', new ValidatorUrl(array('required' => false, 'trim' => true))); if (!$petition->isEmailKind()) { $this->setWidget('intro', new sfWidgetFormTextarea(array(), array('cols' => 90, 'rows' => 5, 'class' => 'markdown'))); $this->setWidget('body', new sfWidgetFormTextarea(array(), array('cols' => 90, 'rows' => 30, 'class' => 'markdown'))); $this->setWidget('footer', new sfWidgetFormTextarea(array(), array('cols' => 90, 'rows' => 5, 'class' => 'markdown'))); $this->getValidator('intro')->setOption('required', false); $this->getValidator('body')->setOption('required', true); $this->getValidator('footer')->setOption('required', false); unset($this['email_subject'], $this['email_body']); } else { $this->setWidget('email_subject', new sfWidgetFormInput(array(), array('size' => 90, 'class' => 'large'))); $this->setWidget('email_body', new sfWidgetFormTextarea(array(), array('cols' => 90, 'rows' => 30, 'class' => 'large elastic highlight'))); $this->getValidator('email_subject')->setOption('required', true); $this->getValidator('email_body')->setOption('required', true); unset($this['intro'], $this['body'], $this['footer']); if ($petition->isGeoKind()) { $subst_fields = $petition->getGeoSubstFields(); $keywords = array(); foreach ($subst_fields as $keyword => $subst_field) { if ($subst_field['id'] != MailingList::FIX_GENDER) { $keywords[] = '<b>' . $keyword . '</b> (' . $subst_field['name'] . ')'; } } if ($this->getObject()->getPetition()->getKind() == Petition::KIND_PLEDGE) { $keywords[] = '<b>#PLEDGE-URL#</b> (Link for the candidate)'; $this->setValidator('email_body', new sfValidatorRegex(array('required' => true, 'pattern' => '/#PLEDGE-URL#/'), array('invalid' => 'Missing the following keywords: #PLEDGE-URL#'))); } foreach (PetitionSigningTable::$KEYWORDS as $keyword) { $keywords[] = $keyword; } $keywords[] = PetitionTable::KEYWORD_PERSONAL_SALUTATION; } else { $keywords = PetitionSigningTable::$KEYWORDS; } $this->getWidgetSchema()->setHelp('email_body', 'You can use the following keywords: ' . implode(', ', $keywords) . '.'); } $this->setWidget('email_validation_subject', new sfWidgetFormInput(array(), array('size' => 90, 'class' => 'large'))); $this->setWidget('email_validation_body', new sfWidgetFormTextarea(array(), array('cols' => 90, 'rows' => 8, 'class' => 'large elastic highlight'))); $this->setValidator('email_validation_body', new ValidatorKeywords(array('required' => true, 'keywords' => array('#VALIDATION-URL#')))); $this->getWidgetSchema()->setHelp('email_validation_body', '#VALIDATION-URL#, #REFERER-URL#, #READMORE-URL#, #TITLE#, #TARGET#, #BACKGROUND#, #INTRO#,' . ' #FOOTER#, #EMAIL-SUBJECT#, #EMAIL-BODY#, #BODY# ' . implode(', ', PetitionSigningTable::$KEYWORDS)); $this->setWidget('email_tellyour_subject', new sfWidgetFormInput(array(), array('size' => 90, 'class' => 'large'))); $this->setWidget('email_tellyour_body', new sfWidgetFormTextarea(array(), array('cols' => 90, 'rows' => 8, 'class' => 'large elastic highlight'))); $this->getWidgetSchema()->setHelp('email_tellyour_body', '#REFERER-URL#, #READMORE-URL#, #TITLE#, #TARGET#, #BACKGROUND#, #INTRO#, #FOOTER#, #EMAIL-SUBJECT#, #EMAIL-BODY#, #BODY#'); $this->setValidator('email_tellyour_body', new sfValidatorString(array('max_length' => 1800))); $this->getWidgetSchema()->setLabel('email_tellyour_subject', 'E-mail "tell your friends" subject'); $this->getWidgetSchema()->setLabel('email_tellyour_body', 'E-mail "tell your friends" body (the final e-mail will be cut after approx. 2000 characters)'); $possible_statuses = array_keys(PetitionText::$STATUS_SHOW); $this->state_count = count($possible_statuses); $possible_statuses_show = PetitionText::calcStatusShow($possible_statuses); $this->setWidget('status', new sfWidgetFormChoice(array('choices' => $possible_statuses_show))); $this->setValidator('status', new sfValidatorChoice(array('choices' => $possible_statuses, 'required' => true))); if ($petition_text->getLanguageId() === null) { $this->setWidget('language_id', new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Language'), 'add_empty' => false, 'query' => Doctrine_Core::getTable('Language')->createQuery('l')->where('l.id NOT IN (SELECT pt.language_id FROM PetitionText pt WHERE pt.petition_id = ?)', $petition_text->getPetitionId())), array('class' => 'ajax_change', 'data-action' => sfContext::getInstance()->getRouting()->generate('translation_default', array('id' => $petition->getCampaign()->getId()))))); $this->setValidator('language_id', new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Language'), 'query' => Doctrine_Core::getTable('Language')->createQuery('l')->where('l.id NOT IN (SELECT pt.language_id FROM PetitionText pt WHERE pt.petition_id = ?)', $petition_text->getPetitionId())))); } else { unset($this['language_id']); } $this->setWidget('privacy_policy_body', new sfWidgetFormTextarea(array(), array('cols' => 90, 'rows' => 30, 'class' => 'markdown highlight'))); $this->getWidgetSchema()->setHelp('privacy_policy_body', '#DATA-OFFICER-NAME#, #DATA-OFFICER-ORGA#, #DATA-OFFICER-EMAIL#, #DATA-OFFICER-WEBSITE#, #DATA-OFFICER-PHONE#, #DATA-OFFICER-MOBILE#, #DATA-OFFICER-STREET#, #DATA-OFFICER-POST-CODE#, #DATA-OFFICER-CITY#, #DATA-OFFICER-COUNTRY#, #DATA-OFFICER-ADDRESS#'); if (!$petition_text->isNew()) { $this->setWidget('updated_at', new sfWidgetFormInputHidden()); $this->setValidator('updated_at', new ValidatorUnchanged(array('fix' => $petition_text->getUpdatedAt()))); $this->setWidget('widget_id', new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('DefaultWidget'), 'add_empty' => true, 'label' => 'Widget for Homepage', 'method' => 'getIdentString', 'query' => Doctrine_Core::getTable('Widget')->createQuery('w')->where('w.petition_text_id = ?', $petition_text->getId())->andWhere('w.status = ?', Widget::STATUS_ACTIVE)))); $this->setValidator('widget_id', new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('DefaultWidget'), 'required' => false, 'query' => Doctrine_Core::getTable('Widget')->createQuery('w')->where('w.petition_text_id = ?', $petition_text->getId())->andWhere('w.status = ?', Widget::STATUS_ACTIVE)))); } // static defaults $defaults = self::$defaults_petition; if ($petition->isEmailKind()) { $defaults = array_merge($defaults, self::$defaults_email); } foreach ($defaults as $def_key => $def_value) { if (isset($this[$def_key])) { $this->setDefault($def_key, $def_value); } } if ($petition->getKind() == Petition::KIND_PLEDGE) { $this->setWidget('pledge_title', new sfWidgetFormInput(array('label' => 'Title'), array('size' => 90, 'class' => 'large'))); $this->setWidget('intro', new sfWidgetFormTextarea(array(), array('cols' => 90, 'rows' => 5, 'class' => 'markdown'))); $this->getWidgetSchema()->setLabel('intro', 'Introduction'); $this->getWidgetSchema()->moveField('intro', sfWidgetFormSchema::AFTER, 'pledge_title'); $this->setValidator('intro', new sfValidatorString(array('required' => false))); unset($this['pledge_comment']); // $this->setWidget('pledge_comment', new sfWidgetFormTextarea(array(), array('cols' => 90, 'rows' => 5, 'class'=>'markdown'))); $this->setWidget('pledge_explantory_annotation', new sfWidgetFormTextarea(array(), array('cols' => 90, 'rows' => 5, 'class' => 'markdown'))); $this->getWidgetSchema()->setLabel('pledge_explantory_annotation', 'Explantory annotation and contact information'); $this->setWidget('pledge_thank_you', new sfWidgetFormTextarea(array(), array('cols' => 90, 'rows' => 5, 'class' => 'markdown'))); $this->getWidgetSchema()->setLabel('pledge_thank_you', '"Thank you" dialog'); $pledge_items = $petition->getPledgeItems(); foreach ($pledge_items as $pledge_item) { /* @var $pledge_item PledgeItem */ if ($petition_text->isNew()) { $pledge_text = new PledgeText(); $pledge_text->setPetitionText($petition_text); $pledge_text->setPledgeItem($pledge_item); } else { $pledge_text = PledgeTextTable::getInstance()->findOneByItemAndText($pledge_item, $petition_text); if (!$pledge_text) { $pledge_text = new PledgeText(); $pledge_text->setPetitionText($petition_text); $pledge_text->setPledgeItem($pledge_item); } } $this->embedForm('pledge_' . $pledge_item->getId(), new PledgeTextForm($pledge_text), '%content%'); $this->getWidgetSchema()->setLabel('pledge_' . $pledge_item->getId(), $pledge_item->getName() . ' (' . $pledge_item->getStatusName() . ')'); } } else { unset($this['pledge_title'], $this['pledge_comment'], $this['pledge_explantory_annotation'], $this['pledge_thank_you']); } // copy defaults from existing text $copy = $this->getOption('copy', null); if ($copy) { foreach (array('title', 'target', 'background', 'intro', 'body', 'footer', 'privacy_policy_body', 'email_validation_subject', 'email_validation_body', 'email_tellyour_subject', 'email_tellyour_body', 'email_subject', 'email_body', 'landing_url', 'pledge_title', 'pledge_comment', 'pledge_explantory_annotation', 'pledge_thank_you') as $field) { if (isset($this[$field]) && $this[$field]) { $this->setDefault($field, $copy[$field]); } } } }
public function findOneByItemAndText(PledgeItem $item, PetitionText $text) { return $this->createQuery('pt')->where('pt.pledge_item_id = ?', $item->getId())->andWhere('pt.petition_text_id = ?', $text->getId())->fetchOne(); }
public function configure() { $this->widgetSchema->setFormFormatterName('policat'); unset($this['created_at'], $this['updated_at'], $this['petition_id'], $this['object_version'], $this['email_targets'], $this['widget_id']); $petition_text = $this->getObject(); $petition = $petition_text->getPetition(); $this->setWidget('title', new sfWidgetFormInput(array(), array('size' => 90))); $this->setWidget('target', new sfWidgetFormTextarea(array(), array('cols' => 90, 'rows' => 3))); $this->setWidget('background', new sfWidgetFormTextarea(array(), array('cols' => 90, 'rows' => 5))); if (!$petition->isEmailKind()) { $this->setWidget('intro', new sfWidgetFormTextarea(array(), array('cols' => 90, 'rows' => 5))); $this->setWidget('body', new sfWidgetFormTextarea(array(), array('cols' => 90, 'rows' => 30))); $this->setWidget('footer', new sfWidgetFormTextarea(array(), array('cols' => 90, 'rows' => 5))); $this->getValidator('intro')->setOption('required', false); $this->getValidator('body')->setOption('required', true); $this->getValidator('footer')->setOption('required', false); unset($this['email_subject'], $this['email_body']); } else { $this->setWidget('email_subject', new sfWidgetFormInput(array(), array('size' => 90))); $this->setWidget('email_body', new sfWidgetFormTextarea(array(), array('cols' => 90, 'rows' => 30))); $this->getValidator('email_subject')->setOption('required', true); $this->getValidator('email_body')->setOption('required', true); unset($this['intro'], $this['body'], $this['footer']); if ($petition->isGeoKind()) { $subst_fields = $petition->getGeoSubstFields(); $keywords = array(); foreach ($subst_fields as $keyword => $subst_field) { if ($subst_field['id'] != MailingList::FIX_GENDER) { $keywords[] = '<b>' . $keyword . '</b> (' . $subst_field['name'] . ')'; } } foreach (PetitionSigningTable::$KEYWORDS as $keyword) { $keywords[] = $keyword; } } else { $keywords = PetitionSigningTable::$KEYWORDS; } $this->getWidgetSchema()->setHelp('email_body', 'You can use the following keywords: ' . implode(', ', $keywords) . '.'); } $this->setWidget('email_validation_subject', new sfWidgetFormInput(array(), array('size' => 90))); $this->setWidget('email_validation_body', new sfWidgetFormTextarea(array(), array('cols' => 90, 'rows' => 8))); $this->setWidget('email_tellyour_subject', new sfWidgetFormInput(array(), array('size' => 90))); $this->setWidget('email_tellyour_body', new sfWidgetFormTextarea(array(), array('cols' => 90, 'rows' => 8))); $possible_statuses = array_keys(PetitionText::$STATUS_SHOW); $this->state_count = count($possible_statuses); $possible_statuses_show = PetitionText::calcStatusShow($possible_statuses); $this->setWidget('status', new sfWidgetFormChoice(array('choices' => $possible_statuses_show))); $this->setValidator('status', new sfValidatorChoice(array('choices' => $possible_statuses, 'required' => true))); if ($petition_text->getLanguageId() === null) { $this->setWidget('language_id', new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Language'), 'add_empty' => false, 'query' => Doctrine_Core::getTable('Language')->createQuery('l')->where('l.id NOT IN (SELECT pt.language_id FROM PetitionText pt WHERE pt.petition_id = ?)', $petition_text->getPetitionId())))); $this->setValidator('language_id', new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Language'), 'query' => Doctrine_Core::getTable('Language')->createQuery('l')->where('l.id NOT IN (SELECT pt.language_id FROM PetitionText pt WHERE pt.petition_id = ?)', $petition_text->getPetitionId())))); } else { unset($this['language_id']); } $this->setWidget('privacy_policy_body', new sfWidgetFormTextarea(array(), array('cols' => 90, 'rows' => 30))); if (!$petition_text->isNew()) { $this->setWidget('updated_at', new sfWidgetFormInputHidden()); $this->setValidator('updated_at', new ValidatorUnchanged(array('fix' => $petition_text->getUpdatedAt()))); $this->setWidget('widget_id', new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('DefaultWidget'), 'add_empty' => true, 'method' => 'getIdentString', 'query' => Doctrine_Core::getTable('Widget')->createQuery('w')->where('w.petition_text_id = ?', $petition_text->getId())->andWhere('w.status = ?', Widget::STATUS_ACTIVE)))); $this->setValidator('widget_id', new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('DefaultWidget'), 'required' => false, 'query' => Doctrine_Core::getTable('Widget')->createQuery('w')->where('w.petition_text_id = ?', $petition_text->getId())->andWhere('w.status = ?', Widget::STATUS_ACTIVE)))); } // static defaults $defaults = self::$defaults_petition; if ($petition->isEmailKind()) { $defaults = array_merge($defaults, self::$defaults_email); } foreach ($defaults as $def_key => $def_value) { if (isset($this[$def_key])) { $this->setDefault($def_key, $def_value); } } // copy defaults from existing text $copy = $this->getOption('copy'); if (isset($copy)) { foreach (array('title', 'target', 'background', 'intro', 'body', 'footer', 'email_validation_subject', 'email_validation_body', 'email_tellyour_subject', 'email_tellyour_body', 'email_subject', 'email_body') as $field) { $this->setDefault($field, $copy[$field]); } } }