/**
  * Verifica se os menus do banco estão atualizados com os do arquivo
  * @param $aDados- array de menus do banco
  * @return boolean
  */
 public function isUpToDate($aDados)
 {
     $aDados = Set::combine($aDados, "/Menu/id", "/Menu");
     App::import("Xml");
     App::import("Folder");
     App::import("File");
     $sCaminhosArquivos = Configure::read("Cms.CheckPoint.menus");
     $oFolder = new Folder($sCaminhosArquivos);
     $aConteudo = $oFolder->read();
     $aArquivos = Set::sort($aConteudo[1], "{n}", "desc");
     if (empty($aArquivos)) {
         return false;
     }
     $oFile = new File($sCaminhosArquivos . $aArquivos[0]);
     $oXml = new Xml($oFile->read());
     $aAntigo = $oXml->toArray();
     foreach ($aDados as &$aMenu) {
         $aMenu['Menu']['content'] = str_replace("\r\n", " ", $aMenu['Menu']['content']);
     }
     if (isset($aAntigo["menus"])) {
         $aAntigo["Menus"] = $aAntigo["menus"];
         unset($aAntigo["menus"]);
     }
     if (isset($aAntigo["Menus"])) {
         $aAntigo = Set::combine($aAntigo["Menus"], "/Menu/id", "/Menu");
         $aRetorno = Set::diff($aDados, $aAntigo);
     }
     return empty($aRetorno);
 }
예제 #2
0
 /**
  * Find all themes in the webroot themed directory
  *
  * @return array
  * 
  */
 function getThemes()
 {
     $themed_dir = WWW_ROOT . 'themed' . DS;
     $filter = array('.', '..');
     $themes = scandir($themed_dir);
     $themes = Set::diff($filter, $themes);
     $themes = array_combine($themes, $themes);
     return $themes;
 }
예제 #3
0
 public function admin_mysql()
 {
     $User = ClassRegistry::init('Users.User');
     $globalVars = $User->query('show global variables');
     $globalVars = array_combine(Set::extract('/VARIABLES/Variable_name', $globalVars), Set::extract('/VARIABLES/Value', $globalVars));
     $localVars = $User->query('show variables');
     $localVars = array_combine(Set::extract('/VARIABLES/Variable_name', $localVars), Set::extract('/VARIABLES/Value', $localVars));
     $localVars = Set::diff($localVars, $globalVars);
     $this->set(compact('globalVars', 'localVars'));
 }
예제 #4
0
 /**
  * Find all themes in the webroot themed directory
  *
  * @return array
  * 
  */
 function getThemes()
 {
     $themed_dir = APP . 'views' . DS . 'themed' . DS;
     $filter = array('.', '..');
     $themes = @scandir($themed_dir);
     if (!$themes) {
         return false;
     }
     $themes = Set::diff($filter, $themes);
     $themes = array_combine($themes, $themes);
     return $themes;
 }
 /**
  * Handles automatic pagination of model records.
  *
  * @param mixed $object Model to paginate (e.g: model instance, or 'Model', or 'Model.InnerModel')
  * @param mixed $scope Additional find conditions to use while paginating
  * @param array $whitelist List of allowed fields for ordering.  This allows you to prevent ordering 
  *   on non-indexed, or undesirable columns.
  * @return array Model query results
  */
 public function paginate($object = null, $scope = array(), $whitelist = array())
 {
     if (is_array($object)) {
         $whitelist = $scope;
         $scope = $object;
         $object = null;
     }
     $object = $this->_getObject($object);
     if (!is_object($object)) {
         throw new MissingModelException($object);
     }
     $class = get_class($object);
     $options = $this->mergeOptions($class);
     $options = $this->validateSort($object, $options, $whitelist);
     $options = $this->checkLimit($options);
     $conditions = $fields = $order = $limit = $page = null;
     if (!isset($options['conditions'])) {
         $options['conditions'] = array();
     }
     $type = 'all';
     if (isset($options[0])) {
         $type = $options[0];
         unset($options[0]);
     }
     extract($options);
     if (is_array($scope) && !empty($scope)) {
         $conditions = array_merge($conditions, $scope);
     } elseif (is_string($scope)) {
         $conditions = array($conditions, $scope);
     }
     $extra = array_intersect_key($options, compact('conditions', 'fields', 'order', 'limit', 'page'));
     if (intval($page) < 1) {
         $page = 1;
     }
     $page = $options['page'] = (int) $page;
     $parameters = compact('conditions', 'fields', 'order', 'limit', 'page');
     $results = $class::find($type, array_merge($parameters, $extra));
     $defaults = $this->getDefaults(get_class($object));
     unset($defaults[0]);
     $count = $results->count(false);
     $pageCount = intval(ceil($count / $limit));
     $paging = array('page' => $page, 'current' => count($results), 'count' => $count, 'prevPage' => $page > 1, 'nextPage' => $count > $page * $limit, 'pageCount' => $pageCount, 'order' => $order, 'limit' => $limit, 'options' => Set::diff($options, $defaults), 'paramType' => $options['paramType']);
     if (!isset($this->Controller->request['paging'])) {
         $this->Controller->request['paging'] = array();
     }
     $this->Controller->request['paging'] = array_merge((array) $this->Controller->request['paging'], array($class => $paging));
     if (!in_array('Paginator', $this->Controller->helpers) && !array_key_exists('Paginator', $this->Controller->helpers)) {
         $this->Controller->helpers[] = 'Paginator';
     }
     return $results;
 }
예제 #6
0
 public function afterSave(Model $Model, $created)
 {
     $User = ClassRegistry::init('User');
     $currentUser = null;
     if ($User->hasMethod('getCurrentUser')) {
         $currentUser = $User->getCurrentUser();
     }
     $data = $Model->find('first', array('conditions' => array($Model->alias . '.' . $Model->primaryKey => $Model->id), 'recursive' => -1));
     $derivative[$Model->alias] = !empty($data) ? $data[$Model->alias] : array();
     $log = array('Log' => array('action' => $created ? 'created' : 'modified', 'diff' => json_encode(array($Model->alias => Set::diff($this->_original[$Model->alias], $derivative[$Model->alias]))), 'model' => $Model->alias, 'model_id' => $Model->id, 'user_id' => $currentUser ? $currentUser[$User->primaryKey] : ''));
     $Log = ClassRegistry::init('History.Log');
     $Log->create();
     $Log->save($log);
 }
