/** * Updates all the group events * * @param int $eventId Event id * @param array $newGroups new goups for the event * * @access public * @return boolean */ function updateGroups($eventId, $newGroups) { if (null == $newGroups) { return false; } if (!is_array($newGroups)) { $newGroups = array($newGroups); } //get old groupid's $tmp = $this->getGroupIDsByEventId($eventId); $oldGroups = Set::extract($tmp, '/GroupEvent/group_id'); $mapping = Set::combine($tmp, '{n}.GroupEvent.group_id', '{n}.GroupEvent.id'); $insertGroups = array(); $deleteGroups = array(); //compare $insertGroups = array_diff($newGroups, $oldGroups); $deleteGroups = array_diff($oldGroups, $newGroups); //insert foreach ($insertGroups as $groupId) { $tmp = array('event_id' => $eventId, 'group_id' => $groupId, 'marked' => 'not reviewed'); $this->save($tmp); $this->id = null; } // delete foreach ($deleteGroups as $groupId) { $this->delete($mapping[$groupId]); $this->id = null; } return true; }
function getSubmission($formId) { $submission = $this->findByCformId($formId); $submission['SubmissionField'] = Set::combine($submission['SubmissionField'], '{n}.form_field', '{n}.response'); $submission = Set::merge($submission['Submission'], $submission['SubmissionField']); return $submission; }
/** * 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_edit method * * @throws NotFoundException * @param string $id * @return void */ public function admin_edit($id = null) { $this->Category->locale = array_keys(Configure::read('Site.languages')); if (!$this->Category->exists($id)) { throw new NotFoundException(__('Invalid category')); } if ($this->request->is('post') || $this->request->is('put')) { if ($this->Category->saveAssociated($this->request->data)) { $this->Session->setFlash(__('The category has been saved')); $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(__('The category could not be saved. Please, try again.')); } } else { $options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id)); $this->request->data = $this->Category->find('first', $options); foreach ($this->Category->actsAs['Translate'] as $field => $fieldAlias) { $translations = Set::combine($this->request->data, $fieldAlias . '.{n}.locale', $fieldAlias . '.{n}.content'); $this->request->data['Category'][$field] = $translations; } } $parentCategories = $this->Category->find('list', array('conditions' => array('parent_id' => null))); $services = $this->Category->Service->find('list'); $statements = $this->Category->Statement->find('list'); $this->set(compact('parentCategories', 'services', 'statements')); }
function new_entry($id = null) { App::import('Model', 'TblData'); $this->TblData = new TblData(); // ブログの設定の読み込み App::import('Model', 'MstBlogSetting'); $this->MstBlogSetting = new MstBlogSetting(); // ユーザカテゴリの取得 App::import('Model', 'TblUserCategory'); $this->TblUserCategory = new TblUserCategory(); $this->MstBlogSetting->recursive = 3; // ブログ設定を読み込む $setting = $this->MstBlogSetting->getBlogSettingByAccountName($this->user['account_name']); $this->set('setting', $setting); $this->set('UserCategory', $this->TblUserCategory->getSelectArray($setting['TblUserCategory'])); // ジャンルの取得 App::import('Model', 'MstGenreMajor'); App::import('Model', 'MstGenreMinor'); $this->MstGenreMajor = new MstGenreMajor(); $this->MstGenreMinor = new MstGenreMinor(); $minorGenre = $this->MstGenreMinor->getGenreList(); // ジャンルのoptgroupが出きるように配列を整理 $genre = Set::combine($minorGenre, '{n}.MstGenreMinor.id', '{n}.MstGenreMinor.name', '{n}.MstGenreMajor.name'); $this->set('genre', $genre); $this->render('new_entry'); }
function config() { $data = $this->find('all'); $data = Set::combine($data, '{n}.Configurator.key', '{n}.Configurator.value'); Cache::write('Config', $data); return $data; }
/** * add method * * @return void */ public function add($event_id = null) { $this->loadModel('StudentInfo'); $student = $this->StudentInfo->findByUserId($this->Session->read('Auth.User.id')); if (empty($student)) { $this->Session->setFlash(__('Your account type cannot sign up for events.'), 'default', array('class' => 'alert alert-danger')); return $this->redirect($this->referer()); } $event = $this->StudentJob->Event->findById($event_id); $jobs = Set::combine($event['Job'], '{n}.id', '{n}.name'); if ($this->request->is('post')) { $job = $this->StudentJob->Job->findById($this->request->data['StudentJob']['job_id']); $this->Hour->addHour($this->request->data, $event); $this->StudentJob->create(); $this->request->data['StudentJob']['event_id'] = $event_id; $this->request->data['StudentJob']['user_id'] = $this->Session->read('Auth.User.id'); $this->request->data['StudentJob']['total_hours'] = $job['Job']['end_time'] - $job['Job']['start_time']; if ($this->StudentJob->save($this->request->data)) { $this->Flash->success(__('The student job has been saved.')); $this->StudentJob->Job->recursive = -1; $job['Job']['available_positions']--; $this->StudentJob->Job->save($job); return $this->redirect('/myEvents'); } else { $this->Flash->error(__('The student job could not be saved. Please, try again.')); } } $this->set(compact('event', 'users', 'jobs')); }
/** * 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')); }
function view($id = null) { if (!$id) { $this->Session->setFlash(sprintf(__('%s non valido', true), 'Forum')); $this->redirect(array('action' => 'index')); } $forum = $this->Forum->find('first', array('conditions' => array('Forum.id' => $id, 'Forum.active' => 1, 'Forum.access_level >= ' => $this->Auth->user('role')), 'contain' => array('User.fullname', 'User.id'))); if (empty($forum)) { $this->Session->setFlash(__('Non puoi accedere a questo forum', true)); $this->redirect(array('action' => 'index')); } $this->paginate = array('Comment' => array('conditions' => array('Comment.model' => 'Forum', 'Comment.item_id' => $id, 'Comment.active' => 1, 'Comment.parent_id' => 0), 'fields' => array('Comment.*', "CONCAT(LastUser.first_name, ' ', LastUser.last_name) AS LastUser__fullname", "CONCAT(User.first_name, ' ', User.last_name) AS User__fullname"), 'order' => array('Comment.created DESC'), 'contain' => array('Comment', 'User', 'LastUser', 'LastComment.created'), 'limit' => 25)); $comments = $this->paginate($this->Forum->Comment); foreach ($comments as $key => $comment) { $comments[$key]['Comment']['status'] = $this->Forum->getThreadStatus($comment['Comment']['id']); } $commentIds = Set::extract('/Comment/id', $comments); $commentsChildren = $this->Comment->find('all', array('conditions' => array('Comment.model' => 'Forum', 'Comment.parent_id' => $commentIds, 'Comment.active' => 1), 'fields' => array('Comment.parent_id', 'count(id) as children'), 'group' => 'parent_id', 'recursive' => -1)); $commentsChildren = Set::combine($commentsChildren, '{n}.Comment.parent_id', '{n}.0.children'); $lastUpdates = $this->Comment->find('all', array('conditions' => array('Comment.model' => 'Forum', 'Comment.parent_id' => $commentIds, 'Comment.active' => 1), 'fields' => array('Comment.parent_id', 'MAX(created) as created'), 'group' => 'parent_id', 'recursive' => -1)); $lastUpdates = Set::combine($lastUpdates, '{n}.Comment.parent_id', '{n}.0.created'); $lastMessages = $this->Comment->find('all', array('conditions' => array('Comment.model' => 'Forum', 'Comment.item_id' => $id, 'Comment.active' => 1), 'order' => array('Comment.created DESC'), 'limit' => 10, 'contain' => array('User.fullname'))); $this->set(compact('forum', 'comments', 'commentsChildren', 'lastUpdates', 'lastMessages')); $this->set('title_for_layout', 'Forum - ' . $forum['Forum']['name']); }
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 admin_search($pattern = null) { $user = parent::getUser(); # code after form submit if (!empty($this->data)) { $pattern = "'%" . $this->data['Rule']['pattern'] . "%'"; $WILDCARD = "'*'"; $search_result = $this->Rule->query('SELECT * FROM rules LEFT JOIN groups on rules.group_id = groups.id LEFT JOIN locations as loc1 on rules.location_id = loc1.id LEFT JOIN locations as loc2 on groups.location_id = loc2.id WHERE (rules.sitename LIKE ' . $pattern . ' OR rules.sitename = ' . $WILDCARD . ') AND (rules.location_id = 1 OR rules.location_id = ' . $this->data['Rule']['locations'] . ') ORDER BY sitename, priority;', $cachequeries = false); #pr($search_result); $this->set('results', $search_result); } if (in_array($user['Role']['name'], $this->priv_roles)) { $allowed_locations = parent::getAdminLocationIds(); $find_condition = array('fields' => array('Location.*'), 'conditions' => array("AND" => array('Location.id' => $allowed_locations, 'Location.id NOT' => "1")), 'order' => 'Location.code'); } else { $find_condition = array('fields' => array('Location.*'), 'order' => 'Location.code', 'conditions' => array("id NOT" => "1")); } $locations_list = $this->Location->find('all', $find_condition); $locations = Set::combine($locations_list, '{n}.Location.id', array('%s %s', '{n}.Location.code', '{n}.Location.name')); $this->set(compact('locations')); }
function find($type, $options = array()) { switch ($type) { case 'concatList': if (!isset($options['fields']) || count($options['fields']) < 2) { return parent::find('list', $options); } if (!isset($options['separator'])) { $options['separator'] = ' - '; } $options['recursive'] = -1; $list = parent::find('all', $options); for ($i = 1; $i <= 2; $i++) { $field[$i] = str_replace($this->alias . '.', '', $options['fields'][$i]); } /* return Set::combine($list, '{n}.'.$this->alias.'.'.$this->primaryKey, array('%s'.$options['separator'].'%s', '{n}.'.$this->alias.'.'.$field[1], '{n}.'.$this->alias.'.'.$field[2])); */ return Set::combine($list, '{n}.' . $this->alias . '.' . $this->{$field}[1], array('%s' . $options['separator'] . '%s', '{n}.' . $this->alias . '.' . $field[1], '{n}.' . $this->alias . '.' . $field[2])); break; default: return parent::find($type, $options); break; } }
/** * admin_index * * @return void */ public function admin_index() { $acoConditions = array('parent_id !=' => null, 'foreign_key' => null, 'alias !=' => null); $acos = $this->Acl->Aco->generateTreeList($acoConditions, '{n}.Aco.id', '{n}.Aco.alias'); $groups = $this->Group->find('list'); $this->set(compact('acos', 'groups')); $groupsAros = $this->AclAro->find('all', array('conditions' => array('AclAro.model' => 'Group', 'AclAro.foreign_key' => array_keys($groups)))); $groupsAros = Set::combine($groupsAros, '{n}.AclAro.foreign_key', '{n}.AclAro.id'); $permissions = array(); foreach ($acos as $acoId => $acoAlias) { if (substr_count($acoAlias, '_') != 0) { $permission = array(); foreach ($groups as $groupId => $groupTitle) { $hasAny = array('aco_id' => $acoId, 'aro_id' => $groupsAros[$groupId], '_create' => 1, '_read' => 1, '_update' => 1, '_delete' => 1); if ($this->AclPermission->hasAny($hasAny)) { $permission[$groupId] = 1; } else { $permission[$groupId] = 0; } $permissions[$acoId] = $permission; } } } $this->set(compact('groupsAros', 'permissions')); $plugins = CakePlugin::loaded(); $controllers_plugins = array(); if (!empty($plugins)) { foreach ($plugins as $plugin) { $controllers_plugins[] = $this->AclUtility->getControllerList($plugin); } } $controllers = array_merge($this->AclUtility->getControllerList(), $this->AclUtility->getControllerList($plugin)); $this->set(compact('controllers')); }
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); } } }
function generatetreegrouped(&$Model, $conditions = null, $keyPath = null, $valuePath = null, $groupPath = null, $recursive = null) { $overrideRecursive = $recursive; extract($this->settings[$Model->alias]); if (!is_null($overrideRecursive)) { $recursive = $overrideRecursive; } if ($keyPath == null && $valuePath == null && $groupPath == null && $Model->hasField($Model->displayField)) { $fields = array($Model->primaryKey, $Model->displayField, 'parent_id', $left, $right); } else { $fields = null; } if ($keyPath == null) { $keyPath = '{n}.' . $Model->alias . '.' . $Model->primaryKey; } if ($valuePath == null) { $valuePath = '{n}.' . $Model->alias . '.' . $Model->displayField; } if ($groupPath == null) { $groupPath = '{n}.' . $Model->alias . '.parent_id'; } $order = $Model->alias . '.' . $left . ' asc'; $results = $Model->find('all', compact('conditions', 'fields', 'order', 'recursive')); $stack = array(); foreach ($results as $i => $result) { while ($stack && $stack[count($stack) - 1] < $result[$Model->alias][$right]) { array_pop($stack); } $stack[] = $result[$Model->alias][$right]; } if (empty($results)) { return array(); } return Set::combine($results, $keyPath, $valuePath, $groupPath); }
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; } }
/** * Verifica se os menus do banco estão atualizados com os do arquivo * @param $aDados- array de menus do banco * @return boolean */ public function isUpToDate($aDados) { $aDados = Set::combine($aDados, "/Menu/id", "/Menu"); App::import("Xml"); App::import("Folder"); App::import("File"); $sCaminhosArquivos = Configure::read("Cms.CheckPoint.menus"); $oFolder = new Folder($sCaminhosArquivos); $aConteudo = $oFolder->read(); $aArquivos = Set::sort($aConteudo[1], "{n}", "desc"); if (empty($aArquivos)) { return false; } $oFile = new File($sCaminhosArquivos . $aArquivos[0]); $oXml = new Xml($oFile->read()); $aAntigo = $oXml->toArray(); foreach ($aDados as &$aMenu) { $aMenu['Menu']['content'] = str_replace("\r\n", " ", $aMenu['Menu']['content']); } if (isset($aAntigo["menus"])) { $aAntigo["Menus"] = $aAntigo["menus"]; unset($aAntigo["menus"]); } if (isset($aAntigo["Menus"])) { $aAntigo = Set::combine($aAntigo["Menus"], "/Menu/id", "/Menu"); $aRetorno = Set::diff($aDados, $aAntigo); } return empty($aRetorno); }
public function main() { $items = $this->Area->AreasElection->find('all', array('fields' => array('AreasElection.Election_id', 'COUNT(AreasElection.id) AS cnt'), 'group' => array('AreasElection.Election_id'), 'order' => array('cnt DESC'))); $rootAreaId = $this->Area->field('id', array('name' => '2014')); foreach ($items as $item) { if ($item[0]['cnt'] > 1) { $areas = $this->Area->find('all', array('fields' => array('Area.id', 'Area.parent_id'), 'conditions' => array('AreasElection.Election_id' => $item['AreasElection']['Election_id']), 'joins' => array(array('table' => 'areas_elections', 'alias' => 'AreasElection', 'type' => 'inner', 'conditions' => array('AreasElection.Area_id = Area.id'))))); $parentAreas = array(); $areaList = Set::combine($areas, '{n}.Area.id', '{n}.Area.parent_id'); foreach ($areas as $area) { if ($area['Area']['parent_id'] != $rootAreaId) { if (!isset($parentAreas[$area['Area']['parent_id']])) { $parentAreas[$area['Area']['parent_id']] = array(); } $parentAreas[$area['Area']['parent_id']][] = $area['Area']['id']; } } foreach ($parentAreas as $parentAreaId => $children) { if ($this->Area->find('count', array('conditions' => array('Area.parent_id' => $parentAreaId))) == count($children)) { echo "Area_id = '{$parentAreaId}' AND Election_id = '{$item['AreasElection']['Election_id']}'\n"; if (!isset($areaList[$parentAreaId])) { $this->Area->AreasElection->create(); $this->Area->AreasElection->save(array('AreasElection' => array('Area_id' => $parentAreaId, 'Election_id' => $item['AreasElection']['Election_id']))); } foreach ($children as $childAreaId) { $aeList = $this->Area->AreasElection->find('list', array('conditions' => array('Area_id' => $childAreaId, 'Election_id' => $item['AreasElection']['Election_id']), 'fields' => array('AreasElection.id', 'AreasElection.id'))); foreach ($aeList as $aeId) { $this->Area->AreasElection->delete($aeId); } } } } } } }
public function admin_group($groupId = 0) { $groupId = intval($groupId); if ($groupId <= 0 || !($aro = $this->Acl->Aro->find('first', array('fields' => array('lft', 'rght'), 'conditions' => array('model' => 'Group', 'foreign_key' => $groupId))))) { $this->Session->setFlash(__('Invalid group', true)); $this->redirect(array('controller' => 'groups', 'action' => 'index')); } $this->loadModel('Group'); $group = $this->Group->find('first', array('conditions' => array('id' => $groupId))); $acos = $this->_getAcos('key'); $nodes = $this->Acl->Aro->find('all', array('fields' => array('Aro.id'), 'conditions' => array('Aro.lft <=' => $aro['Aro']['lft'], 'Aro.rght >=' => $aro['Aro']['rght']), 'order' => array('Aro.lft ASC'), 'contain' => array('Aco' => array('fields' => array('Aco.id'))))); foreach ($nodes as $node) { $permissions = Set::combine($node, 'Aco.{n}.id', 'Aco.{n}.Permission._create'); foreach ($acos as $key => $acoId) { if (!isset($permissions[$acoId])) { $acos[$key] = -1; } else { $acos[$key] = $permissions[$acoId]; } } } $groupPermissions = $this->GroupPermission->find('all', array('order' => array('GroupPermission.parent_id ASC', 'GroupPermission.order ASC'))); if (!empty($this->request->data['GroupPermission'])) { $keyStack = Set::combine($groupPermissions, '{n}.GroupPermission.id', '{n}.GroupPermission'); $allowedStack = array(); foreach ($keyStack as $gpId => $gp) { if (!empty($this->request->data['GroupPermission'][$gpId])) { $acoArray = explode(chr(10), $gp['acos']); foreach ($acoArray as $acoItem) { $allowedStack[$acoItem] = 1; } } } foreach ($acos as $acoAlias => $isAllowed) { if (!isset($allowedStack[$acoAlias])) { $this->Acl->deny($group, $acoAlias); } elseif ($allowedStack[$acoAlias] != $isAllowed) { $this->Acl->allow($group, $acoAlias); } } } $items = array(); foreach ($groupPermissions as $groupPermission) { if ($groupPermission['GroupPermission']['parent_id'] == 0) { $items[$groupPermission['GroupPermission']['id']]['category'] = $groupPermission['GroupPermission']; } else { $groupAcos = explode(chr(10), $groupPermission['GroupPermission']['acos']); $groupPermission['GroupPermission']['acos'] = 1; foreach ($groupAcos as $groupAco) { if ($groupPermission['GroupPermission']['acos'] == 1 && (!isset($acos[$groupAco]) || $acos[$groupAco] == -1)) { $groupPermission['GroupPermission']['acos'] = -1; } } $items[$groupPermission['GroupPermission']['parent_id']]['items'][] = $groupPermission['GroupPermission']; } } $this->set('items', $items); $this->set('group', $group); }
function buscarPagos($cedula, $empresas) { $empresas = Set::combine($empresas, '{n}.Cliente.id', '{n}.Cliente.rif'); foreach ($empresas as $e) { $pagos[$e] = $this->find('all', array('fields' => array('ClienPago.*'), 'joins' => array(array('table' => 'clien_pagos', 'alias' => 'ClienPago', 'type' => 'INNER', 'conditions' => array('ClienPago.cedulaorif' => $cedula, 'ClienPago.RIF_EMP' => $e, 'ClienPago.cod_prod = Producto.codigo'))))); } return $pagos; }
function counties() { $this->autoRender = false; $this->recursive = -1; $counties = $this->find('all', array('fields' => 'DISTINCT Property.County', 'order' => 'Property.County ASC')); $county_list = Set::combine($counties, '{n}.Property.County', '{n}.Property.County'); $this->set('counties', $county_list); }
protected function _findHash($state, $query, $results = array()) { if ($state === 'before') { return $query; } $results = Set::combine($results, '{n}.Config.Name', '{n}.Config'); return $results; }
/** *Edita los tipos de producto que se van a producir con su maestro y detalle */ function edit($id_tipo = null) { if ($id_tipo == null) { $id_tipo = $this->data['Tipo']['id_tipo']; } if (!empty($this->data)) { $this->Tipo->begin(); $save = true; if (!$this->Tipo->save($this->data['Tipo'])) { $save = false; } //print_r($this->data['Tipo']); //exit; #TipoDetalle $detail = 'TipoDetalle'; $i = 0; $errors = array(); $idsTipoDetalle = $this->TipoDetalle->findAll(array('TipoDetalle.id_tipo' => $id_tipo)); $idsTipoDetalle = Set::combine($idsTipoDetalle, '{n}.TipoDetalle.id_tipo_detalle', '{n}.TipoDetalle.id_tipo_detalle'); $ids = array(); foreach ($this->data[$detail] as $k => $v) { $v['id_tipo'] = $id_tipo; $this->{$detail}->id = null; if (!$this->{$detail}->save($v)) { $save = false; $errors[$i] = $this->{$detail}->validationErrors; } #Verificación de que no sea una nueva tarea if (isset($v['id_tipo_detalle'])) { $ids[] = $v['id_tipo_detalle']; } $i++; } if (is_array($idsTipoDetalle)) { $ids = array_diff($idsTipoDetalle, $ids); } $msj = ''; foreach ($ids as $v) { if (!$this->TipoDetalle->del($v)) { $save = false; $msj = '<br/>No es posible borrar algunas actividades por que tienen dependencias'; } } $this->set('errors', $errors); if ($save) { $this->Tipo->commit(); $this->Session->setFlash('Se ha ingresado el tipo de producto correctamente'); $this->redirect("/tipos/"); exit; } else { $this->Session->setFlash('<div class="error-message">Error, Corrija los Errores</div>'); } } else { $this->Tipo->unbindModel(array('hasMany' => array('Producto'))); $this->data = $this->Tipo->findByIdTipo($id_tipo); } $this->set('actividades', $this->Actividad->find('list', array('order' => "Actividad.nombre ASC"))); }
public function startup(&$controller) { $KiekenPicture = ClassRegistry::init('Kieken.KiekenPicture'); $pictures = $KiekenPicture->find('all', array('conditions' => array('KiekenPicture.promote' => 1), 'order' => 'RAND()', 'limit' => 5)); foreach ($pictures as $pictureKey => $picture) { $pictures[$pictureKey]['KiekenFile'] = Set::combine($picture['KiekenFile'], '{n}.thumbname', '{n}'); } $controller->set('kieken_featured', $pictures); }
function buscarGestiones($cedula, $empresas) { //Funcion que busca todas las gestiones de un deudor dada su cedula $empresas = Set::combine($empresas, '{n}.Cliente.id', '{n}.Cliente.rif'); foreach ($empresas as $e) { $gestiones[$e] = $this->find('all', array('fields' => array('ClienGest.*', 'Cobranza.*', 'User.*', 'Gestor.*'), 'conditions' => array('Cobranza.CEDULAORIF' => $cedula, 'Cobranza.RIF_EMP' => $e), 'joins' => array(array('table' => 'clien_gests', 'alias' => 'ClienGest', 'type' => 'INNER', 'conditions' => array('ClienGest.cedulaorif' => $cedula, 'ClienGest.rif_emp' => $e)), array('table' => 'gestors', 'alias' => 'Gestor', 'type' => 'INNER', 'conditions' => array('Gestor.Clave = Cobranza.Gestor')), array('table' => 'users', 'alias' => 'User', 'type' => 'INNER', 'conditions' => array('User.id = Gestor.user_id'))), 'order' => array('ClienGest.id DESC'))); } return $gestiones; }
public function recreateArray($array) { foreach ($array as $key => $value) { $arr = $value['CategoryDesc']; $arr = Set::combine($arr, '{n}.lang_code', '{n}'); $array[$key]['CategoryDesc'] = $arr; } return $array; }
function registrationFields($event, $user_id, $for_output = false) { $fields = array(array('type' => 'group_start', 'question' => __('Team Details', true)), array('id' => TEAM_NAME, 'type' => 'text', 'question' => __('Team Name', true), 'after' => __('The full name of your team.', true), 'required' => true)); if (Configure::read('feature.shirt_colour')) { $fields[] = array('id' => SHIRT_COLOUR, 'type' => 'text', 'question' => __('Shirt Colour', true), 'after' => __('Shirt colour of your team. If you don\'t have team shirts, pick \'light\' or \'dark\'.', true), 'required' => true); } if ($for_output) { $fields[] = array('id' => TEAM_ID, 'type' => 'text', 'question' => __('Team ID', true)); } // These questions are only meaningful when we are creating team records if (!empty($event['Event']['division_id'])) { if (!isset($this->_controller->Team)) { $this->_controller->Team = ClassRegistry::init('Team'); } if (Configure::read('feature.franchises')) { if (array_key_exists('Division', $event)) { $division = $event; } else { $division = $event['Event']; } $this->_controller->Team->Division->addPlayoffs($division); $conditions = array(); // Possibly narrow the list of possible franchises to those that are represented // in the configured divisions if ($division['Division']['is_playoff']) { $this->_controller->Team->contain('Franchise'); $teams = $this->_controller->Team->find('all', array('conditions' => array('Team.division_id' => $division['Division']['season_divisions']))); $franchise_ids = Set::extract('/Franchise/id', $teams); $conditions['Franchise.id'] = $franchise_ids; } $franchises = $this->_controller->Team->Franchise->readByPlayerId($user_id, $conditions); $franchises = Set::combine($franchises, '{n}.id', '{n}.name'); // Teams added to playoff divisions must be in pre-existing franchises if ($division['Division']['is_playoff']) { $extra = '<span class="warning-message">' . __('This MUST be the same franchise that the regular-season team belongs to, or you will NOT be able to correctly set up your roster.', true) . '</span>'; } else { $franchises[-1] = __('Create a new franchise', true); $extra = __('You may also choose to start a new franchise.', true); } $fields[] = array('id' => FRANCHISE_ID, 'type' => 'select', 'question' => __('Franchise', true), 'after' => sprintf(__('Select an existing franchise to add this team to. %s You can only add teams to franchises you own; if you don\'t own the franchise this team should be added to, have the owner transfer ownership to you before registering this team.', true), $extra), 'options' => $franchises, 'required' => true); } if (Configure::read('feature.region_preference') && !empty($event['Event']['ask_region'])) { // Could this model path be any more convoluted? $regions = $this->_controller->Team->Division->Game->GameSlot->Field->Facility->Region->find('list'); $fields[] = array('id' => REGION_PREFERENCE, 'type' => 'select', 'question' => __('Region Preference', true), 'after' => __('Area of city where you would prefer to play.', true), 'options' => $regions); } if (!empty($event['Event']['ask_status'])) { $fields[] = array('id' => OPEN_ROSTER, 'type' => 'checkbox', 'question' => __('Open Roster', true), 'after' => __('If the team roster is open, others can request to join; otherwise, only a coach or captain can add players.', true)); } if (Configure::read('feature.attendance') && !empty($event['Event']['ask_status'])) { $fields[] = array('id' => TRACK_ATTENDANCE, 'type' => 'checkbox', 'question' => __('Attendance Tracking', true), 'default' => true, 'after' => __('Would you like to enable attendance tracking for this team?', true)); } } $fields[] = array('type' => 'group_end'); return $fields; }
function graph($filtertype = null) { $projects = $this->Project->findAll(null, null, 'id ASC'); $projects = Set::combine($projects, '{n}.Project.id', '{n}.Project.name'); $relations = $this->Relation->findAll(null, null, 'project_preceding_id ASC'); $user = $this->User->find('first', array('conditions' => array('User.id' => $this->Auth->user('id')), 'recursive' => -1)); $savedCalculus = unserialize($user['User']['saved_calculus']); $dot = $this->Project->dot($projects, $relations, $this->Auth->user('id'), $savedCalculus['projectIds'], $filtertype); $this->set(array('graphFilename' => $this->Auth->user('id'))); }
function get_log_types() { $LogTypes = Cache::read('log_types'); if ($LogTypes === false) { $Result = $this->SimpleLogType->find('all', array('recursive' => -1)); $LogTypes = Set::combine($Result, '{n}.SimpleLogType.type', '{n}.SimpleLogType.id'); Cache::write('log_types', $LogTypes); } return $LogTypes; }
function view_image($id = null) { if (is_numeric($id)) { $question = $this->Question->findById($id); $line_count = 0; // array of lines $question_text = array(); // Other kinds of newlines causing problems. $question['Question']['question'] = str_replace(array("\r", "\r\n", "\n"), '\\n', $question['Question']['question']); $question_wrapped = wordwrap(strip_tags(QH_urldecode($question['Question']['question'])), $this->number_of_characters, '\\n', true); $question_text = array_merge($question_text, explode('\\n', $question_wrapped)); $line_count += count($question_text); $answers = Set::combine($question['Answer'], '{n}.order', '{n}.answer'); $answer_text = array(); foreach ($answers as $answer) { $answer_wrapped = wordwrap(strip_tags($answer), $this->number_of_characters - 4, '\\n', true); $line_array = explode('\\n', $answer_wrapped); $answer_text[] = $line_array; $line_count += count($line_array); } $box_height = $this->padding * 2 + $this->line_height * $line_count; $box_width = $this->padding * 2 + $this->number_of_characters * $this->character_width; $image = imagecreatetruecolor($box_width, $box_height); $background = imagecolorallocate($image, 255, 255, 255); imagefill($image, 0, 0, $background); $black = imagecolorallocate($image, 0, 0, 0); imagerectangle($image, 0, 0, $box_width - 1, $box_height - 1, $black); $y = $this->padding + $this->character_height; foreach ($question_text as $line) { imagettftext($image, $this->font_size, 0, $this->padding, $y, $black, APP . 'Lib/unifont_5.1.20080907.ttf', html_entity_decode($line)); // h_e_d for preventing in the image... sometimes. Not clear on that, but // this fixed #206. $y += $this->line_height; } foreach ($answer_text as $order => $answer) { if ($order == $question['Question']['correct_answer']) { imagefilledellipse($image, $this->character_width * 3, $y - $this->character_height / 2, 8, 8, $black); } else { imageellipse($image, $this->character_width * 3, $y - $this->character_height / 2, 8, 8, $black); } foreach ($answer as $answer_line) { $answer_line = ' ' . $answer_line; imagettftext($image, $this->font_size, 0, $this->padding, $y, $black, APP . 'Lib/unifont_5.1.20080907.ttf', $answer_line); $y += $this->line_height; } } $this->layout = 'image'; header("Content-type: image/png"); imagepng($image); imagedestroy($image); $this->autoRender = false; } }