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


PHP DataQuery::sort方法代码示例

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


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

示例1: sort

 /**
  * Set the sort order of this data list
  *
  * @see SS_List::sort()
  * @see SQLQuery::orderby
  * @example $list->sort('Name'); // default ASC sorting
  * @example $list->sort('Name DESC'); // DESC sorting
  * @example $list->sort('Name', 'ASC');
  * @example $list->sort(array('Name'=>'ASC,'Age'=>'DESC'));
  *
  * @param String|array Escaped SQL statement. If passed as array, all keys and values are assumed to be escaped.
  * @return DataList
  */
 public function sort()
 {
     if (count(func_get_args()) == 0) {
         return $this;
     }
     if (count(func_get_args()) > 2) {
         throw new InvalidArgumentException('This method takes zero, one or two arguments');
     }
     if (count(func_get_args()) == 2) {
         // sort('Name','Desc')
         if (!in_array(strtolower(func_get_arg(1)), array('desc', 'asc'))) {
             user_error('Second argument to sort must be either ASC or DESC');
         }
         $this->dataQuery->sort(func_get_arg(0), func_get_arg(1));
     } else {
         if (is_string(func_get_arg(0)) && func_get_arg(0)) {
             // sort('Name ASC')
             if (stristr(func_get_arg(0), ' asc') || stristr(func_get_arg(0), ' desc')) {
                 $this->dataQuery->sort(func_get_arg(0));
             } else {
                 $this->dataQuery->sort(func_get_arg(0), 'ASC');
             }
         } else {
             if (is_array(func_get_arg(0))) {
                 // sort(array('Name'=>'desc'));
                 $this->dataQuery->sort(null, null);
                 // wipe the sort
                 foreach (func_get_arg(0) as $col => $dir) {
                     // Convert column expressions to SQL fragment, while still allowing the passing of raw SQL fragments.
                     try {
                         $relCol = $this->getRelationName($col);
                     } catch (InvalidArgumentException $e) {
                         $relCol = $col;
                     }
                     $this->dataQuery->sort($relCol, $dir, false);
                 }
             }
         }
     }
     return $this;
 }
开发者ID:nomidi,项目名称:sapphire,代码行数:54,代码来源:DataList.php

示例2: sort

	/**
	 * Set the sort order of this data list
	 *
	 * @see SS_List::sort()
	 * @see SQLQuery::orderby
	 *
	 * @example $list->sort('Name'); // default ASC sorting
	 * @example $list->sort('Name DESC'); // DESC sorting
	 * @example $list->sort('Name', 'ASC');
	 * @example $list->sort(array('Name'=>'ASC,'Age'=>'DESC'));
	 *
	 * @return DataList
	 */
	public function sort() {
		if(count(func_get_args()) == 0) {
			return $this;
		}
		
		if(count(func_get_args()) > 2) {
			throw new InvalidArgumentException('This method takes zero, one or two arguments');
		}

		if(count(func_get_args()) == 2) {
			// sort('Name','Desc')
			if(!in_array(strtolower(func_get_arg(1)),array('desc','asc'))){
				user_error('Second argument to sort must be either ASC or DESC');
			}
			
			$this->dataQuery->sort(func_get_arg(0), func_get_arg(1));
		}
		else if(is_string(func_get_arg(0)) && func_get_arg(0)){
			// sort('Name ASC')
			if(stristr(func_get_arg(0), ' asc') || stristr(func_get_arg(0), ' desc')) {
				$this->dataQuery->sort(func_get_arg(0));
			} else {
				$this->dataQuery->sort(func_get_arg(0), 'ASC');
			}
		}
		else if(is_array(func_get_arg(0))) {
			// sort(array('Name'=>'desc'));
			$this->dataQuery->sort(null, null); // wipe the sort
			
			foreach(func_get_arg(0) as $col => $dir) {
				$this->dataQuery->sort($this->getRelationName($col), $dir, false);
			}
		}
		
		return $this;
	}
开发者ID:redema,项目名称:sapphire,代码行数:49,代码来源:DataList.php

示例3: testConditionsIncludeTables

 /**
  * Tests that getFinalisedQuery can include all tables
  */
 public function testConditionsIncludeTables()
 {
     // Including filter on parent table only doesn't pull in second
     $query = new DataQuery('DataQueryTest_C');
     $query->sort('"SortOrder"');
     $query->where(array('"DataQueryTest_C"."Title" = ?' => array('First')));
     $result = $query->getFinalisedQuery(array('Title'));
     $from = $result->getFrom();
     $this->assertContains('DataQueryTest_C', array_keys($from));
     $this->assertNotContains('DataQueryTest_E', array_keys($from));
     // Including filter on sub-table requires it
     $query = new DataQuery('DataQueryTest_C');
     $query->sort('"SortOrder"');
     $query->where(array('"DataQueryTest_C"."Title" = ? OR "DataQueryTest_E"."SortOrder" > ?' => array('First', 2)));
     $result = $query->getFinalisedQuery(array('Title'));
     $from = $result->getFrom();
     // Check that including "SortOrder" prompted inclusion of DataQueryTest_E table
     $this->assertContains('DataQueryTest_C', array_keys($from));
     $this->assertContains('DataQueryTest_E', array_keys($from));
     $arrayResult = iterator_to_array($result->execute());
     $first = array_shift($arrayResult);
     $this->assertNotNull($first);
     $this->assertEquals('First', $first['Title']);
     $second = array_shift($arrayResult);
     $this->assertNotNull($second);
     $this->assertEquals('Last', $second['Title']);
     $this->assertEmpty(array_shift($arrayResult));
 }
开发者ID:aaronleslie,项目名称:aaronunix,代码行数:31,代码来源:DataQueryTest.php


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