예제 #7
0
 function _reset($sets = null, $unsets = null)
 {
     unset($this->Controller);
     $this->Controller = new AliasComponentTestController();
     if ($unsets !== null) {
         if ($unsets === true) {
             $this->Controller->components = array();
         } else {
             $components = Set::normalize($this->Controller->components);
             $this->Controller->components = Set::diff($components, array_flip((array) $unsets));
         }
     }
     if ($sets !== null) {
         $this->Controller->components = Set::merge($this->Controller->components, $sets);
     }
     $this->Controller->constructClasses();
     $this->Controller->Component->initialize($this->Controller);
     $this->Controller->beforeFilter();
 }
예제 #8
0
 /**
  * Maps a URL array onto a route and returns the string result, or false if no match
  *
  * @param array $route Route Route
  * @param array $url URL URL to map
  * @return mixed Result (as string) or false if no match
  * @access public
  * @static
  */
 function mapRouteElements($route, $url)
 {
     $_this =& Router::getInstance();
     if (isset($route[3]['prefix'])) {
         $prefix = $route[3]['prefix'];
         unset($route[3]['prefix']);
     }
     $pass = array();
     $defaults = $route[3];
     $routeParams = $route[2];
     $params = Set::diff($url, $defaults);
     foreach ($params as $key => $value) {
         if (is_int($key)) {
             $pass[] = $value;
             unset($params[$key]);
         }
     }
     list($named, $params) = $_this->getNamedElements($params);
     if (!strpos($route[0], '*') && (!empty($pass) || !empty($named))) {
         return false;
     }
     $urlKeys = array_keys($url);
     $paramsKeys = array_keys($params);
     $defaultsKeys = array_keys($defaults);
     if (!empty($params)) {
         if (array_diff($paramsKeys, $routeParams) != array()) {
             return false;
         }
         $required = array_diff($defaultsKeys, $urlKeys);
     }
     $isFilled = true;
     if (!empty($routeParams)) {
         $filled = array_intersect_key($url, array_combine($routeParams, array_keys($routeParams)));
         $isFilled = array_diff($routeParams, array_keys($filled)) == array();
         if (!$isFilled && empty($params)) {
             return false;
         }
     }
     if (empty($params)) {
         return Router::__mapRoute($route, am($url, compact('pass', 'named', 'prefix')));
     } elseif (!empty($routeParams) && !empty($route[3])) {
         if (!empty($required)) {
             return false;
         }
         foreach ($params as $key => $val) {
             if (!isset($url[$key]) || $url[$key] != $val || (!isset($defaults[$key]) || $defaults[$key] != $val) && !in_array($key, $routeParams)) {
                 return false;
             }
         }
     } else {
         if (empty($required) && $defaults['plugin'] == $url['plugin'] && $defaults['controller'] == $url['controller'] && $defaults['action'] == $url['action']) {
             return Router::__mapRoute($route, am($url, compact('pass', 'named', 'prefix')));
         }
         return false;
     }
     if (!empty($route[4])) {
         foreach ($route[4] as $key => $reg) {
             if (array_key_exists($key, $url) && !preg_match('/' . $reg . '/', $url[$key])) {
                 return false;
             }
         }
     }
     return Router::__mapRoute($route, am($filled, compact('pass', 'named', 'prefix')));
 }
예제 #9
0
 public function controller_hash_file_is_out_of_sync()
 {
     if ($this->check_controller_hash_tmp_file()) {
         $stored_controller_hashes = $this->get_stored_controllers_hashes();
         $current_controller_hashes = $this->get_current_controllers_hashes();
         /*
          * Check what controllers have changed
          */
         $updated_controllers = array_keys(Set::diff($current_controller_hashes, $stored_controller_hashes));
         return !empty($updated_controllers);
     }
 }
예제 #10
0
파일: auth.php 프로젝트: areisv/cakewell
 function _diff_dotpaths($key_dotpath, $lock_dotpath)
 {
     $DiffSet = array();
     $KeySet = explode('.', $key_dotpath);
     $LockSet = explode('.', $lock_dotpath);
     $depth_delta = count($KeySet) - count($LockSet);
     if ($depth_delta > 0) {
         foreach (range(1, $depth_delta) as $n) {
             $LockSet[] = $LockSet[count($LockSet) - 1] == '*' ? '*' : '!';
         }
     }
     $SetDiff = Set::diff($KeySet, $LockSet);
     if ($SetDiff) {
         foreach ($KeySet as $n => $x) {
             if (isset($SetDiff[$n]) && $LockSet[$n] != '*') {
                 $DiffSet[$n] = $x;
             }
         }
     }
     return $DiffSet;
 }
예제 #11
0
 function indexOf($condition, $start = 0)
 {
     if (!is_array($condition)) {
         $condition = array('id' => $condition);
     }
     if (!empty($condition)) {
         $i = $start;
         foreach ($this->data['products'] as $index => $product) {
             $product = array_intersect_key($product, $condition);
             if (!count(Set::diff($condition, $product))) {
                 return $index;
             }
             $i++;
         }
     }
     return -1;
 }
