获取素材列表

@since 0.0.1
@param {string} $type 素材的类型
@param {boolean} [$all=true] 是否返回所有
@param {integer} [$page=1] 页码
@param {integer} [$count=20] 每页数量
@return {array}
@example \Yii::$app->wechat->getMaterials($type, $all, $page, $count);
170324
public function getMaterials($type, $all = true, $page = 1, $count = 20) {
		$offset = ($page - 1) * $count;
		$data = $this->getData('/cgi-bin/material/batchget_material', [
			'access_token' => $this->getAccessToken(),
		], Json::encode([
			'type' => $type,
			'offset' => $offset,
			'count' => $count,
		]));

		if($this->errcode == 0) {
			if($all && $offset + $data['item_count'] < $data['total_count']) {
				if($_data = $this->getMaterials($type, $all, $page + 1, $count)) {
					$data['item_count'] += $_data['item_count'];
					$data['item'] = array_merge($data['item'], $_data['item']);
				}
			}

			return $data;
		}

		return [];
	}
391414
public function listData($list, $page = 1, $size = 10)
    {
        $reData['totalPages'] = (int)$list->lastPage();
        $reData['totalCount'] = (int)$list->total();
        $reData['page'] = (int)$page;
        $reData['limit'] = (int)$size;
        $reData['count'] = (int)$list->count();

        if ($page == 1) {
            $reData['firstPage'] = true; //是否为首页
            $reData['hasPrePage'] = false; //是否有上一页
            $reData['prePage'] = 0; //上一页的页数
            if ($reData['totalPages'] == 1) {
                $reData['hasNextPage'] = false; //是否有下一页
                $reData['nextPage'] = 0;
            } else {
                $reData['hasNextPage'] = true; //是否有下一页
                $reData['nextPage'] = 2; //下一页的页数
            }
        } else {
            $reData['firstPage'] = false; //是否为首页
            if ($reData['totalPages'] == 1) {
                $reData['hasPrePage'] = false; //是否有上一页
                $reData['hasNextPage'] = false; //是否有下一页
                $reData['prePage'] = 1; //上一页的页数
                $reData['nextPage'] = 0; //下一页的页数
            } elseif ($page < $reData['totalPages']) {
                $reData['hasPrePage'] = true; //是否有上一页
                $reData['hasNextPage'] = true; //是否有下一页
                $reData['prePage'] = $page - 1; //上一页的页数
                $reData['nextPage'] = $page + 1; //下一页的页数
            } else {
                $reData['hasPrePage'] = true; //是否有上一页
                $reData['hasNextPage'] = false; //是否有下一页
                $reData['prePage'] = $page - 1; //上一页的页数
                $reData['nextPage'] = 0; //下一页的页数
            }
        }

        if ($page == $reData['totalPages']) {
            $reData['lastPage'] = true; //是否是最末页
        } else {
            $reData['lastPage'] = false; //是否是最末页
        }

        $reData['data'] = $list->toArray()['data'];

        return $reData;
    }
817562
function trigger($type, $data)
    {
        /**
         * 异步，将事件压入队列
         */
        if (isset($this->config['async']) && $this->config['async'])
        {
            return $this->getQueueInstance()->push(array('type' => $type, 'data' => $data));
        }
        /**
         * 同步，直接在引发事件时处理
         */
        else
        {
            return $this->_execute($type, $data);
        }
    }
1099177
public static <T> List<T> page(int pageNo, int pageSize, List<T> list) {
		if (isEmpty(list)) {
			return new ArrayList<>(0);
		}

		int resultSize = list.size();
		// 每页条目数大于总数直接返回所有
		if (resultSize <= pageSize) {
			if (pageNo <= 1) {
				return Collections.unmodifiableList(list);
			} else {
				// 越界直接返回空
				return new ArrayList<>(0);
			}
		}
		final int[] startEnd = PageUtil.transToStartEnd(pageNo, pageSize);
		if (startEnd[1] > resultSize) {
			startEnd[1] = resultSize;
		}
		return list.subList(startEnd[0], startEnd[1]);
	}
