public function relativeDateTime(Zend_Date $date = null) { if (null === $date) { return $this; } $todayDate = new Zend_Date(); $diff = $todayDate->sub($date); $mt = new Zend_Measure_Time($diff); $units = $mt->getConversionList(); $chunks = array(Zend_Measure_Time::YEAR, Zend_Measure_Time::MONTH, Zend_Measure_Time::WEEK, Zend_Measure_Time::DAY, Zend_Measure_Time::HOUR, Zend_Measure_Time::MINUTE, Zend_Measure_Time::SECOND); for ($i = 0, $count = count($chunks); $i < $count; ++$i) { $seconds = $units[$chunks[$i]][0]; $unitKey = $chunks[$i]; if (0.0 !== ($result = floor($diff->get(Zend_Date::TIMESTAMP) / $seconds))) { break; } } $translateHelper = new Zend_View_Helper_Translate(); if ($result === (double) 1) { $formatedString = $translateHelper->translate($this->getUnitTemplate($unitKey)); } else { $formatedString = $translateHelper->translate($this->getUnitTemplate($unitKey . 'S')); } $formatedString = str_replace('%value%', (string) $result, $formatedString); return $formatedString; }
/** * this method returns the access for the last * 2 weeks. it automatically cleans itself (drops any records older than * 2 weeks.) * */ public function getLog() { $date = new Zend_Date(); $date->sub('2', Zend_Date::WEEK); $this->delete('date_time < ' . $date->get(Zend_Date::TIMESTAMP)); return $this->fetchAll(null, 'date_time DESC'); }
public function andamento($projeto_id) { $porcentagem = 0; $trabalhados = 0; $horas_projeto = 0; $horas_trabalhadas = 0; // dados do projeto $modelProjeto = new Model_DbTable_Projeto(); $projeto = $modelProjeto->getById($projeto_id); $horas_projeto = $projeto->projeto_horas; $modelControleHoras = new Model_DbTable_ControleHoras(); $horas = $modelControleHoras->fetchAll("projeto_id = {$projeto_id}"); foreach ($horas as $hora) { $zendDateInicio = new Zend_Date($hora->controle_horas_data_inicio); $zendDateFim = new Zend_Date($hora->controle_horas_data_fim); $trabalhados += $zendDateFim->sub($zendDateInicio)->get(Zend_Date::TIMESTAMP); } // converte horas trabalhadas para horas $horas_trabalhadas = $trabalhados / 3600; if ($horas_trabalhadas < 1) { return 0; } if ($horas_projeto == 0) { return 100; } $porcentagem = number_format($horas_trabalhadas * 100 / $horas_projeto, 2, '.', ''); return $porcentagem; }
public function pruneOldBackups() { $current_bucket = Mage::getStoreConfig('system/cloudbackup/bucket_name'); if (!$current_bucket) { $this->log("No bucket is set, we cannot prune old backups."); return; } $s3 = Mage::helper('cloudbackup')->getS3Client(); try { $bucket_contents = $s3->getBucket($current_bucket); $cutoff_date = new Zend_Date(); $cutoff_date->sub($this->NUM_MONTHS, Zend_Date::MONTH); foreach ($bucket_contents as $key) { $bucket_date = new Zend_Date($key['time'], Zend_Date::TIMESTAMP); if ($bucket_date->compare($cutoff_date) == -1) { $this->log($key['name'] . " was created on {$bucket_date} and is older than " . $this->NUM_MONTHS . " months, deleting."); $s3->deleteObject($current_bucket, $key['name']); } } } catch (Exception $e) { Mage::logException($e); $this->log("Failed to while pruning old backups - please see exception.log for details."); return; } }
public function isValid($data) { $isValid = parent::isValid($data); if (empty($data['phone_number']) && empty($data['sms_id']) && (empty($data['date_until']) || empty($data['date_from']))) { $this->addErrorMessage('"Data do" i "Data od" sa wymagane jeżeli nie podasz "SMS ID" lub Numeru telefonu'); return false; } if (empty($data['sms_id']) && empty($data['phone_number'])) { try { $dateCheck = new Zend_Date($data['date_from']); if (!$dateCheck->isEarlier($data['date_until']) and 0 != strcmp($data['date_from'], $data['date_until'])) { $isValid = false; $this->addErrorMessage('"Data do" nie może być wcześniejsza niż "Data od"!'); } $dateSub = new Zend_Date($data['date_until']); $config = Zend_Registry::get('config'); if ($dateSub->sub($dateCheck)->toValue('DD') > $config['search']['mail']['filter']['interval']) { $isValid = false; $this->addErrorMessage('Maksymalny okres z jakiego można wyszukiwać dane to ' . $config['search']['sms']['filter']['interval'] . ' dni'); } } catch (Exception $ex) { $this->addErrorMessage($ex->getMessage()); $isValid = false; } } return $isValid; }
/** * Determine selected BlogEntry items to show on this page * * @param int $limit * @return PaginatedList */ public function FilteredBlogEntries($limit = null) { require_once 'Zend/Date.php'; if ($limit === null) { $limit = BlogTree::$default_entries_limit; } // only use freshness if no action is present (might be displaying tags or rss) if ($this->owner->LandingPageFreshness && !$this->owner->request->param('Action')) { $d = new Zend_Date(SS_Datetime::now()->getValue()); $d->sub($this->owner->LandingPageFreshness, Zend_Date::MONTH); $date = $d->toString('YYYY-MM-dd'); $filter = "\"BlogEntry\".\"Date\" > '{$date}'"; } else { $filter = ''; } // allow filtering by author field and some blogs have an authorID field which // may allow filtering by id if (isset($_GET['author']) && isset($_GET['authorID'])) { $author = Convert::raw2sql($_GET['author']); $id = Convert::raw2sql($_GET['authorID']); $filter .= " \"BlogEntry\".\"Author\" LIKE '" . $author . "' OR \"BlogEntry\".\"AuthorID\" = '" . $id . "'"; } else { if (isset($_GET['author'])) { $filter .= " \"BlogEntry\".\"Author\" LIKE '" . Convert::raw2sql($_GET['author']) . "'"; } else { if (isset($_GET['authorID'])) { $filter .= " \"BlogEntry\".\"AuthorID\" = '" . Convert::raw2sql($_GET['authorID']) . "'"; } } } $date = $this->owner->SelectedDate(); return $this->owner->Entries($limit, $this->owner->SelectedTag(), $date ? $date : '', array(get_class($this), 'FilterByDate'), $filter); }
public function indexAction() { /** * Total de clientes */ $modelClientes = new Model_DbTable_Cliente(); $this->view->clientes = $modelClientes->fetchAll(); /** * Total de propostas */ $modelProposta = new Model_DbTable_Proposta(); $propostas = $modelProposta->fetchAll(); $this->view->propostas = $propostas; $total_horas_propostas = 0; $total_valor_propostas = 0; foreach ($propostas as $proposta) { $total_horas_propostas += $proposta->proposta_horas; $total_valor_propostas += $proposta->proposta_valor; } $this->view->total_horas_proposta = $total_horas_propostas; $this->view->total_valor_proposta = $total_valor_propostas; /** * Total de Projetos */ $modelProjeto = new Model_DbTable_Projeto(); $projetos = $modelProjeto->fetchAll(); $this->view->projetos = $projetos; /** * Total Faturamento */ $modelFaturamento = new Model_DbTable_Faturamento(); $faturamentos = $modelFaturamento->fetchAll(); $faturamento_total = 0; $receber = 0; $recebido = 0; foreach ($faturamentos as $faturamento) { if ($faturamento->faturamento_status === self::STATUS_AGUARDANDO_PAGAMENTO) { $receber += $faturamento->faturamento_valor; } if ($faturamento->faturamento_status === self::STATUS_PAGO) { $recebido += $faturamento->faturamento_valor; } $faturamento_total += $faturamento->faturamento_valor; } $this->view->faturamento_total = $faturamento_total; $this->view->receber = $receber; $this->view->recebido = $recebido; /** * Total de Horas Trbalhadas */ $modelControleHoras = new Model_DbTable_ControleHoras(); $horas = $modelControleHoras->fetchAll(); $horas_trabalhadas = 0; foreach ($horas as $hora) { $zendDateInicio = new Zend_Date($hora->controle_horas_data_inicio); $zendDateFim = new Zend_Date($hora->controle_horas_data_fim); $horas_trabalhadas += $zendDateFim->sub($zendDateInicio)->get(Zend_Date::TIMESTAMP); } $this->view->horas = ceil($horas_trabalhadas / 3600); }
public function collectValidatedAttributes($productCollection) { $attribute = $this->getAttribute(); $arr = explode('_', $attribute); $type = $arr[0]; $period = $arr[1]; $date = new Zend_Date(); $date->sub($period * 24 * 60 * 60); $resource = Mage::getSingleton('core/resource'); $connection = $resource->getConnection('core_read'); switch ($type) { case 'clicks': $expr = new Zend_Db_Expr('SUM(clicks)'); break; case 'orders': $expr = new Zend_Db_Expr('SUM(orders)'); break; case 'revenue': $expr = new Zend_Db_Expr('SUM(revenue)'); break; case 'cr': $expr = new Zend_Db_Expr('SUM(orders) / SUM(clicks) * 100'); break; } $select = $connection->select(); $select->from(array('ta' => $resource->getTableName('feedexport/performance_aggregated')), array($expr))->where('ta.product_id = e.entity_id')->where('ta.period >= ?', $date->toString('YYYY-MM-dd')); $select = $productCollection->getSelect()->columns(array($attribute => $select)); return $this; }
/** * Calculate the difference in seconds between closed and opened * * @return int */ public function getTotal() { if ($this->isOpen()) { return 0; } $opened = new Zend_Date($this->opened); $closed = new Zend_Date($this->closed); return $closed->sub($opened); }
/** * This uses the zend framwork date sub function. * Good for subtracting a number of days from a date. * * @param string $datestring MySQL formatted Date String Y-m-d. * @param string number of days to be subtracted. * @return string result date formatted as a MySQL Date Y-m-d. */ public function dateSub($datestring, $numberofdays = 1) { $dateEl = explode("-", $datestring); $datearray = array('year' => date($dateEl[0]), 'month' => date($dateEl[1]), 'day' => date($dateEl[2])); $rmdate = new Zend_Date($datearray); $rmdate->sub($numberofdays, Zend_Date::DAY); $dateVal = $rmdate->toString('Y-m-d'); return $dateVal; }
public function weeklystatsAction() { $this->disableLayout(); $this->disableViewAutoRender(); $type = $this->getParam('type'); $end = new Zend_Date(); $end->setTime('23:59:59'); $date = new Zend_Date(); $date->sub(6, Zend_Date::DAY); $date->setTime('00:00:01'); //Build reference array $i = 0; //echo $end->getTimestamp(); echo "<br>"; while ($i <= 6) { $referencearray[$date->get('dd-MM-YYYY')] = 0; $date->add(1, Zend_Date::DAY); $i++; } //Get the results array $start = new Zend_date(); $start->sub(6, Zend_Date::DAY); $start->setTime('00:00:01'); $stat = new \Object\Stats(); $results = $stat->getStatistics($this->selectedLocation->getId(), $start, $end); $startoftheweek = $start->get('dd-MM-YYYY'); //echo $start->getTimestamp(); echo "<br>";exit; foreach ($this->selectedLocation->getServings() as $serving) { //initiate orderarray and seatsarray $orderarray = $referencearray; $seatsarray = $referencearray; foreach ($results as $result) { $datein = date("d-m-Y", $result["date_start"]); if ($serving->getId() == $result['serving_id']) { $servingid = $result['serving_id']; if (array_key_exists($datein, $referencearray)) { $orderarray[$datein] = $result["nbre"]; $seatsarray[$datein] = $result["couverts"]; } } } if ($type == 'seats') { $servingarray[$serving->getTitle()] = $seatsarray; } else { $servingarray[$serving->getTitle()] = $orderarray; } } $reponse = new Reponse(); $reponse->data = $servingarray; $reponse->message = "TXT_STATS_SENT"; $reponse->success = true; $this->render($reponse); }
/** * Is this current time before the edit deadline? * * Assumes config directive core.presentation.deadline * * @return boolean */ public function isBeforeEditDeadline() { $config = Zend_Registry::get('config'); $tStart = $this->getTable()->getAdapter()->fetchOne("select tstart from vw_sessions left join vw_session_presentations sp" . " ON (vw_sessions.session_id = sp.session_id) where presentation_id=:presentation_id", array(':presentation_id' => $this->presentation_id)); if ($tStart) { $now = new Zend_Date(); $tStart = new Zend_Date($tStart, Zend_Date::ISO_8601); $deadline = $tStart->sub($config->core->presentation->deadline, Zend_Date::SECOND); if ($now->isEarlier($deadline)) { return true; } } return false; }
public function getbookdetailsAction() { self::createModel(); $request = $this->getRequest(); $acc_no = $request->getParam('acc_no'); $objIsbn = new Lib_Model_DbTable_Isbn(); $objIssueReturn = new Lib_Model_DbTable_IssueReturn(); $book = array(); if (isset($acc_no)) { $bookInfo = Lib_Model_DbTable_Book::getBookInfo($acc_no); if (isset($bookInfo['isbn_id'])) { $book = $objIsbn->getIsbnDetails($bookInfo['isbn_id']); $bookIssued = $objIssueReturn->getIssuedBookInfo($acc_no); //$this->_helper->logger($bookIssued); if ($bookIssued) { $issueDate = new Zend_Date($bookIssued['issue_date'], Zend_Date::ISO_8601); $book['member_id'] = $bookIssued['member_id']; $member_limit = Lib_Model_DbTable_MembershipLimit::getMemberLimit($book['member_id'], $bookInfo['document_type_id']); if (isset($_SESSION['dateFormat'])) { $dateFormat = $_SESSION['dateFormat']; } else { $dateFormat = 'dd/MMM/yyyy'; } $book['issue_date'] = $issueDate->toString($dateFormat); $exp_return_date = $issueDate->addDay($member_limit['day_limit']); $day_late = 0; $objtoday = new Zend_Date(Zend_Date::now(), $dateFormat); if ($exp_return_date->isToday() || $objtoday->isEarlier($exp_return_date)) { $day_late = 0; } else { $objtoday->sub($exp_return_date); $day_late = $objtoday->get(Zend_Date::DAY) - 2; } $book['exp_return_date'] = $exp_return_date->toString($dateFormat); $book['day_late'] = $day_late; $bookStatus = 1; } $book['bookInfo'] = $bookInfo; $this->_helper->json($book); //echo Zend_Json::encode($book); } else { $this->getResponse()->setHttpResponseCode(400); echo 'Either the Acc No "' . $acc_no . '" or its corrosponding ISBN is invalid.'; } } else { $this->getResponse()->setHttpResponseCode(400); echo 'Parameters are insufficient to process.'; } }
public function processOldLogs() { $Date = new Zend_Date(); Zend_Date::setOptions(array('extend_month' => true)); $Date->sub(Mage::getStoreConfig(self::XML_PATH_LOGGER_STORE_DAYS), Zend_Date::DAY); $collection = $this->getCollection()->addOlderThanFilter($Date); if (Mage::getStoreConfig(self::XML_PATH_ENABLE_ARCHIVATION)) { $resourceSingleton = Mage::getResourceSingleton('aw_lib/logger'); $sql = $resourceSingleton->getPartInsertSql('aw_lib_logger', $collection->getSelect()); $resourceSingleton->createBackupFile($sql); } foreach ($collection as $entry) { $entry->delete(); } return $this; }
public function fieldBirthdate($subject, $field, $value) { $label = $this->view->locale()->toDate($value->value, array('size' => 'long', 'timezone' => false)); //$str = $this->view->date($value->value); $parts = @explode('-', $value->value); // Error if not filled out if (count($parts) < 3 || count(array_filter($parts)) < 3) { //$this->addError('Please fill in your birthday.'); return false; } $value = mktime(0, 0, 0, $parts[1], $parts[2], $parts[0]); // Error if too low $date = new Zend_Date($value); $age = (int) (-$date->sub(time()) / 365 / 86400); return $this->encloseInLink($subject, $field, $age, $label, true); }
public function validateAge($value) { $parts = @explode('-', $value); // Error if not filled out if (count($parts) < 3 || count(array_filter($parts)) < 3) { //$this->addError('Please fill in your birthday.'); return false; } $value = mktime(0, 0, 0, $parts[1], $parts[2], $parts[0]); // Error if too low $date = new Zend_Date($value); $age = -$date->sub(time()) / 365 / 86400; if ($age < $this->min_age) { //$this->addError('You are not old enough.'); return false; } return true; }
protected function getDiff(Zend_Date $timeThen, $timeNow = null) { if (!$timeNow instanceof Zend_Date) { $timeNow = new Zend_Date(); } $difference = $timeNow->isLater($timeThen) ? $timeNow->sub($timeThen) : $timeThen->sub($timeNow); //$difference = $timeNow->sub($timeThen); $measure = new Zend_Measure_Time($difference->toValue(), Zend_Measure_Time::SECOND); if ($measure->compare(new Zend_Measure_Time(0)) == 0) { return $measure->convertTo(Zend_Measure_Time::SECOND, 0); } $units = array('SECOND' => array('1', 's'), 'MINUTE' => array('60', 'min'), 'HOUR' => array('3600', 'h'), 'DAY' => array('86400', 'day'), 'WEEK' => array('604800', 'week'), 'MONTH' => array('2628600', 'month'), 'YEAR' => array('31536000', 'year')); foreach ($units as $unitId => $unit) { if (is_array($unit) && $unit[0] / abs($measure->getValue(-1)) > 1) { break; } $convertTo = $unitId; } return $measure->convertTo($convertTo, 0); }
public function render(Varien_Object $row) { $html = ''; $weekendsexclude = Mage::getStoreConfig('reminder/timesettings/weekendsexclude'); // Obtain the order/reminder details $incrementid = $row->getIncrementId(); $reminderorders = Mage::getModel('reminder/reminder')->getCollection()->addFieldToFilter('increment_id', $incrementid)->getItems(); $reminderorder = reset($reminderorders); // Obtain the age $now = new Zend_Date(Mage::getModel('core/date')->gmtTimestamp()); $orderdate = new Zend_Date($row->getCreatedAt(), 'yyyy-MM-dd'); $age = $now->sub($orderdate)->toValue(); $days = ceil($age / 60 / 60 / 24); // Obtain the age (weekend excluded) if ($weekendsexclude == 'enabled') { $start_date = new Zend_Date($row->getCreatedAt(), 'yyyy-MM-dd'); $end_date = new Zend_Date($start_date); $dayscounter = $days; $weekenddays = 0; while ($dayscounter > 0) { $weekdaydigit = $end_date->toValue(Zend_Date::WEEKDAY_DIGIT); if ($weekdaydigit == 0 || $weekdaydigit == 6) { $weekenddays++; } $end_date->addDay(1); $dayscounter--; } $days = $days - $weekenddays; } // Display the HTML $html .= $reminderorder->getReminders(); $html .= ' (age: ' . $days . ')'; $html .= '<br/><a href="' . $this->getUrl('*/*/manipulate/option/add/id/' . $row->getIncrementId()) . '">' . Mage::helper('reminder')->__('add') . ' 1</a>'; $html .= '<br/><a href="' . $this->getUrl('*/*/manipulate/option/sub/id/' . $row->getIncrementId()) . '">' . Mage::helper('reminder')->__('remove') . ' 1</a>'; $html .= '<br/><a href="' . $this->getUrl('*/*/manipulate/option/reset/id/' . $row->getIncrementId()) . '">' . Mage::helper('reminder')->__('reset to') . ' 0</a>'; return $html; }
public function indexAction() { if (!$this->_helper->requireUser->isValid()) { return; } $viewer = Engine_Api::_()->user()->getViewer(); $sysTimezone = date_default_timezone_get(); $timezone = Engine_Api::_()->getApi('settings', 'core')->getSetting('core_locale_timezone', 'GMT'); if ($viewer && $viewer->getIdentity() && !empty($viewer->timezone)) { $timezone = $viewer->timezone; } $this->view->timezone = $timezone; if (null == ($campaign_id = $this->_getParam('campaign_id'))) { $campaign_id = 0; } if (null == ($ad_id = $this->_getParam('ad_id'))) { $ad_id = 0; } if (null == ($export = $this->_getParam('export'))) { $export = 0; } if (null == ($export_type = $this->_getParam('export_type'))) { $export_type = 'xls'; } $this->view->form = $form = new Ynsocialads_Form_Report_Filter(); $form->populate($this->_getAllParams()); $values = $form->getValues(); $this->view->formValues = $values; if ($this->_hasParam('end_date')) { $end = $this->_getParam('end_date'); if ($end && !is_numeric($end)) { $end_date = strtotime($end); } else { if ($end) { $end_date = $end; } } $end_date = new Zend_Date($end_date); } else { $end_date = new Zend_Date(); } if ($this->_hasParam('start_date')) { $start = $this->_getParam('start_date'); if ($start && !is_numeric($start)) { $start_date = strtotime($start); } else { if ($start) { $start_date = $start; } } $start_date = new Zend_Date($start_date); } else { $start_date = new Zend_Date($end_date->getTimestamp()); $start_date->sub(1, 'dd'); } $form->start_date->setValue($start_date->setLocale()->get('MM/dd/yyyy')); $form->end_date->setValue($end_date->setLocale()->get('MM/dd/yyyy')); $end_date->setTimezone($sysTimezone); $start_date->setTimezone($sysTimezone); $campaignTbl = Engine_Api::_()->getItemTable('ynsocialads_campaign'); $select = $campaignTbl->select()->where('user_id = ?', $viewer->getIdentity()); $campaigns = $campaignTbl->fetchAll($select); foreach ($campaigns as $campaign) { $form->campaign_id->addMultiOption($campaign['campaign_id'], $campaign['title']); } $form->campaign_id->setValue($campaign_id); $adTbl = Engine_Api::_()->getDbtable('ads', 'ynsocialads'); $adTotal = array(); if ($campaign_id == 0) { $form->ad_id->setAttrib('disabled', 'disabled'); foreach ($campaigns as $campaign) { $adList = $adTbl->fetchAll($adTbl->select()->where('campaign_id = ?', $campaign['campaign_id'])); foreach ($adList as $ad) { $adTotal[] = $ad->ad_id; } } } else { $ads = $adTbl->fetchAll($adTbl->select('ad_id')->where('campaign_id = ?', $campaign_id)); foreach ($ads as $ad) { $form->ad_id->addMultiOption($ad['ad_id'], $ad['name']); if ($ad_id == 0) { array_push($adTotal, $ad['ad_id']); } } if ($ad_id != 0) { $adTotal = array($ad_id); } $form->ad_id->setValue($ad_id); } $staTable = Engine_Api::_()->getDbtable('tracks', 'ynsocialads'); $staName = $staTable->info('name'); $select = $staTable->select(); $select->where('ad_id IN (?)', $adTotal)->where('date >= ?', $start_date->get('yyyy-MM-dd'))->where('date <= ?', $end_date->get('yyyy-MM-dd'))->order('ad_id ASC'); if (count($adTotal)) { $tracks = $staTable->fetchAll($select); } else { $tracks = array(); } if ($export == 0) { $page = $this->_getParam('page', 1); $this->view->paginator = $paginator = Zend_Paginator::factory($tracks); $this->view->paginator->setItemCountPerPage(10); $this->view->paginator->setCurrentPageNumber($page); $this->_helper->content->setEnabled(); } else { //export to file $filename = "/tmp/csv-" . date("m-d-Y") . ".csv"; $realPath = realpath($filename); if (false === $realPath) { touch($filename); chmod($filename, 0777); } $filename = realpath($filename); $handle = fopen($filename, "w"); $finalData[] = array(utf8_decode($this->view->translate('Date')), utf8_decode($this->view->translate('Ad')), utf8_decode($this->view->translate('Campaign')), utf8_decode($this->view->translate('Start Date')), utf8_decode($this->view->translate('End Date')), utf8_decode($this->view->translate('Running Date')), utf8_decode($this->view->translate('Reaches')), utf8_decode($this->view->translate('Impressions')), utf8_decode($this->view->translate('Clicks')), utf8_decode($this->view->translate('Unique Clicks'))); foreach ($tracks as $item) { $ad = Engine_Api::_()->getItem('ynsocialads_ad', $item['ad_id']); $date = new Zend_Date(strtotime($item['date'])); $finalData[] = array($date->setLocale()->get(Zend_Date::DATE_LONG), $ad->getTitle(), $ad->getCampaign()->getTitle(), $ad->start_date ? utf8_decode($ad->getStartDate()->setLocale()->get(Zend_Date::DATE_LONG)) : '', $ad->end_date ? utf8_decode($ad->getEndDate()->setLocale()->get(Zend_Date::DATE_LONG)) : '', $ad->getRunningDate()->setLocale()->get(Zend_Date::DATE_LONG), $item['reaches'], $item['impressions'], $item['clicks'], $item['unique_clicks']); } if ($export_type == 'xls') { $xls = new Ynsocialads_Api_ExcelExport('UTF-8', false, $start_date->setLocale()->get('MM_dd_YYYY') . '_' . $end_date->setLocale()->get('MM_dd_YYYY')); $xls->addArray($finalData); $xls->generateXML('campaign' . $campaign_id . '_ad' . $ad_id . '_' . $start_date->setLocale()->get('MM_dd_YYYY') . '_' . $end_date->setLocale()->get('MM_dd_YYYY')); exit; } else { foreach ($finalData as $finalRow) { fputcsv($handle, $finalRow); } fclose($handle); $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $csvname = 'campaign' . $campaign_id . '_ad' . $ad_id . '_' . $start_date->setLocale()->get('MM_dd_YYYY') . '_' . $end_date->setLocale()->get('MM_dd_YYYY') . '.csv'; $this->getResponse()->setRawHeader("Content-Type: application/csv; charset=UTF-8")->setRawHeader("Content-Disposition: attachment; filename=" . $csvname)->setRawHeader("Content-Transfer-Encoding: binary")->setRawHeader("Expires: 0")->setRawHeader("Cache-Control: must-revalidate, post-check=0, pre-check=0")->setRawHeader("Pragma: public")->setRawHeader("Content-Length: " . filesize($filename))->sendResponse(); // fix for print out data readfile($filename); unlink($filename); exit; } } }
public function chartDataAction() { // Disable layout and viewrenderer $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); // Get params $type = $this->_getParam('type'); $start = $this->_getParam('start'); $offset = $this->_getParam('offset', 0); $mode = $this->_getParam('mode'); $chunk = $this->_getParam('chunk'); $period = $this->_getParam('period'); $periodCount = $this->_getParam('periodCount', 1); //$end = $this->_getParam('end'); // Validate chunk/period if (!$chunk || !in_array($chunk, $this->_periods)) { $chunk = Zend_Date::DAY; } if (!$period || !in_array($period, $this->_periods)) { $period = Zend_Date::MONTH; } if (array_search($chunk, $this->_periods) >= array_search($period, $this->_periods)) { die('whoops'); return; } // Validate start if ($start && !is_numeric($start)) { $start = strtotime($start); } if (!$start) { $start = time(); } // Fixes issues with month view Zend_Date::setOptions(array('extend_month' => true)); // Get timezone $timezone = Engine_Api::_()->getApi('settings', 'core')->getSetting('core_locale_timezone', 'GMT'); $viewer = Engine_Api::_()->user()->getViewer(); if ($viewer && $viewer->getIdentity() && !empty($viewer->timezone)) { $timezone = $viewer->timezone; } // Make start fit to period? $startObject = new Zend_Date($start); $startObject->setTimezone($timezone); $partMaps = $this->_periodMap[$period]; foreach ($partMaps as $partType => $partValue) { $startObject->set($partValue, $partType); } // Do offset if ($offset != 0) { $startObject->add($offset, $period); } // Get end time $endObject = new Zend_Date($startObject->getTimestamp()); $endObject->setTimezone($timezone); $endObject->add($periodCount, $period); $endObject->sub(1, Zend_Date::SECOND); // Subtract one second // Get data $statsTable = Engine_Api::_()->getDbtable('statistics', 'core'); $statsSelect = $statsTable->select()->where('type = ?', $type)->where('date >= ?', gmdate('Y-m-d H:i:s', $startObject->getTimestamp()))->where('date < ?', gmdate('Y-m-d H:i:s', $endObject->getTimestamp()))->order('date ASC'); $rawData = $statsTable->fetchAll($statsSelect); // Now create data structure $currentObject = clone $startObject; $nextObject = clone $startObject; $data = array(); $dataLabels = array(); $cumulative = 0; $previous = 0; do { $nextObject->add(1, $chunk); $currentObjectTimestamp = $currentObject->getTimestamp(); $nextObjectTimestamp = $nextObject->getTimestamp(); $data[$currentObjectTimestamp] = $cumulative; // Get everything that matches $currentPeriodCount = 0; foreach ($rawData as $rawDatum) { $rawDatumDate = strtotime($rawDatum->date); if ($rawDatumDate >= $currentObjectTimestamp && $rawDatumDate < $nextObjectTimestamp) { $currentPeriodCount += $rawDatum->value; } } // Now do stuff with it switch ($mode) { default: case 'normal': $data[$currentObjectTimestamp] = $currentPeriodCount; break; case 'cumulative': $cumulative += $currentPeriodCount; $data[$currentObjectTimestamp] = $cumulative; break; case 'delta': $data[$currentObjectTimestamp] = $currentPeriodCount - $previous; $previous = $currentPeriodCount; break; } $currentObject->add(1, $chunk); } while ($currentObject->getTimestamp() < $endObject->getTimestamp()); // Reprocess label $labelStrings = array(); $labelDate = new Zend_Date(); foreach ($data as $key => $value) { $labelDate->set($key); $labelStrings[] = $this->view->locale()->toDate($labelDate, array('size' => 'short')); //date('D M d Y', $key); } // Let's expand them by 1.1 just for some nice spacing $minVal = min($data); $maxVal = max($data); $minVal = floor($minVal * ($minVal < 0 ? 1.1 : 1 / 1.1) / 10) * 10; $maxVal = ceil($maxVal * ($maxVal > 0 ? 1.1 : 1 / 1.1) / 10) * 10; // Remove some labels if there are too many $xlabelsteps = 1; if (count($data) > 10) { $xlabelsteps = ceil(count($data) / 10); } // Remove some grid lines if there are too many $xsteps = 1; if (count($data) > 100) { $xsteps = ceil(count($data) / 100); } // Create base chart require_once 'OFC/OFC_Chart.php'; // Make x axis labels $x_axis_labels = new OFC_Elements_Axis_X_Label_Set(); $x_axis_labels->set_steps($xlabelsteps); $x_axis_labels->set_labels($labelStrings); // Make x axis $labels = new OFC_Elements_Axis_X(); $labels->set_labels($x_axis_labels); $labels->set_colour("#416b86"); $labels->set_grid_colour("#dddddd"); $labels->set_steps($xsteps); // Make y axis $yaxis = new OFC_Elements_Axis_Y(); $yaxis->set_range($minVal, $maxVal); $yaxis->set_colour("#416b86"); $yaxis->set_grid_colour("#dddddd"); // Make data $graph = new OFC_Charts_Line(); $graph->set_values(array_values($data)); $graph->set_colour("#5ba1cd"); // Make title $locale = Zend_Registry::get('Locale'); $translate = Zend_Registry::get('Zend_Translate'); $titleStr = $translate->_('_CORE_ADMIN_STATS_' . strtoupper(trim(preg_replace('/[^a-zA-Z0-9]+/', '_', $type), '_'))); $title = new OFC_Elements_Title($titleStr . ': ' . $this->view->locale()->toDateTime($startObject) . ' to ' . $this->view->locale()->toDateTime($endObject)); $title->set_style("{font-size: 14px;font-weight: bold;margin-bottom: 10px; color: #777777;}"); // Make full chart $chart = new OFC_Chart(); $chart->set_bg_colour('#ffffff'); $chart->set_x_axis($labels); $chart->add_y_axis($yaxis); $chart->add_element($graph); $chart->set_title($title); // Send $this->getResponse()->setBody($chart->toPrettyString()); }
/** * Instancia o formulario de emissão de RPS * * @param string $sCodigoVerificacao Código de Verificação * @param Contribuinte_Model_ContribuinteAbstract $oContribuinte Dados do contribuinte * @return Contribuinte_Form_Nota */ private function formNota($sCodigoVerificacao, Contribuinte_Model_ContribuinteAbstract $oContribuinte = NULL) { // Seta o contribuinte da sessão se não for enviado por parâmetro $oContribuinte = $oContribuinte ? $oContribuinte : $this->_session->contribuinte; $iIdContribuinte = $oContribuinte->getIdUsuarioContribuinte(); $maxNota = 0; $maxGuia = 0; $aListaIdContribuinte = $oContribuinte->getContribuintes(); // Calcula quantos dias no passado a nota pode ser emtidida $oParametrosPrefeitura = Administrativo_Model_Prefeitura::getDadosPrefeituraBase(); $max = $oParametrosPrefeitura->getNotaRetroativa(); $oUltimaGuia = Contribuinte_Model_Guia::getUltimaGuiaNota($oContribuinte); $uDataUltimaNota = Contribuinte_Model_Nota::getUltimaNotaEmitidaByContribuinte($aListaIdContribuinte); $dia = new DateTime(); if ($oUltimaGuia != NULL) { if ($oUltimaGuia->getMesComp() + 1 > 12) { $iMes = 1; } else { $iMes = $oUltimaGuia->getMesComp(); } $uDataUltimoDiaCompetencia = new Zend_Date("01/{$iMes}/{$oUltimaGuia->getAnoComp()}"); $uDataUltimoDiaCompetencia->sub(1, Zend_date::DAY); $diff = $dia->diff(new DateTime($uDataUltimoDiaCompetencia->get('YYYY-MM-dd')), TRUE); $maxGuia = $diff->d < $max ? $diff->d : $max; } if ($uDataUltimaNota != NULL) { $diff = $dia->diff(new DateTime($uDataUltimaNota), TRUE); $maxNota = $diff->d < $max ? $diff->d : $max; } if ($maxNota - $maxGuia < $maxGuia) { $max = $maxGuia - 1; } else { if ($maxNota > 0) { $max = $maxNota; } else { $max = 0; } } $dia = $dia->sub(new DateInterval('P' . $max . 'D')); $oForm = new Contribuinte_Form_Nota($sCodigoVerificacao, $dia, '/contribuinte/rps/index', TRUE); if ($oContribuinte !== NULL) { $oParametros = Contribuinte_Model_ParametroContribuinte::getById($iIdContribuinte); $oForm->preencheParametros($oParametros); } return $oForm; }
/** * */ public function calcDiffDaysAction() { $dateInit = new Zend_Date($this->_getParam('date_start')); $dateFinish = new Zend_Date($this->_getParam('date_finish')); $diff = $dateFinish->sub($dateInit); $measure = new Zend_Measure_Time($diff->toValue(), Zend_Measure_Time::SECOND); $diffDays = $measure->convertTo(Zend_Measure_Time::DAY, 0); $this->_helper->json(array('diff' => preg_replace('/[^0-9]/i', '', $diffDays) + 1)); }
/** * test looseBehaviour */ public function testLoose() { $date = new Zend_Date(0, 'de_DE'); try { $date->set(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->set(10, 'de_DE'); $this->assertEquals(10, $date->getTimestamp()); try { $date->add(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->add(10, 'de_DE'); $this->assertEquals(20, $date->getTimestamp()); try { $date->sub(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->sub(10, 'de_DE'); $this->assertEquals(10, $date->getTimestamp()); try { $date->compare(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->equals(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->isEarlier(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->isLater(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setTime(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addTime(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subTime(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareTime(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setDate(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addDate(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subDate(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareDate(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setIso(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addIso(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subIso(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareIso(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setArpa(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addArpa(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subArpa(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareArpa(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setMonth(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addMonth(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subMonth(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareMonth(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setDay(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addDay(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subDay(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareDay(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setWeekday(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addWeekday(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subWeekday(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareWeekday(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setDayOfYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addDayOfYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subDayOfYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareDayOfYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setHour(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addHour(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subHour(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareHour(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setMinute(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addMinute(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subMinute(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareMinute(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setSecond(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addSecond(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subSecond(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareSecond(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setWeek(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addWeek(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subWeek(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareWeek(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } }
/** * Report pause payment action. * * Reports the payment pause to payment provider. */ public function pauseAction() { $transactionId = $this->Request()->getParam('transactionID'); $pause = new Zend_Date($this->Request()->getParam('pause')); $now = new Zend_Date(); $now->setHour(0)->setMinute(0)->setSecond(0); $pause->sub($now); $pause = round($pause->getTimestamp() / 60 / 60 / 24); $pause = $pause > 10 ? 10 : $pause; try { $client = Shopware()->BillsafeClient(); $client->setEncoding('UTF-8'); $result = $client->pauseTransaction(array( 'transactionId' => $transactionId, 'pause' => $pause )); if($result->ack == 'ERROR') { throw new Exception($result->errorList->message, $result->errorList->code); } $this->setPaymentStatus($transactionId, 19); // Verzoegert $this->View()->assign(array('success' => true)); } catch (Exception $e) { $this->View()->assign(array('message' => $e->getMessage(), 'success' => false)); } }
/** * Test for sub */ public function testSub() { $locale = new Zend_Locale('de_AT'); $date = new Zend_Date(0, null, $locale); $d2 = new Zend_Date(1010101010, null, $locale); $retour = $date->set(1234567890); $this->assertSame((string) $retour, '1234567890'); $this->assertSame((string) $date->sub(-10), '1234567900'); $this->assertSame((string) $date->sub(10), '1234567890'); $this->assertSame((string) $date->sub(0), '1234567890'); $date->set($d2); $date->sub(-10, Zend_Date::DAY); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-14T00:36:50+01:00'); $date->sub(10, Zend_Date::DAY); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:50+01:00'); $date->set($d2); $date->sub('Mon', Zend_Date::WEEKDAY_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-03T00:36:50+01:00'); $date->set($d2); $date->sub(-10, Zend_Date::DAY_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-14T00:36:50+01:00'); $date->sub(10, Zend_Date::DAY_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:50+01:00'); $date->set($d2); $date->sub('Montag', Zend_Date::WEEKDAY); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-03T00:36:50+01:00'); $date->set($d2); $date->sub(1, Zend_Date::WEEKDAY_8601); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-03T00:36:50+01:00'); $date->set($d2); try { $date->sub($d2, Zend_Date::DAY_SUFFIX); $this->fail('exception expected'); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); $date->sub(1, Zend_Date::WEEKDAY_DIGIT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-02T00:36:50+01:00'); $date->set($d2); $date->sub(-10, Zend_Date::DAY_OF_YEAR); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-14T00:36:50+01:00'); $date->sub(10, Zend_Date::DAY_OF_YEAR); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:50+01:00'); $date->set($d2); $date->sub('M', Zend_Date::WEEKDAY_NARROW); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-03T00:36:50+01:00'); $date->set($d2); $date->sub('Mo', Zend_Date::WEEKDAY_NAME); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-03T00:36:50+01:00'); $date->set($d2); $date->sub(-10, Zend_Date::WEEK); $this->assertSame($date->get(Zend_Date::W3C), '2002-03-15T00:36:50+01:00'); $date->sub(10, Zend_Date::WEEK); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:50+01:00'); $date->set($d2); $date->sub('April', Zend_Date::MONTH); $this->assertSame($date->get(Zend_Date::W3C), '2001-09-06T01:36:50+02:00'); $date->set($d2); $date->sub(-10, Zend_Date::MONTH_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '2002-11-06T00:36:50+01:00'); $date->sub(10, Zend_Date::MONTH_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-06T00:36:50+01:00'); $date->set($d2); $date->sub('Apr', Zend_Date::MONTH_NAME); $this->assertSame($date->get(Zend_Date::W3C), '2001-09-06T01:36:50+02:00'); $date->set($d2); $date->sub(-10, Zend_Date::MONTH_DIGIT); $this->assertSame($date->get(Zend_Date::W3C), '2002-11-06T00:36:50+01:00'); $date->sub(10, Zend_Date::MONTH_DIGIT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-06T00:36:50+01:00'); $date->set($d2); try { $date->sub($d2, Zend_Date::MONTH_DAYS); $this->fail('exception expected'); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); $date->sub('M', Zend_Date::MONTH_NARROW); $this->assertSame($date->get(Zend_Date::W3C), '2001-10-06T01:36:50+02:00'); $date->set($d2); try { $date->sub($d2, Zend_Date::LEAPYEAR); $this->fail('exception expected'); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); $date->sub(-10, Zend_Date::YEAR_8601); $this->assertSame($date->get(Zend_Date::W3C), '2012-01-05T00:36:50+01:00'); $date->sub(10, Zend_Date::YEAR_8601); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-05T00:36:50+01:00'); $date->set($d2); $date->sub(-10, Zend_Date::YEAR); $this->assertSame($date->get(Zend_Date::W3C), '2012-01-05T00:36:50+01:00'); $date->sub(10, Zend_Date::YEAR); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-05T00:36:50+01:00'); $date->set($d2); $date->sub(10, Zend_Date::YEAR_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '-8-01-07T00:36:50+01:00'); try { $date->sub(-10, Zend_Date::YEAR_SHORT); $this->fail('exception expected'); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); $date->sub(10, Zend_Date::YEAR_SHORT_8601); $this->assertSame($date->get(Zend_Date::W3C), '-8-01-07T00:36:50+01:00'); try { $date->sub(-10, Zend_Date::YEAR_SHORT_8601); $this->fail('exception expected'); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); try { $date->sub('noday', Zend_Date::MERIDIEM); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); $date->sub(-10, Zend_Date::SWATCH); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:51:15+01:00'); $date->sub(10, Zend_Date::SWATCH); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:51+01:00'); $date->set($d2); $date->sub(-10, Zend_Date::HOUR_SHORT_AM); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T10:36:50+01:00'); $date->sub(10, Zend_Date::HOUR_SHORT_AM); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:50+01:00'); $date->set($d2); $date->sub(-10, Zend_Date::HOUR_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T10:36:50+01:00'); $date->sub(10, Zend_Date::HOUR_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:50+01:00'); $date->set($d2); $date->sub(-10, Zend_Date::HOUR_AM); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T10:36:50+01:00'); $date->sub(10, Zend_Date::HOUR_AM); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:50+01:00'); $date->set($d2); $date->sub(-10, Zend_Date::HOUR); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T10:36:50+01:00'); $date->sub(10, Zend_Date::HOUR); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:50+01:00'); $date->set($d2); $date->sub(-10, Zend_Date::MINUTE); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:46:50+01:00'); $date->sub(10, Zend_Date::MINUTE); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:50+01:00'); $date->set($d2); $date->sub(-10, Zend_Date::MINUTE_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:46:50+01:00'); $date->sub(10, Zend_Date::MINUTE_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:50+01:00'); $date->set($d2); $date->sub(-10, Zend_Date::SECOND); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:37:00+01:00'); $date->sub(10, Zend_Date::SECOND); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:50+01:00'); $date->set($d2); $date->sub(-10, Zend_Date::SECOND_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:37:00+01:00'); $date->sub(10, Zend_Date::SECOND_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:50+01:00'); $date->set($d2); $date->sub(-10, Zend_Date::MILLISECOND); $this->assertSame($date->get(Zend_Date::MILLISECOND), 10); $date->sub(10, Zend_Date::MILLISECOND); $this->assertSame($date->get(Zend_Date::MILLISECOND), 0); $date->set($d2); try { $date->sub('noday', Zend_Date::TIMEZONE_NAME); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); try { $date->sub('noday', Zend_Date::DAYLIGHT); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); try { $date->sub('noday', Zend_Date::GMT_DIFF); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); try { $date->sub('noday', Zend_Date::GMT_DIFF_SEP); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); try { $date->sub('noday', Zend_Date::TIMEZONE); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); try { $date->sub('noday', Zend_Date::TIMEZONE_SECS); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); $date->sub('1000-01-02 20:05:12', Zend_Date::ISO_8601); $this->assertSame($date->get(Zend_Date::W3C), '1001-11-25T04:31:38+01:00'); $date->set($d2); $date->sub('1000-01-02T20:05:12+01:00', Zend_Date::ISO_8601); $this->assertSame($date->get(Zend_Date::W3C), '1001-11-25T04:31:38+01:00'); $date->set($d2); $date->sub('Thu, 02 Jan 1000 20:05:12 +0100', Zend_Date::RFC_2822); $this->assertSame($date->get(Zend_Date::W3C), '1001-11-25T04:31:38+01:00'); $date->set($d2); $date->sub(-10, Zend_Date::TIMESTAMP); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:37:00+01:00'); $date->set($d2); try { $date->sub('noday', Zend_Date::ERA); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); try { $date->sub('noday', Zend_Date::ERA_NAME); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); $date->sub('10.02.0005', Zend_Date::DATES); $this->assertSame($date->get(Zend_Date::W3C), '1996-10-27T01:36:50+02:00'); $date->set($d2); $date->sub('Samstag, 10. Februar 0005', Zend_Date::DATE_FULL); $this->assertSame($date->get(Zend_Date::W3C), '1996-10-27T01:36:50+02:00'); $date->set($d2); $date->sub('10. Februar 0005', Zend_Date::DATE_LONG); $this->assertSame($date->get(Zend_Date::W3C), '1996-10-27T01:36:50+02:00'); $date->set($d2); $date->sub('10.02.0005', Zend_Date::DATE_MEDIUM); $this->assertSame($date->get(Zend_Date::W3C), '1996-10-27T01:36:50+02:00'); $date->set($d2); $date->sub('10.02.05', Zend_Date::DATE_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '-4-10-29T00:36:50+01:00'); $date->set($d2); $date->sub('10:05:05', Zend_Date::TIMES); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-03T14:31:45+01:00'); $date->set($d2); $date->sub('10:05 Uhr CET', Zend_Date::TIME_FULL); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-03T14:31:50+01:00'); $date->set($d2); $date->sub('10:05:05 CET', Zend_Date::TIME_LONG); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-03T14:31:45+01:00'); $date->set($d2); $date->sub('10:05:05', Zend_Date::TIME_MEDIUM); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-03T14:31:45+01:00'); $date->set($d2); $date->sub('10:05', Zend_Date::TIME_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-03T14:31:50+01:00'); $date->set($d2); $date->sub('1000-01-02T20:05:12+01:00', Zend_Date::ATOM); $this->assertSame($date->get(Zend_Date::W3C), '1001-11-25T04:31:38+01:00'); $date->set($d2); $date->sub('Saturday, 02-Jan-00 20:05:12 Europe/Vienna', Zend_Date::COOKIE); $this->assertSame($date->get(Zend_Date::W3C), '1-12-03T04:31:38+01:00'); $date->set($d2); $date->sub('Sat, 02 Jan 00 20:05:12 +0100', Zend_Date::RFC_822); $this->assertSame($date->get(Zend_Date::W3C), '1-12-03T04:31:38+01:00'); $date->set($d2); $date->sub('Saturday, 02-Jan-00 20:05:12 Europe/Vienna', Zend_Date::RFC_850); $this->assertSame($date->get(Zend_Date::W3C), '1-12-03T04:31:38+01:00'); $date->set($d2); $date->sub('Sat, 02 Jan 00 20:05:12 +0100', Zend_Date::RFC_1036); $this->assertSame($date->get(Zend_Date::W3C), '1-12-03T04:31:38+01:00'); $date->set($d2); $date->sub('Sat, 02 Jan 1000 20:05:12 +0100', Zend_Date::RFC_1123); $this->assertSame($date->get(Zend_Date::W3C), '1001-11-25T04:31:38+01:00'); $date->set($d2); $date->sub('1000-01-02T20:05:12+01:00', Zend_Date::RFC_3339); $this->assertSame($date->get(Zend_Date::W3C), '1001-11-25T04:31:38+01:00'); $date->set($d2); $date->sub('Sat, 02 Jan 1000 20:05:12 +0100', Zend_Date::RSS); $this->assertSame($date->get(Zend_Date::W3C), '1001-11-25T04:31:38+01:00'); $date->set($d2); $date->sub('1000-01-02T20:05:12+01:00', Zend_Date::W3C); $this->assertSame($date->get(Zend_Date::W3C), '1001-11-25T04:31:38+01:00'); $date->set($d2); $date->sub('1000', 'xx'); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:20:10+01:00'); }
/** * * @param int $feContract * @return string */ public function getFEGreaterDuration($feContract) { $view = Zend_Layout::getMvcInstance()->getView(); $link = '<a href="%s" target="_blank">%s</a>'; $feContractNum = Fefop_Model_Mapper_Contract::buildNumRow($feContract); $feLink = sprintf($link, $view->baseUrl('/fefop/fe-contract/edit/id/' . $feContract->id_fe_contract), $feContractNum); $measure = new Zend_Measure_Time(Fefop_Model_Mapper_FEContract::MOUNTH_LIMIT, Zend_Measure_Time::MONTH); $diffMonths = $measure->convertTo(Zend_Measure_Time::MONTH, 0); $dateInit = new Zend_Date($feContract->date_start); $dateFinish = new Zend_Date($feContract->date_finish); $diff = $dateFinish->sub($dateInit); $measure = new Zend_Measure_Time($diff->toValue(), Zend_Measure_Time::SECOND); $diiffMonth = $measure->convertTo(Zend_Measure_Time::MONTH, 0); return sprintf(self::FE_DURATION_GREATER, $feLink, $diffMonths, $diiffMonth); }
public function coldChainCapacityAction() { $id = $this->_request->getParam('id', ''); if ($id == 4 || $id == "") { $form = new Form_Maps_Mos(); $form->province->setValue($this->_identity->getProvinceId()); $form->coldchain_type->setValue('1'); $date = new Zend_Date(); $day = $date->get(Zend_Date::DAY); if ($day > 10) { $date->sub('1', 'MM'); } else { $date->sub('2', 'MM'); } $form->year->setValue($date->get(Zend_Date::YEAR)); $form->month->setValue($date->get(Zend_Date::MONTH)); $this->view->form = $form; $this->render('cold-chain-district'); $baseurl = Zend_Registry::get('baseurl'); $this->view->headLink()->appendStylesheet($baseurl . '/css/default/maps/map.css'); $this->view->inlineScript()->appendFile($baseurl . '/js/default/maps/symbology.js'); $this->view->inlineScript()->appendFile($baseurl . '/js/default/maps/ccc-district.js'); $this->view->inlineScript()->appendFile($baseurl . '/js/default/maps/IntervalLegend.js'); $this->view->inlineScript()->appendFile($baseurl . '/js/default/maps/Filter.js'); $this->view->inlineScript()->appendFile($baseurl . '/js/default/maps/refineLegend.js'); $this->view->inlineScript()->appendFile($baseurl . '/js/default/maps/download.js'); } else { $form = new Form_Maps_Mos(); if ($this->_identity->getProvinceId()) { $form->prov->setValue($this->_identity->getProvinceId()); } if ($this->_identity->getDistrictId()) { $form->dist->setValue($this->_identity->getDistrictId()); } else { $form->dist->setValue('33'); } $form->coldchain_type->setValue('1'); $date = new Zend_Date(); $day = $date->get(Zend_Date::DAY); if ($day > 10) { $date->sub('1', 'MM'); } else { $date->sub('2', 'MM'); } $form->year->setValue($date->get(Zend_Date::YEAR)); $form->month->setValue($date->get(Zend_Date::MONTH)); $this->view->form = $form; $this->render('cold-chain-tehsil'); $baseurl = Zend_Registry::get('baseurl'); $this->view->headLink()->appendStylesheet($baseurl . '/css/default/maps/map.css'); $this->view->inlineScript()->appendFile($baseurl . '/js/default/maps/symbology.js'); $this->view->inlineScript()->appendFile($baseurl . '/js/default/maps/ccc-tehsil.js'); $this->view->inlineScript()->appendFile($baseurl . '/js/default/maps/IntervalLegend.js'); $this->view->inlineScript()->appendFile($baseurl . '/js/default/maps/Filter.js'); $this->view->inlineScript()->appendFile($baseurl . '/js/default/maps/refineLegend.js'); $this->view->inlineScript()->appendFile($baseurl . '/js/default/maps/download.js'); } }
/** * This function just butchers the date to subtract 5 hours to make webleads work correctly * @param None * @return ZendDate object offset by 5 hours * @author John Burrin */ private function _offsetDate() { $date = new Zend_Date(); // changes $date by subtracting 5 hours $date->sub('5', Zend_Date::HOUR); return $date; }
public function chartAction() { // Disable layout and viewrenderer $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); $viewer = Engine_Api::_()->user()->getViewer(); // Get params $start = $this->_getParam('start'); $offset = $this->_getParam('offset', 0); $type = $this->_getParam('type', 'all'); $mode = $this->_getParam('mode'); $chunk = $this->_getParam('chunk'); $period = $this->_getParam('period'); $periodCount = $this->_getParam('periodCount', 1); $campaign_ids = $this->_getParam('campaign_ids'); // Validate chunk/period if (!$chunk || !in_array($chunk, $this->_periods)) { $chunk = Zend_Date::DAY; } if (!$period || !in_array($period, $this->_periods)) { $period = Zend_Date::MONTH; } if (array_search($chunk, $this->_periods) >= array_search($period, $this->_periods)) { die('whoops'); return; } // Validate start if ($start && !is_numeric($start)) { $start = strtotime($start); } if (!$start) { $start = time(); } // Fixes issues with month view Zend_Date::setOptions(array('extend_month' => true)); // Get timezone $timezone = Engine_Api::_()->getApi('settings', 'core')->getSetting('core_locale_timezone', 'GMT'); if ($viewer && $viewer->getIdentity() && !empty($viewer->timezone)) { $timezone = $viewer->timezone; } // Make start fit to period? $startObject = new Zend_Date($start); $startObject->setTimezone($timezone); $partMaps = $this->_periodMap[$period]; foreach ($partMaps as $partType => $partValue) { $startObject->set($partValue, $partType); } // Do offset if ($offset != 0) { $startObject->add($offset, $period); } $arr_campaigns = array(); if ($campaign_ids) { $arr_campaigns = explode(',', $campaign_ids); } // Get end time $endObject = new Zend_Date($startObject->getTimestamp()); $endObject->setTimezone($timezone); $endObject->add($periodCount, $period); $endObject->sub(1, Zend_Date::SECOND); // Subtract one second $adTbl = Engine_Api::_()->getDbtable('ads', 'ynsocialads'); if (count($arr_campaigns)) { $adList = $adTbl->fetchAll($adTbl->select()->from($adTbl->info("name"), 'ad_id')->where('campaign_id IN (?)', $arr_campaigns)); $adList = $adList->toArray(); } else { $adList = array(); } // Get data $staTable = Engine_Api::_()->getDbtable('statistics', 'ynsocialads'); $staName = $staTable->info('name'); if ($type != "all") { $select = $staTable->select(); // Get data if (count($adList)) { $select->where('ad_id IN (?)', $adList)->where('timestamp >= ?', gmdate('Y-m-d H:i:s', $startObject->getTimestamp()))->where('timestamp < ?', gmdate('Y-m-d H:i:s', $endObject->getTimestamp()))->order('timestamp ASC'); if ($type != "all") { $select->where('type = ?', $type); } $rawData = $staTable->fetchAll($select); } else { $rawData = array(); } // Now create data structure $currentObject = clone $startObject; $nextObject = clone $startObject; $data = array(); $dataLabels = array(); $cumulative = 0; $previous = 0; do { $nextObject->add(1, $chunk); $currentObjectTimestamp = $currentObject->getTimestamp(); $nextObjectTimestamp = $nextObject->getTimestamp(); $data[$this->view->locale()->toDate($currentObjectTimestamp)] = $cumulative; // Get everything that matches $currentPeriodCount = 0; foreach ($rawData as $rawDatum) { $rawDatumDate = strtotime($rawDatum->timestamp); if ($rawDatumDate >= $currentObjectTimestamp && $rawDatumDate < $nextObjectTimestamp) { $currentPeriodCount += 1; } } // Now do stuff with it switch ($mode) { default: case 'normal': $data[$this->view->locale()->toDate($currentObjectTimestamp)] = $currentPeriodCount; break; case 'cumulative': $cumulative += $currentPeriodCount; $data[$this->view->locale()->toDate($currentObjectTimestamp)] = $cumulative; break; case 'delta': $data[$this->view->locale()->toDate($currentObjectTimestamp)] = $currentPeriodCount - $previous; $previous = $currentPeriodCount; break; } $currentObject->add(1, $chunk); } while ($currentObject->getTimestamp() < $endObject->getTimestamp()); // Remove some grid lines if there are too many $xsteps = 1; if (count($data) > 100) { $xsteps = ceil(count($data) / 100); } $title = $this->view->locale()->toDate($startObject) . ' to ' . $this->view->locale()->toDate($endObject); echo Zend_Json::encode(array('json' => $data, 'title' => $title)); } else { $selectClick = $staTable->select(); // Get data if (count($adList)) { $selectClick->where('ad_id IN (?)', $adList)->where('timestamp >= ?', gmdate('Y-m-d H:i:s', $startObject->getTimestamp()))->where('timestamp < ?', gmdate('Y-m-d H:i:s', $endObject->getTimestamp()))->order('timestamp ASC'); $selectClick->where("type = 'click'"); $clickData = $staTable->fetchAll($selectClick); } else { $clickData = array(); } $selectImpression = $staTable->select(); // Get data if (count($adList)) { $selectImpression->where('ad_id IN (?)', $adList)->where('timestamp >= ?', gmdate('Y-m-d H:i:s', $startObject->getTimestamp()))->where('timestamp < ?', gmdate('Y-m-d H:i:s', $endObject->getTimestamp()))->order('timestamp ASC'); $selectImpression->where("type = 'impression'"); $impressionData = $staTable->fetchAll($selectImpression); } else { $impressionData = array(); } // Now create data structure $currentObject = clone $startObject; $nextObject = clone $startObject; $dataClick = array(); $dataImpression = array(); $dataLabels = array(); $cumulativeClick = 0; $cumulativeIm = 0; $previousClick = 0; $previousIm = 0; do { $nextObject->add(1, $chunk); $currentObjectTimestamp = $currentObject->getTimestamp(); $nextObjectTimestamp = $nextObject->getTimestamp(); $dataClick[$this->view->locale()->toDate($currentObjectTimestamp)] = $cumulativeClick; $dataImpression[$this->view->locale()->toDate($currentObjectTimestamp)] = $cumulativeIm; // Get everything that matches $currentPeriodCountClick = 0; foreach ($clickData as $rawDatum) { $rawDatumDate = strtotime($rawDatum->timestamp); if ($rawDatumDate >= $currentObjectTimestamp && $rawDatumDate < $nextObjectTimestamp) { $currentPeriodCountClick += 1; } } $currentPeriodCountIm = 0; foreach ($impressionData as $rawDatum) { $rawDatumDate = strtotime($rawDatum->timestamp); if ($rawDatumDate >= $currentObjectTimestamp && $rawDatumDate < $nextObjectTimestamp) { $currentPeriodCountIm += 1; } } // Now do stuff with it switch ($mode) { default: case 'normal': $dataClick[$this->view->locale()->toDate($currentObjectTimestamp)] = $currentPeriodCountClick; $dataImpression[$this->view->locale()->toDate($currentObjectTimestamp)] = $currentPeriodCountIm; break; case 'cumulative': $cumulativeClick += $currentPeriodCountClick; $cumulativeIm += $currentPeriodCountIm; $dataClick[$this->view->locale()->toDate($currentObjectTimestamp)] = $cumulativeClick; $dataImpression[$this->view->locale()->toDate($currentObjectTimestamp)] = $cumulativeIm; break; case 'delta': $dataClick[$this->view->locale()->toDate($currentObjectTimestamp)] = $currentPeriodCountClick - $previousClick; $dataImpression[$this->view->locale()->toDate($currentObjectTimestamp)] = $currentPeriodCountIm - $previousIm; $previousClick = $currentPeriodCountClick; $previousIm = $currentPeriodCountIm; break; } $currentObject->add(1, $chunk); } while ($currentObject->getTimestamp() < $endObject->getTimestamp()); // Remove some grid lines if there are too many $xsteps = 1; if (count($dataClick) > 100) { $xsteps = ceil(count($dataClick) / 100); } $title = $this->view->locale()->toDate($startObject) . ' to ' . $this->view->locale()->toDate($endObject); echo Zend_Json::encode(array('json' => $dataClick, 'title' => $title, 'json2' => $dataImpression)); } return true; }
function getRandomRecipientForCampaign($campaign_id) { require_once 'Zend/Date.php'; $campaign_info = array(); $campaign_info['id'] = $campaign_id; $campaign_info = $this->getMailCampaigns($campaign_info); $campaign_info = $campaign_info[0]; //var_dump($campaign_info); //exit; $table_clean = TABLE_PREFIX . 'cacaomail_mails_to_send'; $table_clean2 = TABLE_PREFIX . 'cacaomail_mails_to_send_log'; //cleanup $q = "SELECT COUNT(*) as qty, job_email \n\t\tFROM {$table_clean} where job_email !='0' \n\t\tand is_active = 1\n\t\tgroup by job_email\n\t \torder by qty desc\n\t \tlimit 3"; // print $q ; $query = CI::db()->query($q); $query = $query->result_array(); if (!empty($query)) { foreach ($query as $clean_item) { if (intval($clean_item['qty']) > 1) { $q = "select id, job_email from {$table_clean} where job_email='{$clean_item['job_email']}' order by id asc "; $q_clean = CI::db()->query($q); $q_clean = $q_clean->result_array(); $fruit = array_pop($q_clean); foreach ($q_clean as $lets_clean) { //print 'clean up ' . $lets_clean ['job_email'] . "\n"; //$q = "delete from $table_clean where id='{$lets_clean['id']}' "; //$q = CI::db()->query ( $q ); print 'Set inactive ' . $lets_clean['job_email'] . "\n"; $q = "update {$table_clean} set is_active=0 where job_email='{$clean_item['job_email']}' "; //print $q; $q = CI::db()->query($q); //$q = "delete from $table_clean2 where mail_id='{$lets_clean['id']}' "; //$q = CI::db()->query ( $q ); } } } } $table_clean = TABLE_PREFIX . 'cacaomail_mails_to_send'; $q = " update {$table_clean} set is_active=0 where for_download=0 and (job_email='0' ) "; //print $q; //exit; $q = CI::db()->query($q); //more housekeeping $table = TABLE_PREFIX . 'cacaomail_mails_to_send_log'; $table2 = TABLE_PREFIX . 'cacaomail_mails_to_send'; $q = "SELECT mail_id \n\t\tFROM {$table} where job_email is null \n\t\t\n\t \tlimit 300"; // print $q ; $query = CI::db()->query($q); $query = $query->result_array(); // var_dump($query); if (!empty($query)) { foreach ($query as $clean_item) { if (intval($clean_item['mail_id']) != 0) { //print $clean_item ['mail_id']; $q = "select id, job_email from {$table2} where id='{$clean_item['mail_id']}' limit 1 "; //print $q; $q_clean = CI::db()->query($q); $q_clean = $q_clean->row_array(); // var_dump($q_clean); if (!empty($q_clean)) { $q = "update {$table} set job_email='{$q_clean['job_email']}' where mail_id='{$clean_item['mail_id']}'"; // print $q; $q_clean = CI::db()->query($q); } //var_dump($q_clean); } } } //exit; $table = TABLE_PREFIX . 'cacaomail_mails_to_send_log'; $send_to_those_mailing_lists = array(); if (intval($campaign_info['mailists_single_id']) != 0) { $send_to_those_mailing_lists[] = intval($campaign_info['mailists_single_id']); } else { $send_to_those_mailing_lists = explode(',', $campaign_info['mailists_groups_ids']); $ids = array(); //var_dump($send_to_those_mailing_lists); //exit; shuffle($send_to_those_mailing_lists); foreach ($send_to_those_mailing_lists as $i) { $data = array(); $data['group_id'] = $i; $data['is_active'] = 1; $data = $this->getJobfeeds($data); //var_dump($data); if (!empty($data)) { foreach ($data as $i2) { $ids[] = $i2['id']; } } } $send_to_those_mailing_lists = $ids; shuffle($send_to_those_mailing_lists); } //var_dump($send_to_those_mailing_lists); //exit; if (!empty($send_to_those_mailing_lists)) { $mailing_list_groups_query = ' feed_id=0 '; foreach ($send_to_those_mailing_lists as $item) { $mailing_list_groups_query = $mailing_list_groups_query . " or feed_id={$item} "; } $mailing_list_groups_query = " ({$mailing_list_groups_query}) and "; } else { return false; } //exit($mailing_list_groups_query); $date = new Zend_Date(); $date->sub('24', Zend_Date::HOUR); //? $past = $date->toValue(); $past = date("Y-m-d H:i:s", $past); $now = date("Y-m-d H:i:s"); $q = " SELECT mail_id FROM {$table} where mailsent_date > '{$campaign_info['campaign_start_date']}' and mailsent_date < '{$campaign_info['campaign_end_date']}' and campaign_id={$campaign_info['id']} "; $query = CI::db()->query($q); $query = $query->result_array(); $mail_ids_to_exclude = array(); $mails_to_exclude = array(); if (!empty($query)) { foreach ($query as $item) { if (intval($item['mail_id']) != 0) { $mail_ids_to_exclude[] = intval($item['mail_id']); $table2 = TABLE_PREFIX . 'cacaomail_mails_to_send'; $q = " SELECT job_email FROM {$table2} where id={$item['mail_id']} limit 1 "; $q = CI::db()->query($q); $q = $q->row_array(); $mails_to_exclude[] = $q['job_email']; } } $mails_to_exclude = array_unique($mails_to_exclude); $mail_ids_to_exclude = array_unique($mail_ids_to_exclude); } //var_dump($mail_ids_to_exclude); if (!empty($mail_ids_to_exclude)) { $exclude_q = ' id!=0 '; $exclude_mails_q = ' job_email is not null '; foreach ($mail_ids_to_exclude as $i) { $exclude_q = $exclude_q . " AND id<>{$i} "; } foreach ($mails_to_exclude as $i) { $exclude_mails_q = $exclude_mails_q . " AND job_email not like '{$i}' "; } //print $exclude_q; $exclude_q = " ({$exclude_q}) and "; $exclude_mails_q = " ({$exclude_mails_q}) and "; } //print $exclude_q; $repeat_q = false; if (intval($campaign_info['campaign_repeat_days']) != 0) { $sub = intval($campaign_info['campaign_repeat_days']) * 24; //print $sub; $date = new Zend_Date(); $date->sub($sub, Zend_Date::HOUR); //? $future = $date->toValue(); $future = date("Y-m-d H:i:s", $future); $repeat_q = " AND ( job_mailsent_date<'{$future}' or job_mailsent_date is null) "; } $table = TABLE_PREFIX . 'cacaomail_mails_to_send'; $table2 = TABLE_PREFIX . 'cacaomail_mails_to_send_log'; $q = " SELECT * from {$table} where\n\t\t{$mailing_list_groups_query} \n\t\n\t{$exclude_q}\n\t{$exclude_mails_q}\n\t\tis_active=1 and \n\t\t\n\t\t\n\t\t job_email NOT IN (SELECT job_email FROM\n {$table2} where job_email is not null group by job_email) and\n\t\t\n\t\t id NOT IN (SELECT mail_id FROM\n {$table2} where mail_id is not null\n group by mail_id) and\n\t\t\n\t\t\n\t\t(for_download=0 or for_download IS NULL ) and \n\t\tjob_pub_date>='{$campaign_info['campaign_start_date']}' and\n\t\t( job_email IS NOT NULL and\n job_email <> '0' and job_email <> '@' )\n\t\t{$repeat_q}\n\n\t\tgroup by job_email\n\t\tORDER BY rand() DESC\n\t\tlimit 1\n\t\t"; //print $q; //$q = " SELECT * from $table where id=587"; //exit (); $query = CI::db()->query($q); $query = $query->row_array(); if (empty($query)) { return false; } //print $query ['job_email']; //$check = $this->checkIfEmailExits($query ['job_email']); //var_dump($check); //exit; //var_dump($query); $query['job_auto_subject'] = $query['job_title']; if ($query['job_title'] != '') { $temp = false; if (stristr($query['job_title'], 'is looking for') == true) { $mystring = $query['job_title']; $findme = 'looking for'; $pos = strpos($mystring, $findme); $temp = substr($query['job_title'], $pos + strlen($findme), strlen($query['job_title'])); $query['job_auto_subject'] = $temp; } if (stristr($query['job_title'], '-') == true) { $mystring = $query['job_title']; $findme = '-'; $pos = strpos($mystring, $findme); $temp = substr($query['job_title'], 0, $pos); $query['job_auto_subject'] = $temp; } if (stristr($query['job_title'], ':') == true) { $mystring = $query['job_title']; $findme = ':'; $pos = strpos($mystring, $findme); $temp = substr($query['job_title'], $pos + strlen($findme), strlen($query['job_title'])); $query['job_auto_subject'] = $temp; } } //var_dump ( $query ['job_email'] ); //exit($query['job_auto_subject']); return $query; // //var_dump($send_to_those_mailing_lists); //exit; }