예제 #12
0
 /**
  * Maps a URL array onto a route and returns the string result, or false if no match
  *
  * @param array $route Route Route
  * @param array $url URL URL to map
  * @return mixed Result (as string) or false if no match
  * @access public
  * @static
  */
 function mapRouteElements($route, $url)
 {
     if (isset($route[3]['prefix'])) {
         $prefix = $route[3]['prefix'];
         unset($route[3]['prefix']);
     }
     $pass = array();
     $defaults = $route[3];
     $routeParams = $route[2];
     $params = Set::diff($url, $defaults);
     $urlInv = array_combine(array_values($url), array_keys($url));
     $i = 0;
     while (isset($defaults[$i])) {
         if (isset($urlInv[$defaults[$i]])) {
             if (!in_array($defaults[$i], $url) && is_int($urlInv[$defaults[$i]])) {
                 return false;
             }
             unset($urlInv[$defaults[$i]], $defaults[$i]);
         } else {
             return false;
         }
         $i++;
     }
     foreach ($params as $key => $value) {
         if (is_int($key)) {
             $pass[] = $value;
             unset($params[$key]);
         }
     }
     list($named, $params) = Router::getNamedElements($params);
     if (!strpos($route[0], '*') && (!empty($pass) || !empty($named))) {
         return false;
     }
     $urlKeys = array_keys($url);
     $paramsKeys = array_keys($params);
     $defaultsKeys = array_keys($defaults);
     if (!empty($params)) {
         if (array_diff($paramsKeys, $routeParams) != array()) {
             return false;
         }
         $required = array_values(array_diff($routeParams, $urlKeys));
         $reqCount = count($required);
         for ($i = 0; $i < $reqCount; $i++) {
             if (array_key_exists($required[$i], $defaults) && $defaults[$required[$i]] === null) {
                 unset($required[$i]);
             }
         }
     }
     $isFilled = true;
     if (!empty($routeParams)) {
         $filled = array_intersect_key($url, array_combine($routeParams, array_keys($routeParams)));
         $isFilled = array_diff($routeParams, array_keys($filled)) === array();
         if (!$isFilled && empty($params)) {
             return false;
         }
     }
     if (empty($params)) {
         return Router::__mapRoute($route, array_merge($url, compact('pass', 'named', 'prefix')));
     } elseif (!empty($routeParams) && !empty($route[3])) {
         if (!empty($required)) {
             return false;
         }
         foreach ($params as $key => $val) {
             if (!isset($url[$key]) || $url[$key] != $val || (!isset($defaults[$key]) || $defaults[$key] != $val) && !in_array($key, $routeParams)) {
                 if (!isset($defaults[$key])) {
                     continue;
                 }
                 return false;
             }
         }
     } else {
         if (empty($required) && $defaults['plugin'] === $url['plugin'] && $defaults['controller'] === $url['controller'] && $defaults['action'] === $url['action']) {
             return Router::__mapRoute($route, array_merge($url, compact('pass', 'named', 'prefix')));
         }
         return false;
     }
     if (!empty($route[4])) {
         foreach ($route[4] as $key => $reg) {
             if (array_key_exists($key, $url) && !preg_match('#' . $reg . '#', $url[$key])) {
                 return false;
             }
         }
     }
     return Router::__mapRoute($route, array_merge($filled, compact('pass', 'named', 'prefix')));
 }
예제 #13
0
 /**
  * Enter description here...
  *
  * @param Model $model
  * @param unknown_type $linkModel
  * @param string $type Association type
  * @param unknown_type $association
  * @param unknown_type $assocData
  * @param unknown_type $queryData
  * @param unknown_type $external
  * @param unknown_type $resultSet
  * @param integer $recursive Number of levels of association
  * @param array $stack
  */
 function queryAssociation(&$model, &$linkModel, $type, $association, $assocData, &$queryData, $external = false, &$resultSet, $recursive, $stack)
 {
     if ($query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet)) {
         if (!isset($resultSet) || !is_array($resultSet)) {
             if (Configure::read() > 0) {
                 e('<div style = "font: Verdana bold 12px; color: #FF0000">' . sprintf(__('SQL Error in model %s:', true), $model->alias) . ' ');
                 if (isset($this->error) && $this->error != null) {
                     e($this->error);
                 }
                 e('</div>');
             }
             return null;
         }
         $count = count($resultSet);
         if ($type === 'hasMany' && (!isset($assocData['limit']) || empty($assocData['limit']))) {
             $ins = $fetch = array();
             for ($i = 0; $i < $count; $i++) {
                 if ($in = $this->insertQueryData('{$__cakeID__$}', $resultSet[$i], $association, $assocData, $model, $linkModel, $stack)) {
                     $ins[] = $in;
                 }
             }
             if (!empty($ins)) {
                 $fetch = array();
                 $ins = array_chunk($ins, 1000);
                 foreach ($ins as $i) {
                     $q = str_replace('{$__cakeID__$}', join(', ', $i), $query);
                     $q = str_replace('= (', 'IN (', $q);
                     $res = $this->fetchAll($q, $model->cacheQueries, $model->alias);
                     $fetch = array_merge($fetch, $res);
                 }
             }
             if (!empty($fetch) && is_array($fetch)) {
                 if ($recursive > 0) {
                     foreach ($linkModel->__associations as $type1) {
                         foreach ($linkModel->{$type1} as $assoc1 => $assocData1) {
                             $deepModel =& $linkModel->{$assoc1};
                             $tmpStack = $stack;
                             $tmpStack[] = $assoc1;
                             if ($linkModel->useDbConfig === $deepModel->useDbConfig) {
                                 $db =& $this;
                             } else {
                                 $db =& ConnectionManager::getDataSource($deepModel->useDbConfig);
                             }
                             $db->queryAssociation($linkModel, $deepModel, $type1, $assoc1, $assocData1, $queryData, true, $fetch, $recursive - 1, $tmpStack);
                         }
                     }
                 }
             }
             return $this->__mergeHasMany($resultSet, $fetch, $association, $model, $linkModel, $recursive);
         } elseif ($type === 'hasAndBelongsToMany') {
             $ins = $fetch = array();
             for ($i = 0; $i < $count; $i++) {
                 if ($in = $this->insertQueryData('{$__cakeID__$}', $resultSet[$i], $association, $assocData, $model, $linkModel, $stack)) {
                     $ins[] = $in;
                 }
             }
             $foreignKey = $model->hasAndBelongsToMany[$association]['foreignKey'];
             $joinKeys = array($foreignKey, $model->hasAndBelongsToMany[$association]['associationForeignKey']);
             list($with, $habtmFields) = $model->joinModel($model->hasAndBelongsToMany[$association]['with'], $joinKeys);
             $habtmFieldsCount = count($habtmFields);
             if (!empty($ins)) {
                 $fetch = array();
                 $ins = array_chunk($ins, 1000);
                 foreach ($ins as $i) {
                     $q = str_replace('{$__cakeID__$}', '(' . join(', ', $i) . ')', $query);
                     $q = str_replace('= (', 'IN (', $q);
                     $q = str_replace('  WHERE 1 = 1', '', $q);
                     $q = $this->insertQueryData($q, null, $association, $assocData, $model, $linkModel, $stack);
                     if ($q != false) {
                         $res = $this->fetchAll($q, $model->cacheQueries, $model->alias);
                         $fetch = array_merge($fetch, $res);
                     }
                 }
             }
         }
         for ($i = 0; $i < $count; $i++) {
             $row =& $resultSet[$i];
             if ($type !== 'hasAndBelongsToMany') {
                 $q = $this->insertQueryData($query, $resultSet[$i], $association, $assocData, $model, $linkModel, $stack);
                 if ($q != false) {
                     $fetch = $this->fetchAll($q, $model->cacheQueries, $model->alias);
                 } else {
                     $fetch = null;
                 }
             }
             if (!empty($fetch) && is_array($fetch)) {
                 if ($recursive > 0) {
                     foreach ($linkModel->__associations as $type1) {
                         foreach ($linkModel->{$type1} as $assoc1 => $assocData1) {
                             $deepModel =& $linkModel->{$assoc1};
                             if ($type1 === 'belongsTo' || $deepModel->alias === $model->alias && $type === 'belongsTo' || $deepModel->alias != $model->alias) {
                                 $tmpStack = $stack;
                                 $tmpStack[] = $assoc1;
                                 if ($linkModel->useDbConfig == $deepModel->useDbConfig) {
                                     $db =& $this;
                                 } else {
                                     $db =& ConnectionManager::getDataSource($deepModel->useDbConfig);
                                 }
                                 $db->queryAssociation($linkModel, $deepModel, $type1, $assoc1, $assocData1, $queryData, true, $fetch, $recursive - 1, $tmpStack);
                             }
                         }
                     }
                 }
                 if ($type == 'hasAndBelongsToMany') {
                     $merge = array();
                     foreach ($fetch as $j => $data) {
                         if (isset($data[$with]) && $data[$with][$foreignKey] === $row[$model->alias][$model->primaryKey]) {
                             if ($habtmFieldsCount > 2) {
                                 $merge[] = $data;
                             } else {
                                 $merge[] = Set::diff($data, array($with => $data[$with]));
                             }
                         }
                     }
                     if (empty($merge) && !isset($row[$association])) {
                         $row[$association] = $merge;
                     } else {
                         $this->__mergeAssociation($resultSet[$i], $merge, $association, $type);
                     }
                 } else {
                     $this->__mergeAssociation($resultSet[$i], $fetch, $association, $type);
                 }
                 $resultSet[$i][$association] = $linkModel->afterfind($resultSet[$i][$association]);
             } else {
                 $tempArray[0][$association] = false;
                 $this->__mergeAssociation($resultSet[$i], $tempArray, $association, $type);
             }
         }
     }
 }
