/** * Find all comments related to a specific content * @param string $ref Model linked with comments * @param int $ref_id ID of the content linked with the comments * @todo Supprimer les commentaires inline : si le code est suffisamment clair cela se lit tout seul, sinon séparer en sous méthodes protected **/ public function findRelated($ref, $ref_id, $options = array()) { // We had the conditions to find linked comments only $options['conditions']['ref'] = $ref; $options['conditions']['ref_id'] = $ref_id; // We need to retrieve User informations if (!isset($options['contain']['User'])) { $fields = Configure::read('Plugin.Comment.user'); unset($fields['model']); $fields[] = 'id'; $fields = array_values($fields); $options['contain']['User'] = $fields; } $comments = $this->find('all', $options); if (Configure::read('Plugin.Comment.subcomments')) { $comments = Hash::combine($comments, '{n}.Comment.id', '{n}', '{n}.Comment.parent_id'); if (!isset($comments[0])) { return array(); } foreach ($comments[0] as $k => $coms) { $comments[0][$k]['Answer'] = array(); } foreach ($comments as $parent_id => $coms) { if ($parent_id != 0) { $comments[0][$parent_id]['Answer'] = Hash::sort($coms, '{n}.Comment.id', 'ASC'); } } return $comments[0]; } else { return $comments; } }
/** Fetch a list of all matching items */ public function fetchList($field = 'title', $conditions = array(), $options = array()) { $conditions = $this->prepare($conditions); //Break out query and conditions and remember PDO is numbered from 1, not 0 if (!empty($conditions)) { $query = $conditions[0]; unset($conditions[0]); } else { $query = ""; } if (is_array($field)) { $field1 = $field[0]; $field2 = $field[1]; } else { $field1 = 'id'; $field2 = $field; } $f1 = $this->db->quotekey($field1); $f2 = $this->db->quotekey($field2); //Handle empty conditions if (empty($query)) { $query = "1=1"; } $results = $this->db->exec("SELECT {$f1},{$f2} FROM {$this->name} WHERE " . $query, $conditions); $output = Hash::combine($results, '{n}.' . $field1, '{n}.' . $field2); return $output; }
public function edit($id = 0, $parent_id = '') { parent::edit($id, $parent_id); // find all groups of params by category of product $product = $this->Product->findById($this->parent_id); $cat_id = $product['Product']['parent_id']; $conditions = array('parent_id' => $cat_id, 'featured' => 1); $order = 'sorting'; $aParamGroups = $this->ParamGroup->find('all', compact('conditions', 'order')); $aParamGroups = Hash::combine($aParamGroups, '{n}.ParamGroup.id', '{n}'); $this->set('aFormGroups', $aParamGroups); // find all params by groups $conditions = array('object_type' => 'PMFormField', 'parent_id' => array_keys($aParamGroups)); $order = 'sorting'; $aParams = $this->PMFormField->find('all', compact('conditions', 'order')); if ($aParams) { $ids = Hash::extract($aParams, '{n}.PMFormField.id'); $aParams = Hash::combine($aParams, '{n}.PMFormField.id', '{n}', '{n}.PMFormField.parent_id'); } $this->set('aForms', $aParams); // get all values of params $aValues = array(); if ($this->request->is(array('put', 'post'))) { $aValues = $this->request->data('PMFormValue'); } elseif ($id) { $aValues = $this->PMFormValue->getValues('ProductPackParam', $id); } $this->set('aValues', $aValues); }
/** * beforeRender * * @param Controller $controller Controller * @return void * @throws NotFoundException */ public function beforeRender(Controller $controller) { //RequestActionの場合、スキップする if (!empty($controller->request->params['requested'])) { return; } $this->controller = $controller; $this->__prepare(); //pathからページデータ取得 if (isset($this->controller->viewVars['page'])) { $page = $this->controller->viewVars['page']; } else { $this->Page = ClassRegistry::init('Pages.Page'); $page = $this->Page->getPageWithFrame(Current::read('Page.permalink')); if (empty($page)) { throw new NotFoundException(); } } if (Current::hasSettingMode() && Current::isSettingMode() && Current::permission('page_editable')) { $this->controller->request->data['ContainersPage'] = Hash::combine($page, 'Container.{n}.type', 'Container.{n}.ContainersPage'); } ////cancelUrlをセット //if (! isset($this->controller->viewVars['cancelUrl'])) { // $this->controller->set('cancelUrl', $page['Page']['permalink']); //} //Pluginデータ取得 $pluginsRoom = ClassRegistry::init('PluginManager.PluginsRoom'); $plugins = $pluginsRoom->getPlugins($page['Page']['room_id'], Current::read('Language.id')); //ページHelperにセット $results = array('containers' => Hash::combine($page['Container'], '{n}.type', '{n}'), 'boxes' => Hash::combine($page['Box'], '{n}.id', '{n}', '{n}.container_id'), 'plugins' => $plugins); $this->controller->helpers['Pages.PageLayout'] = $results; }
/** * After find callback. Can be used to modify any results returned by find. * * @param Model $model Model using this behavior * @param mixed $results The results of the find operation * @param boolean $primary Whether this model is being queried directly (vs. being queried as an association) * * @return mixed An array value will replace the value of $results - any other value will be ignored. */ public function afterFind(Model $model, $results, $primary = false) { parent::afterFind($model, $results, $primary); if ($primary && array_key_exists($model->alias, $results[0])) { $arrObj = new ArrayObject($results); $iterator = $arrObj->getIterator(); while ($iterator->valid()) { $result = []; if (isset($iterator->current()[$model->alias]) && count($iterator->current()[$model->alias]) > 0) { $key = "{$model->alias}.{$this->settings[$model->alias]['key']}"; $value = "{$model->alias}.{$this->settings[$model->alias]['value']}"; $result = Hash::combine($iterator->current(), $key, $value); } if (!array_key_exists($this->settings[$model->alias]['key'], $iterator->current()[$model->alias]) && !array_key_exists($this->settings[$model->alias]['value'], $iterator->current()[$model->alias])) { $results[$iterator->key()][$model->alias] = Hash::merge($iterator->current()[$model->alias], $result); } else { $results[$iterator->key()][$model->alias] = $result; } $iterator->next(); } } elseif (array_key_exists($model->alias, $results)) { $key = "{n}.{$model->alias}.{$this->settings[$model->alias]['key']}"; $value = "{n}.{$model->alias}.{$this->settings[$model->alias]['value']}"; $output = Hash::combine($results, $key, $value); $results[$model->alias] = $output; } return $results; }
/** * index * * @return void */ public function index() { if (!$this->viewVars['blockId']) { $this->autoRender = false; return; } if (!$this->initLink(['linkFrameSetting'])) { return; } $this->Categories->initCategories(true, '{n}.Category.id'); //条件 $conditions = $this->__setConditions(); //取得 $links = $this->Link->getLinks($conditions); $links = Hash::combine($links, '{n}.Link.id', '{n}', '{n}.Category.id'); //Viewにセット $results = array('links' => $links); $results = $this->camelizeKeyRecursive($results); $this->set($results); //Tokenセット $this->request->data = array('Frame' => array('id' => $this->viewVars['frameId']), 'Link' => array('id' => null, 'key' => null)); $tokenFields = Hash::flatten($this->request->data); $hiddenFields = array('Frame.id'); $this->set('tokenFields', $tokenFields); $this->set('hiddenFields', $hiddenFields); }
public function index($parent_id = '') { // Process filter if ($user_id = $this->request->query('user_id')) { $this->paginate['conditions']['user_id'] = $user_id; } $status = $this->request->query('status'); if ($status != '') { $this->paginate['conditions']['status'] = $status; } $id = $this->request->query('id'); if ($id) { if (strpos($id, ',') !== false) { $id = explode(',', $id); } $this->paginate['conditions']['id'] = $id; } $rowset = parent::index(); $ids = Hash::extract($rowset, '{n}.Order.id'); $orders = $this->Order->getOrder($ids); $ids = Hash::extract($rowset, '{n}.Order.user_id'); $users = Hash::combine($this->User->findAllById($ids), '{n}.User.id', '{n}.User'); $aUserOptions = $this->User->find('list', array('fields' => array('id', 'username'))); $this->set(compact('orders', 'users', 'aUserOptions')); }
/** * Expect RssReaderItem->updateRssReaderItems() * * @return void */ public function testUpdateRssReaderItems() { $rssReaderId = 1; //コンテンツの公開権限true $this->RssReader->Behaviors->attach('Publishable'); $this->RssReader->Behaviors->Publishable->setup($this->RssReader, ['contentPublishable' => true]); //データ生成 $rssReader = $this->RssReader->find('first', array('recursive' => -1, 'conditions' => array('id' => $rssReaderId))); $url = APP . 'Plugin' . DS . 'RssReaders' . DS . 'Test' . DS . 'Fixture' . DS . 'rss_v1.xml'; $xmlData = $this->RssReaderItem->serializeXmlToArray($url); $xmlData = Hash::insert($xmlData, '{n}.rss_reader_id', $rssReaderId); $data = array('RssReader' => $rssReader['RssReader'], 'RssReaderItem' => $xmlData); //登録処理実行 $this->RssReaderItem->updateRssReaderItems($data); //期待値の生成 $expected = $data; //RssReaderのテスト実施 $now = date('Y-m-d H:i:s'); $rssReader = $this->RssReader->find('first', array('recursive' => -1, 'conditions' => array('id' => $rssReaderId))); $date = new DateTime($rssReader['RssReader']['modified']); $this->assertTrue($date->format('Y-m-d H:i:s') <= $now); //RssReaderItemのテスト実施 $result = $this->RssReaderItem->find('all', array('fields' => array('id', 'rss_reader_id', 'title', 'summary', 'link', 'last_updated', 'serialize_value'), 'recursive' => -1, 'conditions' => array('rss_reader_id' => $rssReaderId))); $result = Hash::combine($result, '{n}.RssReaderItem.id', '{n}.RssReaderItem'); $result = Hash::remove($result, '{n}.id'); $this->_assertArray(null, $expected['RssReaderItem'], array_values($result)); }
/** * answerValidation 登録内容の正当性 * * @param object &$model use model * @param array $data Validation対象データ * @param array $question 登録データに対応する項目 * @param array $allAnswers 入力された登録すべて * @return bool */ public function answerChoiceValidation(&$model, $data, $question, $allAnswers) { if (!in_array($question['question_type'], $this->_choiceValidateType)) { return true; } if (!isset($model->data['RegistrationAnswer']['answer_values'])) { return true; } // 項目に設定されている選択肢を配列にまとめる $list = Hash::combine($question['RegistrationChoice'], '{n}.id', '{n}.key'); $ret = true; // 選択された選択肢IDすべてについて調査する $choiceIds = array_keys($model->data['RegistrationAnswer']['answer_values']); foreach ($choiceIds as $choiceId) { // 選択されたIDは、ちゃんと用意されている選択肢の中のひとつであるか if ($choiceId != '' && !Validation::inList(strval($choiceId), $list)) { $ret = false; $model->validationErrors['answer_value'][] = __d('registrations', 'Invalid choice'); } // チェックされている選択肢が「その他」の項目である場合は $choice = Hash::extract($question['RegistrationChoice'], '{n}[key=' . $choiceId . ']'); if ($choice && $choice[0]['other_choice_type'] != RegistrationsComponent::OTHER_CHOICE_TYPE_NO_OTHER_FILED) { // 具体的なテキストが書かれていないといけない if (empty($model->data['RegistrationAnswer']['other_answer_value'])) { $ret = false; $model->validationErrors['answer_value'][] = __d('registrations', 'Please enter something, if you chose the other item'); } } } return $ret; }
/** * edit * * @return void */ public function edit() { if (!$this->initLink()) { return; } $this->Categories->initCategories(true); $this->Paginator->settings = array('Link' => array('order' => array('LinkOrder.weight' => 'asc'), 'conditions' => array('Link.block_id' => $this->viewVars['blockId'], 'Link.is_latest' => true), 'limit' => -1)); $links = $this->Paginator->paginate('Link'); $links = Hash::combine($links, '{n}.LinkOrder.weight', '{n}', '{n}.Category.id'); //POST処理 $data = array(); if ($this->request->isPost()) { //登録処理 $data = $this->data; $this->LinkOrder->saveLinkOrders($data); //validationError if ($this->NetCommons->handleValidationError($this->LinkOrder->validationErrors)) { //リダイレクト $this->redirect(NetCommonsUrl::backToPageUrl()); return; } } $data = Hash::merge(array('links' => $links), $data); $results = $this->camelizeKeyRecursive($data); $this->set($results); }
protected function _findCustomAjax($state, $query, $results = array()) { if ($state == 'before') { return $query; } return Hash::combine($results, 'TestDevice.id', 'TestDevice.name'); }
/** * beforeFilter * * @return void */ public function beforeFilter() { parent::beforeFilter(); $userRoles = $this->UserRole->find('all', array('recursive' => -1, 'conditions' => array($this->UserRole->alias . '.language_id' => Current::read('Language.id')))); $this->set('userRolesName', Hash::combine($userRoles, '{n}.UserRole.key', '{n}.UserRole.name')); $this->set('userRolesDescription', Hash::combine($userRoles, '{n}.UserRole.key', '{n}.UserRole.description')); }
/** * Outputs room plugins * * @param string $roomId rooms.id * @param array $attributes The HTML attributes of the select element. * @return string Formatted CHECKBOX element * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options-for-select-checkbox-and-radio-inputs */ public function checkboxPluginsRoom($roomId, $attributes = array()) { $html = ''; //Modelの呼び出し $this->Plugin = ClassRegistry::init('PluginManager.Plugin'); $this->PluginsRoom = ClassRegistry::init('PluginManager.PluginsRoom'); //findのoptionsセット $findOptions = array('fields' => array($this->Plugin->alias . '.key', $this->Plugin->alias . '.name', $this->PluginsRoom->alias . '.room_id', $this->PluginsRoom->alias . '.plugin_key'), 'conditions' => array($this->Plugin->alias . '.type' => Plugin::PLUGIN_TYPE_FOR_FRAME, $this->Plugin->alias . '.language_id' => Configure::read('Config.languageId')), 'order' => array($this->Plugin->alias . '.weight' => 'asc')); //データ取得 if (isset($attributes['all']) && $attributes['all']) { $plugins = $this->Plugin->find('all', Hash::merge($findOptions, array('recursive' => -1, 'joins' => array(array('table' => $this->PluginsRoom->table, 'alias' => $this->PluginsRoom->alias, 'type' => 'LEFT', 'conditions' => array($this->Plugin->alias . '.key' . ' = ' . $this->PluginsRoom->alias . ' .plugin_key', $this->PluginsRoom->alias . '.room_id' => $roomId)))))); unset($attributes['all']); } else { $plugins = $this->PluginsRoom->find('all', Hash::merge($findOptions, array('recursive' => 0, 'conditions' => array($this->PluginsRoom->alias . '.room_id' => $roomId)))); } //チェックボックスの設定 $options = Hash::combine($plugins, '{n}.Plugin.key', '{n}.Plugin.name'); $this->_View->request->data['Plugin']['key'] = array_keys($options); foreach (array_keys($this->_View->request->data['Plugin']['key']) as $index) { $html .= $this->Form->hidden('Plugin.' . $index . '.key'); } $defaults = Hash::extract($plugins, '{n}.PluginsRoom[room_id=' . $roomId . ']'); $defaults = array_values(Hash::combine($defaults, '{n}.plugin_key', '{n}.plugin_key')); $this->_View->request->data['PluginsRoom']['plugin_key'] = $defaults; $html .= $this->Form->select('PluginsRoom.plugin_key', $options, Hash::merge($attributes, array('multiple' => 'checkbox'))); return $html; }
/** * Javascript strings Localization wrapper for Drupal * @param $locale */ public function l10n($locale) { $strings = DruniqueAPIUtil::call('page_blocks.json', ['tag' => 'javascript'], $locale); $strings = Hash::combine($strings, '{s}.title', '{s}.content'); $this->set(['result' => $strings, '_serialize' => 'result']); $this->response->cache('-1 minute', '+1 days'); }
public function getValues($object_type, $parent_id) { $lang = $this->getLang(); $conditions = compact('lang', 'object_type', 'parent_id'); $rows = $this->find('all', compact('conditions')); return Hash::combine($rows, '{n}.PMFormValue.field_id', '{n}.PMFormValue.value'); }
/** * view * * @return void */ public function view() { $this->__initRssReader(); //RssReaderFrameSettingデータ取得 if (!($rssFrameSetting = $this->RssReaderFrameSetting->getRssReaderFrameSetting($this->viewVars['frameKey']))) { $rssFrameSetting = $this->RssReaderFrameSetting->create(['frame_key' => $this->viewVars['frameKey']]); } $results = $this->camelizeKeyRecursive($rssFrameSetting); $this->set($results); //Rssの最新データ更新 $this->__updateItems(); //RssReaderItemデータ取得 $rssReaderItems = $this->RssReaderItem->getRssReaderItems($this->viewVars['rssReader']['id'], $this->viewVars['rssReaderFrameSetting']['displayNumberPerPage']); $rssReaderItems = Hash::combine($rssReaderItems, '{n}.RssReaderItem.id', '{n}.RssReaderItem'); $results = $this->camelizeKeyRecursive(array('rssReaderItems' => $rssReaderItems)); $this->set($results); //AJAXの処理 //if ($this->request->is('ajax')) { // $this->renderJson(array( // 'rssReader' => $this->viewVars['rssReader'], // 'rssReaderFrameSetting' => $this->viewVars['rssReaderFrameSetting'], // 'rssReaderItems' => $this->viewVars['rssReaderItems'], // )); //} }
public function read_index() { $querystring_params = $this->request->query; $search_term = !empty($querystring_params['q']) ? $querystring_params['q'] : false; $collections = array(); $collectionItems = array(); $collectionItemFields = array(); $users = array(); $limit = 5; $collection_id = !empty($querystring_params['collection_id']) ? $querystring_params['collection_id'] : null; $user_id = !empty($querystring_params['user_id']) ? $querystring_params['user_id'] : null; if ($search_term) { // TODO: multiple paginations (one for each group searched -> paging simulated in view; 'show more' leads to page with more results for particular type of search $collections = $this->Collections->readSearch($search_term, $limit); $collectionItems = $this->CollectionItems->readSearch($search_term, $collection_id, $limit); if (!empty($collectionItems)) { $itemCollections = $this->Collections->readList(array_unique(Hash::extract($collectionItems, '{n}.CollectionItem.collection_id')), true); $itemCollections = Hash::combine($itemCollections, '{n}.Collection.id', '{n}'); foreach ($collectionItems as &$item) { $item = array_merge($item, $itemCollections[$item['CollectionItem']['collection_id']]); } } $collectionItemFields = $this->CollectionItemFields->readSearch($search_term, $collection_id, $limit); $users = $this->Users->readSearch($search_term, $limit); $availabilityLegend = $this->CollectionItems->readAvailabilityLegend(); $this->set('q', $search_term); $this->set('collections', $collections); $this->set('collectionItems', $collectionItems); $this->set('collectionItemFields', $collectionItemFields); $this->set('users', $users); $this->set('availabilityLegend', $availabilityLegend); } }
/** * Displays the Map and pre-loads the ctags and Capsule collections * * @return void */ public function map() { // Get the ctags $ctagCapsules = $this->Capsule->User->getCtagCapsules($this->Auth->user('id')); $ctagDiscoveries = $this->Capsule->User->getCtagDiscoveries($this->Auth->user('id')); // Get the Capsules $capsules = $this->Capsule->getForUser($this->Auth->user('id'), null, null, null, null, array('includeCapsuleOwner' => true)); $capsules = Hash::combine($capsules, "{n}.Capsule.id", "{n}"); $capsules = json_encode($capsules); // Get the Discoveries $discoveries = $this->Capsule->getDiscoveredForUser($this->Auth->user('id'), null, null, null, null, array('includeCapsuleOwner' => true)); $discoveries = Hash::combine($discoveries, "{n}.Capsule.id", "{n}"); $discoveries = json_encode($discoveries); // See if a focus location or Capsule was passed in $lat = isset($this->request->query['lat']) ? $this->request->query['lat'] : null; $lng = isset($this->request->query['lng']) ? $this->request->query['lng'] : null; $focusType = isset($this->request->query['type']) ? $this->request->query['type'] : null; $focusId = isset($this->request->query['id']) ? $this->request->query['id'] : null; $this->set('ctagCapsules', $ctagCapsules); $this->set('ctagDiscoveries', $ctagDiscoveries); $this->set('capsules', $capsules); $this->set('discoveries', $discoveries); $this->set('lat', $lat); $this->set('lng', $lng); $this->set('focusType', $focusType); $this->set('focusId', $focusId); }
/** * afterSave is called after a model is saved. * * @param Model $model Model using this behavior * @param bool $created True if this save created a new record * @param array $options Options passed from Model::save(). * @return bool * @throws InternalErrorException * @see Model::save() */ public function afterSave(Model $model, $created, $options = array()) { if (!isset($model->data['Categories'])) { return true; } $model->loadModels(array('Category' => 'Categories.Category', 'CategoryOrder' => 'Categories.CategoryOrder')); $categoryKeys = Hash::combine($model->data['Categories'], '{n}.Category.key', '{n}.Category.key'); //削除処理 $conditions = array('block_id' => $model->data['Block']['id']); if ($categoryKeys) { $conditions[$model->Category->alias . '.key NOT'] = $categoryKeys; } if (!$model->Category->deleteAll($conditions, false)) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } $conditions = array('block_key' => $model->data['Block']['key']); if ($categoryKeys) { $conditions[$model->CategoryOrder->alias . '.category_key NOT'] = $categoryKeys; } if (!$model->CategoryOrder->deleteAll($conditions, false)) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } //登録処理 foreach ($model->data['Categories'] as $category) { if (!($result = $model->Category->save($category['Category'], false))) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } $category['CategoryOrder']['category_key'] = $result['Category']['key']; if (!$model->CategoryOrder->save($category['CategoryOrder'], false)) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } } return parent::afterSave($model, $created, $options); }
public function list2() { $data = $this->list(); $results = Hash::combine($data['CatalogProduct'], '{n}.product_id', '{n}.name'); ksort($results); return $results; }
/** * UserAttributesRoleデータ取得 * * @param string $roleKey 権限キー * @return array UserAttributesRoleデータ配列 */ public function getUserAttributesRole($roleKey) { $result = $this->find('all', array('recursive' => -1, 'conditions' => array($this->alias . '.role_key' => $roleKey), 'order' => $this->alias . '.id')); if (!$result) { return $result; } return Hash::combine($result, '{n}.' . $this->alias . '.id', '{n}'); }
/** * Default Constructor * * @param View $View The View this helper is being attached to. * @param array $settings Configuration settings for the helper. */ public function __construct(View $View, $settings = array()) { parent::__construct($View, $settings); //Modelの呼び出し $this->User = ClassRegistry::init('Users.User'); $this->UsersLanguage = ClassRegistry::init('Users.UsersLanguage'); $this->userAttributes = Hash::combine(Hash::get($this->_View->viewVars, 'userAttributes', array()), '{n}.{n}.{n}.UserAttribute.key', '{n}.{n}.{n}'); }
/** * testAdminIndex * * @return void */ public function testAdminIndex() { $this->testAction('/admin/taxonomy/terms/index/1'); $this->assertNotEmpty($this->vars['terms']); $expected = array('1' => 'Uncategorized', '2' => 'Announcements'); $termsTree = Hash::combine($this->vars['terms'], '{n}.Term.id', '{n}.Term.title'); $this->assertEquals($expected, $termsTree); }
public function options() { $aOptions = Hash::combine($this->find('all'), '{n}.ProductType.id', '{n}'); $aIcons = array(1 => 'ipad', 4 => 'imac', 5 => 'print'); foreach ($aOptions as $id => &$option) { $option['ProductType']['icon'] = $aIcons[$id]; } return $aOptions; }
public function setOptions(array $options) { // $this->_details = $details; $this->_options = array(); foreach ($options as $option) { $this->_options[$option['alias']] = $option; } $this->__idAliasMapping = Hash::combine($options, '{n}.id', '{n}.alias'); }
public function edit($id = 0) { $costingDb = $this->Costing->findById($id); $this->checkCanDo($costingDb); $hasCosting = $costingDb ? null : false; //neu edit thi lay tat ca product, nguoc lai chi lay product chua co costing $settings = Hash::combine($this->Settings->find("all"), '{n}.Settings.key', '{n}.Settings.val'); $this->set('settings', $settings); $listUser = array(); $listProduct = Hash::combine($this->listProduct($hasCosting), '{n}.Product.id', '{n}.Product.name'); $currentUserId = $this->loggedUser->User->id; $isAdmin = $this->isAdmin(); if ($isAdmin) { $listUser = $this->UserModel->listUser(); } $errorObj = array(); if (empty($this->request->data)) { $this->request->data = $costingDb; if (empty($costingDb)) { $this->request->data['Costing']['exchange'] = $settings['exchange']; } } else { //save $productId = $this->request->data['Costing']['product_id']; $costingByCustomerAndProduct = $this->Costing->find("first", array('conditions' => array('Costing.product_id' => $productId, 'Costing.id !=' => $id))); if ($costingByCustomerAndProduct) { $this->Session->setFlash(__('Customer and Product already exist in costing.'), 'flash/error'); } else { if (!isset($this->request->data['Costing']['user_id'])) { $this->request->data['Costing']['user_id'] = $currentUserId; } $this->Costing->set($this->request->data); if ($this->Costing->validates()) { $costingRecord = $this->Costing->getCostingRecord($this->request->data); $sellingPrice = $costingRecord['sellingPrice']; $this->request->data['Costing']['selling_price'] = $sellingPrice; $this->Costing->set($this->request->data); if ($this->Costing->save()) { $productData = array(); $productData['id'] = $productId; $productData['quantity'] = $this->request->data['Costing']['quantity']; $productData['price'] = $sellingPrice; $this->Product->save($productData, false); $this->Session->setFlash(__('Your data is saved successfully'), 'flash/success'); return $this->redirect(Router::url(array('action' => 'index'))); } else { $errorObj = $this->Costing->validationErrors; $this->Session->setFlash(__('Unable to save your data.'), 'flash/error'); } } } } $this->set('errorObj', $errorObj); $this->set('listUser', $listUser); $this->set("listProduct", $listProduct); }
public function editRoles($id) { $this->set('roles', Hash::combine($this->UserRole->find('all'), '{n}.UserRole.id', '{n}.UserRole.name')); $this->set('selectedRoles', Hash::combine($this->UserRoleAccess->findAllByUserId($id), '{n}.UserRoleAccess.role_id', '{n}.UserRole.name')); $this->set('user', $this->UserModel->findById($id)); if (count($this->request->data) > 0) { $this->UserRoleAccess->updateLinkObjects($id, 'user_id', $this->request->data['rolelist'], 'role_id'); return $this->redirect(Router::url(array('plugin' => 'User', 'controller' => 'User', 'action' => 'search'))); } }
public function getCompletion($user_id, $collection_id, $collection_item_id) { $completions = Hash::combine($this->getCompletions($user_id, $collection_id), '{n}.Completion.collection_item_id', '{n}'); if (isset($completions[$collection_item_id])) { $completion = $completions[$collection_item_id]; } else { $completion = array("Completion" => array("collection_item_id" => $collection_item_id, "completion_status_id" => 1)); } return $completion; }
/** * @see SearchAppController::beforeFilter() */ public function beforeFilter() { $companyIds = $this->Company->findAll(); $companyIds = Hash::combine($companyIds, "{n}.identifier", "{n}.label"); $this->set("canExportCSV", $this->OgAcl->canExportContactsSearchResults()); $this->set("searchTitle", "O&M Client / Company Contacts"); $this->set("companyIds", $companyIds); // FormHelper reads this variable and sets the options parent::beforeFilter(); }
/** * index method * * @param string $id containerId * @throws NotFoundException * @return void */ public function index($id = null) { $container = $this->Container->getContainerWithFrame($id); if (empty($container)) { throw new NotFoundException(); } $containers = array($container['Container']['type'] => $container['Container']); $boxes = Hash::combine($container['Box'], '{n}.id', '{n}', '{n}.container_id'); $this->set('containers', $containers); $this->set('boxes', $boxes); }