示例#1
0
 function applyOperation($op, $val, $parseString = false)
 {
     //debug($op);
     $_this =& Operations::getInstance();
     if ($parseString && is_string($op)) {
         $op = $_this->parseStringOperation($op);
     }
     $opOpt = $_this->getOperator($op);
     if ($opOpt) {
         App::import('Lib', 'SetMulti');
         //debug($opOpt);
         $params = SetMulti::extractHierarchicMulti($opOpt['named'], $op);
         //debug($params);
         $directParams = SetMulti::pregFilterKey('/^[0-9]+$/', $op);
         //debug($directParams);
         $params = $directParams + $params;
         array_unshift($params, $val);
         //debug($params);
         if (isset($opOpt['function']) && $opOpt['function'] === true) {
             $funct = array($_this, '_op_' . $opOpt['name']);
         } elseif (!empty($opOpt['function'])) {
             $funct = $opOpt['function'];
         }
         if (!empty($funct) && is_callable($funct)) {
             return call_user_func_array($funct, $params);
         }
     }
     return null;
 }
示例#2
0
 function getOpt($name)
 {
     if (!empty($this->cache[$name])) {
         return $this->cache[$name];
     }
     $extract = array('typeId' => 'id', 'inheritParent' => 'inherit_parent', 'recursive_links' => 'recursive_links', 'globalLinks' => 'global_links', 'excludeModels' => 'exclude_models');
     $findOpt = array('conditions' => array(), 'recursive' => -1);
     if (is_numeric($name)) {
         $findOpt['conditions']['id'] = $name;
     } else {
         $findOpt['conditions']['name'] = $name;
     }
     $type = $this->find('first', $findOpt);
     App::import('Lib', 'SetMulti');
     $opt = SetMulti::extractHierarchicMulti($extract, $type[$this->alias], array('extractNull' => false));
     $this->cache[$type[$this->alias]['name']] = $opt;
     $this->cache[$type[$this->alias]['id']] = $opt;
     //debug($opt);
     return $opt;
 }
示例#3
0
 function reverseOrderItem($originalOpt, $calculResult)
 {
     if (empty($calculResult)) {
         return $calculResult;
     }
     $extract_data = array('Options.nb' => 'nb', 'Options.data' => 'data', 'DynamicField.price' => 'item_price', 'DynamicField.rebate' => 'item_rebate', 'DynamicField.original_price' => 'item_original_price');
     foreach ($calculResult['OrderItem'] as $pos => $item) {
         $newData = SetMulti::extractHierarchicMulti($extract_data, $item);
         $calculResult['items'][$pos] = Set::merge($originalOpt['items'][$pos], $newData);
     }
     return $calculResult;
 }