예제 #14
0
 /**
  * Get a list of plugins, controllers and actions that don't have any corresponding ACO.
  * To run faster, the method only checks controllers that have not already been checked or that have been modified.
  *
  * Depending on the $update_hash_file, the method may return the missing ACOs only once
  * (in order to show the alert message only once in the view)
  *
  * @param boolean $update_hash_file If true, the method update the controller hash file, making the method returning missing ACOs only once
  * @return array Array of missing ACO nodes by comparing with each existing plugin, controller and action
  */
 public function get_missing_acos($update_hash_file = true)
 {
     if ($this->check_controller_hash_tmp_file()) {
         $missing_aco_nodes = array();
         $stored_controller_hashes = $this->get_stored_controllers_hashes();
         $current_controller_hashes = $this->get_current_controllers_hashes();
         /*
          * Store current controllers hashes on disk
          */
         if ($update_hash_file) {
             $file = new File($this->controllers_hash_file);
             $file->write(serialize($current_controller_hashes));
         }
         /*
          * Check what controllers have changed
          */
         $updated_controllers = array_keys(Set::diff($current_controller_hashes, $stored_controller_hashes));
         if (!empty($updated_controllers)) {
             $aco =& $this->Acl->Aco;
             foreach ($updated_controllers as $controller_name) {
                 $controller_classname = $this->AclReflector->get_controller_classname($controller_name);
                 $methods = $this->AclReflector->get_controller_actions($controller_classname);
                 $aco =& $this->Acl->Aco;
                 foreach ($methods as $method) {
                     $methodNode = $aco->node('controllers/' . $controller_name . '/' . $method);
                     if (empty($methodNode)) {
                         $missing_aco_nodes[] = $controller_name . '/' . $method;
                     }
                 }
             }
         }
         return $missing_aco_nodes;
     }
 }
예제 #15
0
 /**
  * Computa as alterações no registro e retorna um array formatado
  * com os valores antigos e novos
  *
  * 'campo' => array('old' => valor antigo, 'new' => valor novo)
  *
  * @param array $old
  * @param array $new
  *
  * @return array $formatted
  */
 private function diffRecords($old, $new)
 {
     $diff = Set::diff($old, $new);
     $formatted = array();
     foreach ($diff as $key => $value) {
         if (!isset($old[$key]) || !isset($new[$key])) {
             continue;
         }
         $formatted[$key] = array('old' => $old[$key], 'new' => $new[$key]);
     }
     return $formatted;
 }
