db = \Zend_Registry::get('db'); }else{ $this->db = $db; } $this->config = \Zend_Registry::get('config'); //$Listener = new Listener(); //@$this->events()->attachAggregate($Listener); $this->table = new \Helpers\Table(); } public function events(\Zend_EventManager_EventCollection $events = NULL) { if ($events !== NULL) { $this->events = $events; } elseif ($this->events === NULL) { $this->events = new \Zend_EventManager_EventManager(__CLASS__); } return $this->events; } //读取数据 public function preRead($mode = "all") { if($mode == "all") { $sql = "SELECT * FROM {$this->table->reference} where length(ris)<10 or ris is null ORDER BY year DESC,title ASC,id ASC"; $rs = $this->db->query($sql); return $rs->fetchAll(); } }//preRead //将数据组成RIS数组格式 public function processArrayDataToRisData($arrayData,$risPrior = true,$mixAuthor = true,$mixTags = true) { if(!is_array($arrayData)) { return false; } $risData = array(); if($risPrior === true) { $risReader = new RISReader(); } $this->ris = new Ris(); $this->attr = $this->ris->attr; $this->attr_flip = array_flip($this->ris->attr); unset($this->ris); $this->reference = new Reference(); foreach($arrayData as $k=>$v) { $risData[$k] = $this->transformToRis($v); if($mixAuthor === true || $mixTags === true) { if($mixAuthor === true) { $author = $this->reference->getAuthorByReference($v['id'],true); if(is_array($author) && count($author)>0) { $risData[$k] = array_merge($risData[$k],array("AU"=>$author)); } unset($author); }//mixAuthor if($mixTags === true) { $tags = $this->reference->getTagsByReference($v['id'],true); if(is_array($tags) && count($tags) > 0) { $risData[$k] = array_merge($risData[$k],array("KW"=>$tags)); } unset($tags); } } if(!is_array($risData[$k]) || count($risData[$k]) < 1) { unset($risData[$k]); } unset($arrayData[$k]); } return $risData; }//processArrayDataToRisData //单条记录的整编 public function transformToRis($record) { $arr = array(); foreach($record as $k=>$v) { if(!empty($v)) { if(isset($this->attr_flip[$k])) { //echo $k ."-". $this->attr_flip[$k] . '-' .$v; //echo "
"; $arr[$this->attr_flip[$k]] = array(0=>$v); } } } //echo "
"; return $arr; }//transformToRis //输出成文件 public function output($risData) { $risWirte = new RISWriter(); return @$risWirte->writeRecords($risData); }//output }