/** * @param string url - url to use to access events from * @param string $eventType - Sends, Forwards, Bounces, OptOuts, Opens * @return array - Found CampaignEvents */ public function getCampaignEvents($url, $eventType) { $response = $this->CTCTRequest->makeRequest($url, 'GET'); $parsedResponse = simplexml_load_string($response['xml']); $events = array(); foreach ($parsedResponse->entry as $entry) { $events[] = new CampaignEvent(CampaignEvent::createStruct($entry, $eventType)); } return $events; }
public function clientimpressionAction() { ini_set('display_errors', 1); $frontController = Zend_Controller_Front::getInstance(); $frontController->throwExceptions(true); // filter! if (!$this->clientdashboardfilter()) { return; } $this->view->activeTab = 'clientimpression'; include 'open-flash-chart.php'; $request = $this->getRequest(); if ($request->isPost()) { $formData = $request->getPost(); $campaign_id = $formData['campaign_id']; } else { $campaign_id = $request->getParam('id'); } $this->_helper->layout->setLayout($this->getCampaignTemplate($campaign_id)); $this->view->campaign_id = $campaign_id; // get date from db $db = Zend_Registry::get('db'); $select = $db->select(); $select->from('report', array('left(create_date,10) as date', 'accesscode'))->where('report.campaign_id = ?', $campaign_id)->where('report.state = "APPROVED"')->order('date'); $results = $db->fetchAll($select); $accesscodeDbMatchArray = array(); foreach ($results as $result) { $accesscodeDbMatchArray[$result['accesscode']] = $result['date']; } $accesscodeArray = array_keys($accesscodeDbMatchArray); $campaignModel = new Campaign(); $campaign = $campaignModel->fetchRow('id = ' . $campaign_id); // get impression value from ws $db = Zend_Registry::get('db'); $select = $db->select(); $select->from('dashboard_mapping'); $select->where('survey_id = ?', $campaign->i2_survey_id); $select->where('mark="FRIENDS"'); $mappings = $db->fetchRow($select); $indicate2Connect = new Indicate2_Connect(); $response = $indicate2Connect->getAnswerSetForSurvey(array($campaign->i2_survey_id, $campaign->i2_survey_id_en), null, array(array('ContextIndex' => $mappings['context_index'], 'QuestionIndex' => $mappings['question_index'])), 0); // Zend_Debug::dump($mappings);die; $optionArray = array(); if (isset($response->QuestionType) && is_array($response->QuestionType)) { foreach ($response->QuestionType as $questionType) { foreach ($questionType->SelectionQuestionOptionType as $optionObject) { //get min value, like '11-15' = 11 $optionArray[$optionObject->OptionId] = (int) $optionObject->OptionText; } } } else { if (isset($response->QuestionType->SelectionQuestionOptionType)) { foreach ($response->QuestionType->SelectionQuestionOptionType as $optionObject) { //get min value, like '11-15' = 11 if ($optionObject->OptionText == '>=10') { $optionArray[$optionObject->OptionId] = 10; } $optionArray[$optionObject->OptionId] = (int) $optionObject->OptionText; } } } $answerArray = array(); $i = 0; if (isset($response->AnswerSetType)) { foreach ($response->AnswerSetType as $answerObject) { $answerArray[$i++] = array($answerObject->AccessCode, iconv("UTF-8", "gb18030", preg_replace('/[\\n\\r\\t]/', ' ', base64_decode($answerObject->AnswerType->AnswerText)))); } } // create x axis date value (endDate = expireDate/now + 10 days) $this->view->startDate = $startDate = date("Y-m-d", strtotime($campaign->create_date)); if (strtotime($campaign->expire_date) > strtotime(date("Y-m-d"))) { $this->view->xmax = $endDate = date("Y-m-d", strtotime("+10 days", strtotime(date("Y-m-d")))); } else { $this->view->xmax = $endDate = date("Y-m-d", strtotime("+10 days", strtotime($campaign->expire_date))); } if ($request->isPost()) { $formData = $request->getPost(); $this->view->xmax = $endDate = $formData['x_max']; } $resultArray = array(); $xDateArrayLength = 0; while (1) { $resultArray[$startDate] = 0; $startDate = date("Y-m-d", strtotime("+1 days", strtotime($startDate))); $xDateArrayLength++; if ($startDate == $endDate) { $resultArray[$startDate] = 0; $xDateArrayLength++; break; } } //var_dump($resultArray);die; // set sparks initial impressions for each campaign, it should be added if a new campaign is lanuched! switch ($campaign_id) { case '1': $staticsparks = array(50, 110); break; case '2': $staticsparks = array(50, 150, 250, 400, 450); break; case '3': $staticsparks = array(100, 350, 750, 1200, 1500); break; case '4': $staticsparks = array(50, 200, 250); break; case '5': $staticsparks = array(50, 150); break; case '6': $staticsparks = array(50, 150, 350, 500, 900, 1700, 2300, 2500); break; case '7': $staticsparks = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50, 150, 350, 500, 900, 1038); break; case '8': $staticsparks = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 150, 300, 450, 600, 750, 900, 1000); break; case '9': $staticsparks = array(0, 0, 0, 150, 300, 450, 600, 750, 900, 1000); break; case '10': $staticsparks = array(0, 0, 0, 0, 0, 0, 0, 0, 150, 300, 450, 600, 750, 900, 1000); break; case '13': $staticsparks = array(0, 0, 0, 0, 0, 0, 50, 100, 150, 300, 450, 600, 750, 900, 1200); break; default: break; } for ($temp = count($staticsparks); $temp < $xDateArrayLength; $temp++) { $staticsparks[$temp] = $staticsparks[$temp - 1]; } // set everyday impression by using ws data foreach ($answerArray as $answer) { if (!isset($accesscodeDbMatchArray[$answer[0]])) { continue; } if (date("Y-m-d", strtotime($accesscodeDbMatchArray[$answer[0]])) > date("Y-m-d", strtotime($this->view->xmax))) { continue; } if (!array_key_exists($accesscodeDbMatchArray[$answer[0]], $resultArray)) { $resultArray[$accesscodeDbMatchArray[$answer[0]]] = $optionArray[$answer[1]]; } else { $resultArray[$accesscodeDbMatchArray[$answer[0]]] += $optionArray[$answer[1]]; } } //Zend_Debug::dump($optionArray); //Zend_Debug::dump($resultArray); //Zend_Debug::dump($answerArray); //Zend_Debug::dump($accesscodeDbMatchArray); // set line value $sparks = 0; $data_1 = array(); $data_2min = array(); $data_2max = array(); $data_3min = array(); $data_3max = array(); $i = 0; $data_1[0] = $data_2max[0] = $data_2min[0] = $data_3min[0] = $data_3max[0] = $accumulate = 0; $temp = 0; foreach ($resultArray as $result) { if ($result != 0) { $xTodayLength = $temp; } $temp++; } foreach ($resultArray as $result) { if ($i == 0) { $i++; continue; } $accumulate = $result + $accumulate; $data_1[$i] = $accumulate + $staticsparks[$i]; $data_2min[$i] = floor($accumulate * 2.5 + $staticsparks[$i]); $data_2max[$i] = $accumulate * 5 + $staticsparks[$i]; $data_2avg[$i] = $accumulate * 3.75; $data_3min[$i] = floor($data_2avg[$i] * 3) + $data_2min[$i]; $data_3max[$i] = floor($data_2avg[$i] * 4) + $data_2max[$i]; $max = $data_3max[$i]; if ($i == $xTodayLength) { break; } $i++; } // set max y axis value $dateArray = array_keys($resultArray); $y = new y_axis(); if ($request->isPost()) { $formData = $request->getPost(); $max = $formData['y_max']; } else { if ($max < 10000) { $max = ceil($max / 100) * 100; } else { $max = ceil($max / 1000) * 1000; } } $y->set_range(0, $max, $max / 10); $this->view->ymax = $max; // draw lines $x = new x_axis(); $x_labels = new x_axis_labels(); $x_labels->set_labels($dateArray); $x_labels->set_steps(floor($xDateArrayLength / 42) + 1); $x_labels->rotate(40); $x->set_labels($x_labels); $line_1_default_dot = new dot(); $line_1_default_dot->colour('#007DCD')->tooltip('#x_label#: #val#'); $line_1 = new line(); $line_1->set_default_dot_style($line_1_default_dot); $line_1->set_values($data_1); $line_1->set_colour("#007DCD"); $line_1->set_width(1); $line_2min_default_dot = new dot(); $line_2min_default_dot->colour('#81C909')->tooltip('#x_label#: #val#'); $line_2min = new line(); $line_2min->set_default_dot_style($line_2min_default_dot); $line_2min->set_values($data_2min); $line_2min->set_colour("#81C909"); $line_2min->set_width(1); $line_2_default_dot = new dot(); $line_2_default_dot->colour('#81C909')->tooltip('#x_label#: #val#'); $line_2 = new line(); $line_2->set_default_dot_style($line_2_default_dot); $line_2->set_values($data_2max); $line_2->set_colour("#81C909"); $line_2->set_width(1); $line_3_default_dot = new dot(); $line_3_default_dot->colour('#FF0000')->tooltip('#x_label#: #val#'); $line_3 = new line(); $line_3->set_default_dot_style($line_3_default_dot); $line_3->set_values($data_3min); $line_3->set_colour("#FF0000"); $line_3->set_width(1); $line_3max_default_dot = new dot(); $line_3max_default_dot->colour('#FF0000')->tooltip('#x_label#: #val#'); $line_3max = new line(); $line_3max->set_default_dot_style($line_3max_default_dot); $line_3max->set_values($data_3max); $line_3max->set_colour("#FF0000"); $line_3max->set_width(1); //tags $tags = new ofc_tags(); $tags->font("Verdana", 10)->colour("#2F2F2F")->align_x_right(); $this->view->chart = new open_flash_chart(); // create event $campaignEventModel = new CampaignEvent(); $campaignEvents = $campaignEventModel->fetchAll('campaign_id = ' . $campaign_id, 'event_date'); $eventTotal = count($campaignEvents); $eventTemp = 0; foreach ($campaignEvents as $campaignEvent) { $eventDate = floor((strtotime($campaignEvent->event_date) - strtotime($campaign->create_date)) / 86400); $eventDescription = $campaignEvent->event_name; // event line $eventline = new scatter_line('#C5BE97', 1); $def = new hollow_dot(); $def->size(0)->halo_size(0); $eventline->set_default_dot_style($def); $v = array(new scatter_value($eventDate, 0), new scatter_value($eventDate, $this->view->ymax)); $eventline->set_values($v); $this->view->chart->add_element($eventline); // event description $tagAndArrow_Yvalue = 1 - ($eventTotal - $eventTemp++) / 10; if ($tagAndArrow_Yvalue == 0) { $tagAndArrow_Yvalue = 0.1; } $tag_xvalue = $eventDate + 2; $t = new ofc_tag($tag_xvalue, $this->view->ymax * $tagAndArrow_Yvalue); $t->text($eventDescription)->style(false, false, false, 1.0)->padding(0, 0); $tags->append_tag($t); // event arrow $arrowStart_x = $tag_xvalue; $arrowStart_y = $this->view->ymax * $tagAndArrow_Yvalue; $arrowEnd_x = $tag_xvalue - 1.5; $arrowEnd_y = $this->view->ymax * $tagAndArrow_Yvalue; $arrowColor = '#000000'; $arrowBarbLength = 7; $a = new ofc_arrow($arrowStart_x, $arrowStart_y, $arrowEnd_x, $arrowEnd_y, $arrowColor, $arrowBarbLength); $this->view->chart->add_element($a); } $this->view->chart->add_element($line_1); $this->view->chart->add_element($line_2min); $this->view->chart->add_element($line_2); $this->view->chart->add_element($line_3); $this->view->chart->add_element($line_3max); $this->view->chart->add_element($tags); $this->view->chart->set_y_axis($y); $this->view->chart->set_x_axis($x); $this->view->chart->set_bg_colour('#FFFFFF'); }