Exemplo n.º 1
0
 /**
  * 获得资源的标签
  *
  * $res_id single id or an array of id
  * $res_type
  * 
  * return Array multi - res_id=>tags; single - tag
  *
  */
 public function &tagsByRes($res_id, $res_type)
 {
     $resTable = $this->resTable($res_type);
     if (is_array($res_id)) {
         $sql = 'select r.res_id,t.id,t.title';
         $sql .= " from xxt_tag t,{$resTable} r";
         $sql .= ' where t.id=r.tag_id';
         $sql .= " and r.res_id in (" . implode(',', $res_id) . ")";
         $sql .= ' order by r.res_id';
         if ($rels = parent::query_objs($sql)) {
             foreach ($rels as $rel) {
                 $result[$rel->res_id][] = array('id' => $rel->id, 'title' => $rel->title);
             }
         }
     } else {
         $sql = 'select t.id,t.title';
         $sql .= " from xxt_tag t,{$resTable} r";
         $sql .= ' where t.id=r.tag_id';
         $sql .= " and r.res_id='{$res_id}'";
         $result = parent::query_objs($sql);
     }
     !isset($result) && ($result = array());
     return $result;
 }