示例#4
0
 function getRelatedRef($product = null)
 {
     if (!is_array($product)) {
         $id = $product;
         if (!$id) {
             $id = $this->id;
         }
         $this->recursive = -1;
         $product = $this->find('first', array('field' => array('model', 'foreign_id'), 'conditions' => array($this->alias . '.id', $id)));
     }
     $extract_data = array('model' => array('model', $this->name . '.model', 'Options.model'), 'foreign_id' => array('foreign_id', $this->name . '.foreign_id', 'Options.foreign_id'), 'product_id' => array('id', $this->name . '.id', 'Options.id'));
     App::import('Lib', 'Shop.SetMulti');
     $res = SetMulti::extractHierarchicMulti($extract_data, $product);
     return $res;
 }
 function _parse_xls_cols($filePath)
 {
     if (file_exists($filePath)) {
         App::import('Vendor', 'Newsletter.php-ofc-library', array('file' => 'php-ofc-library/open-flash-chart.php'));
         App::import('Vendor', 'Newsletter.PHPExcel', array('file' => 'PHPExcel/IOFactory.php'));
         $objPHPExcel = PHPExcel_IOFactory::load($filePath);
         $objWorksheet = $objPHPExcel->getActiveSheet();
         $highestRow = $objWorksheet->getHighestRow();
         $highestColumn = $objWorksheet->getHighestColumn();
         $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
         /////////////// cols config ///////////////
         $langs = Configure::read('languages');
         $fieldsAlias = array('first_name' => array("first name", "firstname", "prenom"), 'last_name' => array("last name", "lastname", "nom", "nom de famille"), 'email' => array("email", "mail", "courriel"));
         $fieldsCharAlias = array("é" => "e", "è" => "e", "ê" => "e", "_" => " ", "-" => " ");
         $fieldGess = array('email' => '/^[\\w-]+@([\\w-]+\\.)+[\\w-]+$/', 'phone' => '/^\\(?[0-9]{3}\\)?[-\\s]?[0-9]{3}[-\\s]?[0-9]{4}$/', 'sex' => '/^(f|m)$/i', 'name' => '/^[a-z\\s-]+$/i');
         $fields = $this->NewsletterSendlist->NewsletterEmail->schema();
         unset($fields['id'], $fields['created'], $fields['modified'], $fields['sendlist_id']);
         $fields = array_merge(array('first_name' => array(), 'last_name' => array()), $fields);
         $defFieldsAlias = array();
         $fieldsList = array();
         foreach ($fields as $f => $opt) {
             $fieldsList[$f] = __(Inflector::humanize($f), true);
             $defFieldsAlias[$f] = array($f);
             $langTmp = Configure::read('Config.language');
             foreach ($langs as $l) {
                 Configure::write('Config.language', 'Config.language', $l);
                 if (!in_array(__($f, true), $defFieldsAlias[$f])) {
                     $defFieldsAlias[$f][] = __($f, true);
                 }
                 if (!in_array(__d('newsletter', $f, true), $defFieldsAlias[$f])) {
                     $defFieldsAlias[$f][] = __d('newsletter', $f, true);
                 }
             }
             Configure::write('Config.language', $langTmp);
         }
         unset($defFieldsAlias['active']);
         $fieldsAlias = array_merge($defFieldsAlias, $fieldsAlias);
         //debug($fieldsAlias);
         $fieldGess = array_intersect_key($fieldGess, $fieldsAlias);
         //debug($fieldGess);
         /////////////// Test first row ///////////////
         $first_row = array();
         for ($col = 0; $col <= $highestColumnIndex; ++$col) {
             $cell = $objWorksheet->getCellByColumnAndRow($col, 1)->getValue();
             $cell = mb_strtolower($cell);
             $cell = str_replace(array_keys($fieldsCharAlias), array_values($fieldsCharAlias), $cell);
             $first_row[$col] = $cell;
         }
         //debug($first_row);
         $cols_fields = array_flip($first_row);
         App::import('Lib', 'Newsletter.SetMulti');
         $cols_fields = SetMulti::extractHierarchicMulti($fieldsAlias, $cols_fields);
         $cols_fields = SetMulti::filterNot($cols_fields, 'is_null');
         $title_row = !empty($cols_fields);
         /////////////// Test data ///////////////
         $tmpGess = array_diff_key($fieldGess, $cols_fields);
         if (!empty($cols_fields['first_name'])) {
             unset($tmpGess['name']);
         }
         for ($i = 0; $i < 50 && !empty($tmpGess) && $i < $highestRow; $i++) {
             $row = $this->_get_xls_row($objWorksheet, $i + 1 + $title_row);
             //debug($row);
             foreach ($tmpGess as $f => $exp) {
                 foreach ($row as $col => $val) {
                     if (!in_array($col, $cols_fields)) {
                         if (preg_match($exp, $val)) {
                             unset($tmpGess[$f]);
                             $cols_fields[$f] = $col;
                             break;
                         }
                     }
                 }
             }
         }
         $cols_fields = array_flip($cols_fields);
         /////////////// teaser ///////////////
         $teaser = array();
         for ($i = 0; $i < 15 && $i < $highestRow; $i++) {
             $row = $this->_get_xls_row($objWorksheet, $i + 1);
             $teaser[] = $row;
         }
         //debug($cols_fields);
         return array('cols' => $cols_fields, 'fields' => $fieldsList, 'showFirst' => !$title_row, 'teaser' => $teaser);
     }
     return null;
 }
