Пример #1
0
 /**
  * admin_edit method
  *
  * @param mixed $id
  * @return void
  */
 public function admin_edit($id = null)
 {
     $expenses = array();
     if (!empty($this->request->data)) {
         if ($this->Payment->saveAll($this->request->data)) {
             $this->setFlash(__d('lil_expenses', 'Payment has been saved.'));
             return $this->doRedirect();
         }
         $this->setFlash(__d('lil_expenses', 'There are some errors in the form. Please correct all marked fields below.'));
     } else {
         if (!empty($id)) {
             if (!($this->request->data = $this->Payment->find('first', array('conditions' => array('Payment.id' => $id), 'contain' => array('PaymentsExpense'))))) {
                 // must redirect to index because of redirects from delete actions
                 $this->redirect(array('admin' => true, 'plugin' => 'lil_expenses', 'controller' => 'payments', 'action' => 'index'));
             }
             $expenses = $this->Payment->Expense->find('all', array('conditions' => array('Expense.id' => Set::extract('PaymentsExpense.{n}.expense_id', $this->request->data)), 'recursive' => 0));
         } else {
             if (!empty($this->request->params['named']['expense'])) {
                 if ($exp = $this->Payment->Expense->find('first', array('conditions' => array('Expense.id' => $this->request->params['named']['expense']), 'recursive' => 0))) {
                     $this->request->data['Payment']['dat_happened'] = strftime('%Y-%m-%d');
                     $this->request->data['Payment']['descript'] = $exp['Expense']['title'];
                     $this->request->data['Payment']['amount'] = $exp['Expense']['total'];
                 }
                 $expenses = array($exp);
             } else {
                 return $this->error404();
             }
         }
     }
     $this->set(compact('expenses'));
     $this->set('accounts', $accounts = $this->PaymentsAccount->findActive());
     $this->setupRedirect();
 }
Пример #2
0
 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');
     }
 }
Пример #3
0
 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);
 }
 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()));
 }
 public function admin_index()
 {
     $this->set('title_for_layout', __('Content', true));
     $this->Node->recursive = 0;
     $this->paginate['Node']['order'] = 'Node.created DESC';
     $this->paginate['Node']['conditions'] = array();
     $types = $this->Node->Taxonomy->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);
     }
     if (isset($this->params['named']['q'])) {
         App::import('Core', 'Sanitize');
         $q = Sanitize::clean($this->params['named']['q']);
         $this->paginate['Node']['conditions']['OR'] = array('Node.title LIKE' => '%' . $q . '%', 'Node.excerpt LIKE' => '%' . $q . '%', 'Node.body LIKE' => '%' . $q . '%', 'Node.terms LIKE' => '%"' . $q . '"%');
     }
     $nodes = $this->paginate('Node');
     $this->set(compact('nodes', 'types', 'typeAliases'));
     if (isset($this->params['named']['links'])) {
         $this->layout = 'ajax';
         $this->render('admin_links');
     }
 }
Пример #6
0
 /**
  * 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;
     }
 }
Пример #7
0
 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);
 }
Пример #8
0
 function getTeamIds($model, $modelid)
 {
     $this->recursive = 0;
     $teamsObjects = $this->find('all', array('conditions' => array('TeamsObject.status <> ' => 'Deleted', 'TeamsObject.model_id' => $modelid, 'TeamsObject.model' => $model, 'Team.status <> ' => 'Deleted'), 'contain' => array('Team')));
     $teamIDs = Set::extract($teamsObjects, '{n}.Team.id');
     return $teamIDs;
 }
Пример #9
0
 /**
  * After migration callback
  *
  * @param string $direction, up or down direction of migration process
  * @return boolean Should process continue
  * @access public
  */
 function after($direction)
 {
     $output = array();
     // not used
     if ($direction === 'up') {
         if (!class_exists('Security')) {
             App::import('Core', 'Security');
         }
         // create initial user
         $User = $this->generateModel('User');
         $user = array('User' => array('username' => 'admin', 'password' => Security::hash('GuideOnTheSideAdmin#1', null, true), 'role_id' => 2, 'deleted' => 0));
         $this->output('insert_data', 'admin user');
         $User->save($user);
         // populate roles
         $Role = $this->generateModel('Role');
         $roles = array(array('id' => 1, 'name' => 'creator'), array('id' => 2, 'name' => 'admin'));
         $this->output('insert_data', 'roles (' . implode(', ', Set::extract('{n}.name', $roles)) . ')');
         $Role->saveAll($roles);
         if (isset($this->callback)) {
             // currently this just outputs a line break to the CLI
             $this->callback->afterMigration($this->callback, $direction);
         }
     }
     return true;
 }
