Exemplo n.º 1
0
 function byCountry($options, $supplementItem, $order, $supplement_choice, $calcul)
 {
     $defOpt = array('keyPath' => array('order.ShopOrder.shipping_country', 'settings.defaultCountry'), 'subMethod' => null, 'modifProp' => 'total', 'list' => array());
     if (!count(array_intersect_key($options, $defOpt))) {
         $options = array('list' => $options);
     }
     $opt = array_merge($defOpt, $options);
     App::import('Lib', 'Shop.ShopConfig');
     $settings = ShopConfig::load();
     $dataSource = array('settings' => $settings, 'order' => $order, 'calcul' => $calcul);
     App::import('Lib', 'Shop.SetMulti');
     $country = SetMulti::extractHierarchic($opt['keyPath'], $dataSource);
     $val = null;
     if (array_key_exists($country, $opt['list'])) {
         $val = $opt['list'][$country];
     } else {
         App::import('Lib', 'O2form.Geography');
         $continent = Geography::getContinent($country);
         if (array_key_exists($continent, $opt['list'])) {
             $val = $opt['list'][$continent];
         } elseif (array_key_exists('default', $opt['list'])) {
             $val = $opt['list']['default'];
         }
     }
     if (!is_null($val)) {
         if (!empty($opt['subMethod'])) {
             return $this->calculFunct($opt['subMethod'], $val, $supplementItem, $order, $supplement_choice, $calcul);
         }
         $supplementItem[$opt['modifProp']] = $val;
     }
     return $supplementItem;
 }
Exemplo n.º 2
0
 function extractHierarchicMulti($pathsAssoc, $data = null, $options = array())
 {
     $defaultOptions = array('extractNull' => true);
     $options = array_merge($defaultOptions, $options);
     $res = array();
     foreach ($pathsAssoc as $name => $paths) {
         $val = SetMulti::extractHierarchic($paths, $data, $options);
         if (!is_null($val) || $options['extractNull']) {
             $res[$name] = $val;
         }
     }
     return $res;
 }
Exemplo n.º 3
0
 function subitemInput($type, $prod = null, $options = array(), $no = null)
 {
     $view =& ClassRegistry::getObject('view');
     if (!is_array($type)) {
         App::import('Lib', 'Shop.ShopConfig');
         $types = empty($options['types']) ? ShopConfig::getSubProductTypes() : $options['types'];
         if (empty($types[$type])) {
             return null;
         }
         $type = $types[$type];
     }
     $localOpt = array('prefix', 'recursive', 'types', 'subProducts');
     $defOpt = array('prefix' => !is_null($no) && is_numeric($no) ? 'ShopCart.products.' . $no . '.SubItem.' : 'ShopCart.SubItem.', 'label' => $type['label'], 'class' => 'subItem', 'recursive' => true);
     $opt = array_merge($defOpt, $options);
     if (empty($opt['subProducts'])) {
         //debug($prod);
         if (!is_array($prod)) {
             $prod = null;
             $no = $prod;
         }
         $sources = array('prod.ShopProduct.ShopSubproduct.' . $type['name'], 'prod.ShopSubproduct.' . $type['name'], 'data.ShopProduct.ShopSubproduct.' . $type['name'], 'vars.' . Inflector::singularize($this->params['controller']) . '.ShopProduct.ShopSubproduct.' . $type['name']);
         App::import('Lib', 'Shop.SetMulti');
         $data = array('prod' => $prod, 'data' => $this->data, 'vars' => $view->viewVars, 'params' => $this->params);
         $subProducts = SetMulti::extractHierarchic($sources, $data);
     } elseif (!empty($opt['subProducts'][$type['name']])) {
         $subProducts = $opt['subProducts'][$type['name']];
     } else {
         return null;
     }
     $children = array();
     if (empty($subProducts)) {
         return null;
     }
     $name = $opt['prefix'] . $type['name'];
     if ($opt['recursive']) {
         foreach ($subProducts as $subProduct) {
             if (!empty($subProduct['children'])) {
                 $children[$subProduct['id']] = $this->O2form->conditionalBlock($this->subitemInputs($prod, array('types' => $type['children'], 'subProducts' => $subProduct['children'], 'prefix' => $opt['prefix'] . 'children.' . $subProduct['id'] . '.'), $no), $name, $subProduct['id']);
             }
         }
     }
     return $view->element('subproduct_select', array('plugin' => 'shop', 'type' => $type, 'subProducts' => $subProducts, 'name' => $name, 'options' => array_diff_key($opt, array_flip($localOpt)), 'children' => $children));
 }
