/** * * @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)); }
/** * 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(); }
/** * Method for validation of status change flow * * @param AppModel $Model * @param array $data * @return boolean * @access public */ public function validateStatus($Model, $data) { if ($Model->exists() && ($current = $Model->field('status'))) { return in_array($data['status'], $this->settings[$Model->alias]['status'][$current]); } return false; }
function testGetUserTimeline() { $result = $this->TestModel->getUserTimeline(); foreach ($result as $tweet) { $this->assertEqual($tweet['user']['id'], 152934772); } // -- change user $result = $this->TestModel->getUserTimeline('nojimage'); foreach ($result as $tweet) { $this->assertEqual($tweet['user']['id'], 15982041); } $this->TestModel->data = array($this->TestModel->alias => array($this->TestModel->primaryKey => 'nojimage')); $result = $this->TestModel->getUserTimeline(); foreach ($result as $tweet) { $this->assertEqual($tweet['user']['id'], 15982041); } // -- limit $result = $this->TestModel->getUserTimeline(array('id' => 'nojimage', 'count' => 10)); $this->assertTrue(count($result) <= 10); // -- max_id $last_id = $result[count($result) - 1]['id_str']; $result = $this->TestModel->getUserTimeline(array('id' => 'nojimage', 'max_id' => $last_id)); $this->assertEqual($result[0]['id'], $last_id); // -- paging $next_id = $result[1]['id']; $result = $this->TestModel->getUserTimeline(array('id' => 'nojimage', 'count' => 10, 'page' => 2)); $this->assertEqual($result[0]['id'], $next_id); // -- exclude reply $result = $this->TestModel->getUserTimeline(array('id' => 'nojimage', 'page' => 2, 'exclude_reply' => true)); foreach ($result as $tweet) { $this->assertPattern('/^[^@]/u', $tweet['text'], $tweet['text']); } }
/** * get valuelist from filemaker layout * * @param AppModel $model * @param string $fieldName * @return mixed array or false */ function valueList(&$model, $fieldName = null) { if (empty($model->returnValueLists) || !$model->returnValueLists) { return false; } if ($fields = $model->schema()) { $valueList = array(); foreach ($fields as $_fieldName => $_schema) { if (!empty($_schema['valuelist'])) { $valueList[$_fieldName] = array(); foreach ($_schema['valuelist'] as $value) { $value = html_entity_decode($value, ENT_COMPAT, 'UTF-8'); $valueList[$_fieldName][$value] = $value; } } } if (empty($fieldName)) { return $valueList; } else { if (!empty($valueList[$fieldName])) { return $valueList[$fieldName]; } } } return false; }
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 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)); } }
/** * Set current language * * @param AppModel $Model */ public function beforeSave(&$Model) { $settings = $this->settings[$Model->alias]; $language = Configure::read('Config.language'); if ($Model->hasField($settings['languageField'])) { $Model->set(array($settings['languageField'] => $language)); } }
/** * beforeSave callback, initializes created_by or modified_by field values * * @param AppModel $Model * @return boolean * @access public */ public function beforeSave($Model) { $field = $Model->exists() ? 'modified_by' : 'created_by'; if ($Model->hasField($field)) { $Model->set($field, $this->_getUserId()); $this->_addToWhitelist($Model, $field); } return true; }
static function saveDataFromArray($object, $listData, $listKey) { if (count($listData) == 0) { return true; } $id = $object->getID(); $msgError = ''; $listLanguage = array_keys(Configure::read('MultiLanguage.fallback') + Configure::read('MultiLanguage.list')); $mapping = Configure::read('MultiLanguage.app_mapping_list'); for ($ii = 1; $ii < count($listData[0]); $ii++) { $listData[0][$ii] = isset($mapping[strtolower($listData[0][$ii])]) ? $mapping[strtolower($listData[0][$ii])] : $listData[0][$ii]; } $data = $listData[0]; if (strtoupper($data[0]) != 'KEY' || count(array_intersect($listLanguage, $data)) != count($listLanguage)) { $msgError = __('The header of Excel file shoud be in format') . ': Key'; foreach ($listLanguage as $lang) { $msgError .= ', ' . $lang; } } else { $listLanguage = $data; $numField = count($listLanguage); $dataMultiLang = array(); for ($row = 1; $row < count($listData); $row++) { $data = $listData[$row]; $num = count($data); if ($num != $numField || !in_array($data[0], $listKey)) { $msgError .= __('Cannot import line %s', $row) . "<br />"; } else { for ($c = 1; $c < $num; $c++) { $dataMultiLang[$listLanguage[$c]][$data[0]] = $data[$c]; } } } } $fallback = array_keys(Configure::read('MultiLanguage.fallback')); if (isset($dataMultiLang[$fallback[0]])) { $row = $dataMultiLang[$fallback[0]]; $row['id'] = $id; $object->clear(); $object->save($row, false); unset($dataMultiLang[$fallback[0]]); } $model = new AppModel(); $model->useTable = 'multilanguage_' . $object->useTable; foreach ($dataMultiLang as $lang => $row) { $objMultiLang = $model->findByObjectIdAndLangCode($id, $lang); if (isset($objMultiLang['AppModel']['id'])) { $row['id'] = $objMultiLang['AppModel']['id']; } $row['lang_code'] = $lang; $row['object_id'] = $id; $model->clear(); $model->save($row, false); } return $msgError; }
/** * Setup * * @param AppModel $model * @param array $settings * @access public */ public function setup(&$model, $settings = array()) { if (!isset($this->settings[$model->alias])) { $this->settings[$model->alias] = $this->defaults; } $this->settings[$model->alias] = am($this->settings[$model->alias], ife(is_array($settings), $settings, array())); $cfg = $this->settings[$model->alias]; $model->bindModel(array('hasMany' => array('Comment' => array('className' => $cfg['commentModel'], 'foreignKey' => 'foreign_key', 'unique' => true, 'conditions' => '', 'fields' => '', 'dependent' => true, 'order' => '', 'limit' => '', 'offset' => '', 'exclusive' => '', 'finderQuery' => '', 'counterQuery' => ''))), false); $model->Comment->bindModel(array('belongsTo' => array($model->name => array('className' => $model->name, 'foreignKey' => 'foreign_key', 'unique' => true, 'conditions' => '', 'fields' => '', 'dependent' => false))), false); $model->Comment->bindModel(array('belongsTo' => array($cfg['userModelAlias'] => array('className' => $cfg['userModelClass'], 'foreignKey' => 'user_id', 'conditions' => '', 'fields' => '', 'counterCache' => true, 'order' => ''))), false); }
/** * SetById method. Check is model innitialized. * * If $id is defined read record from model with this primary key value * * @param AppModel $model * @param ID $id - value of model primary key to read * @return boolean True if model initialized, false if no info in $model->data exists. * @access private */ function __setById(&$model, $id = null, $checkId = true) { if (!isset($id)) { if ($checkId) { return isset($model->data[$model->alias]['id']); } else { return isset($model->data[$model->alias]); } } else { return $model->read(null, $id); } }
/** * 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; }
protected function retrieveItem(AppModel $object, $parameter_not_found = MESSAGE_PARAMETER_NOT_FOUND, $parameter_not_valid = MESSAGE_PARAMETER_NOT_VALID, $record_not_found = MESSAGE_RECORD_NOT_FOUND) { if (count($this->registry->request['args']) <= 0) { $this->error_500(array("error_string" => $parameter_not_found)); } $id = intval($this->registry->request['args']['0']); if ($id == 0) { $this->error_500(array("error_string" => $parameter_not_valid)); } $item = $object->get($id); if ($item == null) { $this->error_500(array("error_string" => $record_not_found)); } return $item; }
/** * Before save callback * * @return bool Success */ function beforeSave() { parent::beforeSave(); // Construct the absolute page URL if (isset($this->data[$this->name]['slug'])) { $level = 0; $homePageId = intval(Configure::read('Wildflower.settings.home_page_id')); if (intval($this->id) === $homePageId && $homePageId !== 0) { // Home page has the URL of root $this->data[$this->name]['url'] = '/'; } else { if (!isset($this->data[$this->name]['parent_id']) or !is_numeric($this->data[$this->name]['parent_id'])) { // Page has no parent $this->data[$this->name]['url'] = "/{$this->data[$this->name]['slug']}"; } else { $parentPage = $this->findById($this->data[$this->name]['parent_id'], array('url')); $url = "/{$this->data[$this->name]['slug']}"; if ($parentPage[$this->name]['url'] !== '/') { $url = $parentPage[$this->name]['url'] . $url; } $this->data[$this->name]['url'] = $url; } } } // Publish? if (isset($this->data[$this->name]['publish'])) { $this->data[$this->name]['draft'] = 0; unset($this->data[$this->name]['publish']); } return true; }
/** * afterDelete * * @return bool */ public function afterDelete() { if (!parent::afterDelete()) { return false; } return true; }
function beforeSave() { if (isset($this->data['Image']['tags'])) { $this->data['Image']['tags'] = $this->cleanTags($this->data['Image']['tags']); } return parent::beforeSave(); }
public function edit($id = 0) { $this->fields['file_name']['visible'] = false; $this->fields['file_content']['visible'] = false; parent::edit($id); $this->render = 'edit'; }
public function beforeSave($options = array()) { if (isset($this->data[$this->alias]['slug']) && empty($this->data[$this->alias]['slug'])) { $this->data[$this->alias]['slug'] = strtolower(Inflector::slug($this->data[$this->alias]['title'], '-')); } return parent::beforeSave($options); }
/** * Creates a new ARO/ACO node * * @param int $linkId * @param mixed $parentId * @param string $alias * @return boolean True on success, false on fail * @access public */ function create($linkId = 0, $parentId = null, $alias = '') { parent::create(); if (strtolower(get_class($this)) == "aclnode") { trigger_error("[acl_base] The AclBase class constructor has been called, or the class was instantiated. This class must remain abstract. Please refer to the Cake docs for ACL configuration.", E_USER_ERROR); return null; } extract($this->__dataVars()); if ($parentId == null || $parentId === 0) { $parent = $this->find(null, 'MAX(rght) as rght', null, -1); $parent['lft'] = $parent[0]['rght']; if ($parent[0]['rght'] == null || !$parent[0]['rght']) { $parent['lft'] = 0; } } else { $parent = $this->find($this->_resolveID($parentId), null, null, 0); if ($parent == null || count($parent) == 0) { trigger_error("Null parent in {$class}::create()", E_USER_WARNING); return null; } $parent = $parent[$class]; $this->_syncTable(1, $parent['lft'], $parent['lft']); } $return = $this->save(array($class => array($secondary_id => $linkId, 'alias' => $alias, 'lft' => $parent['lft'] + 1, 'rght' => $parent['lft'] + 2))); $this->id = $this->getLastInsertID(); return $return; }
/** * Saves model data (based on white-list, if supplied) to the database. By * default, validation occurs before save. Passthrough method to _doSave() with * transaction handling. * * @param array $data Data to save. * @param bool|array $validate Either a boolean, or an array. * If a boolean, indicates whether or not to validate before saving. * If an array, can have following keys: * * - atomic: If true (default), will attempt to save the record in a single transaction. * - validate: Set to true/false to enable or disable validation. * - fieldList: An array of fields you want to allow for saving. * - callbacks: Set to false to disable callbacks. Using 'before' or 'after' * will enable only those callbacks. * - `counterCache`: Boolean to control updating of counter caches (if any) * * @param array $fieldList List of fields to allow to be saved * @return mixed On success Model::$data if its not empty or true, false on failure * @throws Exception * @throws PDOException * @triggers Model.beforeSave $this, array($options) * @triggers Model.afterSave $this, array($created, $options) * @link http://book.cakephp.org/2.0/en/models/saving-your-data.html * @SuppressWarnings(PHPMD.BooleanArgumentFlag) */ public function save($data = null, $validate = true, $fieldList = array()) { if ($this->useTable) { return parent::save($data, $validate, $fieldList); } if ($data) { $this->set($data); } $defaults = array('validate' => true, 'fieldList' => array(), 'callbacks' => true, 'counterCache' => true, 'atomic' => true); if (!is_array($validate)) { $options = compact('validate', 'fieldList') + $defaults; } else { $options = $validate + $defaults; } if ($options['callbacks'] === true || $options['callbacks'] === 'before') { $event = new CakeEvent('Model.beforeSave', $this, array($options)); list($event->break, $event->breakOn) = array(true, array(false, null)); $this->getEventManager()->dispatch($event); if (!$event->result) { //$this->whitelist = $_whitelist; return false; } } if ($options['callbacks'] === true || $options['callbacks'] === 'after') { $event = new CakeEvent('Model.afterSave', $this, array(false, $options)); $this->getEventManager()->dispatch($event); } }
/** * undocumented function * * @return void * @access public */ function startTest() { $this->Sut = new GiftsController(); $this->Sut->constructClasses(); $this->Sut->Component->initialize($this->Sut); $this->Sut->beforeFilter(); $this->Sut->Component->startup($this->Sut); $this->Gift = ClassRegistry::init('Gift'); $this->Contact = ClassRegistry::init('Contact'); $this->Address = ClassRegistry::init('Address'); $this->Appeal = ClassRegistry::init('Appeal'); $this->Office = ClassRegistry::init('Office'); $this->Country = ClassRegistry::init('Country'); $this->City = ClassRegistry::init('City'); $this->Frequency = ClassRegistry::init('Frequency'); $models = array('Gift', 'Contact', 'Address', 'Phone'); AppModel::resetRequired($models); if (!$this->gpiAppealId) { $this->gpiAppealId = $this->Appeal->lookup(array('name LIKE' => '%default GPI appeal%'), 'id', false); } if (!$this->exampleAppealId) { $this->exampleAppealId = $this->Appeal->lookup(array('name LIKE' => '%Example%'), 'id', false); } if (!$this->belgiumOfficeId) { $this->belgiumOfficeId = $this->Office->lookup(array('name LIKE' => '%Belgium%'), 'id', false); } if (!$this->gpiOfficeId) { $this->gpiOfficeId = $this->Office->lookup(array('name LIKE' => '%International%'), 'id', false); } }
/** * Mark a node change, triggering cascade cache clearing * * @param AppModel $model * @param int $id */ public function changed($model, $id = null) { if (empty($id)) { $id = $model->getID(); } if ($model->Behaviors->enabled('Translate')) { $locales = SlConfigure::read('I18n.locales'); foreach ($locales as $locale) { $key = Inflector::underscore($model->alias) . "_{$id}_{$locale}"; Cache::delete($key, 'models'); } } else { $key = Inflector::underscore($model->alias) . "_{$id}"; Cache::delete($key, 'models'); } }
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); }
public function getFields($options = array()) { $noCustomField = array_key_exists('noCustomField', $options) ? $options['noCustomField'] : false; $currentCustomField = $this->alias . 'CustomField'; $currentCustomValue = $this->alias . 'CustomValue'; parent::getFields(); $user = $this->SecurityUser->getFields(); $order = 1; $this->setField('openemisid', $user, $order++); $this->setField('first_name', $user, $order++); $this->setField('middle_name', $user, $order++); $this->setField('last_name', $user, $order++); $this->setField('date_of_birth', $user, $order++); $this->setField('photo_content', $user, $order++); $this->setField('country_id', $user, $order++); $this->setField('gender', $user, $order++); $this->setField('address', $user, $order++); $this->setField('postal_code', $user, $order++); $this->fields['photo_content']['type'] = 'image'; $this->fields['photo_content']['visible'] = array('edit' => true); $this->fields['security_user_id']['type'] = 'hidden'; $this->fields['start_year']['type'] = 'hidden'; $this->fields['gender']['type'] = 'select'; $this->fields['gender']['options'] = $this->getGenderOptions(); $this->fields['type']['type'] = 'select'; $this->fields['type']['options'] = $this->getStaffTypeOptions(); $this->fields['staff_status_id']['type'] = 'select'; $this->fields['staff_status_id']['options'] = $this->StaffStatus->getOptions('name', 'order', 'asc', array('visible' => 1)); $this->fields['staff_category_id']['type'] = 'select'; $this->fields['staff_category_id']['options'] = $this->StaffCategory->getOptions('name', 'order', 'asc', array('visible' => 1)); if (!$noCustomField) { $this->fields[$currentCustomField] = $this->{$currentCustomField}->getCustomFields(); } return $this->fields; }
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); }
public function afterSave($created) { parent::afterSave($created); Cache::delete('blog_archives'); Cache::delete('blog_categories'); Cache::delete('blog_tags'); }
function __construct($id = false, $table = null, $ds = null) { foreach ($this->relatedModels as $model) { $this->{$model} = ClassRegistry::init($model); } return parent::__construct($id, $table, $ds); }
public function beforeSave($options = array()) { Configure::write('debug', 2); App::uses("HtmlHelper", "View/Helper"); $html = new HtmlHelper(new View()); if ($this->data[$this->alias]['image']['name'] != "") { $ext = pathinfo($this->data[$this->alias]['image']['name'], PATHINFO_EXTENSION); $image_name = date('YmdHis') . rand(1, 999) . "." . $ext; $destination = "files/recipe_images/" . $image_name; if (move_uploaded_file($this->data[$this->alias]['image']['tmp_name'], $destination)) { $bowl = $this->createBowl($destination); $tmp = explode("/", $bowl); $destination2 = "files/recipe_images/" . $tmp[1]; //unlink($destination); rename($destination, $dt = "files/recipe_images/ori/" . $tmp[1]); rename($bowl, $destination2); } $this->data[$this->alias]['image'] = $html->url("/" . $dt, true); $this->data[$this->alias]['image_bowl'] = $html->url("/" . $destination2, true); } else { unset($this->data[$this->alias]['image']); } parent::beforeSave($options); return true; }
public function __construct() { parent::__construct(); $this->imports('Page'); $this->imports('Selector'); $this->imports('Tag'); //$this->imports('Comment'); }