Пример #10
0
 function add($model = null, $id = null, $uid = null)
 {
     if (!empty($this->data)) {
         $model = Set::extract($this->data, 'Coment.model');
         $id = Set::extract($this->data, 'Coment.project_id');
         $a = ClassRegistry::init('Attachment');
         if ($this->Coment->save($this->data)) {
             $coment = $this->Coment->findById($uid);
             //print_r($_REQUEST); die();
             foreach ($this->data['Attachment'] as $file) {
                 $aa = $a->CustomUpload($file[0], $coment['Coment']['id']);
             }
             $this->Coment->create();
             $this->data = array();
             $this->set('successful', false);
             $this->Session->setFlash(__('The Comment has been saved.', true));
         } else {
             $this->Session->setFlash(__('The Comment could not be saved. Please, try again.', true));
         }
     } else {
         $this->data = array('Coment' => array('model' => $model, 'project_id' => $id));
     }
     $this->set('_model', $model);
     $this->set('_project_id', $id);
 }
 public function testPaginate()
 {
     for ($i = 0; $i < 10; $i++) {
         $u = new User();
         $u->save(array('User' => array('username' => 'User ' . $i, 'password' => 'password ' . $i, 'salary' => 100 + $i)));
     }
     $u->flush();
     $this->Controller->request->params['pass'] = array('1');
     $this->Controller->request->query = array();
     $this->Controller->constructClasses();
     $this->Controller->Paginator->settings = array('limit' => 3);
     $results = Set::extract($this->Controller->Paginator->paginate(), '{s}.User.username');
     $this->assertEqual($results, array('User 0', 'User 1', 'User 2'));
     $this->Controller->request->params['named'] = array('sort' => 'salary', 'direction' => 'desc');
     $results = Set::extract($this->Controller->Paginator->paginate(), '{s}.User.username');
     $this->assertEqual($this->Controller->params['paging']['User']['page'], 1);
     $this->assertEqual($results, array('User 9', 'User 8', 'User 7'));
     $this->Controller->request->params['named'] = array('sort' => 'User.salary', 'direction' => 'desc', 'page' => 2);
     $results = Set::extract($this->Controller->Paginator->paginate(), '{s}.User.username');
     $this->assertEqual($this->Controller->params['paging']['User']['page'], 2);
     $this->assertEqual($results, array('User 6', 'User 5', 'User 4'));
     $this->Controller->request->params['named'] = array();
     $this->Controller->Paginator->settings = array('topPaid', 'limit' => 3);
     $results = Set::extract($this->Controller->Paginator->paginate(), '{s}.User.username');
     $this->assertEqual($this->Controller->params['paging']['User']['page'], 1);
     $this->assertEqual($results, array('User 9', 'User 8', 'User 7'));
 }
Пример #12
0
 function generateList4TreeData($conditions = null, $order = null, $limit = null, $keyPath = null, $valuePath = null)
 {
     if ($keyPath == null && $valuePath == null && $this->hasField($this->displayField)) {
         $fields = array($this->primaryKey, $this->displayField);
     } else {
         $fields = null;
     }
     $recursive = $this->recursive;
     if ($recursive >= 1) {
         $this->recursive = -1;
     }
     $result = $this->findAllThreaded($conditions, $fields, $order);
     $this->recursive = $recursive;
     if (!$result) {
         return false;
     }
     if ($keyPath == null) {
         $keyPath = '{n}.' . $this->name . '.' . $this->primaryKey;
     }
     if ($valuePath == null) {
         $valuePath = '{n}.' . $this->name . '.' . $this->displayField;
     }
     $keys = Set::extract($result, $keyPath);
     $vals = Set::extract($result, $valuePath);
     if (!empty($keys) && !empty($vals)) {
         $return = array_combine($keys, $vals);
         return $return;
     }
     return null;
 }
