/** * testFind * * @retun void * @access public */ function testFind() { $result = $this->Produto->find('all'); $expected = array( array( 'Produto' => array( 'id' => 1, 'nome' => 'Produto 1', 'valor' => '1,99' ) ), array( 'Produto' => array( 'id' => 2, 'nome' => 'Produto 2', 'valor' => '1.000,20' ) ), array( 'Produto' => array( 'id' => 3, 'nome' => 'Produto 3', 'valor' => '1.999.000,00' ) ) ); $this->assertEqual($result, $expected); }
/** * Get Forms * * Returns an array of Form Model Objects. * * @param array $where * @return array|bool */ public function get_forms(array $where = array()) { if ('form' != $this->_object->get_type()) { return FALSE; } return $this->_object->find(NULL, $where); }
/** * testDetailFind * * @return void */ public function testUserDetailFind() { $this->UserDetail->recursive = -1; $results = $this->UserDetail->find('all'); $this->assertTrue(!empty($results)); $this->assertTrue(is_array($results)); }
/** * Process menu * * @param object $module * @param object $element * @return object */ public function process($module, $element) { foreach ($element->find('a') as $ele) { if ($type = $ele->attr("data-type")) { if ($type == "separator") { $ele->parent()->addClass("uk-nav-divider"); $ele->parent()->removeChild($ele); } else { $ele->removeAttr('data-type'); if (!$ele->parent()->parent()->hasClass('uk-navbar-nav') && !($module->nav_settings["accordion"] && $ele->parent()->first("ul.level2"))) { $ele->parent()->addClass("uk-nav-header"); foreach ($ele->children() as $child) { $ele->parent()->prepend($child); } $ele->replaceWith($ele->text()); } } } } foreach ($element->first("ul:first")->addClass($module->nav_settings["modifier"])->find('ul.level2 ul') as $ul) { if (!$ul->hasClass('uk-nav-sub')) { $ul->removeAttr("class"); } } foreach ($element->find('li') as $li) { $li->removeAttr('data-id')->removeAttr('data-menu-active')->removeAttr('data-menu-columns')->removeAttr('data-menu-columnwidth')->removeAttr('data-menu-icon')->removeAttr('data-menu-image')->removeAttr('data-menu-subtitle'); $li->removeClass("level1")->removeClass("level2")->removeClass("level3")->removeClass("level4")->parent()->removeClass("level1")->removeClass("level2")->removeClass("level3")->removeClass("level4"); } return $element; }
/** * Process menu * * @param object $module * @param object $element * @return object */ public function process($module, $element) { $element->first('ul:first')->attr('class', 'uk-navbar-nav'); foreach ($element->find('ul.level2') as $ul) { // get parent li $li = $ul->parent(); // get columns $columns = (int) $li->attr('data-menu-columns'); if ($columns > 1) { $i = 0; $column = -1; $children = $ul->children('li'); if ($children->length > $columns) { $remainder = $children->length % $columns; $colrows = ($children->length - $remainder) / $columns; } else { $remainder = 0; $colrows = 1; } foreach ($children as $child) { if ($i-- == 0) { $i = $remainder-- > 0 ? $colrows : $colrows - 1; $column++; } if ($li->children('ul')->length == $column) { $li->append('<ul class="level2"></ul>'); } if ($column > 0) { $li->children('ul')->item($column)->append($child); } } $columns = $column + 1; } else { $columns = 1; } // get width $width = (int) $li->attr('data-menu-columnwidth'); $style = $width > 0 ? sprintf(' style="min-width: %spx; max-width: %spx; width:%spx;"', $columns * $width, $columns * $width, $width) : null; // append dropdown divs $li->append(sprintf('<div class="uk-dropdown uk-dropdown-navbar uk-dropdown-width-%d"%s><div class="uk-grid uk-dropdown-grid"></div></div>', $columns, $style)); $div = $li->first('div.uk-dropdown div.uk-grid'); foreach ($li->children('ul') as $i => $u) { $u->addClass("uk-nav uk-nav-navbar"); $div->append(sprintf('<div class="uk-width-1-%d"></div>', $columns))->children('div')->item($i)->append($u); } } foreach ($element->find('li.level1') as $li) { $li->attr("data-uk-dropdown", "{}"); if ($li->attr('data-menu-subtitle')) { $li->first("a")->addClass('uk-navbar-nav-subtitle'); } } foreach ($element->find("ul.level3") as $list) { $list->addClass("uk-nav-sub"); } return $element; }
/** * Process menu * * @param object $module * @param object $element * @return object */ public function process($module, $element) { $use_scrollspy = false; $active_url = false; //assuming the first active menu item is the current page if ($module->nav_settings['scrollspy'] && ($active = $element->first('li.uk-active'))) { $active = $active->first('a'); $active_url = preg_replace('/#(.+)$/', '', $active->attr('href')); } foreach ($element->find('a') as $ele) { // check if scrollspy needs to be applied if ($module->nav_settings['scrollspy'] && $active_url && strpos($ele->attr('href'), $active_url . '#') !== false) { $use_scrollspy = true; if (strpos($active->attr('href'), '#') === false) { $active->attr('href', '#top'); } $ele->attr('href', strstr($ele->attr('href'), '#')); } if ($type = $ele->attr("data-type")) { if ($type == "separator-line") { $ele->parent()->addClass("uk-nav-divider"); $ele->parent()->removeChild($ele); } else { if ($type == "separator-text") { $ele->removeAttr('data-type'); } else { // header $ele->removeAttr('data-type'); if (!$ele->parent()->parent()->hasClass('uk-navbar-nav') && !($module->nav_settings["accordion"] && $ele->parent()->first("ul.level2"))) { $ele->parent()->addClass("uk-nav-header"); foreach ($ele->children() as $child) { $ele->parent()->prepend($child); } $ele->replaceWith($ele->text()); } } } } } foreach ($element->first("ul:first")->addClass($module->nav_settings["modifier"])->find('ul.level2 ul') as $ul) { if (!$ul->hasClass('uk-nav-sub')) { $ul->removeAttr("class"); } } foreach ($element->find('li') as $li) { $li->removeAttr('data-id')->removeAttr('data-menu-active')->removeAttr('data-menu-columns')->removeAttr('data-menu-columnwidth')->removeAttr('data-menu-icon')->removeAttr('data-menu-image')->removeAttr('data-menu-subtitle'); $li->removeClass("level1")->removeClass("level2")->removeClass("level3")->removeClass("level4")->parent()->removeClass("level1")->removeClass("level2")->removeClass("level3")->removeClass("level4"); } // apply scrollspy if ($use_scrollspy && $active_url) { $element->first('ul:first')->attr('data-uk-scrollspy-nav', '{closest: \'li\', smoothscroll: true}'); } return $element; }
/** * Retrieve a user by the given credentials. * * @param array $credentials * @return \Krenor\LdapAuth\Objects\LdapUser|null */ public function retrieveByCredentials(array $credentials) { $username = $credentials['username']; $result = $this->ldap->find($username); if (!is_null($result)) { $user = new $this->model(); $user->build($result); return $user; } return null; }
/** * Extract the data (title,size,unit_price,description) from the DOM object * @param object $dom Dom object * @return array Data exracted from the DOM */ static function getItemData($dom) { $itemData = []; $title = $dom->find('.productTitleDescriptionContainer h1'); $description = $dom->find('#information .productText p'); $price = $dom->find('.pricePerUnit text'); $itemData['title'] = $title[0]->innertext; //divide by 1024 to get the size of the page in kilobytes and round it $itemData['size'] = round($dom->size / 1024, 2) . 'kb'; //remove the currency sign and trim the string to get the numeric price of the product $itemData['unit_price'] = trim(str_replace('£', '', $price[0]->innertext)); $itemData['description'] = $description[0]->innertext; return $itemData; }
/** * Gets (extended) config * @param string $identifier * @return array */ public function get($identifier) { if (!isset($this->configs[$identifier])) { $files = $this->path->find('config.' . $identifier, false); $config = array(); foreach ($files as $file) { $fileContent = (include $file); $fileContent = $fileContent ? $fileContent : array(); $config = array_merge($config, $fileContent); } $this->config[$identifier] = $config; } return $this->config[$identifier]; }
/** * Get an item by its ID * * @param $id * @param array $columns * @return mixed */ public function find($id, $columns = ['*']) { if (is_null($id) || empty($id)) { throw new InvalidArgumentException('Invalid id'); } return $this->model->find($id, $columns); }
/** * Create and save a token for given record * * @param object $model Model * @param mixed $id Record ID * @param string $field Use this field instead of the configured one * @param int $length Use this length instead of the configured one * @param string $chars Use this chars instead of the configured ones * @return string Token */ public function token($model, $id = null, $field = null, $length = null, $chars = null) { foreach (array_keys($this->default) as $var) { if (empty(${$var})) { ${$var} = $this->settings[$model->alias][$var]; } } $token = false; $charCount = strlen($chars); while (empty($token) || $model->find('count', array('conditions' => array($model->alias . '.' . $field => $token), 'recursive' => -1)) > 0) { $token = ''; for ($i = 0; $i < $length; $i++) { $token .= $chars[mt_rand(0, $charCount - 1)]; } } if (!empty($token)) { if (empty($id)) { $id = $model->id; } if (empty($id)) { $token = false; } else { $model->id = $id; $model->saveField($field, $token); } } return $token; }
/** * Add a "Compile" menu link to the Course Admin block as the top link. * * @author Gerald Albion * date 2014-10-31 * @copyright 2014 Royal Roads University * @param object $settingsnav Main navigation object. * @param object $context Course context. */ function local_compile_extends_settings_navigation($settingsnav, $context) { // Context must be course. if ($context->contextlevel != CONTEXT_COURSE) { return; } // Must be in a valid course: Cannot be course id 0. if ($context->instanceid == 0) { return; } // Must be in a valid course: Course must be retrievable. if (!($course = get_course($context->instanceid))) { return; } // Must be enrolled or otherwise allowed to view the course. if (!(is_enrolled($context) || is_viewing($context))) { return; } // Must have a course admin menu in which to add link. if (!($coursenode = $settingsnav->find('courseadmin', navigation_node::TYPE_COURSE))) { return; } // Good to go. Build the menu item. $url = new moodle_url('/local/compile/list_modules.php', array('id' => $course->id)); $newnode = navigation_node::create(get_string('menucaption', 'local_compile'), $url, navigation_node::NODETYPE_LEAF, 'compile', 'compile', new pix_icon('i/settings', '')); // We want to put this link at the top: find the existing top (first) node. $firstnode = $coursenode->get_children_key_list()[0]; // Add the menu item to the menu, before the first node. $coursenode->add_node($newnode, $firstnode); }
/** * Process menu * * @param object $module * @param object $element * @return object */ public function process($module, $element) { $ul = $element->first('ul:first')->attr('class', 'uk-nav'); if ($module->nav_settings["accordion"]) { $ul->addClass("uk-nav-parent-icon")->addClass("uk-nav-side")->attr("data-uk-nav", "{}"); foreach ($ul->find("ul.level2") as $list) { if ($list->prev()->tag() == 'a' && !$list->prev()->attr("href")) { $list->prev()->attr("href", "#"); } $list->addClass("uk-nav-sub"); } } else { foreach ($ul->find("ul.level2") as $list) { $list->addClass("uk-nav-sub"); } } if ($module->position == "offcanvas") { foreach ($element->find("a") as $span) { if ($span->attr("data-type")) { $span->removeAttr("data-type")->removeAttr("class"); } } } return $element; }
/** * Instantiates a class * * @access private * @param string * @param string * @return null */ function _ci_init_class($class, $prefix = '', $config = FALSE) { $class = strtolower($class); // Is there an associated config file for this class? // {{{ Matchbox $module = $this->_matchbox->argument(3); if ($config === null) { if ($filepath = $this->_matchbox->find('config/' . $class . EXT, $module)) { include $filepath; } } // }}} if ($prefix == '') { $name = class_exists('CI_' . $class) ? 'CI_' . $class : $class; } else { $name = $prefix . $class; } // Set the variable name we will assign the class to $classvar = !isset($this->_ci_varmap[$class]) ? $class : $this->_ci_varmap[$class]; // Instantiate the class $CI =& get_instance(); if ($config !== NULL) { $CI->{$classvar} = new $name($config); } else { $CI->{$classvar} = new $name(); } }
/** * Admin edit * * @param integer $id * @return void * @access public */ public function admin_edit($id = null) { // Protect against administrator edit if ($id == null || $id < 4) { $this->Session->setFlash(__('Invalid request.'), 'flash_message_error'); $this->redirect(array('action' => 'index')); } $errors = null; if (!empty($this->request->data)) { $this->request->data['Aro']['model'] = ''; // update alias with user data if ($this->request->data['Aro']['foreign_key'] != '') { $this->request->data['Aro']['model'] = 'User'; $this->request->data['Aro']['alias'] = $this->User->field('Name', array('id' => $this->request->data['Aro']['foreign_key'])); } $this->Node->recursive = -1; $this->request->data = array_merge($this->Node->read(null, $id), $this->request->data); // alias must be unique $this->Node->validate = array('alias' => array('rule' => 'isUnique', 'message' => __('Group / User name must be unique!!'))); if ($this->Node->save($this->request->data)) { $this->Session->setFlash(__('Saved with success.'), 'flash_message_info'); $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(__('Could not be saved. Please, try again.'), 'flash_message_error'); } } if (empty($this->request->data)) { $this->request->data = $this->Node->read(null, $id); } $parents[0] = "[ " . __('Root') . " ]"; $nodelist = $this->Node->generateTreeList(null, '{n}.Aro.id', '{n}.Aro.alias', ' - ', '-1'); $acolist = $this->Acl->Aco->generateTreeList(null, '{n}.Aco.id', '{n}.Aco.alias', ' - ', '-1'); $acoAccessList = $this->Acl->Aco->generateTreeList(null, '{n}.Aco.id', '{n}.Aco.alias', '', '-1'); $acoAliasList = $acoAccessList; foreach ($acoAccessList as $key => $value) { $alias = ""; $path = $this->Acl->Aco->getPath($key); foreach ($path as $pathAlias) { if ($alias != '') { $alias = $alias . '/'; } $alias = $alias . $pathAlias['Aco']['alias']; } $acoAliasList[$key] = $alias; $acoAccessList[$key] = $this->Acl->check($this->request->data['Aro']['alias'], $alias); #value } if ($nodelist) { foreach ($nodelist as $key => $value) { $parents[$key] = $value; } } $foreignKeys = array(); // if node is group type ( without foreignKey ) do no show available users if ($this->Node->field('foreign_key')) { $usersOnAro = $this->Node->find('list', array('fields' => array('Aro.foreign_key'), 'conditions' => array('Aro.foreign_key <>' => null, 'Aro.id <>' => $id))); $foreignKeys = $this->User->find('list', array('conditions' => array('User.active' => '1', 'NOT' => array('User.id' => $usersOnAro)))); } $this->set(compact('parents', 'acolist', 'foreignKeys', 'acoAccessList', 'acoAliasList')); }
/** * Searches the directory paths for a given file. * * @param mixed $paths An path string or array of path strings to search in * @param string $file The file name to look for. * @return mixed Full path and name for the target file, or false if file not found. */ public function find($paths, $file) { if (!$file) { return false; } return $this->adapter->find((array) $paths, $file); }
/** * 获取集合的数据结构 * * @return array */ private function getSchema() { $schema = array('2d' => array(), 'file' => array(), 'export' => array(), 'post' => array('_id' => array('type' => '_idfield')), 'all' => array(), 'quick' => array(), 'combobox' => array('rshCollectionValueField' => '_id')); $cursor = $this->_structure->find(array('collection_id' => $this->_collection_id)); $cursor->sort(array('orderBy' => 1, '_id' => -1)); while ($cursor->hasNext()) { $row = $cursor->getNext(); $type = $row['type'] == 'filefield' ? 'file' : 'post'; $schema[$type][$row['field']] = $row; $schema['all'][$row['field']] = $row; $this->_fields[$row['field']] = true; $this->_title[$row['field']] = $row['label']; if ($row['type'] === '2dfield') { $schema['2d'][$row['field']] = $row; } if ($row['rshKey']) { $schema['combobox']['rshCollectionKeyField'] = $row['field']; } if ($row['rshValue']) { $schema['combobox']['rshCollectionValueField'] = $row['field']; } if (isset($row['isFatherField']) && $row['isFatherField']) { $this->_fatherField = $row['field']; } // 检查结构的时候,检查允许导出的字段 if (!empty($row['export'])) { $schema['export'][$row['field']] = true; } if (isset($row['isQuick']) && $row['isQuick'] && $row['type'] == 'arrayfield') { $schema['quick'][$row['field']] = $row; } if (!empty($row['rshCollection'])) { $rshCollectionStructures = $this->_structure->findAll(array('collection_id' => $this->getCollectionIdByAlias($row['rshCollection']))); if (!empty($rshCollectionStructures)) { $rshCollectionKeyField = ''; $rshCollectionValueField = '_id'; $rshCollectionValueFieldType = 'textfield'; foreach ($rshCollectionStructures as $rshCollectionStructure) { if ($rshCollectionStructure['rshKey']) { $rshCollectionKeyField = $rshCollectionStructure['field']; } if ($rshCollectionStructure['rshValue']) { $rshCollectionValueField = $rshCollectionStructure['field']; $rshCollectionValueFieldType = $rshCollectionStructure['type']; } } if (empty($rshCollectionKeyField)) { throw new \Exception('字段' . $row['field'] . '的“关联集合”的键值属性尚未设定,请检查表表结构设定'); } $this->_rshCollection[$row['rshCollection']] = array('collectionField' => $row['field'], 'rshCollectionKeyField' => $rshCollectionKeyField, 'rshCollectionValueField' => $rshCollectionValueField, 'rshCollectionValueFieldType' => $rshCollectionValueFieldType); } else { throw new \Exception('字段' . $row['field'] . '的“关联集合”的键值属性尚未设定,请检查表表结构设定'); } } } ksort($this->_title); $this->_schema = $schema; return $schema; }
/** * Grant type: authorization_code * * @see IOAuth2GrantCode::getAuthCode() * * @param string $code * @return AuthCode if valid, null of not */ public function getAuthCode($code) { $authCode = $this->AuthCode->find('first', array('conditions' => array('code' => $code), 'recursive' => -1)); if ($authCode) { return $authCode['AuthCode']; } return null; }
/** * Get all keys and data stored in a cookie * * @access public * @return array|null */ public function getAllData() { if ($this->exists()) { return $this->cookie->find($_COOKIE[$this->name]); } else { return null; } }
/** * Contents After Trash Return * * ゴミ箱から戻した固定ページのテンプレート生成が目的 * * @param CakeEvent $event */ public function contentsAfterTrashReturn(CakeEvent $event) { $id = $event->data; $data = $this->Page->find('first', ['conditions' => ['Content.id' => $id]]); if ($data) { $this->Page->createPageTemplate($data); } }
public function testRecordSetFindFilter() { $expected = array(array('id' => 1, 'data' => 'data1'), array('id' => 2, 'data' => 'data2'), array('id' => 3, 'data' => 'data3'), array('id' => 4, 'data' => 'data4')); $records = $this->_recordSet->find(function ($item) { return true; }); $this->assertEqual($expected, $records->to('array')); }
/** * Extract from DOM object * * @param object $dom * @return int */ public static function parse($dom) { $element = $dom->find('.m_content_recette_info span.preptime'); if ($element->text !== null) { return intval(trim($element->text)); } else { return null; } }
function read_attrib($entity_id = '', $cat_id = '', $allrows = '') { if ($allrows) { $this->allrows = $allrows; } $attrib = $this->custom->find($this->type_app[$this->type], ".{$this->type}.{$entity_id}.{$cat_id}", $this->start, $this->query, $this->sort, $this->order, $this->allrows); $this->total_records = $this->custom->total_records; return $attrib; }
function read_attrib($type_id, $allrows = '') { if ($allrows || phpgw::get_var('allrows') == 1) { $this->allrows = true; } $attrib = $this->custom->find('property', '.location.' . $type_id, $this->start, $this->query, $this->sort, $this->order, $this->allrows); $this->total_records = $this->custom->total_records; return $attrib; }
/** * * @param int $id * @return boolean */ public function requestDevice($id) { $device = $this->mobileDeviceRepository->find($id); $deviceQueue = new \Vlreleases\UserBundle\Entity\MobileDeviceQueue(); $deviceQueue->setStartTime(new \DateTime()); $deviceQueue->setMobileDevice($device); $deviceQueue->setRequester($this->getCurrentUser()); return $this->saveRequester($deviceQueue); }
/** * Update model hidden * 编辑model的hidden字段 * * @return void */ public function enable() { if ($this->pk_id) { $this->model->find($this->pk_id); $this->model->hidden = !$this->model->hidden; $this->model->save(); Redirect::success('状态发布成功'); } }
/** * Extract from DOM object * * @param object $dom * @return string */ public static function parse($dom) { $element = $dom->find('h1.m_title span.item span.fn'); if ($element->text !== null) { return utf8_encode(trim($element->text)); } else { return null; } }
/** * Get the most viewed records for the table * * @param object $Model the model that is being used. * @param int $limit the number or records to return * * @return array the most viewed records */ public function getMostViewed($Model, $limit = 10) { $fields = array($Model->alias . '.id', $Model->alias . '.' . $Model->displayField, $Model->alias . '.views'); if ($Model->hasField('slug')) { $fields[] = $Model->alias . '.slug'; } $rows = $Model->find('all', array('fields' => $fields, 'conditions' => array($Model->alias . '.views > ' => 0), 'order' => array($Model->alias . '.views' => 'DESC'), 'limit' => (int) $limit)); return $rows; }
/** * Returns the object associated with `$this` via a * "has one" relationship. * * @param string $field The object name. * @access protected * @return object */ protected function _get_has_one($field) { $lookup_id = $this->classname() . $this->_meta['pk_separator'] . $this->_meta['key']; $where = array($lookup_id => $this->get_pk()); $this->_db->find('`' . $this->_meta['key'] . '`', $field, $where, 'LIMIT 1'); $result = $this->_db->fetch('assoc'); $obj_id = $result[$this->_meta['key']]; $obj_name = $this->_meta['model_namespace'] . $field; return new $obj_name(array('id' => $obj_id)); }
/** * testTodosEstados * * @retun void * @access public */ function testTodosEstados() { $results = $this->EstadoBrasileiro->todosEstados(); $this->assertTrue(is_array($results['EstadoBrasileiro'])); $this->assertEqual(count($results['EstadoBrasileiro']), 27); $this->assertEqual($results, $this->EstadoBrasileiro->find('all')); $results = $this->EstadoBrasileiro->todosEstados(false); $this->assertTrue(is_array($results['EstadoBrasileiro'])); $this->assertEqual(count($results['EstadoBrasileiro']), 26); }