当前位置: 首页>>代码示例>>PHP>>正文


PHP Set::Extract方法代码示例

本文整理汇总了PHP中Set::Extract方法的典型用法代码示例。如果您正苦于以下问题:PHP Set::Extract方法的具体用法?PHP Set::Extract怎么用?PHP Set::Extract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Set的用法示例。


在下文中一共展示了Set::Extract方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: auto_complete

 function auto_complete()
 {
     $this->loadModel('Product');
     $terms = $this->Product->find('all', array('conditions' => array('Product.productname LIKE' => $this->params['url']['autoCompleteText'] . '%'), 'fields' => array('id', 'productname'), 'limit' => 3, 'recursive' => -1));
     $terms = Set::Extract($terms, '{n}.Product.productname');
     $this->set('terms', $terms);
     $this->layout = 'ajax';
 }
开发者ID:reymedillo,项目名称:www1_dranix_com_ph,代码行数:8,代码来源:FleetsController.php

示例2: getPermissions

 /**
  * Get a list of authorized methods for a particular user/role to a resource
  *
  * @param string $resourceName
  * @return array $permittedMethods
  * @access public
  */
 public function getPermissions($resourceName = null)
 {
     $permissionNames = array();
     $permittedMethods = array();
     $Resource = ClassRegistry::init('Nssrbac.Resource');
     $Permission = ClassRegistry::init('Nssrbac.Permission');
     $roles = $this->Session->read('Auth');
     $myRoleIds = Set::Extract('/Role/id', $roles);
     $permissions = $Permission->find('all', array('conditions' => array('Resource.name' => Inflector::singularize($resourceName)), 'contain' => array('Role' => array('conditions' => array('Role.id' => $myRoleIds)), 'Resource'), 'fields' => array('Permission.name')));
     foreach ($permissions as $p => $permission) {
         if (!empty($permission['Role'])) {
             $permissionNames[] = $permission['Permission']['name'];
         }
     }
     if (is_array($permissionNames)) {
         foreach ($permissionNames as $name) {
             $methods = $this->permissionsMap[$name];
             foreach ($methods as $method) {
                 $permittedMethods[] = $method;
             }
         }
         return $permittedMethods;
     }
 }
开发者ID:neterslandreau,项目名称:nssrbac-dev,代码行数:31,代码来源:app_controller.php

示例3: testCond

 function testCond($cond, $data, $or = false, $empty = false)
 {
     $valid = true;
     $def = $empty;
     $modifKeys = array('and', 'or');
     App::import('Lib', 'Operations');
     foreach ($cond as $key => $cnd) {
         $op = false;
         $path = $key;
         if (is_numeric($path)) {
             $val = $data;
         } elseif (in_array($path, $modifKeys)) {
             $val = $data;
         } elseif (array_key_exists($path, $data)) {
             $val = $data[$path];
         } else {
             $op = Operations::parseStringOperation($path, array('mode' => 'left', 'type' => 'bool', 'sepPattern' => '\\h+'));
             if ($op) {
                 $path = $op['subject'];
             }
             $val = Set::Extract($path, $data);
         }
         if ($op) {
             $op['subject'] = $val;
             $op['val'] = $cnd;
             $valid = Operations::applyOperation($op);
         } elseif (is_null($cnd)) {
             $valid = is_null($val);
         } elseif (is_array($cnd)) {
             $or = $path == 'or';
             $valid = SetMulti::testCond($cnd, $val, $or);
         } elseif (!is_null($data)) {
             $valid = $val == $cnd;
         } else {
             $valid = false;
         }
         if ($valid == $or) {
             return $or;
         }
         $def = $valid;
     }
     return $def;
 }
开发者ID:kevthunder,项目名称:cake-custom-filter,代码行数:43,代码来源:set_multi.php