Пример #13
0
 public function returnSection($section, $locale = 'en_us')
 {
     $en_us = $this->returnEnSection($section);
     //get the us version of the section first
     if ($locale == 'en_us') {
         return $en_us;
     }
     //query up the languages
     if (Set::check(self::$sections, $section . "." . $locale)) {
         return self::$sections[$section][$locale];
     } else {
         $old_locale = $this->locale;
         $this->setLanguage($locale);
         $lang = $this->find("all", array("conditions" => array("Phrase.section" => $section)));
         $this->setLanguage($old_locale);
         foreach ($en_us as $k => $v) {
             $p = Set::extract("/Phrase[token=/" . $k . "/i]/value", $lang);
             if (count($p) > 0) {
                 $en_us[$k] = $p[0];
             }
         }
         //cache the data
         self::$sections[$section][$locale] = $en_us;
     }
     return self::$sections[$section][$locale];
 }
Пример #14
0
 /**
  * read data
  *
  * this is the main method that reads data from the datasource and
  * formats it according to the request from the model.
  *
  * @param mixed $model the model that is requesting data
  * @param mixed $query the qurey that was sent
  *
  * @return the data requested by the model
  */
 function read(&$model, $query)
 {
     $this->request = array_merge($this->request, $model->request);
     $response = $this->__process($this->__getData($this->request));
     if ($query['fields'] == 'count') {
         if (isset($model->map['count'])) {
             $count = Set::extract($model->map['count'], $response);
             $result[0][$model->alias]['count'] = $count;
         } else {
             $count = count(Set::extract($model->map['data'], $response));
             $result[0][$model->alias]['count'] = $count;
         }
         return $result;
     }
     if (isset($model->map['data'])) {
         if (strtolower($query['conditions']) !== 'raw') {
             $response = Set::extract($model->map['data'], $response);
         }
     }
     $i = 0;
     foreach ($response as $key => $value) {
         if (isset($query['limit']) && $i >= $query['limit']) {
             return $result;
         }
         $result[$key][$model->alias] = $value;
         $i++;
     }
     return $result;
 }
Пример #15
0
 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'));
 }
Пример #16
0
 function getSubCategories($id)
 {
     $category = $this->read(null, $id);
     $categories = $this->find('all', array('conditions' => array('lft >= ' => $category['ProductCategory']['lft'], 'rght <= ' => $category['ProductCategory']['rght']), 'fields' => array('id'), 'contain' => array()));
     $categories = Set::extract('/ProductCategory/id', $categories);
     return $categories;
 }
 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']);
 }
Пример #18
0
 function add()
 {
     if (!empty($this->data)) {
         $this->Test->create();
         // Insert the user_id from session
         $this->data = Set::insert($this->data, 'Test.user_id', $this->Auth->user('id'));
         if ($this->Test->save($this->data)) {
             $this->Session->setFlash(__('The Test has been saved', true));
             $type = Set::extract('/Test/type', $this->data);
             // get the test type
             $name = Set::extract('/Test/name', $this->data);
             // get the name
             // pull the id from the database
             $test_id = Set::extract('/Test/id', $this->Test->find('first', array('conditions' => array('Test.name' => $name), 'recursive' => -1)));
             // Fix arrays
             $type = $type[0];
             $test_id = $test_id[0];
             // If type=lookup redirect to add resultLookups
             if (strcmp($type, 'lookup') == 0) {
                 $this->redirect(array('controller' => 'ResultLookups', 'action' => 'add/' . $test_id));
             } else {
                 $this->redirect(array('action' => 'index'));
             }
         } else {
             $this->Session->setFlash(__('The Test could not be saved. Please, try again.', true));
         }
     }
 }
Пример #19
0
 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);
 }