示例#6
0
 function finalizeOrder($order)
 {
     $dataSource = $this->ShopOrder->getDataSource();
     $data = array();
     $data['id'] = $order['ShopOrder']['id'];
     $data['active'] = 1;
     $data['date'] = $dataSource->expression('NOW()');
     $data = array_merge($data, $this->ShopFunct->calculate($order));
     $order['ShopOrder'] = array_merge($order['ShopOrder'], $data);
     $extract = array('id' => 'id', 'final_price' => 'item_price', 'item_price' => 'item_alone_price');
     foreach ($data['OrderItem'] as $item) {
         $itemdata = SetMulti::extractHierarchicMulti($extract, $item);
         $itemdata = array_merge($item, $itemdata);
         $this->ShopOrder->ShopOrdersItem->save($itemdata);
         if (!empty($item['SubItem'])) {
             foreach ($item['SubItem'] as $subitem) {
                 $this->ShopOrder->ShopOrdersItem->ShopOrdersSubitem->save($subitem);
             }
         }
     }
     //debug($data);
     //debug($data['OrderItem']);
     //debug($data['ShopOrdersSubitem']);
     //return null;
     $data['status'] = 'ready';
     $this->ShopOrder->save($data);
     $this->statusUpdated($data['id'], $data['status']);
     $order['ShopOrder'] = array_merge($order['ShopOrder'], $data);
     return $order;
 }
示例#7
0
 function fullPrice($product = null, $options = array())
 {
     if (is_array($product) && empty($product['ShopProduct']) && empty($product[0]['ShopProduct'])) {
         $options = $product;
     } else {
         if (!empty($product)) {
             $options['product'] = $product;
         }
     }
     $defOpt = array('product' => null, 'sources' => array('product', 'viewVars.product', 'viewVars.' . Inflector::singularize($this->params['controller'])), 'paths' => array('original_price' => array('ShopProduct.DynamicField.original_price', 'DynamicField.original_price', 'item_original_price'), 'rebate' => array('ShopProduct.DynamicField.rebate', 'DynamicField.rebate', 'item_rebate'), 'price' => array('ShopProduct.DynamicField.price', 'DynamicField.price', 'item_price')), 'dataOnly' => false);
     $opt = array_merge($defOpt, $options);
     $view =& ClassRegistry::getObject('view');
     $source = array('product' => $opt['product'], 'viewVars' => $view->viewVars, 'params' => $this->params);
     $extract_data = array();
     foreach ($opt['paths'] as $prop_name => $paths) {
         foreach ($opt['sources'] as $sname) {
             foreach ($paths as $path) {
                 $extract_data[$prop_name][] = $sname . '.' . $path;
             }
         }
     }
     App::import('Lib', 'Shop.SetMulti');
     $data = SetMulti::extractHierarchicMulti($extract_data, $source, array('extractNull' => false));
     if ($opt['dataOnly']) {
         return $data;
     } else {
         if (!empty($data)) {
             return $view->element('qualified_price', array('plugin' => 'shop', 'fullPrice' => $data));
         }
     }
 }