예제 #16
0
    function set_utility($method = 'options')
    {
        if ($method == 'merge') {
            $A1 = array('Model' => array('f1' => '1', 'f2' => '1', 'f3' => '1'));
            $A2 = array('Model' => array('f3' => '2', 'f4' => '1', 'f5' => '1'));
            $merged_arrays = array_merge($A1, $A2);
            $added_arrays = $A1 + $A2;
            $merged_recursive = array_merge_recursive($A1, $A2);
            function array_update($arr, $ins)
            {
                if (is_array($arr) && is_array($ins)) {
                    foreach ($ins as $k => $v) {
                        if (isset($arr[$k]) && is_array($v) && is_array($arr[$k])) {
                            $arr[$k] = array_update($arr[$k], $v);
                        } else {
                            $arr[$k] = $v;
                        }
                    }
                } elseif (!is_array($arr) && (strlen($arr) == 0 || $arr == 0)) {
                    $arr = $ins;
                }
                return $arr;
            }
            $array_update = array_update($A1, $A2);
            $set_merge = Set::merge($A1, $A2);
            $REPORT = array('A1' => $A1, 'A2' => $A2, 'merged' => $merged_arrays, 'added' => $added_arrays, 'merged_recursive' => $merged_recursive, 'array_update' => $array_update, 'Set::merge' => $set_merge, 'Set::isEqual($array_update, $set_merge)' => Set::isEqual($array_update, $set_merge));
        } elseif ($method == 'diff') {
            $set = 'a.b.c';
            $DiffList = array('a' => 0, 'a.b' => 0, 'a.b.c' => 1, 'a.b.c.x' => 1, 'a.b.x' => 0, 'a.x' => 0, 'x' => 0, 'b' => 0, 'b.c' => 0, '*' => 1, '*.b.c' => 1, '*.x' => 0);
            $REPORT['results'] = '';
            foreach ($DiffList as $diff_set => $expect) {
                $SetArray = explode('.', $set);
                $DiffArray = explode('.', $diff_set);
                $depth_delta = count($SetArray) - count($DiffArray);
                if ($depth_delta > 0) {
                    foreach (range(1, $depth_delta) as $n) {
                        $DiffArray[] = $DiffArray[count($DiffArray) - 1] == '*' ? '*' : '!';
                    }
                }
                $SetDiff = Set::diff($SetArray, $DiffArray);
                $mismatch = 0;
                if ($SetDiff) {
                    foreach ($SetArray as $n => $x) {
                        if (isset($SetDiff[$n]) && $DiffArray[$n] != '*') {
                            $mismatch = "{$n} => {$x}";
                        }
                    }
                }
                $has_privilege = (int) (!(bool) $mismatch);
                $REPORT[$diff_set] = array('pass' => (int) ($has_privilege == $expect), 'expect' => $expect, 'result' => $has_privilege, 'mismatch' => $mismatch, "{$set} diff {$diff_set}" => $SetDiff);
            }
            $REPORT['results'] = Set::extract('{s}.pass', $REPORT);
            unset($REPORT['results'][0]);
        } else {
            $content = <<<EOMENU
<h3>methods</h3>
<a href="/demo/set_utility/merge">Set::merge</a><br />
<a href="/demo/set_utility/diff">Set::diff</a><br />
EOMENU;
            $this->set('header', 'Gatekeeper Test');
            $this->set('content', $content);
            return $this->render('index');
        }
        $this->set('header', 'Set Examples');
        $this->set('data', $REPORT);
        $this->render('report');
    }
예제 #17
0
 /**
  * Método auxiliar para recuperar a lista de queries do DataSource
  * e remover campos indesejados.
  *
  * @return array
  */
 protected function getCleanLog(Model $Model)
 {
     $ds = $Model->getDataSource();
     $queries = array();
     if (method_exists($ds, 'getLog')) {
         $log = $ds->getLog(false, false);
         $diff = Set::diff($log['log'], $this->cachedQueries);
         $this->cachedQueries = $log['log'];
         foreach ($diff as $entry) {
             if (empty($entry['affected'])) {
                 continue;
             }
             $queries[] = $entry['query'];
         }
     }
     return $queries;
 }
예제 #18
0
 /**
  * Abstract for Hahs/Set/array_diff()
  *
  * @param array $one
  * @param array $two
  * @return array $diff
  */
 private function _diff($one, $two)
 {
     if (class_exists('Hash')) {
         return Hash::diff($one, $two);
     }
     if (class_exists('Set')) {
         return Set::diff($one, $two);
     }
     return array_diff($one, $two);
 }
예제 #19
0
파일: set.test.php 프로젝트: sdoney/cakephp
 /**
  * testDiff method
  *
  * @access public
  * @return void
  */
 function testDiff()
 {
     $a = array(0 => array('name' => 'main'), 1 => array('name' => 'about'));
     $b = array(0 => array('name' => 'main'), 1 => array('name' => 'about'), 2 => array('name' => 'contact'));
     $result = Set::diff($a, $b);
     $expected = array(2 => array('name' => 'contact'));
     $this->assertIdentical($result, $expected);
     $result = Set::diff($a, array());
     $expected = $a;
     $this->assertIdentical($result, $expected);
     $result = Set::diff(array(), $b);
     $expected = $b;
     $this->assertIdentical($result, $expected);
     $b = array(0 => array('name' => 'me'), 1 => array('name' => 'about'));
     $result = Set::diff($a, $b);
     $expected = array(0 => array('name' => 'main'));
     $this->assertIdentical($result, $expected);
     $a = array();
     $b = array('name' => 'bob', 'address' => 'home');
     $result = Set::diff($a, $b);
     $this->assertIdentical($result, $b);
     $a = array('name' => 'bob', 'address' => 'home');
     $b = array();
     $result = Set::diff($a, $b);
     $this->assertIdentical($result, $a);
     $a = array('key' => true, 'another' => false, 'name' => 'me');
     $b = array('key' => 1, 'another' => 0);
     $expected = array('name' => 'me');
     $result = Set::diff($a, $b);
     $this->assertIdentical($result, $expected);
     $a = array('key' => 'value', 'another' => null, 'name' => 'me');
     $b = array('key' => 'differentValue', 'another' => null);
     $expected = array('key' => 'value', 'name' => 'me');
     $result = Set::diff($a, $b);
     $this->assertIdentical($result, $expected);
     $a = array('key' => 'value', 'another' => null, 'name' => 'me');
     $b = array('key' => 'differentValue', 'another' => 'value');
     $expected = array('key' => 'value', 'another' => null, 'name' => 'me');
     $result = Set::diff($a, $b);
     $this->assertIdentical($result, $expected);
     $a = array('key' => 'value', 'another' => null, 'name' => 'me');
     $b = array('key' => 'differentValue', 'another' => 'value');
     $expected = array('key' => 'differentValue', 'another' => 'value', 'name' => 'me');
     $result = Set::diff($b, $a);
     $this->assertIdentical($result, $expected);
     $a = array('key' => 'value', 'another' => null, 'name' => 'me');
     $b = array(0 => 'differentValue', 1 => 'value');
     $expected = $a + $b;
     $result = Set::diff($a, $b);
     $this->assertIdentical($result, $expected);
 }