144148
public function count($type = FALSE)
  {   
	$count = 0;
	
	$messages = $this->_session_get();
	
	if (is_array($messages)){
	
		if ($type === FALSE)
		{
			$count = count($messages);
		}
		else {
			
			foreach($messages as $message){
				
				if ($message->type == $type){
					
					$count++;
				}
			}
			
		}
	}
		
	return $count;
  }
750580
public function count($type = 'admin.web')
    {

        return $this->calendar
            ->scopeQuery(function ($query) use ($type) {
                return $query->where('status', '<>', 'Draft')
                    ->whereUserId(user_id($type))
                    ->whereUserType(user_type($type));
            })->count();
    }
1237020
public function values($type = 'array')
	{
		$data = array(
			'foo' => 1,
			'bar' => true,
			'baz' => array(1, 2, 3),
		);

		switch ($type) {
			case 'request':
				return new \Illuminate\Http\Request(array('type' => $type));
			case 'class':
				return new Test($data);
			case 'object':
				return (object)$data;
			case 'array':
				return $data;
			case 'string':
				return 'hello';
			case 'number':
				return 123;
			case 'boolean':
				return (bool)rand(0, 1);
		}
	}
1315536
private function type($value, $type) {
        
        switch (func_num_args()) {
            case 0 :
            case 1 :
                return false;
            case 2 :
                // 二个参数时, 才执行正常处理逻辑
                
                if (is_array($type)) {
                    foreach ( $type as $t ) {
                        if ($this -> type($value, $t)) {
                            return true;
                        }
                    }
                    return false;
                }
                
                $t = strtolower(gettype($value));
                $type = strtolower($type);
                
                if ($type == $t) {
                    return true;
                } else if ($type == 'mixed') {
                    return true;
                } else {
                    switch ($t) {
                        case "integer" :
                            if ($type == 'int') {
                                return true;
                            }
                        case "double" :
                            return $type == 'number';
                        case "boolean" :
                            return $type == 'bool';
                        case "user function" :
                            return $type == 'function';
                        case "string" :
                        case "array" :
                        case "object" :
                        case "resource" :
                        case "null" :
                        case "unknown type" :
                        default :
                            return false;
                    }
                }
                return false;
            default :
                // 多于两个参数,认为第二个及其后的统统为可能的值.
                $varList = func_get_args();
                $value = array_shift($varList);
                
                return $this -> type($value, $varList);
        }
    
    }
927921
public function fetchAll($type = self::FETCH_TYPE_NUM)
    {
        if ($this->_allFetched) {
            return $this->buffer;
        }
        $results = $this->statement->fetchAll($type);
        if ($results !== false) {
            $this->buffer = array_merge($this->buffer, $results);
        }
        $this->_allFetched = true;
        $this->statement->closeCursor();

        return $this->buffer;
    }
336894
public function All($Page = '') {
      $Session = Gdn::Session();
      $this->Title(T('Inbox'));
      Gdn_Theme::Section('ConversationList');

      list($Offset, $Limit) = OffsetLimit($Page, C('Conversations.Conversations.PerPage', 50));
      
      // Calculate offset
      $this->Offset = $Offset;
      
      $UserID = $this->Request->Get('userid', Gdn::Session()->UserID);
      if ($UserID != Gdn::Session()->UserID) {
         if (!C('Conversations.Moderation.Allow', FALSE)) {
            throw PermissionException();
         }
         $this->Permission('Conversations.Moderation.Manage');
      }
      
      $Conversations = $this->ConversationModel->Get2($UserID, $Offset, $Limit);
      $this->SetData('Conversations', $Conversations->ResultArray());
      
      // Get Conversations Count
      //$CountConversations = $this->ConversationModel->GetCount($UserID);
      //$this->SetData('CountConversations', $CountConversations);
      
      // Build the pager
      if (!$this->Data('_PagerUrl'))
         $this->SetData('_PagerUrl', 'messages/all/{Page}');
      $this->SetData('_Page', $Page);
      $this->SetData('_Limit', $Limit);
      $this->SetData('_CurrentRecords', count($Conversations->ResultArray()));
      
      // Deliver json data if necessary
      if ($this->_DeliveryType != DELIVERY_TYPE_ALL && $this->_DeliveryMethod == DELIVERY_METHOD_XHTML) {
         $this->SetJson('LessRow', $this->Pager->ToString('less'));
         $this->SetJson('MoreRow', $this->Pager->ToString('more'));
         $this->View = 'conversations';
      }
      
      // Build and display page.
      $this->Render();
   }
