function getConfig($data = null) { if (empty($data)) { $data = $this->data; } $template = null; if (is_string($data)) { $template = $data; } else { if (!empty($data['TemplateConfig'])) { return $data['TemplateConfig']; } elseif (!empty($data[$this->alias]['TemplateConfig'])) { return $data[$this->alias]['TemplateConfig']; } if (!empty($data['template'])) { $template = $data['template']; } if (!empty($data[$this->alias]['template'])) { $template = $data[$this->alias]['template']; } } if (!empty($template)) { return ClassCollection::getObject('NewsletterBoxConfig', $template); } return null; }
function getType($cond = null, $Model = null) { if (is_null($cond)) { $cond = $this->data; } App::import('Lib', 'CustomFilter.ClassCollection'); if (empty($Model)) { $Model = $this->CustomFilter->getFilteredModel($cond); } $FilterType = null; $type = !empty($cond[$this->alias]['type']) ? $cond[$this->alias]['type'] : null; if (!$type) { $toCheck = ClassCollection::getList('FilterType', array('hasMethod' => 'detect')); foreach ($toCheck as $ttype) { if ($TestFilterType = ClassCollection::getObject('FilterType', $ttype, array($cond, $Model))) { if ($TestFilterType->detect()) { $FilterType = $TestFilterType; $type = $ttype; } } } if (!$type) { $schema = $Model->schema($cond[$this->alias]['field']); $type = $schema['type']; } } if (empty($FilterType)) { $FilterType = ClassCollection::getObject('FilterType', $type, array($cond, $Model)); } return $FilterType; }
function syncSender() { $Newsletter = ClassRegistry::init('Newsletter.Newsletter'); App::import('Lib', 'Newsletter.NewsletterConfig'); $newsletterSyncTimout = NewsletterConfig::load('newsletterSyncTimout'); //// init sender class //// App::import('Lib', 'Newsletter.ClassCollection'); $senderOpt = NewsletterConfig::load('sender'); if (!is_array($senderOpt)) { $senderOpt = array('name' => $senderOpt); } $sender = ClassCollection::getObject('NewsletterSender', $senderOpt['name']); if (method_exists($sender, 'sync')) { $findOpt = array('fields' => array('Newsletter.id', 'Newsletter.title', 'Newsletter.last_sync', 'Newsletter.date', 'Newsletter.external_key', 'NewsletterSending.last_process_time', 'NewsletterSending.status'), 'conditions' => array(), 'joins' => array(array('alias' => $Newsletter->NewsletterSending->alias, 'table' => $Newsletter->NewsletterSending->useTable, 'type' => 'INNER', 'conditions' => array('NewsletterSending.newsletter_id = Newsletter.id', 'NewsletterSending.confirm' => 1, 'NewsletterSending.active' => 1, 'NewsletterSending.status' => array('done', 'send'), 'or' => array('Newsletter.last_sync IS NULL', 'Newsletter.last_sync < DATE_ADD(NewsletterSending.last_process_time, INTERVAL ' . $newsletterSyncTimout . ')')))), 'limit' => '10', 'group' => 'Newsletter.id', 'order' => 'Newsletter.date DESC', 'recursive' => -1); $toSync = $Newsletter->find('all', $findOpt); if (!empty($toSync)) { $ids = array(); foreach ($toSync as $n) { $ids[] = $n['Newsletter']['id']; } if ($sender->sync($toSync)) { $format = $Newsletter->getDataSource()->columns['datetime']['format']; $Newsletter->updateAll(array('last_sync' => "'" . date($format) . "'"), array('Newsletter.id' => $ids)); } } } }
function __construct($name) { $this->name = $name; App::import('Lib', 'Upgrader.ClassCollection'); $this->config = ClassCollection::getObject('upgrader_config', $name); $this->config->init($this); $this->tests = $this->testsOpt; }
function getTargetHandlers($named = false) { App::import('Lib', 'ClassCollection'); App::import('Lib', 'SetMulti'); $class = ClassCollection::getClass('handler', 'Skills'); $methods = get_class_methods($class); $targetHandlers = SetMulti::pregFilter('/^target\\w*$/', $methods); //debug($targetHandlers); if ($named) { $list = array(); foreach ($targetHandlers as $handler) { $list[$handler] = Inflector::humanize(Inflector::underscore($handler)); } $targetHandlers = $list; } return $targetHandlers; }
function getTemplatesConfig() { $_this =& NewsletterConfig::getInstance(); if (!isset($_this->templates)) { App::import('Lib', 'Newsletter.ClassCollection'); uses('Folder'); $Folder =& new Folder(); $paths = $_this->getAllViewPaths(); foreach ($paths as $path) { if ($Folder->cd($path . '/elements/newsletter')) { $templateFiles = $Folder->find('.+\\.ctp$'); foreach ($templateFiles as &$file) { $name = basename($file, ".ctp"); $config = ClassCollection::getObject('NewsletterConfig', $name); $config->path = $Folder->path . DS . $file; $templates[$name] = $config; } } } $_this->templates = $templates; } return $_this->templates; }
function getBoxElements($template = null) { $paths = $this->getAllViewPaths(); $subPaths = array('/elements/newsletter_box'); if (!empty($template)) { $subPaths[] = '/elements/newsletter_box/' . $template; } foreach ($paths as $path) { foreach ($subPaths as $subPath) { if ($this->Folder->cd($path . $subPath)) { $templateFiles = $this->Folder->find('.+\\.ctp$'); foreach ($templateFiles as &$file) { if (!preg_match("/_edit.ctp\$/", $file)) { $name = basename($file, ".ctp"); $config = ClassCollection::getObject('NewsletterBoxConfig', $name); $boxElements[$name] = $config->getLabel(); //$boxElements[$name] = $name; } } } } } return $boxElements; }
function admin_method_form($name, $prefix) { $this->layout = 'ajax'; App::import('Lib', 'Shop.ClassCollection'); $class = ClassCollection::getClass('promo', $name); $method = new $class(); if (method_exists($method, 'beforeForm')) { $method->beforeForm($this); } $this->set('method', $method); $this->set('prefix', $prefix); }
function _getClass($type, $name) { $_this =& ClassCollection::getInstance(); $options = $_this->getOption($type, $name); $res = array('class' => null, 'import' => array(), 'isParent' => false); if (!empty($options['parent'])) { $inerit = array_intersect_key($options, array_flip($_this->parentInerit)); $parentOpt = Set::Merge($inerit, $options['parent']); $parent = $_this->_getClass(null, $parentOpt); if (empty($parent)) { return null; } else { $res['import'] = $parent['import']; } } $importOpt = $_this->parseImportOption($options); foreach ($importOpt['search'] as $plugin => $search) { foreach ($search as $path) { $iopt = $importOpt; $iopt['search'] = $path; if (App::import($iopt)) { $res['import'][] = $iopt; $res['class'] = $iopt['name']; $res['plugin'] = $plugin == 'app' ? null : $plugin; break 2; } } } if (!$res['class']) { if (!empty($parent) && $options['defaultByParent']) { $res['isParent'] = true; $res['class'] = $parent['class']; $res['plugin'] = $parent['plugin']; } elseif ($options['throwException']) { return array('error' => array('%name% not found.', array('%name%' => $importOpt['name']))); } else { return null; } } return $res; }
function getClass($type, $name, &$isParent = false) { $_this =& ClassCollection::getInstance(); $options = $_this->getOption($type, $name); if (!empty($options['parent'])) { $inerit = array_intersect_key($options, array_flip($_this->parentInerit)); $parentOpt = Set::Merge($inerit, $options['parent']); $parent = $_this->getClass(null, $parentOpt); if (empty($parent)) { return null; } } $importOpt = $_this->parseImportOption($options); //debug($importOpt); if (App::import($importOpt)) { return $importOpt['name']; } else { if (!empty($parent) && $options['defaultByParent']) { $isParent = true; return $parent; } if ($options['throwException']) { debug($importOpt['name'] . ' not found.'); } return null; } }
function getOperations() { $operations = array(); if (is_null($this->defOps)) { $schema = $this->Model->schema($this->fieldname); if (in_array($schema['type'], array('string', 'text'))) { $this->defOps = array('Equals', 'Contains', 'Starts', 'Ends'); } else { $this->defOps = array('Equals', 'Bigger', 'Smaller', 'Between'); } } if (!empty($this->defOps)) { foreach ($this->defOps as $type) { $FilterOperation = ClassCollection::getObject('FilterOperation', $type, array($this)); $operations[$type] = $FilterOperation; } } $toCheck = ClassCollection::getList('FilterOperation', array('hasMethod' => 'detect')); foreach ($toCheck as $type) { if (empty($operations[$type])) { $FilterOperation = ClassCollection::getObject('FilterOperation', $type, array($this)); $operations[$type] = $FilterOperation; } } return $operations; }
function _parseRequest($xmlnode) { $handlerName = $xmlnode->getAttribute('handler'); App::import('Lib', 'ClassCollection'); $handler = ClassCollection::getObject('linkAction', $handlerName); if ($handler) { $aro = array(); if (!empty($this->user)) { $aro[] = $this->User->myNodeRef($this->user['User']['id']); } $handler->defaultAro = $aro; $handler->controller = $this; unset($aro, $handlerName); // free ressources return $handler->execute($xmlnode); } else { return LinkAction::invalidRequest($xmlnode, 404); } }
function getMethods($data = null) { $methods = array(); $methodsOpts = array(); if (empty($data)) { $data = $this->data; } if (!isset($data['ShopPromo'])) { $data = array('ShopPromo' => $data); } if (!empty($data['ShopPromo']['cond'])) { foreach ($data['ShopPromo']['cond'] as $pos => $name) { $opt = array('name' => $name, 'params' => array()); if (!empty($data['ShopPromo']['cond_params'][$pos])) { $opt['params'] = $data['ShopPromo']['cond_params'][$pos]; } $methodsOpts[] = $opt; } } if (!empty($data['ShopPromo']['method'])) { $methodsOpts[] = array('name' => $data['ShopPromo']['method'], 'params' => !empty($data['ShopPromo']['method_params']) ? $data['ShopPromo']['method_params'] : array()); } App::import('Lib', 'Shop.ClassCollection'); foreach ($methodsOpts as $opt) { $class = ClassCollection::getClass('promo', $opt['name']); $method = new $class($data, $opt['params']); $methods[] = $method; } return $methods; }
function _sendEmail($email, $sending, $newsletter = null) { //// init sender class //// App::import('Lib', 'Newsletter.ClassCollection'); $senderOpt = NewsletterConfig::load('sender'); if (!is_array($senderOpt)) { $senderOpt = array('name' => $senderOpt); } $sender = ClassCollection::getObject('NewsletterSender', $senderOpt['name']); $sender->init($this, $senderOpt); //// parse global option //// $opt = $this->_parseGlobalOpt($sending, $newsletter); if (method_exists($sender, 'editGlobalOpt')) { $opt = $sender->editGlobalOpt($opt); } $sender = ClassCollection::getObject('NewsletterSender', $senderOpt['name']); $sender->init($this, $senderOpt); $mailOpt = $this->_parseRecipientOpt($email, $opt); $mailsOptions = array(&$mailOpt); if ($opt['sending']['Newsletter']['TemplateConfig']) { $opt['sending']['Newsletter']['TemplateConfig']->beforeSend($sender, $opt, $mailsOptions); } $res = $this->_sendSingle($sender, $opt, $mailOpt); if ($opt['sending']['Newsletter']['TemplateConfig']) { $opt['sending']['Newsletter']['TemplateConfig']->afterSend($sender, $opt, $mailsOptions); } return $res; }
function getHandler($alias) { App::import('Lib', 'ClassCollection'); return ClassCollection::getObject("handler", $alias); /* //get class name $p = strrpos('.',$alias); if($p===false){ $name = $alias; }else{ $name = substr($alias,$p+1); } $name = ucfirst($name).'Handler'; //init if($exitent = ClassRegistry::getObject($name)){ return $exitent; }else{ $path = str_replace('.',DS,Inflector::underscore($alias)); //if($p===false){ // $path = APP 'libs' . DS . $this->defaultHandlerPath . DS . $path; //} $path .= '_handler.php'; if(!class_exists('Handler')){ App::import('Lib', 'Handler', array('file' =>$this->defaultHandlerPath. DS .'handler.php')); } if(!class_exists($name)){ if(!App::import('Lib', $name, array('file' =>$path))){ debug($name.' not found'); } } $created = null; //debug($name); //debug($path); if(class_exists($name)) { $created = new $name(); } if($created){ ClassRegistry::addObject($name, $created); } return $created; } */ }
function admin_graphs($id = null) { App::import('Vendor', 'Newsletter.php-ofc-library', array('file' => 'php-ofc-library/open-flash-chart.php')); //Configure::write('debug', 0); //$this->layout = null; // generate some random data srand((double) microtime() * 1000000); $title = new title(__d("newsletter", "Views per time", true)); $chart = new open_flash_chart(); $chart->set_title($title); $newsletter = $this->Newsletter->read(null, $id); // Views $dates = array(); $values = array(); //// init sender class //// App::import('Lib', 'Newsletter.ClassCollection'); $senderOpt = NewsletterConfig::load('sender'); if (!is_array($senderOpt)) { $senderOpt = array('name' => $senderOpt); } $sender = ClassCollection::getObject('NewsletterSender', $senderOpt['name']); //// query //// $opt = array('type' => 'graph', 'query' => array('fields' => array('count(*) as nb', 'DATE(NewsletterEvent.date) as date'), 'conditions' => array('NewsletterSended.newsletter_id' => $id, 'or' => array('NewsletterEvent.action' => 'view', array('NewsletterEvent.action IS NULL', 'NewsletterEvent.url' => null))), 'group' => 'DATE(NewsletterEvent.date)', 'order' => 'DATE(NewsletterEvent.date)', 'model' => 'NewsletterEvent')); $data = $this->_get_stats(array('viewByDays' => $opt), $newsletter, $sender); //debug($data); $dates = $data['viewByDays']; $min_value = 99999999; $max_value = 0; foreach ($dates as $d => $val) { if ($val < $min_value) { $min_value = $val; } if ($val > $max_value) { $max_value = $val; } } if ($max_value == $min_value) { $max_value++; $min_value--; } $min_value = 0; //debug($dates); $min_date = key($dates); end($dates); $max_date = key($dates); for ($cur_date = $min_date; $cur_date <= $max_date; $cur_date = $cur_date + 86400) { $x = strtotime('00:00:00', $cur_date); if (isset($dates[$cur_date])) { $values[] = new scatter_value($x, $dates[$cur_date]); } else { $values[] = new scatter_value($x, 0); } } if ($max_date == $min_date) { $max_date += 86400; } //debug($values); //pr($views); $line_dot = new line(); $line_dot->set_values($values); $line_dot->set_text("Views"); $chart->add_element($line_dot); $y = new y_axis(); $y->set_range($min_value, $max_value, ($max_value - $min_value) / 10); $x = new x_axis(); // grid line and tick every 10 $x->set_range(mktime(0, 0, 0, date("m", $min_date), date("d", $min_date), date("Y", $min_date)), mktime(0, 0, 0, date("m", $max_date), date("d", $max_date), date("Y", $max_date))); // show ticks and grid lines for every day: $x->set_steps(86400); $labels = new x_axis_labels(); // tell the labels to render the number as a date: $labels->text('#date:d-m-Y#'); // generate labels for every day $labels->set_steps(86400); // only display every other label (every other day) $labels->visible_steps(ceil(($max_date - $min_date) / 86400 / 20)); $labels->rotate(90); $x->set_labels($labels); $chart->set_x_axis($x); $chart->set_y_axis($y); $chart->set_bg_colour("#FFFFFF"); //print_r($views); //$this->set("allviews",$views[0][0]['count(*)']); $line_dot = new line(); $line_dot->set_values(array(2, 1)); $line_dot->set_text("Unique views"); $line_dot->colour("#0000000"); //$chart->add_element($line_dot); // echo $chart->toPrettyString(); exit; //$this->render(false); }