예제 #20
0
파일: router.php 프로젝트: asairoha/pj01
 /**
  * Attempt to match a url array.  If the url matches the route parameters and settings, then
  * return a generated string url.  If the url doesn't match the route parameters, false will be returned.
  * This method handles the reverse routing or conversion of url arrays into string urls.
  *
  * @param array $url An array of parameters to check matching with.
  * @return mixed Either a string url for the parameters if they match or false.
  * @access public
  */
 function match($url)
 {
     if (!$this->compiled()) {
         $this->compile();
     }
     $defaults = $this->defaults;
     if (isset($defaults['prefix'])) {
         $url['prefix'] = $defaults['prefix'];
     }
     //check that all the key names are in the url
     $keyNames = array_flip($this->keys);
     if (array_intersect_key($keyNames, $url) != $keyNames) {
         return false;
     }
     $diffUnfiltered = Set::diff($url, $defaults);
     $diff = array();
     foreach ($diffUnfiltered as $key => $var) {
         if ($var === 0 || $var === '0' || !empty($var)) {
             $diff[$key] = $var;
         }
     }
     //if a not a greedy route, no extra params are allowed.
     if (!$this->_greedy && array_diff_key($diff, $keyNames) != array()) {
         return false;
     }
     //remove defaults that are also keys. They can cause match failures
     foreach ($this->keys as $key) {
         unset($defaults[$key]);
     }
     $filteredDefaults = array_filter($defaults);
     //if the difference between the url diff and defaults contains keys from defaults its not a match
     if (array_intersect_key($filteredDefaults, $diffUnfiltered) !== array()) {
         return false;
     }
     $passedArgsAndParams = array_diff_key($diff, $filteredDefaults, $keyNames);
     list($named, $params) = Router::getNamedElements($passedArgsAndParams, $url['controller'], $url['action']);
     //remove any pass params, they have numeric indexes, skip any params that are in the defaults
     $pass = array();
     $i = 0;
     while (isset($url[$i])) {
         if (!isset($diff[$i])) {
             $i++;
             continue;
         }
         $pass[] = $url[$i];
         unset($url[$i], $params[$i]);
         $i++;
     }
     //still some left over parameters that weren't named or passed args, bail.
     if (!empty($params)) {
         return false;
     }
     //check patterns for routed params
     if (!empty($this->options)) {
         foreach ($this->options as $key => $pattern) {
             if (array_key_exists($key, $url) && !preg_match('#^' . $pattern . '$#', $url[$key])) {
                 return false;
             }
         }
     }
     return $this->_writeUrl(array_merge($url, compact('pass', 'named')));
 }
예제 #21
0
파일: dbo_source.php 프로젝트: uwitec/eduoa
 /**
  * Enter description here...
  *
  * @param unknown_type $data
  * @param unknown_type $merge
  * @param unknown_type $association
  * @param unknown_type $type
  */
 function __mergeAssociation(&$data, $merge, $association, $type)
 {
     if (isset($merge[0]) && !isset($merge[0][$association])) {
         $association = Inflector::pluralize($association);
     }
     if ($type == 'belongsTo' || $type == 'hasOne') {
         if (isset($merge[$association])) {
             $data[$association] = $merge[$association][0];
         } else {
             if (count($merge[0][$association]) > 1) {
                 foreach ($merge[0] as $assoc => $data2) {
                     if ($assoc != $association) {
                         $merge[0][$association][$assoc] = $data2;
                     }
                 }
             }
             if (!isset($data[$association])) {
                 if ($merge[0][$association] != null) {
                     $data[$association] = $merge[0][$association];
                 } else {
                     $data[$association] = array();
                 }
             } else {
                 if (is_array($merge[0][$association])) {
                     foreach ($data[$association] as $k => $v) {
                         if (!is_array($v)) {
                             $dataAssocTmp[$k] = $v;
                         }
                     }
                     foreach ($merge[0][$association] as $k => $v) {
                         if (!is_array($v)) {
                             $mergeAssocTmp[$k] = $v;
                         }
                     }
                     if (array_keys($merge[0]) === array_keys($data)) {
                         $data[$association][$association] = $merge[0][$association];
                     } else {
                         $diff = Set::diff($dataAssocTmp, $mergeAssocTmp);
                         $data[$association] = array_merge($merge[0][$association], $diff);
                     }
                 }
             }
         }
     } else {
         if ($merge[0][$association] === false) {
             if (!isset($data[$association])) {
                 $data[$association] = array();
             }
         } else {
             foreach ($merge as $i => $row) {
                 if (count($row) == 1) {
                     $data[$association][] = $row[$association];
                 } else {
                     $tmp = array_merge($row[$association], $row);
                     unset($tmp[$association]);
                     $data[$association][] = $tmp;
                 }
             }
         }
     }
 }