示例4: afterFind

 /**
  * afterFind function
  *
  * When looking for English content, if there isn't a current revision, populate with default text
  * When looking for none English content, if there isn't a current revision populate with the English text
  * 	Auto correct any links in content to point at same-language pages
  *
  * @param mixed $results
  * @access public
  * @return void
  */
 function afterFind($results)
 {
     $before = $results;
     $defaultLang = Configure::read('Languages.default');
     if ($this->language == $defaultLang) {
         if (isset($results[0]['Revision'])) {
             foreach ($results as $i => $result) {
                 if (array_key_exists('title', $result['Revision']) && !$result['Revision']['title']) {
                     $results[$i]['Revision']['title'] = __('Default Title', true);
                 }
                 if (array_key_exists('slug', $result['Revision']) && !$result['Revision']['slug']) {
                     $results[$i]['Revision']['slug'] = __('default_slug', true);
                 }
                 if (array_key_exists('content', $result['Revision']) && !$result['Revision']['content']) {
                     $results[$i]['Revision']['content'] = __('Default Content', true);
                 }
                 if (array_key_exists('lang', $result['Revision']) && !$result['Revision']['lang']) {
                     $results[$i]['Revision']['lang'] = $defaultLang;
                 }
             }
         }
         return $results;
     }
     if (isset($results[0]['Revision'])) {
         $missing = false;
         foreach ($results as $result) {
             if (array_key_exists('title', $result['Revision']) && !$result['Revision']['title']) {
                 $missing = true;
                 break;
             }
             if (array_key_exists('slug', $result['Revision']) && !$result['Revision']['slug']) {
                 $missing = true;
                 break;
             }
             if (array_key_exists('content', $result['Revision']) && !$result['Revision']['content']) {
                 $missing = true;
                 break;
             }
         }
         $language = $this->language;
         if ($missing) {
             $this->setLanguage($defaultLang);
             if ($this->__queryData['order'] == array(null)) {
                 unset($this->__queryData['order']);
             }
             $ids = Set::Extract($results, '/Node/id');
             $engResults = $this->find('all', am($this->__queryData, array('conditions' => array('Node.id' => $ids))));
             $this->setLanguage($language);
         }
         $root = trim(Router::url('/'), '/');
         if ($root) {
             $root .= '/';
         }
         $find = '@href="/' . $root . '(?!' . $language . '/)@';
         $replace = 'href="/' . $root . $language . '/';
         foreach ($results as $i => &$result) {
             if (isset($engResults[$i])) {
                 if (array_key_exists('title', $result['Revision']) && !$result['Revision']['title']) {
                     $result['Revision']['title'] = $engResults[$i]['Revision']['title'];
                 }
                 if (array_key_exists('slug', $result['Revision']) && !$result['Revision']['slug']) {
                     $result['Revision']['slug'] = $engResults[$i]['Revision']['slug'];
                 }
                 if (array_key_exists('content', $result['Revision']) && !$result['Revision']['content']) {
                     $result['Revision']['content'] = $engResults[$i]['Revision']['content'];
                 }
                 if (array_key_exists('lang', $result['Revision']) && !$result['Revision']['lang']) {
                     $result['Revision']['lang'] = $defaultLang;
                 }
             }
             //if (isset($result['Revision']['content']) && strpos('href="/', $result['Revision']['content'])) {
             if (isset($result['Revision']['content'])) {
                 $result['Revision']['content'] = preg_replace($find, $replace, $result['Revision']['content']);
             }
         }
     }
     return $results;
 }
开发者ID:sdoney,项目名称:cookbook,代码行数:89,代码来源:node.php

示例5: testDeleteInstructor

 function testDeleteInstructor()
 {
     $empty = null;
     /*
      * Try to delete an valid instructor from a valid assigned course
      * Inputs: Course_id==2 : "Mth321"	(Valid)
      *		   User_id==6 : "INSTRUCTOR2"	(Valid)
      */
     //Run tests
     $this->Course->addInstructor(2, 6);
     $this->Course->deleteInstructor(2, 6);
     $deletedInstructor = $this->Course->getCourseByInstructor(6);
     $this->assertEqual($empty, $deletedInstructor);
     /*
      * Test deleteInstructor() using invalid "course_id" input:
      * Inputs: Course_id==999999 : (Invalid)
      * 		   Course_id==2 : "Math321"	(Valid)
      * 		   User_id==2 : "Peterson"	(Valid)
      */
     //Run tests
     $this->Course->deleteInstructor(999999, 2);
     $invalidCourseInstructor = $this->Course->getCourseByInstructor(999999);
     $this->assertEqual($invalidCourseInstructor, $empty);
     /*
      * Test deleteInstructor() invalid "user_id" input:
      * Inputs: Course_id==2 : "Math321"	(Valid)
      * 		   User_id==13 : 	(inValid)
      */
     //Reused data from previous setup
     $this->Course->deleteInstructor(2, 13);
     $invalidCourseInstructor = $this->Course->getCourseByInstructor(13);
     $this->assertEqual($invalidCourseInstructor, $empty);
     /*
      * Test deleteInstructor on course without instructor
      * Inputs: Course_id==1 : "Math303" (Valid)
      * 		   User_id==4 : "INSTRUCTOR1" 	(Valid)
      */
     //Reused data from previous setup
     $this->Course->addInstructor(1, 5);
     $this->Course->deleteInstructor(1, 5);
     $this->Course->deleteInstructor(1, 5);
     $course = $this->Course->getCourseByInstructor(5);
     $this->assertEqual($course, $empty);
     //Test null inputs;
     //Set up data
     $this->Course->addInstructor(1, 1);
     //Run tests, should have no effects whatsoever
     $this->Course->deleteInstructor(null, 1);
     $this->Course->deleteInstructor(1, null);
     $course = $this->Course->getCourseByInstructor(1);
     $this->assertTrue(in_array('MECH 328', Set::Extract('/Course/course', $course)));
 }
开发者ID:eecian,项目名称:Team08-iPeer,代码行数:52,代码来源:course.test.php


注:本文中的Set::Extract方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。