Пример #20
0
 function listwidgets()
 {
     Configure::write('debug', '0');
     $this->layout = 'ajax';
     //TODO: write a function to do this (and that sanitizes)
     $formdata = $this->params['form'];
     // pagination
     /*$limit = 5;
             $start = 0;
     
             if(!empty($formdata['limit']))
                 $limit = $formdata['limit'];
              
             if(!empty($formdata['start']))
                 $start = $formdata['start'];*/
     $this->Widget->recursive = 0;
     $filter = array('enabled' => '1');
     $fields = array('id', 'name', 'description', 'screenshot', 'modified');
     $widgets = $this->Widget->find('all', array('conditions' => $filter, 'fields' => $fields, 'order' => 'modified DESC'));
     $count = $this->Widget->find('count', array('conditions' => $filter));
     $widgets = Set::extract($widgets, '{n}.Widget');
     foreach ($widgets as &$widget) {
         $widget["popularity"] = rand(1, 5);
         //((float)rand(2,10))/2;
     }
     $results['widgets'] = $widgets;
     $results['totalCount'] = $count;
     $this->set('json', $results);
 }
Пример #21
0
 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;
 }
Пример #22
0
 public function testIndex()
 {
     $vars = $this->testAction('/questions/index/Involvement:1');
     $results = Set::extract('/Question/id', $vars['questions']);
     $expected = array(1, 2);
     $this->assertEqual($results, $expected);
 }
Пример #23
0
 /**
  * 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;
 }
Пример #24
0
 public function beforeSave($options = array())
 {
     if (isset($this->data[$this->name]['type']) && $this->data[$this->name]['type'] == 'IssueCustomField' && !empty($this->data['CustomField']['id'])) {
         $this->bindModel(array('hasMany' => array('CustomFieldsTracker')), false);
         $assoc_trackers = Set::extract('{n}.CustomFieldsTracker.tracker_id', $this->CustomFieldsTracker->find('all', array('conditions' => array('custom_field_id' => $this->data['CustomField']['id']))));
         $tracker_ids = empty($this->data[$this->name]['tracker_id']) ? array() : $this->data[$this->name]['tracker_id'];
         $this->__add_trackers = array_diff($tracker_ids, $assoc_trackers ? $assoc_trackers : array());
         $this->__del_trackers = array_diff($assoc_trackers ? $assoc_trackers : array(), $tracker_ids);
     }
     unset($this->data[$this->name]['tracker_id']);
     App::Import('vendor', 'georgious-cakephp-yaml-migrations-and-fixtures/spyc/spyc');
     if (!empty($this->data[$this->name]['possible_values']) && $this->data[$this->name]['field_format'] == 'list') {
         if (empty($this->data[$this->name]['possible_values'][count($this->data[$this->name]['possible_values']) - 1])) {
             unset($this->data[$this->name]['possible_values'][count($this->data[$this->name]['possible_values']) - 1]);
         }
         $this->data[$this->name]['possible_values'] = Spyc::YAMLDump($this->data[$this->name]['possible_values'], true);
     } else {
         $this->data[$this->name]['possible_values'] = '--- []';
     }
     if (empty($this->data[$this->name]['min_length'])) {
         $this->data[$this->name]['min_length'] = 0;
     }
     if (empty($this->data[$this->name]['max_length'])) {
         $this->data[$this->name]['max_length'] = 0;
     }
     return true;
 }
Пример #25
0
 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);
     }
 }
Пример #26
0
 /**
  * Admin index
  *
  * @return void
  * @access public
  */
 public function admin_index()
 {
     $nodelist = $this->Node->generateTreeList(null, '{n}.Aro.id', '{n}.Aro.alias', ' - ', '-1');
     $groupNodeList = $this->Node->find('all', array('recursive' => 0, 'conditions' => array('foreign_key' => null)));
     $groupNodeList = Set::extract('/Aro/id', $groupNodeList);
     $this->set(compact('nodelist', 'groupNodeList'));
 }
 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 _send($message)
 {
     //seleziono tutti i sottogruppi attivi
     $this->NewsletterMessage->Usergroup->recursive = -1;
     $baseGroup = $this->NewsletterMessage->Usergroup->findById($message['NewsletterMessage']['usergroup_id']);
     $usergroups = $this->NewsletterMessage->Usergroup->find('all', array('conditions' => array('lft >= ' => $baseGroup['Usergroup']['lft'], 'rght <= ' => $baseGroup['Usergroup']['rght'], 'active' => 1), 'fields' => array('id')));
     $usergroupsIds = Set::extract('/Usergroup/id', $usergroups);
     //<- sottogruppi
     $users = $this->NewsletterMessage->User->find('all', array('conditions' => array('User.active' => 1, 'usergroup_id' => $usergroupsIds), 'fields' => array('email'), 'recursive' => -1));
     $users = Set::extract('/User/email', $users);
     $errors = array();
     foreach ($users as $user) {
         $this->Email->reset();
         $this->Email->to = $user;
         $this->Email->subject = '[' . Configure::read('GAS.name') . '] ' . $message['NewsletterMessage']['title'];
         $this->Email->from = Configure::read('email.from');
         $this->Email->replyTo = $message['NewsletterMessage']['reply_to'];
         $this->Email->sendAs = 'html';
         $this->Email->template = 'admin_newsletter_message';
         $title = $message['NewsletterMessage']['title'];
         $text = $message['NewsletterMessage']['text'];
         $this->set(compact('user', 'title', 'text'));
         if (!$this->Email->send()) {
             $this->log($this->name . '->' . $this->action . ' email not sent to: ' . $user, 'newsletter_mail_errors');
             $errors[] = $user;
         }
     }
     if (empty($errors)) {
         return true;
     } else {
         return $errors;
     }
 }