예제 #22
0
 /**
  * Enter description here...
  *
  * @param unknown_type $data
  * @param unknown_type $merge
  * @param unknown_type $association
  * @param unknown_type $type
  * @param boolean $selfJoin
  * @access private
  */
 function __mergeAssociation(&$data, $merge, $association, $type, $selfJoin = false)
 {
     if (isset($merge[0]) && !isset($merge[0][$association])) {
         $association = Inflector::pluralize($association);
     }
     if ($type == 'belongsTo' || $type == 'hasOne') {
         if (isset($merge[$association])) {
             $data[$association] = $merge[$association][0];
         } else {
             if (count($merge[0][$association]) > 1) {
                 foreach ($merge[0] as $assoc => $data2) {
                     if ($assoc != $association) {
                         $merge[0][$association][$assoc] = $data2;
                     }
                 }
             }
             if (!isset($data[$association])) {
                 if ($merge[0][$association] != null) {
                     $data[$association] = $merge[0][$association];
                 } else {
                     $data[$association] = array();
                 }
             } else {
                 if (is_array($merge[0][$association])) {
                     foreach ($data[$association] as $k => $v) {
                         if (!is_array($v)) {
                             $dataAssocTmp[$k] = $v;
                         }
                     }
                     foreach ($merge[0][$association] as $k => $v) {
                         if (!is_array($v)) {
                             $mergeAssocTmp[$k] = $v;
                         }
                     }
                     $dataKeys = array_keys($data);
                     $mergeKeys = array_keys($merge[0]);
                     if ($mergeKeys[0] === $dataKeys[0] || $mergeKeys === $dataKeys) {
                         $data[$association][$association] = $merge[0][$association];
                     } else {
                         $diff = Set::diff($dataAssocTmp, $mergeAssocTmp);
                         $data[$association] = array_merge($merge[0][$association], $diff);
                     }
                 } elseif ($selfJoin && array_key_exists($association, $merge[0])) {
                     $data[$association] = array_merge($data[$association], array($association => array()));
                 }
             }
         }
     } else {
         if (isset($merge[0][$association]) && $merge[0][$association] === false) {
             if (!isset($data[$association])) {
                 $data[$association] = array();
             }
         } else {
             foreach ($merge as $i => $row) {
                 if (count($row) == 1) {
                     if (empty($data[$association]) || isset($data[$association]) && !in_array($row[$association], $data[$association])) {
                         $data[$association][] = $row[$association];
                     }
                 } else {
                     if (!empty($row)) {
                         $tmp = array_merge($row[$association], $row);
                         unset($tmp[$association]);
                         $data[$association][] = $tmp;
                     }
                 }
             }
         }
     }
 }
예제 #23
0
 /**
  * testDiff method
  *
  * @access public
  * @return void
  */
 function testDiff()
 {
     $a = array(0 => array('name' => 'main'), 1 => array('name' => 'about'));
     $b = array(0 => array('name' => 'main'), 1 => array('name' => 'about'), 2 => array('name' => 'contact'));
     $result = Set::diff($a, $b);
     $expected = array(2 => array('name' => 'contact'));
     $this->assertIdentical($result, $expected);
     $result = Set::diff($a, array());
     $expected = $a;
     $this->assertIdentical($result, $expected);
     $result = Set::diff(array(), $b);
     $expected = $b;
     $this->assertIdentical($result, $expected);
     $b = array(0 => array('name' => 'me'), 1 => array('name' => 'about'));
     $result = Set::diff($a, $b);
     $expected = array(0 => array('name' => 'main'));
     $this->assertIdentical($result, $expected);
 }
예제 #24
0
 /**
  * Generates a plain or Ajax link with pagination parameters
  *
  * @param  string $title Title for the link.
  * @param  mixed $url Url for the action. See Router::url()
  * @param  array $options Options for the link. See #options for list of keys.
  * @return string A link with pagination parameters.
  */
 function link($title, $url = array(), $options = array())
 {
     $options = am(array('model' => null, 'escape' => true), $options);
     $model = $options['model'];
     unset($options['model']);
     if (!empty($this->options)) {
         $options = am($this->options, $options);
     }
     $paging = $this->params($model);
     $urlOption = null;
     if (isset($options['url'])) {
         $urlOption = $options['url'];
         unset($options['url']);
     }
     $url = am(array_filter(Set::diff(am($paging['defaults'], $paging['options']), $paging['defaults'])), $urlOption, $url);
     if (isset($url['order'])) {
         $sort = $direction = null;
         if (is_array($url['order'])) {
             list($sort, $direction) = array($this->sortKey($model, $url), current($url['order']));
         }
         unset($url['order']);
         $url = am($url, compact('sort', 'direction'));
     }
     $obj = isset($options['update']) ? 'Ajax' : 'Html';
     $url = am(array('page' => $this->current($model)), $url);
     return $this->{$obj}->link($title, Set::filter($url, true), $options);
 }
예제 #25
0
 /**
  * Merges passed URL options with current pagination state to generate a pagination URL.
  *
  * @param  array $options Pagination/URL options array
  * @param  boolean $asArray
  * @param  string $model Which model to paginate on
  * @return mixed By default, returns a full pagination URL string for use in non-standard contexts (i.e. JavaScript)
  */
 function url($options = array(), $asArray = false, $model = null)
 {
     $paging = $this->params($model);
     $url = array_merge(array_filter(Set::diff(array_merge($paging['defaults'], $paging['options']), $paging['defaults'])), $options);
     if (isset($url['order'])) {
         $sort = $direction = null;
         if (is_array($url['order'])) {
             list($sort, $direction) = array($this->sortKey($model, $url), current($url['order']));
             $key = array_keys($url['order']);
             if (strpos($key[0], '.') !== false) {
                 list($model) = explode('.', $key[0]);
                 $sort = $model . '.' . $sort;
             }
         }
         unset($url['order']);
         $url = array_merge($url, compact('sort', 'direction'));
     }
     if ($asArray) {
         return $url;
     }
     return parent::url($url);
 }
예제 #26
0
 /**
  * constuct, handle settings
  */
 public function __construct(View $view, $settings = array())
 {
     parent::__construct($view, $settings);
     // auto load config file (if exists)
     if (!empty($settings['autoLoadConfig']) || file_exists(APP . 'Config' . DS . 'eip.php')) {
         Configure::load('eip');
     }
     $eipConfig = (array) Configure::read('Eip');
     if (!empty($eipConfig)) {
         // extend settings with config (settings override on conflict)
         $settings = Set::merge(Set::diff($eipConfig, array(null)), $settings);
     }
     if (!empty($settings['pathToJs'])) {
         $this->pathToJs = $settings['pathToJs'];
     }
     if (!empty($settings['pathToCss'])) {
         $this->pathToCss = $settings['pathToCss'];
     }
     if (!empty($settings['options'])) {
         $this->options = array_merge($this->options, $settings['options']);
     }
 }
