public function addSet($name) { $s = new Set(); $s->setName($name); $this->sets[] = $s; return $s; }
/** * @test */ public function whenIteratingOverSet_ThenReturnAllUniqueItems() { $item1 = 'A'; $item2 = 'B'; $set = new Set(); $set->add($item1); $set->add($item2); $values = array(); foreach ($set as $key => $value) { $values[$key] = $value; } $this->assertEquals(array(0 => 'A', 1 => 'B'), $values); }
public function collaborators() { $subscriptions = $this->Subscription->findAllByClassAndForeignId('Workspace', $this->Session->read('Workspace.id')); $subscribers = Set::extract('/Subscription/user_id', $subscriptions); $subscribers = $this->Subscription->User->find('all', array('conditions' => array('User.id' => $subscribers), 'fields' => array('id', 'name', 'email', 'facebook_id'))); $this->set('subscribers', $subscribers); }
protected function _render($options) { $metaFields = array_keys(Set::filter(Set::booleanize($this->getParam('metaFields')))); echo '<div class="line-meta-details">'; echo $this->Html->postDetails($metaFields, array('prefixes' => array('author' => __('By', 'gummfw'), 'date' => __('/', 'gummfw'), 'comments' => __('/', 'gummfw'), 'category' => __('/', 'gummfw')), 'formats' => array('date' => 'd F Y'))); echo '</div>'; }
public function admin_index() { $this->set('title_for_layout', __('Content', true)); $this->Node->recursive = 0; $this->paginate['Node']['order'] = 'Node.id DESC'; $this->paginate['Node']['conditions'] = array(); $types = $this->Node->Term->Vocabulary->Type->find('all'); $typeAliases = Set::extract('/Type/alias', $types); $this->paginate['Node']['conditions']['Node.type'] = $typeAliases; if (isset($this->params['named']['filter'])) { $filters = $this->Croogo->extractFilter(); foreach ($filters as $filterKey => $filterValue) { if (strpos($filterKey, '.') === false) { $filterKey = 'Node.' . $filterKey; } $this->paginate['Node']['conditions'][$filterKey] = $filterValue; } $this->set('filters', $filters); } $nodes = $this->paginate('Node'); $this->set(compact('nodes', 'types', 'typeAliases')); if (isset($this->params['named']['links'])) { $this->layout = 'ajax'; $this->render('admin_links'); } }
/** * * @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('/'); }
function afterFind($data) { if ($data && is_array($data) && !Set::numeric(array_keys($data))) { $data = array($data); } if (is_array($data) && Set::numeric(array_keys($data))) { foreach ($data as $i => $row) { if (empty($row['user']) && !empty($row['sender'])) { $row['user'] = $row['sender']; $row['message'] = true; } else { $row['message'] = false; } $data[$i] = array('Item' => array('provider_key' => $row['id'], 'message' => $row['message'], 'text' => $row['text'], 'client' => $this->parse($row, 'source'), 'link' => 'http://twitter.com/' . $row['user']['screen_name'] . '/status/' . $row['id'], 'reply_user_provider_key' => $this->parse($row, 'in_reply_to_user_id'), 'reply_status_provider_key' => $this->parse($row, 'in_reply_to_status_id'), 'posted' => date('Y-m-d H:i:s', strtotime($row['created_at']))), 'Origin' => array('provider_key' => $row['user']['id'], 'name' => $row['user']['screen_name'], 'profile' => $row['user']['description'], 'origin_link' => $row['user']['url'], 'follower_count' => $row['user']['followers_count'], 'following_count' => $row['user']['friends_count'], 'update_count' => $row['user']['statuses_count'], 'avatar' => $row['user']['profile_image_url'], 'link' => 'http://twitter.com/' . $row['user']['screen_name'])); if ($this->name == 'TwitterAccount') { $data[$i]['Origin']['following'] = true; } if (!empty($row['retweeted_status'])) { $data[$i]['Item']['text'] = $row['retweeted_status']['text']; $data[$i]['ForwardOrigin'] = array('provider_key' => $row['retweeted_status']['user']['id'], 'name' => $row['retweeted_status']['user']['screen_name'], 'profile' => $row['retweeted_status']['user']['description'], 'origin_link' => $row['retweeted_status']['user']['url'], 'follower_count' => $row['retweeted_status']['user']['followers_count'], 'following_count' => $row['retweeted_status']['user']['friends_count'], 'update_count' => $row['retweeted_status']['user']['statuses_count'], 'avatar' => $row['retweeted_status']['user']['profile_image_url'], 'link' => 'http://twitter.com/' . $row['retweeted_status']['user']['screen_name']); } } } else { if (is_string($data)) { $dataArray = explode('&', $data); $data = array(); foreach ($dataArray as $value) { list($key, $value) = explode('=', $value); $data[$key] = $value; } } } return $data; }
function edit($id) { // if( (isset($this->data['Service']['submit'])) || (empty($this->data)) ) { if (empty($this->data)) { if (!$id) { $this->Session->setFlash('Invalid Service'); $this->redirect($this->referer('/')); } $this->data = $this->Service->findById($id); //$this->set('service',$this->data); $this->pageTitle = "Edit Service: {$this->data['Service']['title']}"; $this->set('user', Set::combine($this->Service->User->find('all', array('recursive' => 0)), '{n}.User.id', '{n}.User.name')); $this->set('customers', Set::combine($this->Service->Customer->find('all', array('recursive' => 0)), '{n}.Customer.id', '{n}.Customer.company_name')); } else { //$this->set('service',$this->Service->find(array('Service.id'=>$id))); if ($this->Service->save($this->data)) { $this->Session->setFlash("Website saved successfully."); $this->redirect($this->referer("/customers/view/{$this->data['Service']['customer_id']}")); } else { $this->Session->setFlash('Please correct errors below.'); $this->set('user', Set::combine($this->Service->User->find('all', array('recursive' => 0)), '{n}.User.id', '{n}.User.name')); $this->set('customers', Set::combine($this->Service->Customer->find('all', array('recursive' => 0)), '{n}.Customer.id', '{n}.Customer.company_name')); $this->pageTitle = 'Edit Service: ' . $this->data['Service']['title']; } } }
function index() { $this->Phrase->recursive = 0; $phrases = $this->paginate('Phrase'); $this->set('phrases', $phrases); //get the list of locales $this->loadModel("Locale"); //$locales = $this->Locale->find("list",array("fields"=>array("Locale.locale","Locale.name"),"order"=>array("name"=>"ASC"))); $locales = Lang::localeList(); $this->set("locales", $locales); //set the incoming locale to the session if (!empty($this->request->data)) { if (Set::check($this->request->data, "Phrase.selectLocale")) { $this->Session->write("ControlPanel.translate_locale", $this->request->data['Phrase']['selectLocale']); } } //get the locale from the session if ($this->Session->check("ControlPanel.translate_locale")) { $translate_locale = $this->Session->read("ControlPanel.translate_locale"); } else { $translate_locale = 'en_us'; $this->request->data['Phrase']['selectLocale'] = 'en_us'; } $this->request->data['Phrase']['selectLocale'] = $translate_locale; $this->Phrase->setLanguage($translate_locale); //get the trnaslated phrases $ids = Set::extract("/Phrase/id", $phrases); //pr($this->Session->read()); $locale_phrases = $this->Phrase->find('all', array("conditions" => array("Phrase.id" => $ids))); $this->set("locale_phrases", $locale_phrases); }
/** * 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 validate($prod, $order) { //debug($this->params); //debug($order); if (empty($order['ShopOrdersItem'])) { return false; } $ids = Set::extract('ShopOrdersItem.{n}.product_id', $order); $this->ShopProduct = ClassRegistry::init('Shop.ShopProduct'); $this->ShopProduct->Aro = ClassRegistry::init('Aro'); if (!empty($this->params['aroProduct'])) { $findOpt = array('fields' => array('Aro.foreign_key'), 'conditions' => array('Aro.model' => 'ShopProduct', 'Aro.foreign_key' => $ids), 'joins' => array(array('alias' => 'Parent', 'table' => $this->ShopProduct->Aro->useTable, 'type' => 'INNER', 'conditions' => array('Parent.id' => $this->params['aroProduct'], 'Aro.lft BETWEEN Parent.lft AND Parent.rght')))); $match = $this->ShopProduct->Aro->find('list', $findOpt); $match = array_values($match); } else { $match = $ids; } $qty = 0; foreach ($order['ShopOrdersItem'] as $item) { if (!empty($item['product_id']) && in_array($item['product_id'], $match)) { $qty += $item['nb']; } } return (!is_numeric($this->params['min']) || $qty >= $this->params['min']) && (!is_numeric($this->params['max']) || $qty <= $this->params['max']); }
public function edit($id = null) { if (!$this->Session->check('Workspace.id')) { $this->Redirect->flash('not_in_workspace', array('controller' => 'workspaces', 'action' => 'index')); } if (!empty($this->data['TaskGroup'])) { if (!empty($this->data['TaskGroup']['id']) && !empty($this->data['TaskGroup']['assigned_to_id'])) { $this->TaskGroup->id = $this->data['TaskGroup']['id']; $oldAssignedToId = $this->TaskGroup->field('assigned_to_id'); } } $Subscription = ClassRegistry::init('Subscription'); $subscribers = $Subscription->findAllByClassAndForeignId('Workspace', $this->Session->read('Workspace.id')); $subscribers = Set::extract('/Subscription/user_id', $subscribers); $assignedTos = $this->TaskGroup->User->findList(array('conditions' => array('User.id' => $subscribers), 'fields' => array('id', 'name'))); $this->set(compact('assignedTos')); $milestones = $this->TaskGroup->Milestone->find('list', array('conditions' => array('workspace_id' => $this->Session->read('Workspace.id')))); $this->set(compact('milestones')); $stacksConditions = array(); if ($this->Session->check('Milestone.id')) { $stacksConditions = array('conditions' => array('milestone_id' => $this->Session->read('Milestone.id'))); } else { $stacksConditions = array('conditions' => array('workspace_id' => $this->Session->read('Workspace.id'))); } $stacks = $this->TaskGroup->Stack->find('list', $stacksConditions); $this->set(compact('stacks')); parent::edit($id, array('controller' => 'tasks', 'action' => 'index')); }
/** * 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); }
/** * Extract all required information from a CanteenOrder to send to the GatewayAccount Processor * @param CanteenOrder $CanteenOrder * @return Array: */ public static function formatCanteenOrder($CanteenOrder) { $t = array(); $customer = $CanteenOrder['BillingAddress']; #TRANSACTION $t['Transaction']['currency_id'] = Set::classicExtract($CanteenOrder, "CanteenOrder.currency_id"); $t['Transaction']['amount'] = Set::classicExtract($CanteenOrder, "CanteenOrder.grand_total"); $t['Transaction']['foreign_key'] = Set::classicExtract($CanteenOrder, "CanteenOrder.id"); $t['Transaction']['model'] = "CanteenOrder"; #CUSTOMER $t['Customer']['first_name'] = Set::classicExtract($customer, "first_name"); $t['Customer']['last_name'] = Set::classicExtract($customer, "last_name"); $t['Customer']['address'] = Set::classicExtract($customer, "street") . " " . Set::classicExtract($customer, "apt"); $t['Customer']['postal'] = Set::classicExtract($customer, "postal_code"); $t['Customer']['country'] = Set::classicExtract($customer, "country_code"); $t['Customer']['email'] = Set::classicExtract($customer, "email"); $t['Customer']['city'] = Set::classicExtract($customer, "city"); $t['Customer']['state'] = Set::classicExtract($customer, "state"); $t['Customer']['phone'] = Set::classicExtract($customer, "phone"); $t['Customer']['user_id'] = Set::classicExtract($customer, "user_id"); #CARD DATA $t['CardData']['number'] = Set::classicExtract($CanteenOrder, "CardData.number"); $t['CardData']['exp_year'] = Set::classicExtract($CanteenOrder, "CardData.exp_year"); $t['CardData']['exp_month'] = Set::classicExtract($CanteenOrder, "CardData.exp_month"); $t['CardData']['code'] = Set::classicExtract($CanteenOrder, "CardData.code"); return $t; }
/** * リスト用の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); } }
function index() { $this->name = 'feedbacks'; $feedbacks = $this->Feedback->getAllFeedbacks(); $user_ids = Set::extract('/Feedback/user_id', $feedbacks); $this->set(array('feedbacks' => $feedbacks, 'feedback_posters' => $this->Profile->getProfilesInfoFromUserIds($user_ids), 'feedback_count' => $this->FeedbackComment->countFeedbackComments())); }
/** * Method to output a tag-cloud formatted based on the weight of the tags * * @param array $tags Tag data array * @param array $options Display options. Valid keys are: * - shuffle: true to shuffle the tag list, false to display them in the same order than passed [default: true] * - extract: Set::extract() compatible format string. Path to extract weight values from the $tags array [default: {n}.Tag.weight] * - before: string to be displayed before each generated link. "%size%" will be replaced with tag size calculated from the weight [default: empty] * - after: string to be displayed after each generated link. "%size%" will be replaced with tag size calculated from the weight [default: empty] * - maxSize: size of the heaviest tag [default: 160] * - minSize: size of the lightest tag [default: 80] * - url: an array containing the default URL * - named: the named parameter used to send the tag [default: by] * - paramType: the type of URL parameters used (named or querystring) [default: named] * @return string */ public function display($tags = null, $options = array()) { if (empty($tags) || !is_array($tags)) { return ''; } $defaults = array('tagModel' => 'Tag', 'shuffle' => true, 'extract' => '{n}.Tag.weight', 'before' => '', 'after' => '', 'maxSize' => 160, 'minSize' => 80, 'url' => array('controller' => 'search'), 'named' => 'by', 'paramType' => 'named'); $options = array_merge($defaults, $options); $weights = Set::extract($tags, $options['extract']); $maxWeight = max($weights); $minWeight = min($weights); // find the range of values $spread = $maxWeight - $minWeight; if (0 == $spread) { $spread = 1; } if ($options['shuffle'] == true) { shuffle($tags); } $cloud = null; foreach ($tags as $tag) { $data = Set::extract(array($tag), $options['extract']); $tagWeight = array_pop($data); $size = $options['minSize'] + ($tagWeight - $minWeight) * (($options['maxSize'] - $options['minSize']) / $spread); $size = $tag[$options['tagModel']]['size'] = ceil($size); $cloud .= $this->_replace($options['before'], $size); $cloud .= $this->Html->link($tag[$options['tagModel']]['name'], $this->_tagUrl($tag, $options), array('id' => 'tag-' . $tag[$options['tagModel']]['id'])) . ' '; $cloud .= $this->_replace($options['after'], $size); } return $cloud; }
public function testIndex() { $vars = $this->testAction('involvement_leaders/index/Involvement:1', array('return' => 'vars')); $results = Set::extract('/Leader', $vars['leaders']); $expected = array(array('Leader' => array('id' => 2, 'user_id' => 1, 'model' => 'Involvement', 'model_id' => 1, 'created' => '2010-04-09 07:28:57', 'modified' => '2010-04-09 07:28:57'))); $this->assertEqual($results, $expected); }
function getBilanServiceWithSqlQuery($id = 'all') { // Méthode 3 : à l'aide d'une requête SQL directe $prefix = $this->tablePrefix; if ($id == 'all' or $id == null) { $sql = "SELECT perso_id AS id, perso_id, SUM( h_cours ) AS h_cours, SUM( h_td ) AS h_td, SUM( h_tp ) AS h_tp FROM {$prefix}matieres_persos AS MatieresPerso GROUP BY perso_id"; $result = $this->query($sql); $result = Set::combine($result, '{n}.MatieresPerso.id', '{n}.0'); // Mise en forme l'array pour avoir perso_id comme clé return $result; } else { App::import('Sanitize'); $id = Sanitize::paranoid($id); // use Sanitize for $id to avoid SQL injection $sql = "SELECT perso_id AS id, perso_id, SUM( h_cours ) AS h_cours, SUM( h_td ) AS h_td, SUM( h_tp ) AS h_tp FROM {$prefix}matieres_persos AS MatieresPerso WHERE perso_id={$id} GROUP BY perso_id LIMIT 1"; $result = $this->query($sql); if (!empty($result[0])) { //$result = Set::merge($result[0]["MatieresPerso"], $result[0][0]); //return $result; return $result[0][0]; } else { return array('h_cours' => 0, 'h_td' => 0, 'h_tp' => 0); } } }
/** * 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; }
public function cakeArrayToArray($data, $options = array()) { $options += array('fields' => array(), 'models' => array()); $options['fields'] = Set::normalize($options['fields'], false); $options['models'] = Set::normalize($options['models'], false); $options += array('defaultModel' => count($options['models']) == 1 ? $options['models'][0] : null); $firstRow = true; $array = array(); foreach ($data as $item) { foreach ($item as $model => $fields) { if ($options['models'] && !in_array($model, $options['models'])) { continue; } foreach ($fields as $field => $value) { if ($options['fields'] && !in_array($field, $options['fields']) && !in_array("{$model}.{$field}", $options['fields'])) { continue; } if ($firstRow) { if ($model == $options['defaultModel']) { $array[0][] = $field; } else { $array[0][] = "{$model}.{$field}"; } } $row[] = $value; } $array[] = $row; } $firstRow = false; } return $array; }
/** * 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); }
function _create_attendance($team, $event_id, $date) { if (array_key_exists('id', $team)) { $team_id = $team['id']; } else { $team_id = $team['Team']['id']; } // Find event details $this->contain(); $event = $this->read(null, $event_id); if (!$event) { return; } if ($event['TeamEvent']['team_id'] != $team_id) { return; } // Find all attendance records for this event $attendance = $this->Attendance->find('all', array('contain' => false, 'conditions' => array('team_event_id' => $event_id))); // Extract list of players on the roster as of this date $roster = Set::extract("/Person/TeamsPerson[created<={$date}]/../.", $team); // Go through the roster and make sure there are records for all players on this date. $attendance_update = array(); foreach ($roster as $person) { $update = false; $conditions = "[person_id={$person['id']}]"; $record = Set::extract("/Attendance{$conditions}/.", $attendance); if (empty($record)) { // We didn't find any appropriate record, so create a new one $attendance_update[] = array('team_id' => $team_id, 'game_date' => $date, 'team_event_id' => $event_id, 'person_id' => $person['id'], 'status' => ATTENDANCE_UNKNOWN); } } if (!empty($attendance_update)) { $this->Attendance->saveAll($attendance_update); } }
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 admin_index() { $q = null; if (isset($this->params['named']['q']) && strlen(trim($this->params['named']['q'])) > 0) { $q = $this->params['named']['q']; } elseif (isset($this->data['Artist']['q']) && strlen(trim($this->data['Artist']['q'])) > 0) { $q = $this->data['Artist']['q']; $this->params['named']['q'] = $q; } if ($q !== null) { $this->paginate['conditions']['OR'] = array('ShopPromotion.code LIKE' => '%' . $q . '%', 'ShopPromotion.title_fre LIKE' => '%' . $q . '%', 'ShopPromotion.title_eng LIKE' => '%' . $q . '%', 'ShopPromotion.desc_fre LIKE' => '%' . $q . '%', 'ShopPromotion.desc_eng LIKE' => '%' . $q . '%'); } $this->paginate['order'] = 'ShopPromotion.created DESC'; $this->ShopPromotion->recursive = 0; $shopPromotions = $this->paginate(); //////////// calcul use count //////////// $ids = Set::extract('{n}.ShopPromotion.id', $shopPromotions); $useCounts = $this->ShopPromotion->ShopCoupon->find('all', array('fields' => array('COUNT(*) as `uses`', 'ShopCoupon.shop_promotion_id'), 'conditions' => array('ShopCoupon.shop_promotion_id' => $ids, 'ShopOrder.status' => array('ordered', 'paid', 'shipped')), 'group' => 'shop_promotion_id', 'contain' => array('ShopOrder'))); $useCounts = array_combine(Set::extract('{n}.ShopCoupon.shop_promotion_id', $useCounts), Set::extract('{n}.0.uses', $useCounts)); foreach ($shopPromotions as &$promo) { $promo['ShopPromotion']['uses'] = !empty($useCounts[$promo['ShopPromotion']['id']]) ? $useCounts[$promo['ShopPromotion']['id']] : 0; } $this->set('shopPromotions', $shopPromotions); $this->set('operators', $this->ShopPromotion->operators); }
function evaluate($affiliate, $params, $team, $strict, $text_reason, $complete, $absolute_url) { if ($text_reason) { $this->reason = sprintf(__('have signed the %s waiver', true), $this->waiver); } else { App::import('Helper', 'Html'); $html = new HtmlHelper(); $url = array('controller' => 'waivers', 'action' => 'sign', 'waiver' => $this->config[0], 'date' => $this->date); if ($absolute_url) { $url = $html->url($url, true); } else { $url['return'] = true; } $this->reason = $html->link(sprintf(__('have signed the %s waiver', true), $this->waiver), $url); } $this->redirect = array('controller' => 'waivers', 'action' => 'sign', 'waiver' => $this->config[0], 'date' => $this->date); if (!$strict) { $this->invariant = true; return true; } if (is_array($params) && array_key_exists('Waiver', $params)) { $matches = array_intersect($this->config, Set::extract("/Waiver/WaiversPerson[valid_from<={$this->date}][valid_until>={$this->date}]/waiver_id", $params)); if (!empty($matches)) { $this->invariant = true; return true; } } return false; }
function find($type, $options = array()) { switch ($type) { case 'superlist': $total_fields = count($options['fields']); if (!isset($options['fields']) || $total_fields < 3) { return parent::find('list', $options); } if (!isset($options['separator'])) { $options['separator'] = ' '; } if (!isset($options['format'])) { $options['format'] = '%s'; for ($i = 2; $i < $total_fields; $i++) { $options['format'] .= "{$options['separator']}%s"; } } $options['recursive'] = -1; $list = parent::find('all', $options); $formatVals = array(); $formatVals[0] = $options['format']; for ($i = 1; $i < $total_fields; $i++) { $formatVals[$i] = "{n}.{$this->alias}." . str_replace("{$this->alias}.", '', $options['fields'][$i]); } return Set::combine($list, "{n}.{$this->alias}.{$this->primaryKey}", $formatVals); break; default: return parent::find($type, $options); break; } }
function find($type, $query = array()) { if (is_array($type)) { $query = $type; } else { $query['type'] = $type; } if (!is_array($query)) { $query = array('Title' => $query); } $map = array('info' => 'ResponseGroup', 'type' => 'SearchIndex'); foreach ($map as $old => $new) { $query[$new] = $query[$old]; unset($query[$old]); } foreach ($query as $key => $val) { if (preg_match('/^[a-z]/', $key)) { $query[Inflector::camelize($key)] = $val; unset($query[$key]); } } $query = am(array('Service' => 'AWSECommerceService', 'AWSAccessKeyId' => $this->config['key'], 'Operation' => 'ItemSearch', 'Version' => '2008-06-28'), $query); $r = $this->Http->get('http://ecs.amazonaws.com/onca/xml', $query); $r = Set::reverse(new Xml($r)); return $r; }
/** * Get teammates user_id for the teams for some model, model_id * @author Oleg D. */ function temmatesOfCompletedOrPendingTeams($model, $modelID) { $sql = "SELECT DISTINCT(tm.user_id)\n FROM teams t\n INNER JOIN teammates tm ON t.id = tm.team_id\n INNER JOIN teams_objects tob ON t.id = tob.team_id\n WHERE tob.model = '" . $model . "' AND tob.model_id = " . $modelID . " AND tob.status = 'created' AND tm.status IN ('Creator', 'Accepted','Pending') AND t.status IN ('Completed','Created','Pending')"; $results = $this->query($sql); $usersIDs = Set::combine($results, '{n}.tm.user_id', '{n}.tm.user_id'); return $usersIDs; }
/** * admin_index * * @return void */ public function admin_index() { $this->set('title_for_layout', __('Permissions')); $acoConditions = array('parent_id !=' => null, 'foreign_key' => null, 'alias !=' => null); $acos = $this->Acl->Aco->generateTreeList($acoConditions, '{n}.Aco.id', '{n}.Aco.alias'); $roles = $this->Role->find('list'); $this->set(compact('acos', 'roles')); $rolesAros = $this->AclAro->find('all', array('conditions' => array('AclAro.model' => 'Role', 'AclAro.foreign_key' => array_keys($roles)))); $rolesAros = Set::combine($rolesAros, '{n}.AclAro.foreign_key', '{n}.AclAro.id'); $permissions = array(); // acoId => roleId => bool foreach ($acos as $acoId => $acoAlias) { if (substr_count($acoAlias, '_') != 0) { $permission = array(); foreach ($roles as $roleId => $roleTitle) { $hasAny = array('aco_id' => $acoId, 'aro_id' => $rolesAros[$roleId], '_create' => 1, '_read' => 1, '_update' => 1, '_delete' => 1); if ($this->AclPermission->hasAny($hasAny)) { $permission[$roleId] = 1; } else { $permission[$roleId] = 0; } $permissions[$acoId] = $permission; } } } $this->set(compact('rolesAros', 'permissions')); }