1209511
public function getPage4Type($type)
    {
        $cachingKey = Caching::PAGE_INFO . '_' . $type;

        $pageInfo = $this->cachingHelperService->getItem($cachingKey, function () use ($type) {
            /** @var \PServerCore\Entity\Repository\PageInfo $repository */
            $repository = $this->entityManager->getRepository(
                $this->collectionOptions->getEntityOptions()->getPageInfo()
            );
            return $repository->getPageData4Type($type);
        });

        return $pageInfo;
    }
889047
public function lists($type, $offset = 0, $count = 20, $agentId)
    {
        $params = array(
                   'type' => $type,
                   'offset' => intval($offset),
                   'count' => min(20, $count),
                   'agentid' => $agentId,
                  );

        return $this->http->jsonPost(self::API_FOREVER_LIST, $params);
    }
26905
final public function page($page = 1, $num = 10)
    {
        $page = max($page, 1);
        $start = ($page - 1) * $num;
        $this->limit($num, $start);
        $bak = $this->_sql;
        $infos = $this->_getAll();

        $this->_sql = $bak;
        $querySql = $this->sql;
        $total = $this->count();
        //重新组装两个SQL
        $this->sql = "Rows:" . $querySql . "\n Count:" . $this->sql;
        return [$infos, $total];
    }
225255
function getPlayList($type){
        $list = file_get_contents(__DIR__.'/data.json');
        $list = json_decode($list,true);

        if($type === "video"){
            if(isset($list["video"])&& $list["video"]) {
                return $list["video"];
            }
        }
        if($type === "audio"){
            if(isset($list["audio"])&& $list["audio"]) {
                return $list["audio"];
            }
        }
        //此时应该返回为false；
        return $list;
    }
968314
public function gatherElementsFromType( $type )
	{
		if ( is_string( $type ) )
		{
			$type = $this->getType( $type );
		}

		if ( ! is_array( $type ) ) return false;

		$elements = array();

		foreach ( array( 'elements', 'sequence', 'choice', 'group' ) as $typeComponent )
		{
			if ( ! isset( $type[ $typeComponent ] ) )
			{
				continue;
			}

			foreach ( $type[ $typeComponent ] as $id => $element )
			{
				if ( $id == 'restrictionType')
				{
					continue;
				}

				if ( $id == 'elements' )
				{
					$elements += $element;
					continue;
				}

				$result = $this->gatherElementsFromType( $element );
				if ( ! $result )
				{
					$elements[ "{$element['prefix']}:{$element['name']}" ] = $element;
				}

				$elements += $result;
			}

		}

		return $elements;
	}
53867
protected function addItemToTheStartOfPageArray($pageArray, $page, $type)
    {
        array_unshift($pageArray, [
            'page' => $page,
            'label' => $this->paginationConfig['labels'][$type],
            'type' => $type
        ]);

        return $pageArray;
    }
943054
public static function list($parameters = null, $page = 1, $limit = 20)
    {
        // static function.
        $di = Di::getDefault();
        $manager = $di->getShared('modelsManager');

        //
        if ($parameters instanceof PhalconModel\Query\BuilderInterface) {
            $builder = $parameters;
        } else {
            if (!is_array($parameters)) {
                $params[] = $parameters;
            } else {
                $params = $parameters;
            }
            //
            $builder = $manager->createBuilder($params);
            $builder->from(get_called_class());

            if (isset($params['limit'])) {
                $limit = $params['limit'];
            }
        }

        $options = [
            'builder' => $builder,
            'limit'   => $limit,
            'page'    => $page,
        ];

        return $di->get('Pails\\Plugins\\Paginator', [$options]);
    }