public function countByPetition(Petition $petition, $timeToLive = 600)
 {
     $query = $this->queryAll()->where('w.petition_id = ? AND w.status = ?', array($petition->getId(), Widget::STATUS_ACTIVE));
     if ($timeToLive) {
         $query->useResultCache(true, $timeToLive);
     }
     return $query->count();
 }
 public function queryByPetition(Petition $petition, $fetch_users = true)
 {
     $query = $this->createQuery('pr')->where('pr.petition_id = ?', $petition->getId());
     if ($fetch_users) {
         $query->addFrom('pr.User u');
     }
     return $query;
 }
 /** @deprecated do not use! it is slow */
 public function countPendingMails(Petition $petition = null)
 {
     $query = self::getInstance()->createQuery('sc')->leftJoin('sc.PetitionSigning s');
     if ($petition) {
         $query->where('s.petition_id = ?', $petition->getId());
     }
     $query->leftJoin('s.PetitionSigningWave w')->andWhere('sc.wave = w.wave and w.status = ?', PetitionSigning::STATUS_PENDING);
     return $query->count();
 }
Example #4
0
 public function testCantCreateIfMandateIsExpired()
 {
     Yii::app()->db->createCommand()->update('mandate', array('expiration_ts' => '2014-04-21 00:00:00'), 'id = 1');
     $mandate = Mandate::model()->findByPk(1);
     $this->assertFalse($mandate->isActive());
     $petition = new Petition();
     $petition->title = 'Some petition';
     $petition->content = 'Petition content';
     $petition->mandate_id = 1;
     $petition->creator_id = 2;
     $this->assertFalse($petition->save());
 }
 public function sumContactStatus($status, Petition $petition = null)
 {
     $query = self::getInstance()->createQuery('psw')->select('SUM(psw.contact_num) as contact_num_sum')->where('psw.status = ?', $status);
     if ($petition) {
         $query->leftJoin('psw.PetitionSigning ps')->andWhere('ps.petition_id = ?', $petition->getId());
     }
     $result = $query->fetchArray();
     if (isset($result[0])) {
         $num = $result[0]['contact_num_sum'];
         return $num ? $num : 0;
     }
     return 0;
 }
 /**
  *
  * @param Petition $petition
  * @param bool $fetch_lang
  * @return Doctrine_Query
  */
 public function queryByPetition(Petition $petition, $fetch_lang = true, $status = null, $language_id = null)
 {
     $query = $this->createQuery('pt')->where('pt.petition_id = ?', $petition->getId())->orderBy('pt.id');
     if ($fetch_lang) {
         $query->leftJoin('pt.Language l')->select('pt.*, l.*');
     }
     if ($status !== null) {
         $query->andWhere('pt.status = ?', $status);
     }
     if ($language_id !== null) {
         $query->andWhere('pt.language_id = ?', $language_id);
     }
     return $query;
 }
Example #7
0
 public function testRateSavesAfterValidation()
 {
     $petition = new Petition();
     $petition->title = 'Some petition';
     $petition->content = 'Petition content';
     $petition->mandate_id = 1;
     $petition->creator_id = 2;
     $petition->save();
     $petitionRate = new PetitionRate();
     $petitionRate->target_id = $petition->id;
     $petitionRate->user_id = 2;
     $petitionRate->score = PetitionRate::SCORE_POSITIVE;
     $this->assertTrue($petitionRate->validate());
     $this->assertTrue($petitionRate->save());
 }
Example #8
0
 public static function renderWidget($params)
 {
     $widget = WidgetTable::getInstance()->fetch($params[1]);
     if (!$widget || $widget->getStatus() != Widget::STATUS_ACTIVE) {
         return '';
     }
     $context = sfContext::getInstance();
     $petition = $widget->getPetition();
     $url = $context->getRouting()->generate('sign_hp', array('id' => $widget['id'], 'hash' => $widget->getLastHash(true)), true);
     $count = $petition->getCount(60);
     $target = $count . '-' . Petition::calcTarget($count, $petition->getTargetNum());
     $widget_id = $widget['id'];
     $stylings = json_decode($widget->getStylings(), true);
     $stylings['type'] = 'embed';
     $stylings['url'] = $url;
     $stylings['width'] = 'auto';
     $stylings['count'] = number_format($count, 0, '.', ',') . ' ' . 'people so far';
     $stylings['target'] = $target;
     return '<script type="text/javascript">' . self::getInitJS() . self::getAddStyleJS($widget_id, $stylings) . self::getWidgetHereJs($widget_id, false) . '</script>';
 }