Exemplo n.º 4
0
 function updateSearchTable(&$Model, $id = null, $data = array(), $created = false)
 {
     if (empty($id)) {
         $id = $Model->id;
     }
     if (!empty($id)) {
         if (empty($data)) {
             $data = $Model->data;
         }
         if (empty($data)) {
             $data = $Model->read(null, $id);
         }
         if (!empty($data['SearchTable'])) {
             $search_data = $data['SearchTable'];
         }
         if (isset($data[$Model->alias]['active'])) {
             $search_data['active'] = $data[$Model->alias]['active'];
         } elseif (!$Model->hasField('active')) {
             $search_data['active'] = 1;
         }
         $plugin = $Model->searchOptions['plugin'];
         $model = $Model->alias;
         if (!$created) {
             $Model->SearchTable->recursive = -1;
             $cond = array('model' => $model, 'foreign_id' => $id);
             if (!is_null($plugin)) {
                 if (empty($plugin)) {
                     $cond['plugin'] = null;
                 } else {
                     $cond['plugin'] = $plugin;
                 }
             }
             $searchTable = $Model->SearchTable->find('first', array('conditions' => $cond));
             if ($searchTable) {
                 /****** UPDATE ******/
                 $search_data['id'] = $searchTable['SearchTable']['id'];
                 $plugin = $searchTable['SearchTable']['plugin'];
             } else {
                 $created = true;
             }
         }
         if ($created) {
             /****** ADD ******/
             if (is_null($plugin)) {
                 $parent_class = get_parent_class($model);
                 if ($parent_class != 'AppModel') {
                     if (preg_match("/^([\\w]+)AppModel\$/", $parent_class, $matches)) {
                         $plugin = $matches[1];
                     }
                 }
             }
             $search_data['foreign_id'] = $id;
             if (empty($plugin)) {
                 $search_data['plugin'] = null;
             } else {
                 $search_data['plugin'] = $plugin;
             }
             $search_data['model'] = $model;
             $data[$Model->alias]['id'] = $id;
         }
         $modelName = implode('.', array_filter(array($plugin, $model)));
         /****** Calculate title ******/
         $paths = (array) $Model->searchOptions['title'];
         App::import('Lib', 'Search.SetMulti');
         foreach ($Model->searchOptions['langs'] as $lang) {
             $l_paths = $this->_addBasePath($this->_addLangPath($paths, $lang), $model);
             $search_data['title_' . $lang] = SetMulti::extractHierarchic($l_paths, $data);
             $search_data['title_for_search_' . $lang] = $Model->SearchTable->cleanSearchData($search_data['title_' . $lang]);
         }
         /****** Calculate desc ******/
         $paths = (array) $Model->searchOptions['desc'];
         foreach ($Model->searchOptions['langs'] as $lang) {
             $l_paths = $this->_addBasePath($this->_addLangPath($paths, $lang), $model);
             $search_data['content_' . $lang] = SetMulti::extractHierarchic($l_paths, $data);
         }
         /****** Calculate content for search ******/
         $paths = (array) $Model->searchOptions['content'];
         foreach ($Model->searchOptions['langs'] as $lang) {
             $l_paths = $this->_addBasePath($this->_addLangPath($paths, $lang), $model);
             $search_data['content_for_search_' . $lang] = implode(' ', $Model->SearchTable->cleanSearchData(array_filter(SetMulti::extractMulti($l_paths, $data))));
         }
         /****** Calculate URL ******/
         $urlData = array('plugin' => Inflector::underscore($plugin), 'controller' => Inflector::tableize($model), 'id' => $id);
         foreach ($Model->searchOptions['langs'] as $lang) {
             $l_urlData = $urlData;
             $l_urlData['lang'] = $lang;
             $url = $Model->searchOptions['url'];
             if (is_array($url)) {
                 foreach ($url as $paramName => &$param) {
                     preg_match("/{([\\w]+)}/", $param, $matches);
                     if (!empty($matches)) {
                         $srch = $matches[0];
                         $dname = $matches[1];
                         $rep = '';
                         if (!empty($l_urlData[$dname])) {
                             $rep = $l_urlData[$dname];
                         }
                         $param = str_replace($srch, $rep, $param);
                     }
                     if (empty($param) && !in_array($paramName, $Model->searchOptions['urlKeepEmpty'])) {
                         unset($url[$paramName]);
                     }
                 }
             }
             if (method_exists($Model, 'search_url')) {
                 $res = $Model->search_url($url, $data, $lang);
                 if (is_array($res) || is_string($res)) {
                     $url = $res;
                 }
             }
             $base = Router::url('/');
             $search_data['link_' . $lang] = preg_replace('/^' . preg_quote($base, '/') . '/', '/', Router::url($url));
         }
         /****** Calculate type ******/
         foreach ($Model->searchOptions['langs'] as $lang) {
             if (empty($Model->searchOptions['type'])) {
                 $search_data['type_' . $lang] = $this->_translate($lang, $model);
             } elseif (is_array($Model->searchOptions['type'])) {
                 $search_data['type_' . $lang] = $Model->searchOptions['type'][$lang];
             } else {
                 $search_data['type_' . $lang] = $Model->searchOptions['type'];
             }
         }
         /****** SAVE ******/
         $Model->SearchTable->create();
         //debug($search_data);
         $Model->SearchTable->save($search_data);
     }
 }