Пример #29
0
 /**
  * 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;
 }
Пример #30
0
 public function dc_report_()
 {
     //$this->loadModel('Tag');
     //$this->loadModel('DailyopsTag');
     //$ids = '9,10,19,34,42,132,167,220,339,504,621,780,847,849,892,1005,1082,1190,2136,2208,2266,2743,2839,2883,2964,3674,3753,4201';
     //$ids = '9,10,19,34,42,68,69,132,167,220,339,504,621,780,847,849,892,962,1000,1003,1005,1082,1190,1552,1659,2089,2136,2146,2208,2209,2266,2390,2405,2441,2743,2839,2883,2930,2938,2964,2966,2967,3064,3065,3066,3067,3068,3069,3392,3674,3753,4201,4203';
     $keys = array("Steve Berra", "Berra", "Chris Cole", "Rob Dyrdek", "Colin Mckay", "Josh Kalis", "Mikemo Capaldi", "Mike mo capaldi", "mikey taylor", "matt miller", "danny way", "felipe gustavo", "evan smith", "davis torgerson", "marquise henry", "nyjah huston", "wes kremer", "batb", "babt3", "batb4", "batb5", "batb6", "batbIII", "batbIV", "batbv", "batbvi");
     $or = array();
     foreach ($keys as $k => $v) {
         $or[] = array("Tag.name LIKE" => "%" . str_replace(" ", "%", $v) . "%");
     }
     //die(pr($or));
     $tags = $this->Tag->find("all", array("conditions" => array("OR" => $or), "contain" => array("Dailyop" => array("DailyopMediaItem" => array("MediaFile", "order" => array("DailyopMediaItem.display_weight" => "ASC"), "limit" => 1)))));
     $ids = Set::extract("/Dailyop/DailyopMediaItem/MediaFile/id", $tags);
     $mids = array();
     foreach ($ids as $v) {
         $mids[$v] = $v;
     }
     $mids = array_values($mids);
     $id_str = "";
     foreach ($mids as $v) {
         $id_str .= "'{$v}',";
     }
     $id_str = rtrim($id_str, ",");
     die($id_str);
     die(implode(",", $mids));
     $posts = $this->Dailyop->find("all", array("conditions" => array("OR" => array(array("Dailyop.name LIKE" => "%dc%"), array("Dailyop.sub_title LIKE" => "%dc%"))), "contain" => array("DailyopMediaItem" => array("MediaFile", "order" => array("DailyopMediaItem.display_weight" => "ASC"), "limit" => 1))));
     $ids = Set::extract("/DailyopMediaItem/MediaFile/id", $posts);
     $id_str = implode(",", $ids);
     die($id_str);
 }