Example #9
0
 public function testPetitionsLists()
 {
     $this->open('userPage/petitions/1');
     $this->waitForPresent($this->getCssSel('container'));
     $this->waitForPresent($this->getCssSel('myPetitions.petitionsFeed'));
     $this->waitForPresent($this->getCssSel('petitionsForMe.petitionsFeed'));
     $this->assertPetitionsTotalCountIs($count = 15, 'petitionsForMe');
     $this->assertPetitionsOnPageCountIs($count, 'petitionsForMe');
     $this->assertPetitionsTotalCountIs($count = 16, 'myPetitions');
     $this->assertPetitionsOnPageCountIs($count, 'myPetitions');
     $petitions = Petition::model()->findAllByAttributes(array('creator_id' => 1));
     $this->assertPetitionsFeedContains($petitions, 'myPetitions');
     $petitions = Petition::model()->findAllByAttributes(array('mandate_id' => Mandate::model()->getUsersMandates(1)));
     $this->assertPetitionsFeedContains($petitions, 'petitionsForMe');
     $this->open('userPage/petitions/2');
     $this->waitForPresent($this->getCssSel('container'));
     $this->waitForPresent($this->getCssSel('petitionsFeed'));
     $this->assertElementNotPresent($this->getCssSel('myPetitions'));
     $this->assertElementNotPresent($this->getCssSel('petitionsForMe'));
     $this->assertPetitionsTotalCountIs(0);
     $this->assertElementContainsText($this->getCssSel('petitionsFeed.item'), 'There is no items.');
 }
 public function executeFeature()
 {
     $title = trim(StoreTable::value(StoreTable::PORTAL_HOME_TITLE, ''));
     $this->title = $title ? $title : 'Featured action';
     $markup = trim(StoreTable::value(StoreTable::PORTAL_HOME_MARKUP, ''));
     if ($markup) {
         $markup = preg_replace_callback('/#KEYVISUAL-(\\d+)#/', array($this, 'getKeyvisualUrl'), $markup);
         $markup = preg_replace('/#WIDGET-(\\d+)#/', 'PasjhkX\\1KmsownedS', $markup);
         // prevent markdown messing up widget
         $markup = UtilMarkdown::transform($markup, true, true);
         $this->markup = preg_replace_callback('/PasjhkX(\\d+)KmsownedS/', array('UtilWidget', 'renderWidget'), $markup);
         return;
     }
     $id = PetitionTable::getInstance()->createQuery('p')->where('p.status = ?', Petition::STATUS_ACTIVE)->andWhere('p.homepage = 1')->leftJoin('p.Campaign c')->andWhere('c.status = ?', CampaignTable::STATUS_ACTIVE)->leftJoin('p.PetitionText pt')->andWhere('pt.status = ?', PetitionText::STATUS_ACTIVE)->andWhere('pt.language_id = ?', 'en')->leftJoin('pt.DefaultWidget w')->andWhere('w.status = ?', Widget::STATUS_ACTIVE)->select('p.id')->addSelect('(SELECT count(z.id) FROM PetitionSigning z WHERE DATE_SUB(NOW(),INTERVAL 1 DAY) <= z.created_at  and z.petition_id = p.id and z.status = ' . PetitionSigning::STATUS_VERIFIED . ') as signings24')->limit(1)->orderBy('signings24 DESC, p.id ASC')->fetchArray();
     if ($id) {
         $id = $id[0]['id'];
         $petition = PetitionTable::getInstance()->createQuery('p')->where('p.id = ?', $id)->andWhere('p.status = ?', Petition::STATUS_ACTIVE)->andWhere('p.homepage = 1')->leftJoin('p.Campaign c')->andWhere('c.status = ?', CampaignTable::STATUS_ACTIVE)->leftJoin('p.PetitionText pt')->andWhere('pt.status = ?', PetitionText::STATUS_ACTIVE)->andWhere('pt.language_id = ?', 'en')->leftJoin('pt.DefaultWidget w')->andWhere('w.status = ?', Widget::STATUS_ACTIVE)->select('p.name, p.object_version, p.kind, p.language_id, p.twitter_tags, p.key_visual, p.read_more_url, pt.id, pt.object_version, pt.title, pt.target, pt.body, pt.footer, pt.email_subject, pt.email_body, w.id, w.object_version, w.title, w.target, w.intro, w.footer, w.email_subject, w.email_body, w.stylings')->fetchOne();
         if ($petition) {
             /* @var $petition Petition */
             $text = $petition['PetitionText'][0];
             $widget = $text['DefaultWidget'];
             $url = $this->generateUrl('sign_hp', array('id' => $widget['id'], 'hash' => $widget->getLastHash(true)), true);
             $this->count = $petition->getCount(60);
             $this->target = $this->count . '-' . Petition::calcTarget($this->count, $petition->getTargetNum());
             $this->widget_id = $widget['id'];
             $this->stylings = json_decode($widget->getStylings(), true);
             $this->stylings['type'] = 'embed';
             $this->stylings['url'] = $url;
             $this->stylings['width'] = 'auto';
         }
     }
 }
 public function isPetitionMember(Petition $petition, $orCampaignAdmin = false)
 {
     if ($orCampaignAdmin && $this->isCampaignAdmin($petition->getCampaign())) {
         return true;
     }
     $pr = $this->getRightsByPetition($petition);
     return $pr && $pr->getActive() && ($pr->getMember() || $pr->getAdmin()) && $this->isCampaignMember($petition->getCampaign());
 }
 public function getChoices(Petition $petition, $first, $active_pledge_item_ids = false)
 {
     $ts = $petition->getTargetSelectors();
     $choices = array();
     $query = $this->createQuery('ml')->where('ml.id = ?', $petition->getMailingListId());
     $fix_field = false;
     $direct_contact = false;
     if (count($ts) > 1) {
         $second = $ts[1]['id'];
         if (is_numeric($second)) {
             $query->leftJoin('ml.MailingListMeta mlm2')->andWhere('mlm2.id = ?', $second)->leftJoin('mlm2.MailingListMetaChoice mlmc2')->leftJoin('mlmc2.ContactMeta cm2')->leftJoin('cm2.Contact c')->select('DISTINCT ml.id, mlm2.id, mlmc2.*');
         } else {
             $fix_field = true;
             $col = $ts[1]['id'];
             $query->leftJoin('ml.Contact c')->groupBy("c.{$col}")->select("DISTINCT ml.id, c.id, c.{$col}");
         }
     } else {
         $direct_contact = true;
         $query->leftJoin('ml.Contact c')->select('DISTINCT ml.id, c.firstname, c.lastname, c.country');
     }
     if (is_numeric($ts[0]['id'])) {
         $query->leftJoin('c.ContactMeta cm1');
         if (array_key_exists('kind', $ts[0]) && $ts[0]['kind'] == MailingListMeta::KIND_MAPPING) {
             $query->andWhere('cm1.mailing_list_meta_choice_id IN (SELECT mlmc1.id FROM MailingListMetaChoice mlmc1 WHERE mlmc1.mailing_list_meta_id = ? AND mlmc1.choice = ?)', array($ts[0]['meta_id'], $first));
         } else {
             $query->andWhere('cm1.mailing_list_meta_choice_id = ?', $first);
         }
     } else {
         $col = $ts[0]['id'];
         $query->andWhere("c.{$col} = ?", $first);
         // should be secure
     }
     $list = $query->execute();
     $pledges = array();
     $infos = array();
     $pledge_table = PledgeTable::getInstance();
     $pledge_info_columns = $petition->getPledgeInfoColumnsArray();
     if ($list) {
         if ($direct_contact) {
             foreach ($list[0]['Contact'] as $choice) {
                 /* @var $choice Contact */
                 $choices[$choice['id']] = $choice['firstname'] . ' ' . $choice['lastname'];
             }
             $pledges = $pledge_table->getPledgesForContacts($list[0]['Contact'], $active_pledge_item_ids);
             $infos = ContactTable::getInstance()->getPledgeInfoColumns($list[0]['Contact'], $pledge_info_columns);
         } else {
             if ($fix_field) {
                 $col = $ts[1]['id'];
                 foreach ($list[0]['Contact'] as $choice) {
                     $choices[$choice[$col]] = $choice[$col];
                 }
             } else {
                 foreach ($list[0]['MailingListMeta'][0]['MailingListMetaChoice'] as $choice) {
                     $choices[$choice['id']] = $choice['choice'];
                 }
             }
         }
     }
     return array('choices' => $choices, 'pledges' => $direct_contact && $active_pledge_item_ids !== false ? $pledges : false, 'infos' => $infos);
 }
