function correctAction(){ $semester_id = $this->_getParam("semester_id"); $day = $this->_getParam("day"); //todo... $where = array(); $where['lx_lessons.semester_id = ?'] = array("type"=>1,"val"=>$semester_id); $where['lx_lessons.lvalue = ?'] = array("type"=>1,"val"=>'1'); $where['lx_lessons.day = ?'] = array("type"=>1,"val"=>$day); $where['lx_lessons.user_id > ?'] = array("type"=>1,"val"=>0); $aLessons = $this->dao_lessons->getlessons($where,array('day desc','lorder desc','user_id desc'), false, false, false, array("id","day","lorder","lvalue","user_id","course_id")); $a = $c = $d = array(); foreach($aLessons as $key=>$val) { $a[$val['user_id']][$val['id']] = $val['lorder']; } foreach($a as $k=>$v) { $total = count($v); if($total > 1) { if($total !== count(array_unique($v))) { foreach ($v as $key2 => $value2) { $c[$k][$value2][] = $key2; } } } } foreach ($c as $key3 => $value3) { foreach ($value3 as $key4 => $value4) { if(count($value4) > 1) { $d[$key4] = $value4; } } } $total = $this->updateCourse($d); echo $total; } function updateCourse($data) { $total = 0; foreach ($data as $k => $v) { $count = count($v); foreach ($v as $k1 => $v1) { $dataLessons['id'] = $v1; $dataLessons['lvalue'] = 1/$count; $res = $this->dao_lessons->updateLessons($dataLessons); if($res){ $total ++; } } } return $total; }
function correct2Action(){ $semester_id = $this->_getParam("semester_id"); $day = $this->_getParam("day"); //todo... $where = array(); $where['lx_lessons.semester_id = ?'] = array("type"=>1,"val"=>$semester_id); //$where['lx_lessons.lvalue = ?'] = array("type"=>1,"val"=>'1'); $where['lx_lessons.day = ?'] = array("type"=>1,"val"=>$day); $where['lx_lessons.user_id > ?'] = array("type"=>1,"val"=>0); $aLessons = $this->dao_lessons->getlessons($where,false, false, false, false, array("COUNT(id) as num","day","lorder","user_id"),false,array('day','lorder','user_id')); foreach($aLessons as $key=>$val) { if($val['num'] == 1) { unset($aLessons[$key]); } } print_r($aLessons);exit;