Beispiel #1
0
 /**
  * Show a paginated list of campaigns
  *
  * @param int $page
  *
  * @return \Qubes\Defero\Applications\Defero\Views\Campaigns\CampaignsView
  */
 public function renderIndex($page = 1)
 {
     $db = (new Campaign())->connection();
     $postData = $this->request()->postVariables();
     $where = [];
     if ($postData) {
         if ($postData['label'] != "") {
             $where['label'] = $postData['label'];
         }
         if ($postData['active'] != "") {
             $where['active'] = $postData['active'];
         }
         if ($postData['sendType'] != "") {
             $where['send_type'] = $postData['sendType'];
         }
     }
     $query = "SELECT c.id, c.name, c.data_source, t.subject, c.send_type, c.label,\n      c.available_languages, c.active\n      FROM defero_campaign_campaigns c\n      INNER JOIN defero_messages m ON c.id=m.campaign_id\n      INNER JOIN defero_message_translations t ON m.id=t.source_id\n      WHERE t.language='en'";
     foreach ($where as $field => $value) {
         $query .= ' AND c.' . $db->escapeColumnName($field) . "='" . $db->escapeString($value) . "'";
     }
     $query .= ' ORDER BY sort_order';
     /**
      * @var \mysqli_result $results
      */
     $results = $db->query($query);
     $campaigns = [];
     while ($row = $results->fetch_object()) {
         $row->titledSendType = Strings::titleize((new SendType())->constFromValue((string) $row->send_type));
         $row->availableLanguages = json_decode($row->available_languages);
         $campaigns[] = $row;
     }
     $options['sendTypeOptions'] = array_flip((new SendType())->getConstList());
     $options['activeOptions'] = [1 => 'Yes', 0 => 'No'];
     $options['labelOptions'] = Campaign::labels();
     return new CampaignsView($campaigns, $options, $postData);
 }
Beispiel #2
0
 public function getTitledSendType()
 {
     return Strings::titleize($this->sendTypes()->constFromValue((string) $this->sendType));
 }