/** * Filter input array by key value pairs * @param array $data rawData * @return array filtered data array */ public function filter(CArrayDataProvider $data) { $temp = $data->getData(); foreach ($temp as $index => $item) { foreach ($this->filters as $key => $value) { if ($value == '') { continue; } // bypass empty filter $test = false; // value to test for if ($item instanceof CModel) { if (isset($item->{$key}) == false) { throw new CException("Property " . get_class($item) . "::{$key} does not exist!"); } $test = $item->{$key}; } elseif (is_array($item)) { if (!array_key_exists($key, $item)) { throw new CException("Key {$key} does not exist in Array!"); } $test = $item[$key]; } else { throw new CException("Data in CArrayDataProvider must be an array of arrays or CModels!"); } if (stripos($test, $value) === false) { unset($temp[$index]); } } } $data->setData(array_values($temp)); return $data; }
/** * Displays and send messages in the specified queue. * @param string $queue_name * @param string $subscriber_id */ public function actionMessages($queue_name, $subscriber_id = null) { if (($subscriber_id = trim($subscriber_id)) === '') { $subscriber_id = null; } list($queue, $authItems) = $this->loadQueue($queue_name, array('nfy.message.read', 'nfy.message.create')); $this->verifySubscriber($queue, $subscriber_id); $formModel = new MessageForm('create'); if ($authItems['nfy.message.create'] && isset($_POST['MessageForm'])) { $formModel->attributes = $_POST['MessageForm']; if ($formModel->validate()) { $queue->send($formModel->content, $formModel->category); $this->redirect(array('messages', 'queue_name' => $queue_name, 'subscriber_id' => $subscriber_id)); } } $dataProvider = null; if ($authItems['nfy.message.read']) { $dataProvider = new CArrayDataProvider($queue->peek($subscriber_id, 200, array(NfyMessage::AVAILABLE, NfyMessage::RESERVED, NfyMessage::DELETED)), array('sort' => array('attributes' => array('id'), 'defaultOrder' => array('id' => CSort::SORT_DESC)))); // reverse display order to simulate a chat window, where latest message is right above the message form $dataProvider->setData(array_reverse($dataProvider->getData())); } $this->render('messages', array('queue' => $queue, 'queue_name' => $queue_name, 'dataProvider' => $dataProvider, 'model' => $formModel, 'authItems' => $authItems)); }
public static function mycoupon() { $organID = Yii::app()->user->getOrganID(); //判断优惠券是否过期 $sql = "select ID ,CouponSn,Amount,PromoID,CreateTime,Valid from pap_coupon_manage where" . " IsUse=0 and OwnerID={$organID} and (CreateTime+3600*24*Valid)>UNIX_TIMESTAMP(NOW())" . " order by Amount DESC"; $rawData = Yii::app()->papdb->createCommand($sql)->queryAll(); $dataProvider = new CArrayDataProvider($rawData, array('id' => 'coupon', 'pagination' => array('pageSize' => 10000))); $data = $dataProvider->getData(); foreach ($data as $key => $val) { //截止日期 $data[$key]['EndTime'] = intval($val['CreateTime']) + 3600 * 24 * intval($val['Valid']); } $dataProvider->setData($data); return $dataProvider; }
public function actionCozinha($id = null) { $dataPizzas = array(); $dataCombinados = array(); $dataProdutoPedido = array(); $model = array(); $modelPizzaria = Pizzaria::model()->find(); if (!empty($id)) { $model = $this->loadModel($id); $dataProdutoPedido = new CArrayDataProvider('ProdutoPedido'); $dataProdutoPedido->setData($model->produtoPedidos); switch ($modelPizzaria->tipo_restaurante) { case TipoRestaurante::_TIPO_PIZZARIA_: $dataPizzas = new CArrayDataProvider('Pizza'); $dataPizzas->setData($model->pizzas); break; default: $dataCombinados = new CArrayDataProvider('CombinadoPedido'); $dataCombinados->setData($model->combinadoPedidos); break; } } $modelPedidosPreparando = Pedido::model()->preparando()->findAll(); $dataPedidosPreparando = new CArrayDataProvider($modelPedidosPreparando); $this->render('cozinha', array('model' => $model, 'dataPizzas' => $dataPizzas, 'dataCombinados' => $dataCombinados, 'dataProdutoPedido' => $dataProdutoPedido, 'modelPizzaria' => $modelPizzaria, 'dataPedidosPreparando' => $dataPedidosPreparando)); }