public function create_image_records($this_id) { $media_model = new MediaModel(); $media_model->where(array('event_id' => $this_id))->delete(); $match_all = array(); preg_match_all('/thumb600_([^\\"]+)\\"/i', $_POST['description'], $match_all); foreach ($match_all[1] as $url) { $media_model->add(array('url' => $url, 'event_id' => $this_id, 'type' => 'image')); } }
/** * 媒体页面 首页 */ function index() { import('ORG.Util.Page'); $medias = new MediaModel(); //判断是否有搜索 $keyword = trim($_POST['keyword']); /* $ftype = trim($_POST['ftype']); if(!empty($keyword) && !empty($ftype)){ //如果查询的是发布字段(因为发布字段和排序都是以整数来排列的) if ($ftype == 'published' || $ftype == 'order' || $ftype == 'id'){ $where[$ftype] = array('eq',$keyword); }else{ $where[$ftype] = array('like','%'.$keyword.'%'); } } */ if (is_numeric($keyword)) { $where['id'] = array('eq', $keyword); } else { $where['description'] = array('like', '%' . $keyword . '%'); } //切换状态 $change_pub = trim($_POST['change_published']); if ($change_pub) { $where['published'] = array('eq', $change_pub); } //传值在前台判断 $this->assign('change_pub', $change_pub); //得到分页需要的总文章数 $count = $medias->where($where)->count(); $page = new Page($count, C('PAGESIZE')); $show = $page->show(); $this->assign("show", $show); //得到文章数据 $list = $medias->where($where)->order('id DESC')->limit($page->firstRow . ',' . $page->listRows)->select(); $this->assign('medias', $list); $this->display(); }
public function events_by_event($id, $type = 'ngo', $count = 6, $has_image = true) { $geo_weight = 10; $category_weight = 200; $event_model = new EventsModel(); $media_model = new MediaModel(); $event = $event_model->find($id); if (!$event) { return false; } $my_longitude = $event['longitude']; $my_latitude = $event['latitude']; $sql = "select id,name,longitude,latitude,description, {$geo_weight}*(abs(longitude-{$my_longitude})+abs(latitude-{$my_latitude})) score from events where type='{$type}' and longitude is not null order by score limit {$count}"; $result = $event_model->query($sql); if ($has_image) { for ($i = 0; $i < count($result); $i++) { $result[$i]['image'] = $media_model->where(array('event_id' => $result[$i]['id'], 'type' => image))->find(); } } return $result; }