Beispiel #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;
 }
Beispiel #2
0
 function beforeFind(&$model, $queryData)
 {
     $postprocess = $this->settings[$model->alias]['delete'] || $this->settings[$model->alias]['disable'];
     if ($this->checkLifetime($model) && (!empty($queryData['fields']) || !empty($queryData['limit']) || !$postprocess)) {
         $ef = $this->settings[$model->alias]['end_field'];
         $neededfields = array('id', $ef);
         if ($this->settings[$model->alias]['allways_postprocess']) {
             if (empty($queryData['fields'])) {
                 foreach ($neededfields as $needed) {
                     if (!count(array_intersect($queryData['fields'], array($needed, $model->alias . '.' . $needed)))) {
                         $queryData['fields'][] = $model->alias . '.' . $needed;
                         break;
                     }
                 }
             }
         } else {
             $postprocess = $postprocess && empty($queryData['limit']);
             if ($postprocess) {
                 foreach ($neededfields as $needed) {
                     if (!count(array_intersect((array) $queryData['fields'], array($needed, $model->alias . '.' . $needed)))) {
                         $postprocess = false;
                         break;
                     }
                 }
             }
             if (!$postprocess) {
                 // postprocess impossible or insecure
                 $time = $this->_getQueryTime(&$model);
                 $sf = $this->settings[$model->alias]['start_field'];
                 $timeout = $this->settings[$model->alias]['timeout'];
                 App::import('Lib', 'SetMulti');
                 if ($model->hasField($sf) && (empty($queryData['conditions']) || !count(SetMulti::pregFilterKey('/' . $sf . '/', $queryData['conditions'])))) {
                     $queryData['conditions'][] = array('or' => array($model->alias . '.' . $sf . ' IS NULL', $model->alias . '.' . $sf . ' <=' => $time));
                 }
                 if ($model->hasField($ef) && (empty($queryData['conditions']) || !count(SetMulti::pregFilterKey('/' . $ef . '/', $queryData['conditions'])))) {
                     $queryData['conditions'][] = array('or' => array($model->alias . '.' . $ef . ' IS NULL', $model->alias . '.' . $ef . ' >=' => $this->_modifTime($model, $time, -$timeout)));
                 }
             }
         }
     }
     return $queryData;
 }
 function shipping_billing($id = null)
 {
     if (!$id && isset($this->params['named']['id']) && is_numeric($this->params['named']['id'])) {
         $id = $this->params['named']['id'];
     }
     if (!empty($this->data)) {
         $id = $this->data['ShopOrder']['id'];
     }
     if (!$id) {
         $this->Session->setFlash(sprintf(__('Invalid %s', true), 'shop order'));
         $this->redirect(array('action' => 'index'));
     }
     $this->OrderFunct->tcheckAcl($id);
     $this->ShopOrder->checkActive = false;
     $this->ShopOrder->recursive = -1;
     $order = $this->ShopOrder->read(null, $id);
     debug($order);
     if (!empty($order['ShopOrder']['confirm'])) {
         $this->redirect(array('action' => 'add', $id));
     }
     if (!empty($this->data)) {
         //$this->dispatchComponentCallback('shipping_save');
         //$this->dispatchComponentCallback('billing_save');
         $data = $this->data['ShopOrder'];
         $pattern = '/(^id$)|(^use_shipping$)|(^use_billing$)|(^shipping_)|(^billing_)|(^both_)/';
         App::import('Lib', 'Shop.SetMulti');
         $data = SetMulti::pregFilterKey($pattern, $data);
         $this->ShopOrder->save($data);
         $remind = $data;
         unset($remind['id']);
         $this->Session->write('Shop.address', $remind);
         $this->redirect(array('action' => 'add', $id));
     } else {
         $remind = $this->Session->read('Shop.address');
         if (!empty($remind)) {
             $remind = array_diff_key($remind, array_filter($order['ShopOrder']));
             $order['ShopOrder'] = array_merge($order['ShopOrder'], $remind);
         }
         $this->data = $order;
     }
 }
Beispiel #4
0
 function beforeSave()
 {
     $named = isset($this->data[$this->name]);
     if ($named) {
         $data = $this->data[$this->name];
     } else {
         $data = $this->data;
     }
     if (isset($data['id'])) {
         $id = $data['id'];
     } else {
         $id = $this->id;
     }
     if (!empty($data['use_shipping'])) {
         if (!empty($data['shipping_address'])) {
             $shipping_data = $data;
         } elseif (!empty($id)) {
             $shipping_data = $this->read(null, $id);
             $shipping_data = $shipping_data[$this->name];
         }
         if (!empty($shipping_data)) {
             $prefix_from = "shipping_";
             $prefix_to = "billing_";
             foreach ($shipping_data as $key => $val) {
                 if (substr($key, 0, strlen($prefix_from)) == $prefix_from) {
                     $sufix = substr($key, strlen($prefix_from));
                     //if(empty($data[$prefix_to.$sufix])){
                     $data[$prefix_to . $sufix] = $shipping_data[$key];
                     //}
                 }
             }
         }
     }
     if (!empty($data['use_billing'])) {
         if (!empty($data['billing_address'])) {
             $billing_data = $data;
         } elseif (!empty($id)) {
             $billing_data = $this->read(null, $id);
             $billing_data = $billing_data[$this->name];
         }
         if (!empty($billing_data)) {
             $prefix_from = "billing_";
             $prefix_to = "shipping_";
             foreach ($billing_data as $key => $val) {
                 if (substr($key, 0, strlen($prefix_from)) == $prefix_from) {
                     $sufix = substr($key, strlen($prefix_from));
                     //if(empty($data[$prefix_to.$sufix])){
                     $data[$prefix_to . $sufix] = $billing_data[$key];
                     //}
                 }
             }
         }
     }
     App::import('Lib', 'Shop.SetMulti');
     $both_keys = SetMulti::pregFilterKey('/^both_/', $data);
     foreach ($both_keys as $key => $val) {
         $key = preg_replace('/^both_/', '', $key);
         if (empty($data["billing_" . $key])) {
             $data["billing_" . $key] = $val;
         }
         if (empty($data["shipping_" . $key])) {
             $data["shipping_" . $key] = $val;
         }
     }
     $fieldsToAlias = array('billing_country' => 'country', 'billing_region' => 'region', 'shipping_country' => 'country', 'shipping_region' => 'region');
     App::import('lib', 'Shop.Alias');
     $data = Alias::applyAliasMulti($data, $fieldsToAlias);
     if ($named) {
         $this->data = array($this->name => $data);
     } else {
         $this->data = $data;
     }
     return true;
 }