예제 #27
0
 /**
  * Merges passed URL options with current pagination state to generate a pagination URL.
  *
  * @param  array $options Pagination/URL options array
  * @param  boolean $asArray
  * @param  string $model Which model to paginate on
  * @return mixed By default, returns a full pagination URL string for use in non-standard contexts (i.e. JavaScript)
  */
 function url($options = array(), $asArray = false, $model = null)
 {
     $paging = $this->params($model);
     if (!empty($paging['defaults'])) {
         $url = array_merge(array_filter(Set::diff(array_merge($paging['defaults'], $paging['options']), [])), $options);
     } else {
         $url = array_merge(array_filter(Set::diff(array_merge([], $paging['options']), [])), $options);
     }
     if (isset($url['order'])) {
         $sort = $direction = null;
         if (is_array($url['order'])) {
             list($sort, $direction) = array($this->sortKey($model, $url), current($url['order']));
         }
         unset($url['order']);
         $url = array_merge($url, compact('sort', 'direction'));
     }
     if ($asArray) {
         return $url;
     }
     return parent::url($url);
 }
예제 #28
0
 function testNumericKeyExtraction()
 {
     $data = array('plugin' => null, 'controller' => '', 'action' => '', 1, 'whatever');
     $this->assertIdentical(Set::extract($data, '{n}'), array(1, 'whatever'));
     $this->assertIdentical(Set::diff($data, Set::extract($data, '{n}')), array('plugin' => null, 'controller' => '', 'action' => ''));
 }
예제 #29
0
 /**
  * testDiff method
  *
  * @return void
  */
 public function testDiff()
 {
     $a = array(0 => array('name' => 'main'), 1 => array('name' => 'about'));
     $b = array(0 => array('name' => 'main'), 1 => array('name' => 'about'), 2 => array('name' => 'contact'));
     $result = Set::diff($a, $b);
     $expected = array(2 => array('name' => 'contact'));
     $this->assertEquals($expected, $result);
     $result = Set::diff($a, array());
     $expected = $a;
     $this->assertEquals($expected, $result);
     $result = Set::diff(array(), $b);
     $expected = $b;
     $this->assertEquals($expected, $result);
     $b = array(0 => array('name' => 'me'), 1 => array('name' => 'about'));
     $result = Set::diff($a, $b);
     $expected = array(0 => array('name' => 'main'));
     $this->assertEquals($expected, $result);
     $a = array();
     $b = array('name' => 'bob', 'address' => 'home');
     $result = Set::diff($a, $b);
     $this->assertEquals($b, $result);
     $a = array('name' => 'bob', 'address' => 'home');
     $b = array();
     $result = Set::diff($a, $b);
     $this->assertEquals($a, $result);
     $a = array('key' => TRUE, 'another' => FALSE, 'name' => 'me');
     $b = array('key' => 1, 'another' => 0);
     $expected = array('name' => 'me');
     $result = Set::diff($a, $b);
     $this->assertEquals($expected, $result);
     $a = array('key' => 'value', 'another' => NULL, 'name' => 'me');
     $b = array('key' => 'differentValue', 'another' => NULL);
     $expected = array('key' => 'value', 'name' => 'me');
     $result = Set::diff($a, $b);
     $this->assertEquals($expected, $result);
     $a = array('key' => 'value', 'another' => NULL, 'name' => 'me');
     $b = array('key' => 'differentValue', 'another' => 'value');
     $expected = array('key' => 'value', 'another' => NULL, 'name' => 'me');
     $result = Set::diff($a, $b);
     $this->assertEquals($expected, $result);
     $a = array('key' => 'value', 'another' => NULL, 'name' => 'me');
     $b = array('key' => 'differentValue', 'another' => 'value');
     $expected = array('key' => 'differentValue', 'another' => 'value', 'name' => 'me');
     $result = Set::diff($b, $a);
     $this->assertEquals($expected, $result);
     $a = array('key' => 'value', 'another' => NULL, 'name' => 'me');
     $b = array(0 => 'differentValue', 1 => 'value');
     $expected = $a + $b;
     $result = Set::diff($a, $b);
     $this->assertEquals($expected, $result);
 }
예제 #30
0
 /**
  * busca las clavez de edicion que estan en elementos html que no se pueden editar como botones inputs selects y textarea
  * y genera la salida necesaria para que estos se puedan editar
  * @param string $output referencia a la vairable de la salida
  */
 function __processInvisiblesKeys(&$output)
 {
     # se obtienen las clavez que estan dentro de las etiquetas select
     $output = preg_replace_callback('/<(?<tag>select) [^>]*>(.*?)<\\/select>/is', array($this, '__getUneditablesElementsKeys'), $output);
     # se obteienen las clavez que estan dentro de las etiquetas buttons
     $output = preg_replace_callback('/<(?<tag>button) ([^>]*)>(?<keys>.*?)<\\/button>/is', array($this, '__getUneditablesElementsKeys'), $output);
     # inputs
     $output = preg_replace_callback('/<(?<tag>input) ([^>]*)\\/>/is', array($this, '__getUneditablesElementsKeys'), $output);
     # imagenes
     $output = preg_replace_callback('/<(?<tag>img) ([^>]*)\\/>/is', array($this, '__getUneditablesElementsKeys'), $output);
     # links
     $output = preg_replace_callback('/<(?<tag>a) ([^>]*)>/is', array($this, '__getUneditablesElementsKeys'), $output);
     # clavez de edicion que estan en textareas
     $output = preg_replace_callback('/<(?<tag>textarea) [^>]*>(?<keys>.*?)<\\/textarea>/is', array($this, '__getUneditablesElementsKeys'), $output);
     # pr($this->__uneditablesKeys);
     $out = "";
     if (!empty($this->__uneditablesKeys)) {
         $this->__uneditablesKeys = Set::diff($this->__uneditablesKeys);
         $out .= $this->__uneditableElementsOutput();
     }
     $output = preg_replace('/(<\\/body>)/iU', $out . '$1 ', $output);
 }