コード例 #1
0
 /**
  *
  * @param Petition $petition
  * @param string $ts_1
  * @param string $ts_2
  * @param PetitionSigning $existing_signing
  * @return Doctrine_Query
  */
 public function queryByTargetSelector(Petition $petition, $ts_1, $ts_2, $existing_signing = null)
 {
     $ts = $petition->getTargetSelectors();
     $query = $this->createQuery('c')->where('c.mailing_list_id = ?', $petition->getMailingListId());
     if ($existing_signing) {
         $query->andWhere('c.id NOT IN (SELECT psc.contact_id FROM PetitionSigningContact psc WHERE psc.petition_signing_id = ?)', $existing_signing->getId());
     }
     if ($ts_1 && count($ts) > 0) {
         $sel = $ts[0]['id'];
         if (is_numeric($sel)) {
             $is_mapping = array_key_exists('kind', $ts[0]) && $ts[0]['kind'] == MailingListMeta::KIND_MAPPING;
             $is_choice = array_key_exists('kind', $ts[0]) && $ts[0]['kind'] == MailingListMeta::KIND_CHOICE;
             $query->leftJoin('c.ContactMeta cm1');
             if ($is_mapping) {
                 $mapped_ts1 = MappingPairTable::getInstance()->getMapByIdAndA($ts[0]['mapping_id'], $ts_1);
                 $query->andWhere('cm1.mailing_list_meta_id = ?', $ts[0]['meta_id'])->leftJoin('cm1.MailingListMetaChoice mlmc1')->andWhereIn('mlmc1.choice', $mapped_ts1);
             } elseif ($is_choice && is_numeric($ts_1)) {
                 $query->andWhere('cm1.mailing_list_meta_id = ?', $sel)->andWhere('cm1.mailing_list_meta_choice_id = ?', $ts_1);
             } else {
                 // should not happen
                 $query->andWhere('cm1.mailing_list_meta_id = ?', $sel)->andWhere('cm1.value = ?', $ts_1);
             }
         } else {
             if ($sel === 'contact') {
                 if (is_numeric($ts_1)) {
                     $query->andWhere("c.id = ?", $ts_1);
                 }
             } else {
                 if (is_string($ts_1) && $ts_1 != 'all') {
                     $query->andWhere("c.{$sel} = ?", $ts_1);
                 }
             }
         }
         if ($ts_2 && count($ts) > 1) {
             $sel = $ts[1]['id'];
             if (is_numeric($sel)) {
                 if (is_numeric($ts_2)) {
                     $query->leftJoin('c.ContactMeta cm2')->andWhere('cm2.mailing_list_meta_id = ?', $sel)->andWhere('cm2.mailing_list_meta_choice_id = ?', $ts_2);
                 }
             } else {
                 if (is_string($ts_2) && $ts_2 != 'all') {
                     $query->andWhere("c.{$sel} = ?", $ts_2);
                 }
             }
         } else {
             if (is_numeric($ts_2)) {
                 $query->andWhere("c.id = ?", $ts_2);
             }
         }
     }
     return $query;
 }
コード例 #2
0
 public function executeDeletePair(sfWebRequest $request)
 {
     $pair = MappingPairTable::getInstance()->find($request->getParameter('id'));
     if (!$pair) {
         return $this->notFound();
     }
     /* @var $pair MappingPair */
     $form = new BaseForm();
     $form->getWidgetSchema()->setNameFormat('delete_pair[%s]');
     $form->bind($request->getPostParameter($form->getName()));
     if ($form->isValid()) {
         $id = $pair->getId();
         $pair->delete();
         return $this->ajax()->remove('#pair_' . $id)->remove('#pair_form_' . $id)->render();
     } else {
         return $this->ajax()->form($form)->render();
     }
 }
コード例 #3
0
 public function getTargetSelectorChoices($first)
 {
     $tagging_cache = sfCacheTaggingToolkit::getTaggingCache();
     $cache_key = 'Petition_TS1_' . $this->getId() . '_' . (is_scalar($first) ? $first : md5(json_encode($first)));
     $cached_ret = $tagging_cache->get($cache_key, null);
     if ($cached_ret !== null) {
         return $cached_ret;
     }
     $ts = $this->getTargetSelectors();
     $is_pledge = $this->getKind() == Petition::KIND_PLEDGE;
     $ret = false;
     if ($ts && is_scalar($first)) {
         if ($is_pledge) {
             $active_pledge_item_ids = $this->getActivePledgeItemIds();
         } else {
             $active_pledge_item_ids = false;
         }
         if (array_key_exists($first, $ts[0]['choices'])) {
             if (array_key_exists('mapping_id', $ts[0]) && $ts[0]['mapping_id']) {
                 $mapped = MappingPairTable::getInstance()->getMapByIdAndA($ts[0]['mapping_id'], $first);
                 $ret = array('choices' => array(), 'pledges' => false, 'infos' => array());
                 foreach ($mapped as $b) {
                     $choices_and_pledges = MailingListTable::getInstance()->getChoices($this, $b, $active_pledge_item_ids);
                     if ($choices_and_pledges['pledges'] !== false && $ret['pledges'] === false) {
                         $ret['pledges'] = array();
                     }
                     foreach ($choices_and_pledges['choices'] as $k => $v) {
                         $ret['choices'][$k] = $v;
                         if ($choices_and_pledges['pledges'] !== false) {
                             // we got Contacts with Pledges and maybe Infos
                             if (array_key_exists($k, $choices_and_pledges['pledges'])) {
                                 $ret['pledges'][$k] = $choices_and_pledges['pledges'][$k];
                             }
                             if (array_key_exists($k, $choices_and_pledges['infos'])) {
                                 $ret['infos'][$k] = $choices_and_pledges['infos'][$k];
                             }
                         }
                     }
                 }
             } else {
                 $ret = MailingListTable::getInstance()->getChoices($this, $first, $active_pledge_item_ids);
             }
         }
     }
     if ($ret === false) {
         array('choices' => array(), 'pledges' => $is_pledge ? array() : false, 'infos' => array());
     }
     $tags = $this->getCacheTags();
     if ($this->getMailingListId()) {
         $tags = array_merge($tags, $this->getMailingList()->getCacheTags());
     }
     $tagging_cache->set($cache_key, $ret, 24 * 3600, $tags);
     return $ret;
 }