示例#8
0
文件: tile.php 项目: kevthunder/arch
 function getPos($source = null)
 {
     if (is_null($source)) {
         $source = $this;
     }
     $pos = null;
     if (!is_array($source) && is_numeric($source)) {
         $data['id'] = $source;
     } else {
         $extractData = array('id' => array('data.' . $this->alias . '.id', 'data.id', $this->alias . '.id', 'id'), 'x' => array('data.' . $this->alias . '.x', 'data.x', $this->alias . '.x', 'x'), 'y' => array('data.' . $this->alias . '.y', 'data.y', $this->alias . '.y', 'y'), 'zone_id' => array('data.' . $this->alias . '.zone_id', 'data.zone_id', $this->alias . '.zone_id', 'zone_id'));
         App::import('Lib', 'SetMulti');
         $data = SetMulti::extractHierarchicMulti($extractData, $source);
     }
     //debug($data);
     if (isset($data['x']) && isset($data['x'])) {
         $pos = $data;
         unset($pos['id']);
     } elseif (!empty($data['id'])) {
         $tmp = $this->recursive;
         $this->recursive = -1;
         $pos = $this->find('first', array('fields' => array('id', 'x', 'y', 'zone_id'), 'conditions' => array('id' => $data['id'])));
         $pos = $pos[$this->alias];
         $this->recursive = $tmp;
     }
     //debug($pos);
     return $pos;
 }
 function add($model = null, $id = null, $nb = 1)
 {
     $extract_data = array('products.model' => array('data.ShopCart.model', 'params.named.model', 'params.model', 'pass.model'), 'products.foreign_id' => array('data.ShopCart.id', 'params.named.id', 'params.id', 'pass.id'), 'products.nb' => array('data.ShopCart.nb', 'params.named.nb', 'params.nb', 'pass.nb'), 'back_encoded' => array('params.named.back', 'params.back'), 'redirect_encoded' => array('params.named.redirect', 'params.redirect'), 'redirect' => array('data.ShopCart.redirect'), 'back' => array('data.ShopCart.back'), 'products.SubItem' => array('data.ShopCart.SubItem'));
     App::import('Lib', 'Shop.SetMulti');
     $source = array('params' => $this->params, 'data' => $this->data, 'pass' => array('model' => $model, 'id' => $id, 'nb' => $nb));
     $opt = SetMulti::extractHierarchicMulti($extract_data, $source);
     if (!empty($opt['back_encoded'])) {
         App::import('Lib', 'Shop.UrlParam');
         $opt['back'] = UrlParam::decode($opt['back_encoded']);
         unset($opt['back_encoded']);
     }
     $redirect = array('action' => 'index');
     if (!empty($opt['redirect_encoded'])) {
         App::import('Lib', 'Shop.UrlParam');
         $opt['redirect'] = UrlParam::decode($opt['redirect_encoded']);
         unset($opt['redirect_encoded']);
     }
     if (!empty($opt['redirect'])) {
         $redirect = $opt['redirect'];
         $opt['redirect'] = false;
     }
     if (empty($opt['products']['foreign_id']) || empty($opt['products']['model'])) {
         $this->Session->setFlash(sprintf(__('Invalid %s', true), 'product'));
         $this->redirect($redirect);
     }
     $this->CartMaker->add($opt);
     $this->redirect($redirect);
 }
示例#10
0
 function getTimedEventOptions(&$model, $entry = null, $options = array())
 {
     $defOpt = $this->timedEventDefOpt;
     unset($defOpt['data']);
     $opt = Set::merge($defOpt, $options);
     if (empty($opt['data'])) {
         $opt['data'] = array();
     }
     $opt['data'] = array_merge(array_intersect_key($opt, $this->timedEventDefOpt['data']), $opt['data']);
     if (!empty($opt['timeField'])) {
         $opt['source']['time'][] = $model->alias . '.' . $opt['timeField'];
     }
     if (!empty($opt['eventType'])) {
         $event_type = $opt['eventType'];
         if (!is_numeric($event_type)) {
             $event_type = $model->Event->EventType->find('first', array('field' => 'id', 'conditions' => array('name' => $event_type)));
             if (!empty($event_type)) {
                 $event_type = $event_type['EventType']['id'];
             }
         }
         $opt['data']['event_type_id'] = $event_type;
     }
     if (!empty($opt['role'])) {
         $opt['source'][$opt['role'] . '_id'] = 'Node.id';
     }
     if (!empty($opt['source'])) {
         App::import('Lib', 'SetMulti');
         $opt['data'] = array_merge($opt['data'], SetMulti::extractHierarchicMulti($opt['source'], $entry));
     }
     if (empty($opt['data']['x']) || empty($opt['data']['y'])) {
         $model->Behaviors->attach('Util');
         if ($model->hasMethod('getPos')) {
             $pos = $model->getPos($entry);
             if (!empty($pos)) {
                 $opt['data'] = array_merge($pos, $opt['data']);
             }
         }
     }
     $opt['data'] = array_merge($this->timedEventDefOpt['data'], $opt['data']);
     if (!empty($opt['data']['event_type_id']) && !empty($opt['data']['time']) && !empty($opt['data']['owner_id'])) {
         return $opt;
     }
     return null;
 }