Ejemplo n.º 1
0
 function _getConflictSolution(&$model, $curval, $subsequants = null, $options = array())
 {
     $defaultOptions = array('allowSubsequant' => true, 'override' => true, 'absolute' => false);
     $options = array_merge($defaultOptions, (array) $options);
     $actions = array('save' => array(), 'delete' => array());
     if (!empty($subsequants)) {
         if (!$options['allowSubsequant']) {
             return false;
         }
         foreach ($subsequants as $sub) {
             if (!empty($sub['Planning']['absolute'])) {
                 break;
             }
             if (empty($sub['Planning']['operation'])) {
                 if (!$options['override']) {
                     $actions['delete'][$sub['Planning']['id']] = $sub['Planning'];
                 } else {
                     return false;
                 }
             } else {
                 App::import('Lib', 'Operations');
                 $curval = Operations::applyOperation($sub['Planning']['operation'], $curval);
                 $plan = array('id' => $sub['Planning']['id'], 'value' => $curval);
                 $actions['save'][] = $plan;
             }
         }
     }
     return $actions;
 }
Ejemplo n.º 2
0
 function testCond($cond, $data, $or = false, $empty = false)
 {
     $valid = true;
     $def = $empty;
     $modifKeys = array('and', 'or');
     App::import('Lib', 'Operations');
     foreach ($cond as $key => $cnd) {
         $op = false;
         $path = $key;
         if (is_numeric($path)) {
             $val = $data;
         } elseif (in_array($path, $modifKeys)) {
             $val = $data;
         } elseif (array_key_exists($path, $data)) {
             $val = $data[$path];
         } else {
             $op = Operations::parseStringOperation($path, array('mode' => 'left', 'type' => 'bool', 'sepPattern' => '\\h+'));
             if ($op) {
                 $path = $op['subject'];
             }
             $val = Set::Extract($path, $data);
         }
         if ($op) {
             $op['subject'] = $val;
             $op['val'] = $cnd;
             $valid = Operations::applyOperation($op);
         } elseif (is_null($cnd)) {
             $valid = is_null($val);
         } elseif (is_array($cnd)) {
             $or = $path == 'or';
             $valid = SetMulti::testCond($cnd, $val, $or);
         } elseif (!is_null($data)) {
             $valid = $val == $cnd;
         } else {
             $valid = false;
         }
         if ($valid == $or) {
             return $or;
         }
         $def = $valid;
     }
     return $def;
 }
Ejemplo n.º 3
0
 function modifyTarget(&$options, $params)
 {
     debug($params);
     $this->Node = ClassRegistry::init('Node');
     $nodes = $this->Node->getNodes($options['acos'], array('fields' => array('foreign_key', 'model')));
     foreach ($nodes as $node) {
         if (!empty($node['Node']['model'])) {
             $model = ClassRegistry::init($node['Node']['model']);
             if ($model) {
                 $target = $model->read(array($model->primaryKey, $params['name']), $node['Node']['foreign_key']);
                 if ($target) {
                     App::import('Lib', 'Operations');
                     if (isset($params['operation'])) {
                         //debug($params['operation']);
                         $target[$model->alias][$params['name']] = Operations::applyOperation($params['operation'], $target[$model->alias][$params['name']], true);
                     }
                     //debug($target);
                     $model->save($target);
                 }
             }
         }
     }
     //debug($node);
     //debug($params);
 }