public function input($name, $options = array()) { $default = array('type' => null, 'label' => null, 'before' => null, 'after' => null, 'div' => array('class' => 'input')); $options = Set::merge($default, $options); $out = array(); $label = $options['label']; $out[] = $this->Form->label($name, $label); $options['label'] = false; $divOptions = $options['div']; $options['div'] = false; $options['error'] = array('wrap' => 'span', 'class' => 'help-block'); if ($options['after']) { $options['after'] = $this->Html->tag('span', $options['after'], array('class' => 'help-inline')); } if ($options['before']) { $options = $this->_prepend($options['before'], $options); } $form = $this->Form->input($name, $options); if (!empty($options['multiple']) && $options['multiple'] === 'checkbox') { $form = $this->_multipleCheckbox($form); } $out[] = $this->Html->div($divOptions['class'], $form, $divOptions); $errorClass = ''; if ($this->Form->error($name)) { $errorClass = ' error'; } return $this->Html->div('clearfix' . $errorClass, implode("\n", $out)); }
/** * setup * * @param Model $Model * @param array $config * @return void */ public function setup(Model $Model, $config = array()) { $recipe = Configure::read('Oven.recipe'); if (!empty($recipe)) { foreach ($recipe as $key => $type) { $modelName = Inflector::classify($key); if (!isset($this->settings['uploadFields'][$modelName])) { $this->settings['uploadFields'][$modelName] = array(); } if (!empty($type['schema'])) { foreach ($type['schema'] as $field => $val) { if (empty($val['type'])) { continue; } if ($val['type'] == 'file') { $this->settings['uploadFields'][$modelName][] = $field; } } } } } if (empty($config['uploadLocation'])) { $config['uploadLocation'] = Configure::read('Oven.config.upload_location'); if (empty($config['uploadLocation'])) { $config['uploadLocation'] = WWW_ROOT . 'files' . DS . 'uploads' . DS; } } if (!file_exists($config['uploadLocation'])) { new Folder($config['uploadLocation'], true); } $this->settings = Set::merge($this->settings, $config); }
/** * * @param AppController $controller * @param array $settings */ public function initialize($controller, $settings = array()) { $this->settings = Set::merge($this->settings, $settings); $this->controller = $controller; $this->getTwitterSource(); $this->Cookie->path = Router::url('/'); }
/** * リスト用のimgタグを出力する * * @param array $uploaderFile * @param array $options * @return string imgタグ */ public function file($uploaderFile, $options = array()) { if (isset($uploaderFile['UploaderFile'])) { $uploaderFile = $uploaderFile['UploaderFile']; } $imgUrl = $this->getFileUrl($uploaderFile['name']); $pathInfo = pathinfo($uploaderFile['name']); $ext = $pathInfo['extension']; $_options = array('alt' => $uploaderFile['alt']); $options = Set::merge($_options, $options); if (in_array(strtolower($ext), array('gif', 'jpg', 'png'))) { if (isset($options['size'])) { $resizeName = $pathInfo['filename'] . '__' . $options['size'] . '.' . $ext; if (!empty($uploaderFile['publish_begin']) || !empty($uploaderFile['publish_end'])) { $savePath = $this->savePath . 'limited' . DS . $resizeName; } else { $savePath = $this->savePath . $resizeName; } if (file_exists($savePath)) { $imgUrl = $this->getFileUrl($resizeName); unset($options['size']); } } return $this->Html->image($imgUrl, $options); } else { $imgUrl = 'Uploader.icon_upload_file.png'; return $this->Html->image($imgUrl, $options); } }
/** * Returns a tag cloud * * The result contains a "weight" field which has a normalized size of the tag * occurrence set. The min and max size can be set by passing 'minSize" and * 'maxSize' to the query. This value can be used in the view to controll the * size of the tag font. * * @todo Ideas to improve this are welcome * @param string * @param array * @param array * @return array * @access public */ public function _findCloud($state, $query, $results = array()) { if ($state == 'before') { $options = array('minSize' => 10, 'maxSize' => 20, 'page' => null, 'limit' => null, 'order' => null, 'joins' => null, 'offset' => null, 'contain' => 'Tag', 'conditions' => array(), 'fields' => 'Tag.*, Tagged.tag_id, COUNT(*) AS occurrence', 'group' => 'Tagged.tag_id'); foreach ($query as $key => $value) { if (!empty($value)) { $options[$key] = $value; } } $query = $options; if (isset($query['model'])) { $query['conditions'] = Set::merge($query['conditions'], array('Tagged.model' => $query['model'])); } return $query; } elseif ($state == 'after') { if (!empty($results) && isset($results[0][0]['occurrence'])) { $weights = Set::extract($results, '{n}.0.occurrence'); $maxWeight = max($weights); $minWeight = min($weights); $spread = $maxWeight - $minWeight; if (0 == $spread) { $spread = 1; } foreach ($results as $key => $result) { $size = $query['minSize'] + ($result[0]['occurrence'] - $minWeight) * (($query['maxSize'] - $query['minSize']) / $spread); $results[$key]['Tag']['occurrence'] = $result[0]['occurrence']; $results[$key]['Tag']['weight'] = ceil($size); } } return $results; } }
function productContain(&$model, $opt = array()) { $model->Behaviors->attach('Containable'); $contains = Set::merge($opt, array('ShopProduct' => array('ShopSubproduct'))); $model->contain($contains); return $contains; }
function beforeFind($model, $query) { $options = $this->settings[$model->alias]; $conditions = array("{$model->alias}.{$options['field']}" => $options['value']); $query['conditions'] = Set::merge($query['conditions'], $conditions); return $query; }
/** * Constructor * * @param ComponentCollection $collection A ComponentCollection for this component * @param array $settings Array of settings. */ public function __construct(ComponentCollection $collection, $settings = array()) { parent::__construct($collection, $settings); $this->_checkAndSetCookieLifeTime(); $this->settings = Set::merge($this->_defaults, $settings); $this->configureCookie($this->settings['cookie']); }
function read($query) { $query = Set::merge($this->_queryDefaults, $query); $this->setLimits($query); if (isset($query['max_query_time'])) { $this->setMaxQueryTime($query['max_query_time']); } if (isset($query['match_mode'])) { $this->setMatchMode($query['match_mode']); } if (isset($query['rank_mode'])) { $this->setRankMode($query['rank_mode']); } if (isset($query['sort_mode'])) { $this->setSortMode($query['sort_mode']); } if (isset($query['filters'])) { foreach ($query['filters'] as $filter) { $this->setFilter($filter); } } // if(count(explode(",",$query['index'])) > 1) { // $this->setArrayResult(true); // } $this->sphinx->SetFieldWeights(array("title" => 2, "contestant_responses_response" => 2, "profiles_country" => 1)); $result = $this->sphinx->Query($query['query'], $query['index']); if ($result === false) { trigger_error("sphinx query failed: " . $this->sphinx->GetLastError()); } $this->reset(); return $result; }
function setup($model, $settings = array()) { if ($this->_setup) { return; } $this->_settings = Set::merge($this->_settings, $settings['models']); }
/** * input * * @param string $fieldName * @param array $opts * * @todo Checkboxes break with this */ public function input($fieldName, $opts = array()) { $opts = Set::merge(array('div' => array('class' => 'control-group'), 'between' => '<div class="controls">', 'after' => '</div>', 'class' => 'input-xlarge', 'label' => array('class' => 'control-label')), $opts); if (!empty($opts['help'])) { $opts['after'] = '<p class="help-block">' . $opts['help'] . '</p>' . $opts['after']; unset($opts['help']); } if (is_string($opts['label'])) { $opts['label'] = array('text' => $opts['label'], 'class' => 'control-label'); } if (!empty($opts['type'])) { switch ($opts['type']) { case 'ckeditor': $opts['type'] = 'textarea'; break; case 'boolean': $opts['type'] = 'radio'; $opts['multiple'] = true; $opts['options'] = array(1 => 'Yes', 0 => 'No'); break; case 'slug': // TODO: ADD JS TO AUTO-FILL FROM DISPLAY FIELD $opts['type'] = 'text'; break; } } return parent::input($fieldName, $opts); }
/** * リスト用のimgタグを出力する * * @param array $uploaderFile * @param array $options * @return string imgタグ */ function file($uploaderFile, $options = array()) { if (isset($uploaderFile['UploaderFile'])) { $uploaderFile = $uploaderFile['UploaderFile']; } $imgUrl = $this->_getFileUrl($uploaderFile['name']); $pathInfo = pathinfo($uploaderFile['name']); $ext = $pathInfo['extension']; $_options = array('alt' => $uploaderFile['alt']); $options = Set::merge($_options, $options); if (in_array(strtolower($ext), array('gif', 'jpg', 'png'))) { if (isset($options['size'])) { $basename = basename($uploaderFile['name'], '.' . $ext); $resizeName = $basename . '__' . $options['size'] . '.' . $ext; if (file_exists($this->savePath . $resizeName)) { $imgUrl = $this->_getFileUrl($resizeName); unset($options['size']); } } return $this->Html->image($imgUrl, $options); } else { $imgUrl = '/uploader/img/icon_upload_file.png'; return $this->Html->image($imgUrl, $options); } }
/** * Displays the Recaptcha input * * @param array $options An array of options * * ### Options: * * - `recaptchaOptions` assoc array of options to pass into RecaptchaOptions var, like 'theme', 'lang' * or 'custom_translations' to runtime configure the widget. * * @return string The resulting mark up * @access public */ public function display($options = array()) { $defaults = array('element' => null, 'publicKey' => Configure::read('Recaptcha.publicKey'), 'error' => null, 'ssl' => true, 'error' => false, 'div' => array('class' => 'recaptcha'), 'recaptchaOptions' => array('theme' => 'red', 'lang' => 'en', 'custom_translations' => array())); $options = Set::merge($defaults, $options); extract($options); if ($ssl) { $server = $this->secureApiUrl; } else { $server = $this->apiUrl; } $errorpart = ""; if ($error) { $errorpart = "&error=" . $error; } if (!empty($element)) { $elementOptions = array(); if (is_array($element)) { $keys = array_keys($element); $elementOptions = $element[$keys[0]]; } $View = $this->__view(); return $View->element($element, $elementOptions); } $jsonOptions = json_encode($recaptchaOptions); unset($recaptchaOptions); if (empty($this->params['isAjax'])) { $configScript = sprintf('var RecaptchaOptions = %s', $jsonOptions); $this->Html->scriptBlock($configScript, array('inline' => false)); $script = '<script type="text/javascript" src="' . $server . '/challenge?k=' . $publicKey . '"></script> <noscript> <iframe src="' . $server . '/noscript?k=' . $publicKey . '" height="300" width="500" frameborder="0"></iframe><br/> <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea> <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/> </noscript>'; if (!empty($error)) { $script .= $this->Form->error($error); } if ($options['div'] != false) { $script = $this->Html->tag('div', $script, $options['div']); } return $script; } $id = uniqid('recaptcha-'); return '<div id="' . $id . '"></div>' . '<script> if (window.Recaptcha == undefined) { (function() { var headID = document.getElementsByTagName("head")[0]; var newScript = document.createElement("script"); newScript.type = "text/javascript"; newScript.onload = function() { Recaptcha.create("' . $publicKey . '", "' . $id . '", ' . $jsonOptions . '); }; newScript.src = "' . $server . '/js/recaptcha_ajax.js" headID.appendChild(newScript); })(); } else { setTimeout(\'Recaptcha.create("' . $publicKey . '", "' . $id . '", ' . $jsonOptions . ')\', 1000); } </script>'; }
function _ifProfilePhoto(&$model, $options, $id) { $profilePhoto = $model->read('profile_profile_id', $id); $profile_profile_id = $profilePhoto['ProfilePhoto']['profile_profile_id']; $options = Set::merge($options, array('conditions' => array('ProfilePhoto.profile_profile_id' => $profile_profile_id))); return $options; }
/** * Setup the behavior * * @param object $Model instance of model * @param array $config array of configuration settings. * @return void * @access public */ function setup(&$Model, $config = array()) { if (!is_array($config)) { $config = array($config); } $settings = Set::merge($this->_baseConfig, $config); if (!isset($this->settings[$Model->alias])) { $this->settings[$Model->alias] = $settings; } else { $this->settings[$Model->alias] = Set::merge($this->settings[$Model->alias], (array) $settings); } // $indexModel = $this->Model->name . 'Index'; /* $this->Model->bindModel(array( 'hasMany' => array( $indexModel => array( 'className' => 'Indexable.IndexableIndex', 'foreignKey' => 'model_id', ), ), )); */ // $this->IndexModel = $this->Model->$indexModel; // $this->IndexModel->bindModel(array('belongsTo' => array($this->Model->alias => array('foreignKey' => 'model_id')))); // $this->IndexModel->setSource(strtolower($this->Model->name) . '_index'); }
/** * Initializes component by loading all configuration files from * all plugins found in application. Configuration files should be * placed in \app\plugins\your_plugin\config\ directory. Be careful, * it will overwrite all settings loaded from \app\config if the * setting name matches. * At the end it will execute an 'initialize' callback method loaded * from \plugins\your_plugin\{your_plugin}_auto_loader.php file * * @param object $controller - reference to the controller * @param array $settings - component settings, list of autoload files * @return void * @access public */ function initialize(&$controller, $settings = array()) { $this->__controller =& $controller; $this->__settings = Set::merge($this->__settings, $this->__settingsUnique((array) $settings)); if (empty($this->__settings['priority'])) { $this->__settings['priority'] = Configure::listobjects('plugin'); } else { foreach (Configure::listobjects('plugin') as $plugin) { if (!in_array($plugin, $this->__settings['priority'])) { array_push($this->__settings['priority'], $plugin); } } } foreach ($this->__settings['priority'] as $plugin) { $is_parent_class = strpos(get_parent_class($controller), Inflector::classify($plugin)) !== false; if ($this->__settings['permanently'] || !$this->__settings['permanently'] && $is_parent_class) { foreach ($this->__settings['autoload'] as $type) { App::import('Plugin', Inflector::classify("{$plugin}_{$type}"), array('file' => Inflector::underscore($plugin) . DS . 'config' . DS . $type . '.php')); } } } if ($this->__settings['primary']) { $ordering = $this->__controller->Component->_primary; $new_ordering[] = 'PluginHandler'; foreach ($ordering as $component_name) { if (!in_array($component_name, $new_ordering)) { $new_ordering[] = $component_name; } } $this->__controller->Component->_primary = $new_ordering; } $this->loaderExecute('initialize'); }
function generateJoins(&$Model, $alias, $assoc, $type, $options = array()) { $options = Set::merge(array('type' => 'LEFT'), $options); $joins = array(); $foreignKey = $assoc['foreignKey']; switch ($type) { case 'hasOne': case 'hasMany': $conditions = array("{$alias}.{$foreignKey}" => "{$Model->alias}.{$Model->primaryKey}"); break; case 'belongsTo': $conditions = array("{$alias}.{$Model->{$alias}->primaryKey}" => "{$Model->alias}.{$foreignKey}"); break; case 'hasAndBelongsToMany': $joins = $this->createJoins($Model, $assoc['with'], $assoc, 'habtmSecond', $options); $conditions = array("{$alias}.{$Model->{$alias}->primaryKey}" => "{$assoc['with']}.{$assoc['associationForeignKey']}"); break; case 'habtmSecond': $conditions = array("{$alias}.{$foreignKey}" => "{$Model->alias}.{$Model->primaryKey}"); break; } $join = array('table' => $type == 'habtmSecond' ? $assoc['joinTable'] : $Model->{$alias}->table, 'alias' => $alias, 'type' => $options['type'], 'conditions' => $conditions); $joins[] = $join; return $joins; }
/** * @param array $scripts to minify * @param array $options theme */ public function css($scripts, $options = array()) { if (Configure::read('debug') || Configure::read('Minify.minify') === false) { return $this->Html->css($scripts); } $options = Set::merge(array('theme' => $this->_View->theme, 'plugin' => false, 'subdir' => false), $options); extract($options); $path = APP; if (!empty($theme)) { $path = App::themePath($theme); } elseif (!empty($plugin)) { $path = CakePlugin::pluginPath($plugin); } $targetDirectory = $path . DS . 'webroot' . DS . 'css' . DS; $outputfile = $targetDirectory . $subdir . DS . 'minified-' . sha1(join(':', $scripts)) . '.css'; if (file_exists($outputfile)) { $outputfile = str_replace($targetDirectory, '', $outputfile); return $this->Html->css($outputfile); } $contents = ''; foreach ($scripts as $script) { $file = $targetDirectory . $script; if (!preg_match('/\\.css$/', $file)) { $file .= '.css'; } $contents .= file_get_contents($file); } $contents = Minify_CSS_Compressor::process($contents); file_put_contents($outputfile, $contents); return $this->Html->css($scripts); }
/** * Setup */ public function setup(Model $model, $config = array()) { $this->settings[$model->alias] = Set::merge($this->_defaults, $config); if ($this->_hasTrackableFields($model)) { $this->_setupBelongsTo($model); } }
function findListCount($options = array()) { /*$cache = Cache::read('BlogCategoryList'); $cacheKey = 'BlogCategoryList-'.Configure::read('Config.language'); if(!empty($cache[$cacheKey])){ return $cache[$cacheKey]; }*/ App::import('Lib', 'Blog.BlogConfig'); $defOpt = BlogConfig::load('categoryList'); $opt = Set::merge($defOpt, $options); $this->BlogCategory = ClassRegistry::init('Blog.BlogCategory'); $this->BlogCategory->recursive = 1; $categoryList = array(); if ($opt['allCategoriesLink']) { $chTotal = $this->BlogCategory->BlogPost->find('count'); $categoryList[0] = array('id' => null, 'title' => __($opt['allCategoriesLink']['label'], true), 'count' => $chTotal); } $joinModel = $this->BlogCategory->BlogCategoriesBlogPost; $findOpt = array('fields' => array($this->BlogCategory->alias . '.id', $this->BlogCategory->alias . '.title', 'COUNT(' . $this->BlogCategory->BlogPost->alias . '.' . $this->BlogCategory->BlogPost->primaryKey . ') as `count`'), 'conditions' => array($this->BlogCategory->BlogPost->alias . '.active' => true), 'group' => array($this->BlogCategory->alias . '.' . $this->BlogCategory->primaryKey), 'joins' => array(array('alias' => $joinModel->alias, 'table' => $joinModel->table, 'type' => 'INNER', 'conditions' => array($joinModel->alias . '.blog_category_id = ' . $this->BlogCategory->alias . '.' . $this->BlogCategory->primaryKey)), array('alias' => $this->BlogCategory->BlogPost->alias, 'table' => $this->BlogCategory->BlogPost->table, 'type' => 'INNER', 'conditions' => array($joinModel->alias . '.blog_post_id = ' . $this->BlogCategory->BlogPost->alias . '.' . $this->BlogCategory->BlogPost->primaryKey))), 'recursive' => -1); $categories = $this->BlogCategory->find('all', $findOpt); if (!empty($categories)) { foreach ($categories as $k => $cat) { $cb = $cat[0]['count']; if ($cb > 0 || $opt['hideEmpty'] != true) { $categoryList[$cat['BlogCategory']['id']] = array('id' => $cat['BlogCategory']['id'], 'title' => $cat['BlogCategory']['title'], 'count' => $cb); } } } //pr($categories); /*$cache[$cacheKey] = $categoryList; Cache::write('BlogCategoryList', $cache);*/ return $categoryList; }
public function beforeFilter() { parent::beforeFilter(); // what pages are allowed for non-logged-in users $this->Auth->allow('xml'); $this->Auth->allow('nids'); $this->Auth->allow('hids_md5'); $this->Auth->allow('hids_sha1'); $this->Auth->allow('text'); $this->Auth->allow('dot'); // TODO Audit, activate logable in a Controller if (count($this->uses) && $this->{$this->modelClass}->Behaviors->attached('SysLogLogable')) { $this->{$this->modelClass}->setUserData($this->activeUser); } // convert uuid to id if present in the url, and overwrite id field if (isset($this->params->query['uuid'])) { $params = array('conditions' => array('Event.uuid' => $this->params->query['uuid']), 'recursive' => 0, 'fields' => 'Event.id'); $result = $this->Event->find('first', $params); if (isset($result['Event']) && isset($result['Event']['id'])) { $id = $result['Event']['id']; $this->params->addParams(array('pass' => array($id))); // FIXME find better way to change id variable if uuid is found. params->url and params->here is not modified accordingly now } } // if not admin or own org, check private as well.. if (!$this->_IsSiteAdmin()) { $this->paginate = Set::merge($this->paginate, array('conditions' => array("OR" => array(array('Event.org =' => $this->Auth->user('org')), array('Event.distribution >' => 0))))); } }
/** * Method for verifying the API key * * @param array $options Overrides for $this->_defaults * @access public */ function verify($options) { $defaults = array('apikey' => $this->_defaults['apikey'], 'providerkey' => $this->_defaults['providerkey']); $options = array('apikey' => $options['apikey'], 'providerkey' => $options['providerkey']); $options = Set::merge($defaults, $options); return $this->api('verify', $options); }
/** * Constructor * * @param ComponentCollection $collection The controller for this request. * @param string $settings An array of settings. This class does not use any settings. */ public function __construct(ComponentCollection $collection, $settings = array()) { $this->_Collection = $collection; $controller = $collection->getController(); $this->controller($controller); $this->settings = Set::merge($this->settings, $settings); }
public function afterFind($results, $primary = false) { if (isset($results[0][$this->alias]['class'])) { foreach ($results as $key => $result) { $associated = array(); $class = $result[$this->alias]['class']; $foreignId = $result[$this->alias]['foreign_id']; if ($class && $foreignId) { $associatedConditions = array('conditions' => array($class . '.id' => $foreignId)); if (isset($this->__polyConditions[$class])) { $associatedConditions = Set::merge($associatedConditions, $this->__polyConditions[$class]); } $result = $result[$this->alias]; if (!isset($this->{$class})) { $this->bindModel(array('belongsTo' => array($class => array('conditions' => array($this->alias . '.' . 'class' => $class), 'foreignKey' => 'foreign_id')))); } $associated = $this->{$class}->find('first', $associatedConditions); if (empty($associated)) { unset($results[$key]); // @todo temporary until I can figure out how to not return results that have empty } else { $associated[$class]['display_field'] = $associated[$class][$this->{$class}->displayField]; $results[$key][$class] = $associated[$class]; unset($associated[$class]); $results[$key][$class] = Set::merge($results[$key][$class], $associated); } } } } return $results; }
/** * initCore * Setup your Config/core.php * * @param array $config * @return boolean * @throws CakeException */ public function initCore($config = array()) { $path = $this->appPath . 'Config' . DS . 'core.php'; if (!file_exists($path)) { throw new CakeException(__d('oven', 'Core config file could not be found.')); } if (!is_writable($path)) { throw new CakeException(__d('oven', 'Core config is not writable.')); } $config = Set::merge(array('salt' => substr(str_shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'), 0, 40), 'cipherSeed' => str_shuffle(str_repeat('0123456789', 3))), $config); // READ FILE $file = new File($path); $contents = $file->read(); // CHANGE SALT $replace = "Configure::write('Security.salt', 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi');"; $with = "Configure::write('Security.salt', '" . $config['salt'] . "');"; $contents = str_replace($replace, $with, $contents); // CHANGE CIPHERSEED $replace = "Configure::write('Security.cipherSeed', '76859309657453542496749683645');"; $with = "Configure::write('Security.cipherSeed', '" . $config['cipherSeed'] . "');"; $contents = str_replace($replace, $with, $contents); // TURN ON ADMIN ROUTING $replace = "//Configure::write('Routing.prefixes', array('admin'));"; $with = "Configure::write('Routing.prefixes', array('admin'));"; $contents = str_replace($replace, $with, $contents); // WRITE FILE $file->write($contents); $file->close(); return true; }
function beforeFind(&$model, $query) { $default = array('lon' => null, 'lat' => null, 'dist' => '1km'); $query = Set::merge($default, $query); $lon = (double) $query['lon']; $lat = (double) $query['lat']; $dist = $query['dist']; if ($lon && $lat) { if (strpos($dist, 'km') === false && strpos($dist, 'm')) { $dist = floatval($dist) / 1000; } else { $dist = floatval($dist); } $lon1 = $lon - $dist / abs(cos(deg2rad($lat)) * 69.09 * 1.609344); $lon2 = $lon + $dist / abs(cos(deg2rad($lat)) * 69.09 * 1.609344); $lat1 = $lat - $dist / (69.09 * 1.609344); $lat2 = $lat + $dist / (69.09 * 1.609344); $conditions = array("{$model->alias}.lon BETWEEN ? AND ?" => array($lon1, $lon2), "{$model->alias}.lat BETWEEN ? AND ?" => array($lat1, $lat2)); $query = Set::merge($query, array('conditions' => $conditions)); } unset($query['lon']); unset($query['lat']); unset($query['dist']); if ($model->findQueryType !== 'count') { $fields = array("{$model->alias}.*", "3956*2*ASIN(\n\t\t\t\t\tSQRT(\n\t\t\t\t\t\tPOWER(\n\t\t\t\t\t\t\tSIN(({$lat}-`{$model->alias}`.`lat`)\n\t\t\t\t\t\t\t*pi()/180/2),2\n\t\t\t\t\t\t)\n\t\t\t\t\t\t+COS({$lat}*pi()/180)\n\t\t\t\t\t\t*COS(`{$model->alias}`.`lat`*pi()/180)\n\t\t\t\t\t\t*POWER(\n\t\t\t\t\t\t\tSIN(({$lon}-`{$model->alias}`.`lon`)\n\t\t\t\t\t\t\t*pi()/180/2),2\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\t\t\t\t)*1.609344*1000 AS `distance`"); $order = array('distance ASC'); $query = Set::merge($query, array('fields' => $fields), array('order' => $order)); } return $query; }
public function __construct($View = null, $settings = array()) { $settings = Set::merge(array('engine' => 'Tools.NumberLib'), $settings); parent::__construct($View, $settings); /* $i18n = Configure::read('Currency'); if (!empty($i18n['code'])) { $this->code = $i18n['code']; } if (!empty($i18n['places'])) { $this->places = $i18n['places']; } if (!empty($i18n['symbolRight'])) { $this->symbolRight = $i18n['symbolRight']; } if (!empty($i18n['symbolLeft'])) { $this->symbolLeft = $i18n['symbolLeft']; } if (isset($i18n['decimals'])) { $this->decimalPoint = $i18n['decimals']; } if (isset($i18n['thousands'])) { $this->thousandsPoint = $i18n['thousands']; } */ }
function imageSetup($model, $config = array()) { $settings = Set::merge(array('baseDir' => 'upload'), $config); if (!isset($settings['fields'])) { $settings['fields'] = array(); } $fields = array(); foreach ($settings['fields'] as $key => $value) { $field = ife(is_numeric($key), $value, $key); $conf = ife(is_numeric($key), array(), ife(is_array($value), $value, array())); //if (!is_array($field)) $field=array('name'=>$field); $conf = Set::merge(array('thumbnail' => array('prefix' => 'thumb', 'create' => false, 'width' => '100', 'height' => '100', 'aspect' => true, 'allow_enlarge' => true), 'resize' => null, 'versions' => array()), $conf); foreach ($conf['versions'] as $id => $version) { $conf['versions'][$id] = Set::merge(array('aspect' => true, 'allow_enlarge' => false), $version); } if (is_array($conf['resize'])) { if (!isset($conf['resize']['aspect'])) { $conf['resize']['aspect'] = true; } if (!isset($conf['resize']['allow_enlarge'])) { $conf['resize']['allow_enlarge'] = false; } } $fields[$field] = $conf; } $settings['fields'] = $fields; $this->settings[$model->name] = $settings; //debug($settings); //exit; }
/** * Internal method to locate the entire node represented by a key. * * @param mixed $options * @return mixed */ protected function _findNode($options = array()) { if (is_string($options)) { $options = array('name' => $options); } $options = Set::merge(array('model' => null, 'foreign_id' => null, 'name' => null, 'parent_id' => null), $options); unset($options['value']); $this->setScope($options['model'], $options['foreign_id']); $path = explode('.', $options['name']); $path_count = count($path); $parent_id = $options['parent_id']; $node = null; foreach ($path as $idx => $path_key) { $node = $this->find('first', array('conditions' => array_merge($options, array('parent_id' => $parent_id, 'name' => $path_key)))); if (empty($node)) { break; } $node = $node['Metadatum']; if ($path_count == $idx + 1) { if ($node['rght'] > $node['lft'] + 1) { $children = $this->children($node['id'], true); if (!empty($children)) { $node['value'] = Set::extract($children, '/Metadatum/.'); } } break; } $parent_id = $node['id']; } return $node; }
function setup(&$Model, $settings = array()) { if (!isset($this->__settings[$Model->alias])) { $this->__settings[$Model->alias] = array('enabled' => true, 'foreignKey' => 'id', 'tokenField' => 'token', 'tokenLength' => 5, 'maxIterations' => 10); } $this->__settings[$Model->alias] = Set::merge($this->__settings[$Model->alias], $settings); }