Example #13
0
 public function executeWidgetOuter(sfWebRequest $request)
 {
     $this->fetchWidget();
     $petition = $this->widget['Petition'];
     /* @var $petition Petition */
     $petition_text = $this->widget['PetitionText'];
     /* @var $petition_text PetitionText */
     $this->count = $petition->getCount(60);
     $this->target = $this->count . '-' . Petition::calcTarget($this->count, $this->widget->getPetition()->getTargetNum());
     $image_prefix = ($request->isSecure() ? 'https://' : 'http://') . $request->getHost() . '/' . $request->getRelativeUrlRoot() . 'images/';
     $this->kind = $this->widget->getPetition()->getKind();
     $this->lang = $this->widget->getPetitionText()->getLanguageId();
     $this->getUser()->setCulture($this->lang);
     $this->label_mode = $this->widget->getPetition()->getLabelMode();
     $stylings = json_decode($this->widget->getStylings(), true);
     if (!is_array($stylings)) {
         $stylings = array();
     }
     $widget_colors = $petition->getWidgetIndividualiseDesign();
     foreach (array('title_color', 'body_color', 'button_color', 'bg_left_color', 'bg_right_color', 'form_title_color') as $style) {
         if (!$widget_colors || !isset($stylings[$style]) || !$stylings[$style]) {
             $stylings[$style] = $petition['style_' . $style];
         }
     }
     $this->stylings = $stylings;
     $this->keyvisual = $this->widget->getPetition()->getKeyVisual() ? $image_prefix . 'keyvisual/' . $this->widget->getPetition()->getKeyVisual() : null;
     $this->sprite = $image_prefix . 'policat.spr.png';
     $this->url = $this->getContext()->getRouting()->generate('sign', array('id' => $this->widget['id'], 'hash' => $this->widget->getLastHash(true)), true);
     $this->getResponse()->setContentType('text/javascript');
     $this->setLayout(false);
     $title = $this->widget->getTitle();
     if (!$petition->getWidgetIndividualiseText()) {
         $title = $petition_text->getTitle();
     }
     $this->title = Util::enc($title);
 }