Exemplo n.º 5
0
 function updatePathing($id = null)
 {
     if (empty($id)) {
         $id = $this->id;
     }
     $this->Behaviors->attach('Containable');
     $data = $this->find('first', array('conditions' => array($this->alias . '.id' => $id), 'contain' => array('Tile' => array('Node'), 'StructureType', 'Node')));
     debug($data);
     $pathingData = $data['StructureType']['pathing'];
     //$pathingData = array('4x4'=>10);<
     $this->Event = ClassRegistry::init('Event');
     $this->Event->recursive = -1;
     $existing = $this->Event->find('all', array('conditions' => array('phase' => 1, 'context' => 'Pathing', 'owner_id' => $data['Node']['id'])));
     debug($existing);
     $toDelete = array();
     foreach ($existing as $event) {
         $ekey = $event['Event']['aco_id'] . ':' . $event['Event']['event_type_id'];
         if (empty($toDelete[$ekey])) {
             $toDelete[$ekey] = $event['Event'];
         } else {
             $toDelete[] = $event['Event'];
         }
     }
     //debug($toDelete);
     if (!empty($pathingData)) {
         foreach ($tmp = $pathingData as $key => $val) {
             if (strpos($key, 'x') !== false) {
                 list($w, $h) = explode('x', $key, 2);
                 for ($x = 0; $x < $w; $x++) {
                     for ($y = 0; $y < $h; $y++) {
                         $pathingData[$x . ';' . $y] = $val;
                     }
                 }
                 unset($pathingData[$key]);
             } elseif (strpos($key, ';') === false) {
                 unset($pathingData[$key]);
             }
         }
         $maxX = $maxY = 0;
         foreach ($pathingData as $key => $val) {
             list($x, $y) = explode(';', $key, 2);
             $maxX = max($maxX, $x);
             $maxY = max($maxY, $y);
         }
         if ($maxX > 0 || $maxY > 0) {
             $tiles = $this->Tile->getRect(array('w' => $maxX + 1, 'h' => $maxY + 1, 'centerTile' => $data['Tile'], 'aliased' => true));
         } else {
             $tiles = array('0;0' => $data['Tile']);
         }
         debug($tiles);
         $events = array();
         App::import('Lib', 'SetMulti');
         foreach ($pathingData as $key => $val) {
             if (isset($tiles[$key])) {
                 foreach ((array) $val as $t) {
                     $event = array('aro_id' => null, 'aco_id' => SetMulti::extractHierarchic(array('Node.id', 'Tile.Node.id'), $tiles[$key]), 'handler' => 'false', 'event_type_id' => $t, 'phase' => 1, 'active' => 1, 'context' => 'Pathing', 'owner_id' => $data['Node']['id']);
                     $exist = false;
                     $ekey = $event['aco_id'] . ':' . $event['event_type_id'];
                     if (!empty($toDelete[$ekey])) {
                         $exist = $toDelete[$ekey];
                         unset($toDelete[$ekey]);
                     }
                     if ($exist && count(array_diff_assoc($event, $exist)) > 0) {
                         $exist = false;
                     }
                     if (!$exist) {
                         $events[] = $event;
                     }
                 }
             }
         }
         //debug($toDelete);
         debug($events);
         foreach ($events as $event) {
             $this->Event->create();
             $this->Event->save($event);
         }
         foreach ($toDelete as $event) {
             $this->Event->delete($event['id']);
         }
         $pathing = array();
     }
 }
 function admin_import($id = null)
 {
     //$allowedTypes = array('application/vnd.ms-excel','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
     $allowedExt = array('xls', 'xlsx');
     $moveFolder = TMP . "newletter_import" . DS;
     App::import('Lib', 'Newsletter.SetMulti');
     $filename = SetMulti::extractHierarchic(array('params.named.filename', 'params.filename', 'data.NewsletterSendlist.filename'), $this);
     if (!empty($filename)) {
         $moveFullPath = $moveFolder . $filename;
         $this->data['NewsletterSendlist']['filename'] = $filename;
     }
     if (!empty($this->data)) {
         if (!empty($this->data['NewsletterSendlist']['import_file'])) {
             $uploadFile = $this->data['NewsletterSendlist']['import_file'];
             $ext = pathinfo($uploadFile['name'], PATHINFO_EXTENSION);
             if (!in_array($ext, $allowedExt)) {
                 //if(!in_array($uploadFile['type'],$allowedTypes)){
                 $this->Session->setFlash(__d('newsletter', 'This file type is not supported.', true));
             } elseif ($uploadFile['error'] == UPLOAD_ERR_OK) {
                 $folderOk = is_dir($moveFolder);
                 if (!$folderOk) {
                     if (mkdir($moveFolder, 0777)) {
                         $folderOk = true;
                     } else {
                         $this->Session->setFlash(__d('newsletter', 'could not Create upload folder', true));
                     }
                 }
                 if ($folderOk) {
                     $filename = pathinfo($uploadFile['name'], PATHINFO_FILENAME);
                     $ext = pathinfo($uploadFile['name'], PATHINFO_EXTENSION);
                     $num = 0;
                     do {
                         $num++;
                         $movePath = $filename . str_pad($num, 3, '0', STR_PAD_LEFT) . '.' . $ext;
                         $moveFullPath = $moveFolder . $movePath;
                     } while (file_exists($moveFullPath));
                     //debug($moveFullPath);
                     if (move_uploaded_file($uploadFile['tmp_name'], $moveFullPath)) {
                         $this->data['NewsletterSendlist']['filename'] = $movePath;
                         $this->redirect(array('filename' => $movePath));
                     } else {
                         $this->Session->setFlash(__d('newsletter', 'Upload Error', true) . '.');
                     }
                 }
             } else {
                 $this->Session->setFlash(__d('newsletter', 'Upload Error', true));
             }
         }
     }
     $this->NewsletterSendlist->recursive = -1;
     $lists = $this->NewsletterSendlist->find('list');
     $this->set('lists', $lists);
     if (!empty($moveFullPath) && file_exists($moveFullPath)) {
         if (!empty($this->data) && !empty($this->data['NewsletterSendlist']['cols'])) {
             if (in_array('email', $this->data['NewsletterSendlist']['cols'])) {
                 $this->_import_xls($moveFullPath);
             } else {
                 $this->Session->setFlash(__d('newsletter', 'You must at least select one column as the email field', true));
             }
         }
         $this->set($this->_parse_xls_cols($moveFullPath));
         $this->render('admin_import_cols');
     } else {
     }
 }
Exemplo n.º 7
0
 function currency($number, $currency = null)
 {
     if (is_null($currency)) {
         $currency = Configure::read('Shop.currency');
     }
     $lang = Configure::read('Config.language');
     $find = array();
     if (!empty($currency)) {
         $find[] = $currency . '-' . $lang;
         $find[] = $currency;
     }
     $find[] = $lang;
     $find[] = 'default';
     App::import('Lib', 'Shop.SetMulti');
     $format = SetMulti::extractHierarchic($find, $this->currencyFormats);
     return $this->Number->format($number, $format);
 }