2012-12-27 08:42:56 +00:00
< ? php
class IndexController extends Zend_Controller_Action
{
function preDispatch ()
{
$this -> view -> config = Zend_Registry :: get ( 'config' );
$this -> db = Zend_Registry :: get ( 'db' );
$this -> view -> theme = new Theme ();
2014-05-28 09:44:03 +00:00
$this -> submd = $this -> view -> config -> sub -> metadata ;
2014-06-12 03:28:48 +00:00
$this -> subnews = $this -> view -> config -> sub -> news ;
2014-06-13 10:13:29 +00:00
# $this->_helper->layout->setLayout('index');
2014-05-28 09:44:03 +00:00
//$this->view->main_nav_pageID = "index";
2012-12-27 08:42:56 +00:00
}
function indexAction ()
{
//统计数据
2015-01-30 15:20:12 +00:00
$sql = " select (select count(*) from users) as usernum,(select count(*) from { $this -> submd } ) as metanum,
( select count ( distinct d . uuid ) from dataorder d left join offlineapp f on d . offlineappid = f . id where d . uuid in ( select uuid from meteorologymd ) and d . ts_approved is not null and d . status in ( 0 , 5 ) ) as offlinenum ,
( select count ( * ) from datavisual where uuid in ( select uuid from { $this -> submd }) and status = 1 ) as visualnum " ;
2012-12-27 08:42:56 +00:00
$row = $this -> db -> fetchRow ( $sql );
$this -> view -> usernum = $row [ 'usernum' ];
$this -> view -> metanum = $row [ 'metanum' ];
$this -> view -> offlinenum = $row [ 'offlinenum' ];
2015-01-30 15:20:12 +00:00
$this -> view -> visualnum = $row [ 'visualnum' ];
2012-12-27 08:42:56 +00:00
/* $sql = 'select count(*) from metadata' ;
$row = $this -> db -> fetchRow ( $sql );
$this -> view -> metanum = $row [ 'count' ]; */
2014-05-28 09:44:03 +00:00
$sql = " select sum(filesize) as sum,datatype from { $this -> submd } group by datatype " ;
2012-12-27 08:42:56 +00:00
$rows = $this -> db -> fetchAll ( $sql );
foreach ( $rows as $row )
{
if ( $row [ 'datatype' ])
$this -> view -> offlinesize = $row [ 'sum' ];
else
$this -> view -> onlinesize = $row [ 'sum' ];
}
//下载最多数据(top 5)
2014-05-28 09:44:03 +00:00
$sql = " select uuid,title,id from { $this -> submd } where id in (select m.id from { $this -> submd } m left join dataorder d on m.uuid=d.uuid where m.datatype=0 group by m.id order by count(d.uuid) desc limit 5) " ;
2017-04-24 03:22:13 +00:00
//最新数据
$sql = " select id,uuid,title,ts_created from { $this -> submd } order by ts_created desc limit 5 " ;
$this -> db -> setFetchMode ( Zend_Db :: FETCH_BOTH );
2012-12-27 08:42:56 +00:00
$this -> view -> mdtop = $this -> db -> fetchAll ( $sql );
2014-05-28 09:44:03 +00:00
$sql = " select uuid,title,id from { $this -> submd } where id in (select m.id from { $this -> submd } m left join dataorder d on m.uuid=d.uuid where m.datatype=1 group by m.id order by count(d.uuid) desc limit 5) " ;
2012-12-27 08:42:56 +00:00
$this -> view -> offlinemdtop = $this -> db -> fetchAll ( $sql );
2014-05-28 09:44:03 +00:00
$sql = " select m.uuid,m.title,m.id,m.description from { $this -> submd } m left join thumbnail t on m.id=t.id where length(t.data)>2 order by random() " ;
2012-12-27 08:42:56 +00:00
$this -> view -> mdrandom = $this -> db -> fetchRow ( $sql );
//搜索
$this -> view -> addHelperPath ( 'helper' , 'Zend_View_Helper_' );
$searchform = new SearchForm ();
//$searchform->removeElement('submit');
$this -> view -> searchform = $searchform ;
$News = new Archive ( $this -> db );
$time = date ( " Y-m-d H:i:s " , time ());
2014-06-12 03:25:06 +00:00
$sql = " SELECT * FROM archive WHERE is_pub=true and sub=' $this->subnews ' AND ts_published<' $time ' AND image!=''
and id in ( select ar_catalog . aid from ar_category left join ar_catalog on ar_category . id = ar_catalog . cid where ar_category . code = 'featured' ) order by ts_published desc LIMIT 5 " ;
2012-12-27 08:42:56 +00:00
$sth = $this -> db -> query ( $sql );
$rows = $sth -> fetchAll ( PDO :: FETCH_BOTH );
foreach ( $rows as $k => $v )
{
$url = $News -> getArchiveUrlByCid ( $v [ 'id' ]);
$rows [ $k ][ 'url' ] = $url [ 'archive_url' ];
}
$this -> view -> news = $rows ;
2012-12-31 03:48:10 +00:00
2013-05-07 01:10:44 +00:00
//$time = date("Y-m-d H:i:s",time());
2014-06-12 03:25:06 +00:00
$sql = " SELECT * FROM archive WHERE is_pub=true and sub=' $this->subnews ' AND ts_published<now()
and id in ( select ar_catalog . aid from ar_catalog left join ar_category on ar_catalog . cid = ar_category . id where ar_category . ptype = 'news' )
2014-06-16 02:15:32 +00:00
order by ts_published desc LIMIT 5 " ;
2012-12-31 03:48:10 +00:00
$sth = $this -> db -> query ( $sql );
$rows = $sth -> fetchAll ( PDO :: FETCH_BOTH );
foreach ( $rows as $k => $v )
{
$url = $News -> getArchiveUrlByCid ( $v [ 'id' ]);
$rows [ $k ][ 'url' ] = $url [ 'archive_url' ];
$rows [ $k ][ 'type_title' ] = $url [ 'type_title' ];
$rows [ $k ][ 'type_url' ] = $url [ 'type_url' ];
}
2014-06-12 03:41:38 +00:00
$this -> view -> list_news = $rows ;
2014-06-12 03:43:20 +00:00
$sql = " select * from $this->submd where uuid in (select uuid from datavisual) order by ts_created desc limit 5 " ;
2014-06-12 03:41:38 +00:00
$sth = $this -> db -> query ( $sql );
$this -> view -> visualdata = $sth -> fetchAll ( PDO :: FETCH_BOTH );
2012-12-27 08:42:56 +00:00
}
}