Example #14
0
 public function executeNew(sfWebRequest $request)
 {
     if (!$this->getGuardUser()->hasCampaigns()) {
         $this->redirect($this->getContext()->getRouting()->generate('dashboard', array(), true) . '?no_campaign=1');
     }
     $petition = new Petition();
     $petition->setHomepage(1);
     $petition->setWithCountry(1);
     $petition->setKind(Petition::KIND_PETITION);
     $petition->setStartAt(gmdate('Y-m-d'));
     $petition->setEndAt(gmdate('Y-m-d', strtotime('next year')));
     $petition->setFromName($this->getGuardUser()->getOrganisation() ?: $this->getGuardUser()->getName());
     $petition->setFromEmail($this->getGuardUser()->getEmailAddress());
     $campaign_id = $request->getGetParameter('campaign');
     if (is_numeric($campaign_id)) {
         $campaign = CampaignTable::getInstance()->findById($campaign_id, $this->userIsAdmin());
         if ($campaign) {
             $petition->setCampaign($campaign);
         }
     }
     $this->form = new NewPetitionForm($petition, array(NewPetitionForm::OPTION_USER => $this->getGuardUser()));
     if ($request->isMethod('post')) {
         $this->form->bind($request->getPostParameter($this->form->getName()));
         if ($this->form->isValid()) {
             $con = PetitionTable::getInstance()->getConnection();
             $con->beginTransaction();
             try {
                 $this->form->save();
                 $petition = $this->form->getObject();
                 $pr = new PetitionRights();
                 $pr->setPetition($petition);
                 $pr->setUser($this->getGuardUser());
                 $pr->setActive(1);
                 $pr->setAdmin(0);
                 $pr->setMember(1);
                 $pr->save();
                 $con->commit();
             } catch (Exception $e) {
                 $con->rollback();
             }
             return $this->ajax()->redirectRotue('petition_edit_', array('id' => $petition->getId()))->render();
         } else {
             return $this->ajax()->form($this->form)->render();
         }
     }
     $this->includeChosen();
 }
 public function configure()
 {
     $this->widgetSchema->setFormFormatterName('bootstrap');
     $this->widgetSchema->setNameFormat('edit_widget[%s]');
     $petition = $this->getObject()->getPetition();
     unset($this['user_id'], $this['data_owner'], $this['created_at'], $this['updated_at'], $this['campaign_id'], $this['petition_id'], $this['petition_text_id'], $this['stylings'], $this['email'], $this['organisation'], $this['validation_kind'], $this['validation_data'], $this['validation_status'], $this['edit_code'], $this['object_version'], $this['parent_id'], $this['ref'], $this['paypal_email'], $this['activity_at'], $this['last_ref']);
     $parent = $this->getObject()->getParentId() ? $this->getObject()->getParent() : null;
     if ($this->isNew()) {
         $this->setWidget('id', new sfWidgetFormInput(array(), array('size' => 4)));
         $this->setValidator('id', new ValidatorFreeId(array('required' => false, ValidatorFreeId::OPTION_MODEL => $this->getModelName())));
     }
     $this->setWidget('title', new sfWidgetFormInput(array(), array('size' => 90, 'class' => 'large')));
     $this->setWidget('styling_type', new sfWidgetFormChoice(array('choices' => array('popup' => 'Popup', 'embed' => 'Embed'))));
     $this->setValidator('styling_type', new sfValidatorChoice(array('choices' => array('popup', 'embed'))));
     $this->setDefault('styling_type', $this->getObject()->getStyling('type', 'embed'));
     $this->widgetSchema->setLabel('styling_type', 'Widget type');
     $choices = array('auto' => 'auto');
     for ($i = 440; $i <= 740; $i++) {
         $choices[$i] = $i;
     }
     //$this->setWidget('styling_width',    new sfWidgetFormInput());
     $this->setWidget('styling_width', new sfWidgetFormChoice(array('choices' => $choices)));
     $this->setValidator('styling_width', new sfValidatorChoice(array('choices' => array_keys($choices))));
     $this->setDefault('styling_width', $this->getObject()->getStyling('width', $parent ? $parent->getStyling('width') : 'auto'));
     $this->widgetSchema->setLabel('styling_width', 'Width');
     if ($petition->getWidgetIndividualiseDesign()) {
         $this->setWidget('styling_title_color', new sfWidgetFormInput(array(), array('class' => 'color {hash:true}')));
         $this->setValidator('styling_title_color', new ValidatorCssColor(array('min_length' => 7, 'max_length' => 7)));
         $this->setDefault('styling_title_color', $this->getObject()->getStyling('title_color', $parent ? $parent->getStyling('title_color') : $petition->getStyleTitleColor()));
         $this->widgetSchema->setLabel('styling_title_color', 'Text title');
         $this->setWidget('styling_body_color', new sfWidgetFormInput(array(), array('class' => 'color {hash:true}')));
         $this->setValidator('styling_body_color', new ValidatorCssColor(array('min_length' => 7, 'max_length' => 7)));
         $this->setDefault('styling_body_color', $this->getObject()->getStyling('body_color', $parent ? $parent->getStyling('body_color') : $petition->getStyleBodyColor()));
         $this->widgetSchema->setLabel('styling_body_color', 'Text body');
         $this->setWidget('styling_bg_left_color', new sfWidgetFormInput(array(), array('class' => 'color {hash:true}')));
         $this->setValidator('styling_bg_left_color', new ValidatorCssColor(array('min_length' => 7, 'max_length' => 7)));
         $this->setDefault('styling_bg_left_color', $this->getObject()->getStyling('bg_left_color', $parent ? $parent->getStyling('bg_left_color') : $petition->getStyleBgLeftColor()));
         $this->widgetSchema->setLabel('styling_bg_left_color', 'Backgr left');
         $this->setWidget('styling_bg_right_color', new sfWidgetFormInput(array(), array('class' => 'color {hash:true}')));
         $this->setValidator('styling_bg_right_color', new ValidatorCssColor(array('min_length' => 7, 'max_length' => 7)));
         $this->setDefault('styling_bg_right_color', $this->getObject()->getStyling('bg_right_color', $parent ? $parent->getStyling('bg_right_color') : $petition->getStyleBgRightColor()));
         $this->widgetSchema->setLabel('styling_bg_right_color', 'Backgr right');
         $this->setWidget('styling_form_title_color', new sfWidgetFormInput(array(), array('class' => 'color {hash:true}')));
         $this->setValidator('styling_form_title_color', new ValidatorCssColor(array('min_length' => 7, 'max_length' => 7)));
         $this->setDefault('styling_form_title_color', $this->getObject()->getStyling('form_title_color', $parent ? $parent->getStyling('form_title_color') : $petition->getStyleFormTitleColor()));
         $this->widgetSchema->setLabel('styling_form_title_color', 'Form title');
         $this->setWidget('styling_button_color', new sfWidgetFormInput(array(), array('class' => 'color {hash:true}')));
         $this->setValidator('styling_button_color', new ValidatorCssColor(array('min_length' => 7, 'max_length' => 7)));
         $this->setDefault('styling_button_color', $this->getObject()->getStyling('button_color', $parent ? $parent->getStyling('button_color') : $petition->getStyleButtonColor()));
         $this->widgetSchema->setLabel('styling_button_color', 'Button');
     }
     $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->setWidget('background', new sfWidgetFormTextarea(array(), array('cols' => 90, 'rows' => 5, 'class' => 'markdown')));
     if (!$petition->isEmailKind()) {
         $this->setWidget('intro', new sfWidgetFormTextarea(array(), array('cols' => 90, 'rows' => 5, 'class' => 'large')));
         $this->setWidget('footer', new sfWidgetFormTextarea(array(), array('cols' => 90, 'rows' => 5, 'class' => 'large')));
         $this->getValidator('intro')->setOption('required', false);
         $this->getValidator('footer')->setOption('required', false);
         unset($this['email_subject'], $this['email_body']);
     } else {
         if ($petition->getKind() == Petition::KIND_PLEDGE) {
             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' => 5, 'class' => 'large elastic highlight')));
             $this->getValidator('email_subject')->setOption('required', true);
             $this->getValidator('email_body')->setOption('required', true);
         }
         unset($this['intro'], $this['footer']);
         if ($petition->getKind() != Petition::KIND_PLEDGE) {
             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;
                 }
                 $keywords[] = PetitionTable::KEYWORD_PERSONAL_SALUTATION;
             } else {
                 $keywords = PetitionSigningTable::$KEYWORDS;
             }
             $this->getWidgetSchema()->setHelp('email_body', 'You can use the following keywords: ' . implode(', ', $keywords) . '.');
         }
     }
     $defaults = $this->getObject()->getPetitionText();
     if ($this->getObject()->getParentId()) {
         $defaults = $this->getObject()->getParent();
     }
     if ($this->getObject()->isNew()) {
         foreach (array('title', 'target', 'background', 'intro', 'footer', 'email_subject', 'email_body') as $field) {
             if (isset($this[$field])) {
                 $this->setDefault($field, $defaults[$field]);
             }
         }
     }
     $possible_statuses = Widget::$STATUS_SHOW;
     unset($possible_statuses[Widget::STATUS_DRAFT]);
     $possible_statuses = array_keys($possible_statuses);
     $this->state_count = count($possible_statuses);
     $possible_statuses_show = Petition::calcStatusShow($possible_statuses);
     $this->setWidget('status', new sfWidgetFormChoice(array('choices' => $possible_statuses_show)));
     $this->setValidator('status', new sfValidatorChoice(array('choices' => $possible_statuses, 'required' => true)));
     //    }
     //    else
     //    {
     //      $this->getObject()->setStatus(Widget::STATUS_ACTIVE);
     //      unset($this['status']);
     //    }
     $petition_paypal_email = $petition->getPaypalEmail();
     if (is_string($petition_paypal_email) && strpos($petition_paypal_email, '@') || !$this instanceof WidgetPublicForm) {
         $this->setWidget('paypal_email', new WidgetFormInputInverseCheckbox(array('value_attribute_value' => 'ignore')));
         $this->setValidator('paypal_email', new ValidatorInverseCheckbox(array('value_attribute_value' => 'ignore')));
         $this->getWidgetSchema()->setLabel('paypal_email', 'Include fundraising form');
     }
     if (!$this->getObject()->isNew()) {
         $this->setWidget('updated_at', new sfWidgetFormInputHidden());
         $this->setValidator('updated_at', new ValidatorUnchanged(array('fix' => $this->getObject()->getUpdatedAt())));
     }
     $this->setWidget('landing_url', new sfWidgetFormInput(array('label' => 'Email Validation Landingpage - auto forwarding to external page', 'default' => $this->getObject()->getInheritLandingUrl()), 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->getWidgetIndividualiseText()) {
         foreach (array('title', 'target', 'background', 'intro', 'footer', 'email_subject', 'email_body') as $field) {
             if (isset($this[$field])) {
                 unset($this[$field]);
             }
         }
     }
 }
 public function queryByActivePetitionTexts(Petition $petition)
 {
     return $this->queryAll()->leftJoin('l.PetitionText pt')->andWhere('pt.petition_id = ?', $petition->getId())->andWhere('pt.status = ?', PetitionText::STATUS_ACTIVE);
 }
 private static function daySql()
 {
     if (self::$_day_sql === null) {
         self::$_day_sql = gmdate('Y-m-d');
     }
     return self::$_day_sql;
 }
