public static function find($id) { $row = parent::find($id, UserModel::get_table_name()); $um = new UserModel($row["first_name"], $row["last_name"], $row["email"], $row["password"], $row["last_login"], $row["failed_login_attempts"], $row["date_created"]); $um->id = $row["id"]; return $um; }
public static function find($id) { $row = parent::find($id, PageModel::get_table_name()); $pm = new PageModel($row["page_text"], $row["adventure_id"], $row["image_url"], $row["date_created"]); $pm->id = $row["id"]; return $pm; }
/** * * @param AppModel $model */ public function refreshMirror($model, $checkPendingOperations = false) { if ($checkPendingOperations) { if ($this->_pending[$model->alias] > 0) { return; } $this->_pending[$model->alias] = 0; } $config = $this->settings[$model->alias]; if ($model->Behaviors->enabled('Translate')) { if ($config['findOptions']['recursive'] >= 0 || $model->Behaviors->Translate->settings[$model->alias]) { $oldLang = SlConfigure::read('I18n.lang'); $locales = SlConfigure::read('I18n.locales'); $localesPreg = '/_' . implode('$|_', $locales) . '$/'; foreach ($locales as $lang => $locale) { Sl::setLocale($lang); $data = $model->find($config['findType'], $config['findOptions']); if ($config['collectionField']) { $this->_cleanup($config['name'], $locale); } $this->_write($config['name'], $this->_prepareData($model, $config, $data, $localesPreg), $locale); } Sl::setLocale($oldLang); return; } } $data = $model->find($config['findType'], $config['findOptions']); if ($config['collectionField']) { $this->_cleanup($config['name']); } $this->_write($config['name'], $this->_prepareData($model, $config, $data)); }
public function find($conditions = null, $fields = array(), $order = null, $recursive = null) { if (isset($this->userType) && $this->userType == 'admin') { $this->contain("{$this->User->alias}.Hospital.code"); } return parent::find($conditions, $fields, $order, $recursive); }
function __validateOneUser() { if (parent::find('count')) { return false; } return true; }
public function find($type = 'first', $queryData = array()) { $catalog_field = 'backup_catalog'; $this->hasMany['Dataset']['conditions'][$catalog_field] = '1'; $queryData = array_merge_recursive(array('order' => array('Datachannel.ord' => 'asc'), 'limit' => 100), $queryData); return parent::find($type, $queryData); }
/** * Register pingback comment. Used by pingback server * * @param AppModel $model * @param string $modelId * @param array $options * @param string $sourceUri * @param string $targetUri * @return boolean */ public function pingbackRegisterComment(&$model, $modelId, $sourceUri, $targetUri) { extract($this->settings[$model->alias]); if ($model->{$commentAlias}->hasAny(array($commentAlias . '.foreign_key' => $modelId, 'author_url' => $sourceUri))) { throw new XmlRpcResponseException(0, 'Pingback already registries in system.'); } $sourceBody = $this->loadPageContent($sourceUri); if (strpos($sourceBody, $targetUri) === false) { throw new XmlRpcResponseException(0, 'Source link is not detected in target blog.'); } $sourceBody = $this->cleanupPage($sourceBody); $title = $this->fetchTitle($sourceBody); $cite = $this->fetchPingbackCite($sourceBody, $sourceUri, $targetUri); $isSpam = false; $data = array('comment_type' => 'pingback', 'author_name' => $title . 'blog', 'author_url' => $sourceUri, 'title' => $title, 'foreign_key' => $modelId, 'model' => $model->alias, 'body' => $cite); if ($model->{$commentAlias}->Behaviors->enabled('Antispamable')) { $isSpam = $model->isSpam(); } $data['is_spam'] = $isSpam ? 'spam' : 'clean'; $modelData = $model->find('first', array('conditions' => array('id' => $modelId), 'recursive' => -1)); if (!empty($modelData[$model->alias][$requireApproveModelField])) { $data[$requireApproveCommentField] = 0; } $model->{$commentAlias}->create($data); return $model->{$commentAlias}->save(); }
public static function find($id) { $row = parent::find($id, AdventureModel::get_table_name()); $am = new AdventureModel($row["title"], $row["user_id"], $row["date_created"]); $am->id = $row["id"]; return $am; }
function find($type = 'first', $queryData = array()) { $this->belongsTo['Folder']['conditions']['Application.enabled'] = '1'; $fields = array('Application.id', 'Application.slug', 'Application.name', 'Application.plugin', 'Application.type', 'Application.home', 'Folder.id', 'Folder.slug', 'Folder.name', 'Application.folder_id'); $queryData = array_merge(array('fields' => $fields, 'order' => array(array('Application.ord' => 'asc')), 'limit' => 100, 'conditions' => array('Application.enabled' => '1')), $queryData); return parent::find($type, $queryData); }
public function find($type = 'first', $queryData = array()) { if ($type == 'first' && (($alias = @$queryData['conditions']['Dataset.alias']) || ($alias = @$queryData['conditions']['Dataset.base_alias']))) { App::import('model', 'MPCache'); $this->MPCache = new MPCache(); $output = $this->MPCache->getDataset($alias, @$queryData['full']); if (!empty($output)) { $output['orders'] = isset($output['orders_es']) ? $output['orders_es'] : array(); } if (!empty($output['filters'])) { foreach ($output['filters'] as &$f) { if (strpos($f['filter']['field'], '.') === false) { $f['filter']['field'] = $alias . '.' . $f['filter']['field']; } } } return $output; } $fields = array(); if (isset($queryData['fields'])) { $fields = $queryData['fields']; } else { $fields = array('Dataset.id', 'Dataset.alias', 'Dataset.name', 'Dataset.class', 'Dataset.count', 'Dataset.channel_id', 'Dataset.default_sort', 'Datachannel.id', 'Datachannel.nazwa', 'Datachannel.slug', 'App.id', 'App.name', 'App.plugin', 'App.slug'); } $queryData = array_merge_recursive(array('fields' => $fields, 'limit' => 100), $queryData); return parent::find($type, $queryData); }
/** * Returns a result set array. * * Also used to perform new-notation finds, where the first argument is type of find operation to perform * (sum / all / first / count / neighbors / list / threaded ), * second parameter options for finding ( indexed array, including: 'conditions', 'limit', * 'recursive', 'page', 'fields', 'offset', 'order') * * Eg: * {{{ * find('all', array( * 'conditions' => array('name' => 'Thomas Anderson'), * 'fields' => array('name', 'email'), * 'order' => 'field3 DESC', * 'recursive' => 2, * 'group' => 'type' * )); * }}} * * Specifying 'fields' for new-notation 'list': * * - If no fields are specified, then 'id' is used for key and 'model->displayField' is used for value. * - If a single field is specified, 'id' is used for key and specified field is used for value. * - If three fields are specified, they are used (in order) for key, value and group. * - Otherwise, first and second fields are used for key and value. * * @param array $conditions SQL conditions array, or type of find operation (all / first / count / neighbors / list / threaded) * @param mixed $fields Either a single string of a field name, or an array of field names, or options for matching * @param string $order SQL ORDER BY conditions (e.g. "price DESC" or "name ASC") * @param integer $recursive The number of levels deep to fetch associated records * @return array Array of records * @access public * @link http://book.cakephp.org/view/449/find */ function find($conditions = null, $fields = array(), $order = null, $recursive = null) { if (!empty($conditions)) { $conditions = strtolower($conditions); if ($conditions == 'sum') { $campoAMeter = array('sum("FondosLineasDeAccion"."monto") AS "FondosLineasDeAccion__sum"'); if (is_array($fields)) { if (!empty($fields['fields'])) { $fields['fields'] = Set::merge($fields['fields'], $campoAMeter); } else { $fields['fields'] = $campoAMeter; } if (!empty($fields['group'])) { $fields['fields'] = Set::merge($fields['fields'], $fields['group']); } } elseif (is_string($fields)) { return parent::find($conditions, $fields, $order, $recursive); } $trajo = parent::find('all', $fields, $order, $recursive); if (count($trajo) > 1) { return $trajo; } else { return $trajo[0]['FondosLineasDeAccion']['sum']; } } } return parent::find($conditions, $fields, $order, $recursive); }
public static function find($id) { $row = parent::find($id, QuestionModel::get_table_name()); $qm = new QuestionModel($row["page_id"], $row["q_and_a"], $row["date_created"]); $qm->id = $row["id"]; return $qm; }
function main() { if (empty($this->args)) { return $this->err('Usage: ./cake fixturize <table>'); } if ($this->args[0] == '?') { return $this->out('Usage: ./cake fixturize <table> [-force] [-reindex]'); } $options = array('force' => false, 'reindex' => false); foreach ($this->params as $key => $val) { foreach ($options as $name => $option) { if (isset($this->params[$name]) || isset($this->params['-' . $name]) || isset($this->params[$name[0]])) { $options[$name] = true; } } } foreach ($this->args as $table) { $name = Inflector::classify($table); $Model = new AppModel(array('name' => $name, 'table' => $table)); $file = sprintf('%stests/fixtures/%s_fixture.php', APP, Inflector::underscore($name)); $File = new File($file); if ($File->exists() && !$options['force']) { $this->err(sprintf('File %s already exists, use --force option.', $file)); continue; } $records = $Model->find('all'); $out = array(); $out[] = '<?php'; $out[] = ''; $out[] = sprintf('class %sFixture extends CakeTestFixture {', $name); $out[] = sprintf(' var $name = \'%s\';', $name); $out[] = ' var $records = array('; $File->write(join("\n", $out)); foreach ($records as $record) { $out = array(); $out[] = ' array('; if ($options['reindex']) { foreach (array('old_id', 'vendor_id') as $field) { if ($Model->hasField($field)) { $record[$name][$field] = $record[$name]['id']; break; } } $record[$name]['id'] = String::uuid(); } foreach ($record[$name] as $field => $val) { $out[] = sprintf(' \'%s\' => \'%s\',', addcslashes($field, "'"), addcslashes($val, "'")); } $out[] = ' ),'; $File->write(join("\n", $out)); } $out = array(); $out[] = ' );'; $out[] = '}'; $out[] = ''; $out[] = '?>'; $File->write(join("\n", $out)); $this->out(sprintf('-> Create %sFixture with %d records (%d bytes) in "%s"', $name, count($records), $File->size(), $file)); } }
function main() { if (empty($this->args)) { return $this->err('Usage: ./cake uuidize <table>'); } if ($this->args[0] == '?') { return $this->out('Usage: ./cake uuidize <table> [-force] [-reindex]'); } $options = array('force' => false, 'reindex' => false); foreach ($this->params as $key => $val) { foreach ($options as $name => $option) { if (isset($this->params[$name]) || isset($this->params['-' . $name]) || isset($this->params[$name[0]])) { $options[$name] = true; } } } foreach ($this->args as $table) { $name = Inflector::classify($table); $Model = new AppModel(array('name' => $name, 'table' => $table)); $records = $Model->find('all'); foreach ($records as $record) { $Model->updateAll(array('id' => '"' . String::uuid() . '"'), array('id' => $record[$name]['id'])); } } }
function find($type = 'first', $options = array()) { if (isset($options['hideSecret']) && $options['hideSecret'] == true) { $options['conditions'] = am(@$options['conditions'], array('AND' => array("LOCATE('s', SUBSTRING_INDEX(Channel.defmodes, ' ', 1))" => 0, "LOCATE('p', SUBSTRING_INDEX(Channel.defmodes, ' ', 1))" => 0))); } unset($options['hideSecret']); return parent::find($type, $options); }
function __findFollowing() { $origins = parent::find('all', array('fields' => array('Origin.name'), 'conditions' => array('Origin.following' => true), 'order' => array('Origin.name' => 'asc'))); $ret = array(); foreach ($origins as $origin) { $ret[] = '@' . $origin['Origin']['name']; } return $ret; }
public function find($conditions = null, $fields = array(), $order = null, $recursive = null) { $result = Cache::read('test', 'short'); if (!$result) { $result = parent::find($conditions, $fields, $order, $recursive); Cache::write('test', $result, 'short'); } return $result; }
/** * Overwrite find so I can do some nice things with it. * * Type 'last' finds the last record by created date. * * {@inheritDoc} */ public function find($type = 'first', $options = array()) { switch ($type) { case 'last': $options = array_merge($options, array('order' => "{$this->alias}.{$this->primaryKey} DESC")); return parent::find('first', $options); default: return parent::find($type, $options); } }
function __findOrSave($tags) { $existing = parent::find('list', array('fields' => array('Tag.Id', 'Tag.name'), 'conditions' => array('Tag.name' => $tags))); $new = array_diff($tags, $existing); foreach ($new as $tag) { $this->create(); $this->save(array('name' => $tag)); $existing[$this->id] = $tag; } return $existing; }
/** * find override * * @param type $type * @param array $query * @return type */ public function find($type = 'first', $query = array()) { // [TIPS] // CakePHPはdefaultでAssociation指定の全Modelがリレーションされてしまうので // ContainableBehaviorを有効にしつつ、containの空配列を強制的に追加することで、 // defaultでMainモデル以外の配列が戻らなくなるように調整 if (!isset($query['contain'])) { $query['contain'] = false; } return parent::find($type, $query); }
public function find($type = 'first', $params = array()) { $return_db = parent::find($type, $params); if (isset($return_db['User'])) { //small hack for loading media image sprintf (can slow the request ) $user = ClassRegistry::init('User'); $return_db2 = $user->read(null, $return_db['User']['id']); $return_db['User'] = $return_db2['User']; //end hack } return $return_db; }
/** * beforeSave callback, initializes unique code fields * * @param AppModel $Model * @return boolean * @access public */ public function beforeSave($Model) { extract($this->settings[$Model->alias]); if ($field && !$Model->exists()) { do { $token = $this->generateToken($Model, $length, $possible, $notStartWith); } while ((bool) $Model->find('count', array('conditions' => array($field => $token)))); $Model->set($field, $token); $this->_addToWhitelist($Model, $field); } return true; }
public function search($keyword) { $this->request = array('uri' => array('host' => 'api.cosm.com', 'path' => 'v2/feeds.json?per_page=10&tag=smartcitizen&q=' . urlencode($keyword)), 'header' => array('X-ApiKey' => Configure::read('cosm.apikey'))); $return = parent::find('all'); if (!$return) { return; } $feeds = array(); foreach ($return['results'] as $key => $feed) { $feeds[$key]['Feed'] = $this->_format($feed); } return $feeds; }
/** * Upgrade to 4.0.0. */ public function to_400() { $this->out('<warning>This upgrade will delete the following tables after migration: settings, access, access_levels, profiles, reported.</warning>'); $answer = strtoupper($this->in('All data will be migrated to the new admin system, are you sure you want to continue?', array('Y', 'N'))); if ($answer === 'N') { exit; } // Migrate old reports to the new admin system $this->out('<success>Migrating reports...</success>'); $ItemReport = ClassRegistry::init('Admin.ItemReport'); $Reported = new AppModel(null, 'reported', $this->dbConfig); $Reported->alias = 'Reported'; $Reported->tablePrefix = $this->tablePrefix; foreach ($Reported->find('all') as $report) { switch ($report['Reported']['itemType']) { case 1: $model = 'Forum.Topic'; break; case 2: $model = 'Forum.Post'; break; case 3: $model = $this->usersModel; break; } $ItemReport->reportItem(array('reporter_id' => $report['Reported']['user_id'], 'model' => $model, 'foreign_key' => $report['Reported']['item_id'], 'item' => $report['Reported']['item_id'], 'reason' => $report['Reported']['comment'], 'created' => $report['Reported']['created'])); } // Migrate profile data to users table $this->out('<success>Migrating user profiles...</success>'); $User = ClassRegistry::init($this->usersModel); $fieldMap = Configure::read('User.fieldMap'); $Profile = new AppModel(null, 'profiles', $this->dbConfig); $Profile->alias = 'Profile'; $Profile->tablePrefix = $this->tablePrefix; foreach ($Profile->find('all') as $prof) { $query = array(); foreach (array('signature', 'locale', 'timezone', 'totalPosts', 'totalTopics', 'lastLogin') as $field) { if ($key = $fieldMap[$field]) { $query[$key] = $prof['Profile'][$field]; } } if (!$query) { continue; } $User->id = $prof['Profile']['user_id']; $User->save(array_filter($query), false); } // Delete tables handled by parent shell $this->out('<success>Deleting old tables...</success>'); return true; }
function __findLetter($options = array()) { if (!isset($options['letter']) || $options['letter'] == '#') { $c = array('OR' => array('ASCII(LEFT(UserProfile.username,1)) < ' => 65, 'AND' => array('ASCII(LEFT(UserProfile.username,1)) >' => 90, 'ASCII(LEFT(UserProfile.username,1)) <' => 97), 'ASCII(LEFT(UserProfile.username,1)) >' => 122)); /* Handle special characters */ } else { $c = array('LEFT(UserProfile.username,1)' => $options['letter'][0]); } $options['conditions'] = am(@$options['conditions'], $c); unset($options['letter']); $output = 'all'; if (isset($options['output'])) { $output = $options['output']; unset($options['output']); } return parent::find($output, $options); }
/** * beforeSave callback, initializes slugs * * @param AppModel $Model * @return boolean * @access public */ public function beforeSave($Model) { if (empty($this->settings[$Model->alias]) || $Model->id && !$this->settings[$Model->alias]['overwrite']) { return true; } $label = ''; foreach ($this->settings[$Model->alias]['label'] as $field) { if (!empty($Model->data[$Model->alias][$field])) { $label .= ($label ? ' ' : '') . $Model->data[$Model->alias][$field]; } } if ($label) { $slug = $this->__slug($label, $this->settings[$Model->alias]); $conditions = array($Model->alias . '.' . $this->settings[$Model->alias]['slug'] => 'LIKE ' . $slug . '%'); if ($Model->id) { $conditions[$Model->alias . '.' . $Model->primaryKey] = '!= ' . $Model->id; } if ($scope = $this->settings[$Model->alias]['scope']) { if (empty($Model->data[$Model->alias][$scope])) { trigger_error('SluggableBehavior: missing data for SAVING scoped field ' . $scope . ' in model ' . $Model->name, E_USER_ERROR); return false; } $conditions[$Model->alias . '.' . $scope] = $Model->data[$Model->alias][$scope]; } $fields = array($Model->primaryKey, $this->settings[$Model->alias]['slug']); $recursive = -1; $sameUrls = null; if ($result = $Model->find('all', compact('conditions', 'fields', 'recursive'))) { if ($sameUrls = Set::extract($result, '{n}.' . $Model->alias . '.' . $this->settings[$Model->alias]['slug'])) { $begginingSlug = $slug; $index = 1; while ($index > 0) { if (!in_array($begginingSlug . $this->settings[$Model->alias]['separator'] . $index, $sameUrls)) { $slug = $begginingSlug . $this->settings[$Model->alias]['separator'] . $index; $index = -1; } $index++; } } } $this->_addToWhitelist($Model, $this->settings[$Model->alias]['slug']); $Model->data[$Model->alias][$this->settings[$Model->alias]['slug']] = $slug; } return true; }
public function read($fields = null, $id = null) { $return_cosm = $this->Cosm->read($fields, $id); $return_db = parent::find('first', array('conditions' => array('Feed.cosm_id' => $return_cosm['id']))); if ($return_db['Feed']) { //small hack for loading media image sprintf $user = ClassRegistry::init('User'); $return_db2 = $user->read(null, $return_db['Feed']['user_id']); $return_db['User'] = $return_db2['User']; //end hack $return = $return_db; $return['Feed'] = array_merge($return_db['Feed'], $return_cosm); } else { $return['Feed'] = $return_cosm; } // debug($return_db); return $return; }
/** * * @param AppModel $model * @param int $id */ public function findCached($model, $what, $options = array()) { if (empty($options['fields'])) { $options['fields'] = "{$model->alias}.{$model->primaryKey}"; } $results = $model->find($what, $options); if ($results && is_array($results)) { if (isset($results[0])) { $data = array(); foreach ($results as $item) { $data[] = $this->readCached($model, $item[$model->alias][$model->primaryKey]); } return $data; } else { return $this->readCached($model, $results[$model->alias][$model->primaryKey]); } } return $results; }
public function find($type = 'first', $query = array()) { $model = $this; if ($type === 'list' && empty($query) && !empty($model->_listDataCache)) { return $model->_listDataCache; } $alias = $model->alias; $deleted = $model->deleted; $sort = $model->sort; $deleteFlag = $model->logicDeleteFlag; if (!isset($query['conditions'])) { $query['conditions'] = array(); } if ($deleteFlag) { $query['conditions'][$alias . '.' . $deleted] = null; } if (!isset($query['order']) && empty($query['order'])) { $query['order'] = array($alias . '.' . $sort => 'ASC'); } return parent::find($type, $query); }
/** * Overriden to implement 'near' find type, and support for 'count' with 'near' * * @param array $conditions SQL conditions array, or type of find operation (all / first / count / neighbors / list / threaded) * @param mixed $fields Either a single string of a field name, or an array of field names, or options for matching * @param string $order SQL ORDER BY conditions (e.g. "price DESC" or "name ASC") * @param integer $recursive The number of levels deep to fetch associated records * @return array Array of records */ public function find($conditions = null, $fields = array(), $order = null, $recursive = null) { $findMethods = array_merge($this->_findMethods, array('near' => true)); $findType = is_string($conditions) && $conditions != 'count' && array_key_exists($conditions, $findMethods) ? $conditions : null; if (empty($findType) && is_string($conditions) && $conditions == 'count' && !empty($fields['type']) && array_key_exists($fields['type'], $findMethods)) { $findType = $fields['type']; unset($fields['type']); } if ($findType == 'near' && $this->Behaviors->enabled('Geocodable')) { $type = $conditions == 'near' ? 'all' : $conditions; $query = $fields; if (!empty($query['address'])) { foreach (array('address', 'unit', 'distance') as $field) { ${$field} = isset($query[$field]) ? $query[$field] : null; unset($query[$field]); } return $this->near($type, $address, $distance, $unit, $query); } } return parent::find($conditions, $fields, $order, $recursive); }