Пример #1
0
 public function listItems($arrParams = null, $Option = null)
 {
     $db = Zend_Registry::get('connectDb');
     //$db = Zend_Db::factory($adapter,$config);
     $paginator = $arrParams['paginator'];
     $ssFilter = $arrParams['ssFilter'];
     if ($Option['task'] == 'admin-list') {
         $select = $db->select()->from('da_news AS ns', array('news_id', 'title_news', 'status', 'img_news_sml', 'img_news_big', 'news_hot', 'hits', 'created', 'created_by', 'order'))->joinLeft('da_users AS dau', 'dau.id = ns.created_by', array('user_name as author'))->joinLeft('da_category AS dac', 'dac.category_id = ns.news_type', array('category_name'));
         if (!empty($ssFilter['col']) && !empty($ssFilter['order'])) {
             $select->order($ssFilter['col'] . ' ' . $ssFilter['order']);
         }
         if ($paginator['itemCountPerPage'] > 0) {
             $page = $paginator['currentPage'];
             $rowCount = $paginator['itemCountPerPage'];
             $select->limitPage($page, $rowCount);
         }
         if (!empty($ssFilter['keywords'])) {
             $keywords = '%' . $ssFilter['keywords'] . '%';
             $select->where('ns.title_news LIKE ?', $keywords, STRING);
         }
         if ($ssFilter['cat_id'] > 0) {
             $select2 = $db->select()->from('da_category AS dac', array('dac.category_id', 'dac.category_name', 'dac.status', 'dac.PARENTS', 'dac.order', 'dac.created_by'));
             $result2 = $db->fetchAll($select2);
             $system = new Zendda_System_Recursive($result2);
             $result2 = $system->buildArray($ssFilter['cat_id']);
             if (count($result2) > 1) {
                 array_unshift($result2, array('category_id' => $ssFilter['cat_id']));
                 $ids = '(';
                 $i = 0;
                 foreach ($result2 as $key => $value) {
                     if ($i == count($result2) - 1) {
                         $ids .= $value['category_id'] . ')';
                     } else {
                         $ids .= $value['category_id'] . ',';
                     }
                     $i++;
                 }
                 $select->where('ns.news_type IN ' . $ids);
             } else {
                 $select->where('ns.news_type = ? ', $ssFilter['cat_id'], INTEGER);
             }
         }
         $result = $db->fetchAll($select);
     }
     return $result;
 }
Пример #2
0
 public function getListItem($arrParams = null, $options = null)
 {
     $db = Zend_Registry::get('connectDb');
     $paginator = $arrParams['paginator'];
     $ssFilter = $arrParams['ssFilter'];
     if ($options['task'] == 'list-category') {
         $select = $db->select()->from('da_news AS ne', array('news_id', 'title_news', 'summary_news', 'img_news_sml', 'created'))->joinLeft('da_category AS cat', 'cat.category_id = ne.news_type', array('category_name'))->where('ne.status = 1');
         if ($paginator['itemCountPerPage'] > 0) {
             $page = $paginator['currentPage'];
             $rowCount = $paginator['itemCountPerPage'];
             $select->limitPage($page, $rowCount);
         }
         if ($ssFilter['cat_id'] != 2) {
             $select->order('ne.created DESC');
         }
         if ($ssFilter['cat_id'] > 0) {
             $select2 = $db->select()->from('da_category AS cat', array('cat.category_id', 'cat.category_name', 'cat.parents', 'cat.status', 'cat.order', 'cat.created_BY'))->where('cat.status = 1');
             $result2 = $db->fetchAll($select2);
             $system = new Zendda_System_Recursive($result2);
             $result2 = $system->buildArray($ssFilter['cat_id']);
             if (count($result2) > 1) {
                 array_unshift($result2, array('category_id' => $ssFilter['cat_id']));
                 $ids = '(';
                 $i = 0;
                 foreach ($result2 as $key => $value) {
                     if ($i == count($result2) - 1) {
                         $ids .= $value['category_id'] . ')';
                     } else {
                         $ids .= $value['category_id'] . ',';
                     }
                     $i++;
                 }
                 $this->_ids = $ids;
                 $select->where('ne.news_type IN ' . $ids);
             } else {
                 $this->_ids = '(' . $ssFilter['cat_id'] . ')';
                 $select->where('ne.news_type = ? ', $ssFilter['cat_id']);
             }
         }
         $result = $db->fetchAll($select);
     }
     return $result;
 }
Пример #3
0
 public function deleteItem($arrParams = null, $Option = null)
 {
     if ($Option['task'] == 'admin-delete') {
         $db = Zend_Registry::get('connectDb');
         $id = $arrParams['id'];
         $select = $db->select()->from('da_category AS pc', array('pc.category_id', 'pc.category_name', 'pc.status', 'pc.parents', 'pc.order', 'pc.created_by'));
         $result = $db->fetchAll($select);
         $system = new Zendda_System_Recursive($result);
         $result = $system->buildArray($id);
         array_unshift($result, array('id' => $id));
         foreach ($result as $key => $value) {
             $where = 'category_id = (' . $value['id'] . ')';
             $this->delete($where);
         }
     }
     if ($Option['task'] == 'admin-multi-delete') {
         $cid = $arrParams['cid'];
         if (count($cid) > 0) {
             $db = Zend_Registry::get('connectDb');
             $id = $arrParams['id'];
             $select = $db->select()->from('da_category AS pc', array('category_id', 'category_name', 'status', 'parents', 'order', 'created_by'));
             $result = $db->fetchAll($select);
             $newArray = array();
             foreach ($cid as $key => $val) {
                 $id = $val;
                 $newArray[] = array('id' => $id);
                 $system = new Zendda_System_Recursive($result);
                 $tmp = $system->buildArray($id);
                 foreach ($tmp as $keyTmp => $valTmp) {
                     $newArray[] = $valTmp;
                 }
             }
             if (count($newArray) > 0) {
                 foreach ($newArray as $keyNew => $valNew) {
                     $where = ' category_id = ' . $valNew['id'];
                     $this->delete($where);
                 }
             }
         }
     }
 }