Example #18
0
 /**
  * This should only be called by an Admin
  */
 public function handleDeletePetition(Petition $petition)
 {
     $petition->delete();
     return Redirect::to('petitions');
 }
Example #19
0
 public function executeCounterbar(sfWebRequest $request)
 {
     $widget = Doctrine_Core::getTable('Widget')->find($request->getParameter('id'));
     /* @var $widget Widget */
     $this->count = $widget->getPetition()->getCount(60);
     $this->target = Petition::calcTarget($this->count, $widget->getPetition()->getTargetNum());
     $this->lang = $widget->getPetitionText()->getLanguageId();
     $this->getUser()->setCulture($this->lang);
     $this->stylings = json_decode($widget->getStylings(), true);
     $this->widgetid = $widget->getId();
     $this->markup = $this->getPartial('counterbar', array('count' => $this->count, 'target' => $this->target, 'stylings' => $this->stylings, 'widgetid' => $this->widgetid));
     $this->getResponse()->setContentType('text/javascript');
     $this->setLayout(false);
 }
 /**
  *
  * @param MailingList $ml
  * @param Petition $pledges_by_petition
  * @return Doctrine_Query
  */
 public function queryByMailingList(MailingList $ml, $pledges_by_petition = null)
 {
     $query = $this->createQuery('c INDEXBY c.id')->where('c.mailing_list_id = ?', $ml->getId())->orderBy('c.id');
     if ($pledges_by_petition) {
         $query->leftJoin('c.Pledges p INDEXBY p.pledge_item_id');
         $query->select('c.*, p.*');
         $query->andWhere('p.contact_id IS NULL OR (p.pledge_item_id IN (SELECT pi.id FROM PledgeItem pi WHERE pi.petition_id = ?))', $pledges_by_petition->getId());
     } else {
         $query->select('c.*');
     }
     return $query;
 }
 public function configure()
 {
     $this->widgetSchema->setFormFormatterName('bootstrap');
     $this->widgetSchema->setNameFormat('edit_petition[%s]');
     $user = $this->getOption(self::USER, null);
     /* @var $user sfGuardUser */
     unset($this['created_at'], $this['updated_at'], $this['campaign_id'], $this['object_version'], $this['email_targets']);
     unset($this['addnote'], $this['mailing_list_id'], $this['editable'], $this['auto_greeting'], $this['key_visual'], $this['kind']);
     unset($this['nametype'], $this['language_id'], $this['paypal_email'], $this['with_comments'], $this['with_address']);
     unset($this['with_country'], $this['default_country'], $this['pledge_header_visual'], $this['pledge_key_visual']);
     unset($this['pledge_background_color'], $this['pledge_color'], $this['pledge_head_color'], $this['pledge_font']);
     unset($this['pledge_info_columns'], $this['pledge_with_comments'], $this['activity_at'], $this['deleted_pendings']);
     unset($this['label_mode']);
     $this->setWidget('name', new sfWidgetFormTextarea(array('label' => 'Action name'), array('cols' => 90, 'rows' => 2, 'class' => 'add_popover', 'data-content' => 'Give your action a short and memorisable name. It won\'t be shown to your supporters. It\'s only for your and your colleague\'s overview.')));
     $this->getWidgetSchema()->setLabel('addnum', 'Sign-on counter start');
     $this->getWidget('addnum')->setAttribute('class', 'add_popover');
     $this->getWidget('addnum')->setAttribute('data-content', 'Add the number of activists that have signed-on to your action in the streets or via another e-action tool. The number will be added to the live counter in all widgets of your e-action. Be honest :-)');
     $this->getWidgetSchema()->setLabel('target_num', 'Sign-on counter target');
     $this->getWidget('target_num')->setAttribute('class', 'add_popover');
     $this->getWidget('target_num')->setAttribute('data-content', 'Add your action target as the number of sign-ons that you want to achieve. If you keep "0" in this field, the counter in all widgets will automatically set a motivating target – not too low, not too high – and increase the target automatically to the next level, once a level is met. We recommend keeping "0"in this field to use the automatic target setting. It\'s a fun feature :-) ');
     $this->setWidget('read_more_url', new sfWidgetFormInput(array('label' => '"Read more" link'), array('size' => 90, 'class' => 'add_popover large', 'data-content' => 'Add the URL of your campaign site (if you have a central one), including "http://" or http://www. ".  A "Read more" link will appear underneath your e-action. You may leave this field free.', 'placeholder' => 'https://www.example.com/')));
     $this->setValidator('read_more_url', new ValidatorUrl(array('required' => false)));
     $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', 'placeholder' => 'https://www.example.com/thank-you')));
     $this->setValidator('landing_url', new ValidatorUrl(array('required' => false, 'trim' => true)));
     $this->setWidget('key_visual', new sfWidgetFormInputFileEditable(array('file_src' => '/images/keyvisual/' . $this->getObject()->getKeyVisual(), 'is_image' => true, 'with_delete' => false, 'template' => '<div>%file%<br />%input%<br />%delete% %delete_label%</div>')));
     $this->setValidator('key_visual', new sfValidatorFile(array('required' => false, 'mime_categories' => 'web_images', 'path' => sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'keyvisual')));
     $this->getWidgetSchema()->setHelp('key_visual', 'Your key visual should be a strong visual expression of what your action is about. It should not contain text in case your action will be multi-lingual. Make sure, your image wider than 150 pixel but not bigger than 20kB in size. Note: portrait images will be cropped to square format!');
     $this->setWidget('show_keyvisual', new sfWidgetFormChoice(array('choices' => array(0 => 'no', 1 => 'yes'), 'label' => 'Show key visual in signing widget'), array()));
     $this->setValidator('show_keyvisual', new sfValidatorChoice(array('choices' => array(0, 1), 'required' => true)));
     if (StoreTable::value(StoreTable::DONATIONS_PAYPAL)) {
         $this->setWidget('paypal_email', new sfWidgetFormInput(array('label' => 'Paypal account for donations'), array('size' => 90, 'class' => 'add_popover', 'data-content' => 'Add your Paypal ID or Paypal email to ask your activists to support your campaign. A "Donate" link will appear underneath your e-action. If people click it, they are asked to donate a free amount of money via Paypal transaction or credit card payment powered by Paypal. You may leave this field free.')));
         $this->setValidator('paypal_email', new ValidatorEmail(array('required' => false, 'max_length' => 80)));
     }
     $this->setWidget('from_name', new sfWidgetFormInput(array(), array('size' => 90, 'class' => 'add_popover', 'data-content' => 'Any activist who wants to support your action will receive a verification email. In order to make their participation count, activists must click on the validation link in their verification email, in order to proof their consent. Otherwise, anyone could sign up to an action in anothers\' name. Please specify the name and email address that should appear as the sender of these emails. We recommend, you choose a short name that resembles the action title, and your own email address. Note: you must provide a valid email address to which you have access!')));
     $this->setValidator('from_name', new sfValidatorString(array('required' => true, 'max_length' => 80)));
     $this->setWidget('from_email', new sfWidgetFormInput(array(), array('size' => 90, 'class' => 'add_popover', 'data-content' => 'Any activist who wants to support your action will receive a verification email. In order to make their participation count, activists must click on the validation link in their verification email, in order to proof their consent. Otherwise, anyone could sign up to an action in anothers\' name. Please specify the name and email address that should appear as the sender of these emails. We recommend, you choose a short name that resembles the action title, and your own email address. Note: you must provide a valid email address to which you have access!', 'placeholder' => '*****@*****.**')));
     $this->setValidator('from_email', new ValidatorEmail(array('required' => true, 'max_length' => 80)));
     $this->getWidgetSchema()->setHelp('from_email', 'Please check if the email domain server of the email you provided allows PoliCAT to send emails with your address. Do not use an address if the SPF check result is "fail". You may use an email address if the SPF check result is "none" or "softfail". However, be aware that in these cases a certain percentage of your validation and action emails might be considered spam by some email clients. Ideally, ask your email server admin to add ' . sfConfig::get('app_spf_ip') . ' in their SPF record."');
     $this->setWidget('homepage', new sfWidgetFormChoice(array('label' => 'Feature on e-action portal', 'choices' => array('0' => 'no', '1' => 'yes')), array('class' => 'add_popover', 'data-content' => 'Select "yes" to feature your e-action on the homepage of our e-action community. Note that for each translation, you need to create at least one widget (in the translations tab) and assign it to the homepage (in the settings of each language), otherwise your action will not be featured! Disclaimer: our friendly admin will cast her or his meticulous eyes over your action and reserves the right to take your action off the portal homepage. We guess that\'s quite unlikely :-)')));
     $this->setValidator('homepage', new sfValidatorChoice(array('choices' => array('0', '1'))));
     $this->setWidget('twitter_tags', new sfWidgetFormInput(array('label' => 'Twitter hashtags'), array('size' => 90, 'class' => 'add_popover', 'data-content' => 'Enter your distinctive action tags, preceded by "#". Leave a blank space between tags. Your action tags will be added to standard tweets of your supporters. Tweets including these tags will be featured on the homepage.')));
     $possible_statuses = $this->getObject()->calcPossibleStatusForUser($user);
     if (in_array(Petition::STATUS_DELETED, $possible_statuses)) {
         $this->has_delete_status = true;
     }
     $this->setWidget('status', new sfWidgetFormChoice(array('choices' => Petition::calcStatusShow($possible_statuses)), array('class' => 'add_popover', 'data-content' => 'Keep the status on draft as long as you want to play around with the e-action settings in this tab. Note that in order to publish the e-action and create widgets, you must set the status to "active". ')));
     $this->setValidator('status', new sfValidatorChoice(array('choices' => $possible_statuses, 'required' => true)));
     $this->setWidget('updated_at', new sfWidgetFormInputHidden());
     $this->setValidator('updated_at', new ValidatorUnchanged(array('fix' => $this->getObject()->getUpdatedAt())));
     $this->setWidget('start_at', new sfWidgetFormInput(array('type' => 'date'), array('class' => 'add_popover', 'data-content' => 'Leave empty to go live as of immediate. If you pick a later date, you can nevertheless already create widgets and embed them into other websites. However, widgets will not allow for sign-ons before the start date.')));
     $this->setWidget('end_at', new sfWidgetFormInput(array('type' => 'date'), array('class' => 'add_popover', 'data-content' => 'Pick an end date for your action. When this date has passed, your widgets will not allow for any more sign-ons. Pick a realistic end date. You may change it at later stage, if necessary.')));
     $fonts = array('"Helvetica Neue",Helvetica,Arial,sans-serif', 'Georgia, serif', '"Palatino Linotype", "Book Antiqua", Palatino, serif', '"Times New Roman", Times, serif', 'Arial, Helvetica, sans-serif', '"Arial Black", Gadget, sans-serif', '"Comic Sans MS", cursive, sans-serif', 'Impact, Charcoal, sans-serif', '"Lucida Sans Unicode", "Lucida Grande", sans-serif', 'Tahoma, Geneva, sans-serif', '"Trebuchet MS", Helvetica, sans-serif', 'Verdana, Geneva, sans-serif', '"Courier New", Courier, monospace', '"Lucida Console", Monaco, monospace', '"Lucida Sans Unicode", Vardana, Arial');
     if ($this->getObject()->isEmailKind()) {
         // EMAIL, GEO, GEO_EXTRA => editable
         $this->setWidget('editable', new sfWidgetFormChoice(array('choices' => Petition::$EDITABLE_SHOW, 'label' => 'Text editable'), array('class' => 'add_popover', 'data-content' => 'If you enable this, activists can modify the action email text as they wish. We recommend you keep the box ticked and encourage your activists to personalise their action emails.')));
         $this->setValidator('editable', new sfValidatorChoice(array('choices' => array_keys(Petition::$EDITABLE_SHOW), 'required' => true)));
         if ($this->getObject()->getKind() == Petition::KIND_OLD_EMAIL_ACTION || $this->getObject()->getKind() == Petition::KIND_EMAIL_ACTION) {
             // EMAIL  => email_target_email_*, email_target_name_*
             $email_targets_json = $this->getObject()->getEmailTargets();
             if (is_string($email_targets_json)) {
                 $email_targets_json = json_decode($email_targets_json, true);
             }
             $email_targets = array();
             if (is_array($email_targets_json)) {
                 foreach ($email_targets_json as $email => $name) {
                     $email_targets[] = array('email' => $email, 'name' => $name);
                 }
             }
             $labels = array(1 => array('Name of recipient', 'Email address of recipient'), 2 => array('Name (2nd, optional)', 'Email (2nd, optional)'), 3 => array('Name (3rd, optional)', 'Email (3rd, optional)'));
             for ($i = 1; $i <= 3; $i++) {
                 $this->setWidget("email_target_email_{$i}", new sfWidgetFormInputText(array('label' => $labels[$i][1]), array('size' => 90, 'class' => 'add_popover', 'data-content' => 'Fill in the and email address of your target: the recipient of your email-action.' . ($i > 1 ? ' You may leave this field blank.' : ''))));
                 $this->setValidator("email_target_email_{$i}", new ValidatorEmail(array('max_length' => 80, 'min_length' => 3, 'required' => false, 'trim' => true)));
                 if (isset($email_targets[$i - 1])) {
                     $this->setDefault("email_target_email_{$i}", $email_targets[$i - 1]['email']);
                 }
                 $this->setWidget("email_target_name_{$i}", new sfWidgetFormInputText(array('label' => $labels[$i][0]), array('size' => 90, 'class' => 'add_popover', 'data-content' => 'Fill in the full name of your target: the recipient of your email-action.' . ($i > 1 ? ' You may leave this field blank.' : ''))));
                 $this->setValidator("email_target_name_{$i}", new sfValidatorString(array('max_length' => 80, 'min_length' => 3, 'required' => false, 'trim' => true)));
                 if (isset($email_targets[$i - 1])) {
                     $this->setDefault("email_target_name_{$i}", $email_targets[$i - 1]['name']);
                 }
             }
         }
         if ($this->getObject()->getKind() == Petition::KIND_PLEDGE) {
             $this->setWidget('pledge_with_comments', new sfWidgetFormChoice(array('label' => 'Enable comments', 'choices' => array('0' => 'no', '1' => 'yes')), array()));
             $this->setValidator('pledge_with_comments', new sfValidatorChoice(array('choices' => array('0', '1'))));
             $this->setWidget('pledge_header_visual', new sfWidgetFormInputFileEditable(array('file_src' => '/images/pledge_header_visual/' . $this->getObject()->getPledgeHeaderVisual(), 'is_image' => true, 'with_delete' => false, 'template' => '<div>%file%<br />%input%<br />%delete% %delete_label%</div>', 'label' => 'Header visual')));
             $this->getWidgetSchema()->setHelp('pledge_header_visual', 'Width should be 1170px and height about 180px. Keep the file small (<80KB). Compress PNGs with tools like http://optipng.sourceforge.net/');
             $this->setValidator('pledge_header_visual', new sfValidatorFile(array('required' => false, 'mime_categories' => 'web_images', 'path' => sfConfig::get('sf_web_dir') . '/images/pledge_header_visual')));
             $this->setWidget('pledge_key_visual', new sfWidgetFormInputFileEditable(array('file_src' => '/images/pledge_key_visual/' . $this->getObject()->getPledgeKeyVisual(), 'is_image' => true, 'with_delete' => false, 'template' => '<div>%file%<br />%input%<br />%delete% %delete_label%</div>', 'label' => 'Key visual')));
             $this->getWidgetSchema()->setHelp('pledge_key_visual', 'Dimensions should be about 140x140px. Keep the file small (<80KB).');
             $this->setValidator('pledge_key_visual', new sfValidatorFile(array('required' => false, 'mime_categories' => 'web_images', 'path' => sfConfig::get('sf_web_dir') . '/images/pledge_key_visual')));
             $this->setWidget('pledge_background_color', new sfWidgetFormInputText(array('label' => 'Background colour'), array('class' => 'color')));
             $this->setValidator('pledge_background_color', new sfValidatorRegex(array('pattern' => '/^[0-9a-f]{6}$/i')));
             $this->setWidget('pledge_color', new sfWidgetFormInputText(array('label' => 'Text colour'), array('class' => 'color')));
             $this->setValidator('pledge_color', new sfValidatorRegex(array('pattern' => '/^[0-9a-f]{6}$/i')));
             $this->setWidget('pledge_head_color', new sfWidgetFormInputText(array('label' => 'Header text colour'), array('class' => 'color')));
             $this->setValidator('pledge_head_color', new sfValidatorRegex(array('pattern' => '/^[0-9a-f]{6}$/i')));
             $this->setWidget('pledge_font', new sfWidgetFormChoice(array('choices' => array_combine($fonts, $fonts), 'label' => 'Font')));
             $this->setValidator('pledge_font', new sfValidatorChoice(array('choices' => $fonts)));
             $info_columns = $this->getObject()->getMailingListId() ? $this->getObject()->getMailingList()->getPledgeColumns() : array('country' => 'Country');
             $this->setWidget('pledge_info_columns_comma', new sfWidgetFormInput(array('type' => 'hidden', 'default' => $this->getObject()->getPledgeInfoColumnsComma(array_keys($info_columns)), 'label' => 'Target data displayed in widget'), array('class' => 'no-chosen select2sort', 'data-tags' => json_encode($info_columns), 'style' => 'width:220px', 'data-maximumSelectionSize' => 2)));
             $this->setValidator('pledge_info_columns_comma', new sfValidatorString(array('required' => false)));
         }
     }
     $this->setWidget('widget_individualise', new sfWidgetFormChoice(array('choices' => PetitionTable::$INDIVIDUALISE, 'label' => 'Setup')));
     $this->setValidator('widget_individualise', new sfValidatorChoice(array('required' => true, 'choices' => array_keys(PetitionTable::$INDIVIDUALISE))));
     $fonts[] = '"Open Sans", sans-serif';
     $this->setWidget('style_font_family', new sfWidgetFormChoice(array('choices' => array_combine($fonts, $fonts), 'label' => 'Font')));
     $this->setValidator('style_font_family', new sfValidatorChoice(array('choices' => $fonts)));
     $this->setWidget('style_title_color', new sfWidgetFormInput(array('label' => 'Title colour'), array('class' => 'color {hash:true}')));
     $this->setValidator('style_title_color', new ValidatorCssColor(array('min_length' => 7, 'max_length' => 7)));
     $this->setWidget('style_body_color', new sfWidgetFormInput(array('label' => 'Body colour'), array('class' => 'color {hash:true}')));
     $this->setValidator('style_body_color', new ValidatorCssColor(array('min_length' => 7, 'max_length' => 7)));
     $this->setWidget('style_button_color', new sfWidgetFormInput(array('label' => 'Button colour'), array('class' => 'color {hash:true}')));
     $this->setValidator('style_button_color', new ValidatorCssColor(array('min_length' => 7, 'max_length' => 7)));
     $this->setWidget('style_bg_left_color', new sfWidgetFormInput(array('label' => 'Background left colour'), array('class' => 'color {hash:true}')));
     $this->setValidator('style_bg_left_color', new ValidatorCssColor(array('min_length' => 7, 'max_length' => 7)));
     $this->setWidget('style_bg_right_color', new sfWidgetFormInput(array('label' => 'Background right colour'), array('class' => 'color {hash:true}')));
     $this->setValidator('style_bg_right_color', new ValidatorCssColor(array('min_length' => 7, 'max_length' => 7)));
     $this->setWidget('style_form_title_color', new sfWidgetFormInput(array('label' => 'Form title'), array('class' => 'color {hash:true}')));
     $this->setValidator('style_form_title_color', new ValidatorCssColor(array('min_length' => 7, 'max_length' => 7)));
     $this->getWidgetSchema()->setLabel('country_collection_id', 'Restrict Countries');
     $this->getWidgetSchema()->setHelp('country_collection_id', 'As a standard, activists can select their home country from a list of all countries in the world. You may restrict the number of country options shown, so activists can pick their country faster.');
     if ($this->getObject()->getKind() == Petition::KIND_PETITION) {
         $this->setWidget('label_mode', new sfWidgetFormChoice(array('choices' => PetitionTable::$LABEL_MODE, 'label' => 'Petition labelling')));
         $this->setValidator('label_mode', new sfValidatorChoice(array('choices' => array_keys(PetitionTable::$LABEL_MODE))));
     }
 }
