예제 #1
0
 /**
  * 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;
 }
예제 #2
0
 public function testGetSortedDataByInnerArrayField()
 {
     $simpleArray = array(array('innerArray' => array('sortField' => 1)), array('innerArray' => array('sortField' => 0)));
     $dataProvider = new CArrayDataProvider($simpleArray, array('sort' => array('attributes' => array('sort' => array('asc' => 'innerArray.sortField ASC', 'desc' => 'innerArray.sortField DESC', 'label' => 'Sorting', 'default' => 'asc')), 'defaultOrder' => array('sort' => CSort::SORT_ASC))));
     $sortedArray = array(array('innerArray' => array('sortField' => 0)), array('innerArray' => array('sortField' => 1)));
     $this->assertEquals($sortedArray, $dataProvider->getData());
 }
 public function testCaseInsensitiveSort()
 {
     // source data
     $unsortedProjects = array(array('title' => 'Zabbix', 'license' => 'GPL'), array('title' => 'munin', 'license' => 'GPL'), array('title' => 'Arch Linux', 'license' => 'GPL'), array('title' => 'Nagios', 'license' => 'GPL'), array('title' => 'zend framework', 'license' => 'BSD'), array('title' => 'Zope', 'license' => 'ZPL'), array('title' => 'active-record', 'license' => false), array('title' => 'ActiveState', 'license' => false), array('title' => 'mach', 'license' => false), array('title' => 'MySQL', 'license' => 'GPL'), array('title' => 'mssql', 'license' => 'EULA'), array('title' => 'Master-Master', 'license' => false), array('title' => 'Zend Engine', 'license' => false), array('title' => 'Mageia Linux', 'license' => 'GNU GPL'), array('title' => 'nginx', 'license' => 'BSD'), array('title' => 'Mozilla Firefox', 'license' => 'MPL'));
     // expected data
     $sortedProjects = array(array('title' => 'active-record', 'license' => false), array('title' => 'ActiveState', 'license' => false), array('title' => 'Arch Linux', 'license' => 'GPL'), array('title' => 'mach', 'license' => false), array('title' => 'Mageia Linux', 'license' => 'GNU GPL'), array('title' => 'Master-Master', 'license' => false), array('title' => 'Mozilla Firefox', 'license' => 'MPL'), array('title' => 'mssql', 'license' => 'EULA'), array('title' => 'munin', 'license' => 'GPL'), array('title' => 'MySQL', 'license' => 'GPL'), array('title' => 'Nagios', 'license' => 'GPL'), array('title' => 'nginx', 'license' => 'BSD'), array('title' => 'Zabbix', 'license' => 'GPL'), array('title' => 'Zend Engine', 'license' => false), array('title' => 'zend framework', 'license' => 'BSD'), array('title' => 'Zope', 'license' => 'ZPL'));
     $dataProvider = new CArrayDataProvider($unsortedProjects, array('sort' => array('attributes' => array('sort' => array('asc' => 'title ASC', 'desc' => 'title DESC', 'label' => 'Title', 'default' => 'desc')), 'defaultOrder' => array('sort' => CSort::SORT_ASC)), 'pagination' => array('pageSize' => 100500)));
     // we're explicitly setting case insensitive sort
     $dataProvider->caseSensitiveSort = false;
     $this->assertEquals($sortedProjects, $dataProvider->getData());
 }
예제 #4
0
 /**
  * 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));
 }
예제 #5
0
 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;
 }
예제 #6
0
 public function actionAttendedStudent()
 {
     $search_params = array();
     $model = new RsStudent();
     //#8227	141110
     //        $sql_status = $model->sql_status();
     //        $sql = $sql_status['sql'];
     //        if($_REQUEST) {
     //            if (isset($_REQUEST['s_status']) && $_REQUEST['s_status'] == 0){
     //                $search_params['s_status'] = $_REQUEST['s_status'];
     //                $sql = "select DISTINCT ON (rs_student.id) rs_student.*, 0 as status from rs_student inner join rs_test_result on rs_test_result.student_id = rs_student.id and pof = 1";
     //                if ((isset($_REQUEST['start_date']) && $_REQUEST['start_date']!='') && (isset($_REQUEST['end_date']) && $_REQUEST['end_date']!=''))
     //                {
     //                    $sql = $sql." and date BETWEEN '".$_REQUEST['start_date']."' AND '".$_REQUEST['end_date']."'";
     //                    $search_params['start_date'] = $_REQUEST['start_date'];
     //                    $search_params['end_date'] = $_REQUEST['end_date'];
     //                }else{
     //                    if((isset($_REQUEST['start_date']) && $_REQUEST['start_date']!='') && ($_REQUEST['end_date']==''))
     //                    {
     //                        $sql = $sql." and date >= '".$_REQUEST['start_date']."'";
     //                        $search_params['start_date'] = $_REQUEST['start_date'];
     //                    }
     //                    if(($_REQUEST['start_date']=='') && (isset($_REQUEST['end_date']) && $_REQUEST['end_date']))
     //                    {
     //                        $sql = $sql." and date <= '".$_REQUEST['end_date']."'";
     //                        $search_params['end_date'] = $_REQUEST['end_date'];
     //                    }
     //                }
     //            }
     //            if (isset($_REQUEST['s_status']) && $_REQUEST['s_status'] == 1){
     //                $search_params['s_status'] = $_REQUEST['s_status'];
     //                $sql = "select DISTINCT ON (id) * from ((".$sql_status['sql_eligible'].") union (".$sql_status['sql_not_pof'].")) as tbl order by id,status";
     //            }
     //            if (isset($_REQUEST['s_status']) && $_REQUEST['s_status'] == 2){
     //                $search_params['s_status'] = $_REQUEST['s_status'];
     //                if ((isset($_REQUEST['start_date']) && $_REQUEST['start_date']) && (isset($_REQUEST['end_date']) && $_REQUEST['end_date']))
     //                {
     //                    $sql = "select DISTINCT ON (id) * from (";
     //                    $sql .= "(".$sql_status['sql_pof']." and date BETWEEN '".$_REQUEST['start_date']."' AND '".$_REQUEST['end_date']."')";
     //                    $sql .= " union (".$sql_status['sql_eligible'].")".
     //                            ' union ('.$sql_status['sql_not_pof']." and date BETWEEN '".$_REQUEST['start_date']."' AND '".$_REQUEST['end_date']."')";
     //                    $sql .= ")as tbl order by id,status";
     //                    $search_params['start_date'] = $_REQUEST['start_date'];
     //                    $search_params['end_date'] = $_REQUEST['end_date'];
     //                }else
     //                {
     //                    if((isset($_REQUEST['start_date']) && $_REQUEST['start_date']!='') && ($_REQUEST['end_date']==''))
     //                    {
     //                        $sql = "select DISTINCT ON (id) * from (";
     //                        $sql .= "(".$sql_status['sql_pof']." and date >= '".$_REQUEST['start_date']."')";
     //                        $sql .= " union (".$sql_status['sql_eligible'].")".
     //                            " union (".$sql_status['sql_not_pof']." and date >= '".$_REQUEST['start_date']."')";
     //                        $sql .= ")as tbl order by id,status";
     //                        $search_params['start_date'] = $_REQUEST['start_date'];
     //                    }
     //                    if(($_REQUEST['start_date']=='') && (isset($_REQUEST['end_date']) && $_REQUEST['end_date']))
     //                    {
     //                        $sql = "select DISTINCT ON (id) * from (";
     //                        $sql .= "(".$sql_status['sql_pof']." and date <= '".$_REQUEST['end_date']."')";
     //                        $sql .= " union (".$sql_status['sql_eligible'].")".
     //                            " union (".$sql_status['sql_not_pof']." and date <= '".$_REQUEST['end_date']."')";
     //                        $sql .= ")as tbl order by id,status";
     //                        $search_params['end_date'] = $_REQUEST['end_date'];
     //                    }
     //                }
     //            }
     //        }
     $sql = '';
     if ($_REQUEST) {
         if (isset($_REQUEST['s_status'])) {
             $search_params['s_status'] = $_REQUEST['s_status'];
         }
         $search_params['start_date'] = '';
         $search_params['end_date'] = '';
         $Cond = '';
         if (isset($_REQUEST['start_date']) && $_REQUEST['start_date'] != '' && (isset($_REQUEST['end_date']) && $_REQUEST['end_date'] != '')) {
             $Cond = "date BETWEEN '" . $_REQUEST['start_date'] . "' AND '" . $_REQUEST['end_date'] . "'";
             $search_params['start_date'] = $_REQUEST['start_date'];
             $search_params['end_date'] = $_REQUEST['end_date'];
         } else {
             if (isset($_REQUEST['start_date']) && $_REQUEST['start_date'] != '' && $_REQUEST['end_date'] == '') {
                 $Cond = "date >= '" . $_REQUEST['start_date'] . "'";
                 $search_params['start_date'] = $_REQUEST['start_date'];
             }
             if (@$_REQUEST['start_date'] == '' && (isset($_REQUEST['end_date']) && $_REQUEST['end_date'])) {
                 $Cond = "date <= '" . $_REQUEST['end_date'] . "'";
                 $search_params['end_date'] = $_REQUEST['end_date'];
             }
         }
         $sql_status = $model->sql_status(array('date' => $Cond));
         $sql = $sql_status['sql'];
         if (isset($_REQUEST['s_status']) && $_REQUEST['s_status'] == 0) {
             $sql = $sql_status['sql_pof'];
         }
         if (isset($_REQUEST['s_status']) && $_REQUEST['s_status'] == 1) {
             $sql = "select DISTINCT ON (id) * from ((" . $sql_status['sql_eligible'] . ") union (" . $sql_status['sql_not_pof'] . ")) as tbl order by id,status_rank";
         }
         if (isset($_REQUEST['s_status']) && $_REQUEST['s_status'] == 2) {
             $sql = "select DISTINCT ON (id) * from (";
             $sql .= "(" . $sql_status['sql_pof'] . ")";
             $sql .= " union (" . $sql_status['sql_eligible'] . ")" . " union (" . $sql_status['sql_not_pof'] . ")";
             $sql .= ")as tbl order by id,status_rank";
         }
     } else {
         $sql_status = $model->sql_status();
         $sql = $sql_status['sql'];
     }
     $list_student = $model->data_query($sql);
     $dataProvider = new CArrayDataProvider($list_student, array('pagination' => array('pageSize' => 10)));
     $pages = $dataProvider->pagination;
     $list_student = $dataProvider->getData();
     $this->render('attendedStudent', array('list_student' => $list_student, "pages" => $pages, 'searchParams' => $search_params));
 }