Example #22
0
# required fields
#  response pages
# modinput2 needs to be changed to modinput 4 and not break
$modid = 7;
$intro_id = 42;
include_once "AMP/BaseDB.php";
include_once "AMP/BaseTemplate.php";
#include_once("AMP/BaseModuleIntro.php");
require_once 'AMP/UserData/Input.inc.php';
require_once 'Modules/Petition/ComponentMap.inc.php';
$pid = isset($_REQUEST['pid']) && $_REQUEST['pid'] ? intval($_REQUEST['pid']) : false;
$modin = isset($_REQUEST['modin']) && $_REQUEST['modin'] ? intval($_REQUEST['modin']) : false;
$map = new ComponentMap_Petition();
$current_petition = $map->getComponent('source');
if ($modin && !$pid) {
    $pid = Petition::findByModin($modin);
}
$current_petition->read($pid);
if ($current_petition->id) {
    // Fetch the form instance specified by submitted modin value.
    $udm = new UserDataInput($dbcon, $current_petition->getFormId());
    // Was data submitted via the web?
    $sub = isset($_REQUEST['btnUdmSubmit']) && $_REQUEST['btnUdmSubmit'];
    //OUTPUT THE PAGE
    echo $current_petition->progressBox();
    // Fetch or save user data.
    if ($udm->submitted) {
        // Save only if submitted data is present, and the user is
        // authenticated, or if the submission is anonymous (i.e., !$uid)
        $save_success = $udm->saveUser();
        echo $udm->output();
Example #23
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Petition::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 public function countPendingByPetition(Petition $petition, $timeToLive = 600)
 {
     $query = $this->queryAll('ps')->where('ps.petition_id = ? AND ps.status = ?', array($petition->getId(), PetitionSigning::STATUS_PENDING));
     if ($timeToLive) {
         $query->useResultCache(true, $timeToLive);
     }
     return $query->count();
 }
 public function queryByPetition(Petition $petition)
 {
     return $this->createQuery('t')->where('t.petition_id = ?', $petition->getId())->orderBy('t.name ASC');
 }
Example #26
0
global $cgi;
switch (appconf('show')) {
    case 'current':
        $petition = new Petition();
        $petition->multilingual = true;
        $petition->orderBy('ts desc');
        $petition->limit(1);
        $single = array_shift($petition->find(array()));
        $cgi->id = $single->id;
        page_title($single->name);
        echo template_simple('current.spt', $single);
        break;
    case 'list':
    default:
        if ($parameters['id']) {
            $petition = new Petition();
            $petition->multilingual = true;
            $single = $petition->get($parameters['id']);
            $cgi->id = $single->id;
            page_title($single->name);
            echo template_simple('current.spt', $single);
        } else {
            $petition = new Petition();
            $petition->multilingual = true;
            $petition->orderBy('ts desc');
            $petition->listFields('id, name, ts, description');
            page_title(intl_get('Petitions'));
            echo template_simple('list.spt', $petition->find(array()));
        }
        break;
}
 protected function createPetition()
 {
     $this->waitForPresent($this->getCssSel('container'));
     $this->assertElementPresent($this->getCssSel('tabs.createPetition'));
     $this->click($this->getCssSel('tabs.createPetition'));
     $this->waitForPresent($this->getCssSel('newPetitionForm'));
     $newPetitionTitle = 'New petition ' . time();
     $newPetitionText = $newPetitionTitle . ' text here.';
     $this->type($this->getCssSel('newPetitionForm') . ' input[name="Petition[title]"]', $newPetitionTitle);
     $this->type($this->getCssSel('newPetitionForm') . ' textarea', $newPetitionText);
     $this->click($this->getCssSel('newPetitionForm') . ' input.btn[type="submit"]');
     $this->waitForVisible($this->getCssSel('petitionsFeed'));
     $this->waitForElementContainsText($this->getCssSel('petitionsFeed.item.title'), $newPetitionTitle);
     $petition = Petition::model()->findByAttributes(array('title' => $newPetitionTitle));
     return $petition;
 }