public function configure() { unset($this['dm_user_id'], $this['created_at'], $this['updated_at'], $this['is_active']); $this->getObject()->setDmUserId(sfcontext::getInstance()->getUser()->getAttribute('user_id', ' ', 'dmSecurityUser')); /* $years = range(1900, date('Y')); $today = array( 'year' => date('Y'), 'month' => date('n'), 'day' => date('j') ); $this->widgetSchema['fecha_antes'] = new sfWidgetFormDate(array(/*'format' => '%year%', */ /*'years' => array_combine($years, $years), 'default' => $today)); /*$this->widgetSchema['fecha_despues'] = new sfWidgetFormDate(array(/*'format' => '%year%', */ /*'years' => array_combine($years, $years), 'default' => $today)); */ $this->widgetSchema['fecha_antes'] = new sfWidgetFormChoice(array('choices' => array('' => '', 1900 => 1900, 1950 => 1950, 1960 => 1960, 1970 => 1970, 1980 => 1980, 1990 => 1990, 2000 => 2000, 2001 => 2001, 2002 => 2002, 2003 => 2003, 2004 => 2004, 2005 => 2005, 2006 => 2006, 2007 => 2007, 2008 => 2008, 2009 => 2009, 2010 => 2010, 2011 => 2011, 'Actualidad' => 'Actualidad'))); $this->widgetSchema['fecha_despues'] = new sfWidgetFormChoice(array('choices' => array('' => '', 1900 => 1900, 1950 => 1950, 1960 => 1960, 1970 => 1970, 1980 => 1980, 1990 => 1990, 2000 => 2000, 2001 => 2001, 2002 => 2002, 2003 => 2003, 2004 => 2004, 2005 => 2005, 2006 => 2006, 2007 => 2007, 2008 => 2008, 2009 => 2009, 2010 => 2010, 2011 => 2011, 'Actualidad' => 'Actualidad'))); $this->widgetSchema->setLabels(array('fecha_antes' => 'Publicado entre', 'fecha_despues' => 'Y')); $this->setValidators(array('titulo' => new sfValidatorString(array('min_length' => 10), array('required' => 'Debe escribir un titulo sugerente', 'min_length' => 'El titulo debe tener al menos 10 caracteres')), 'mensaje' => new sfValidatorString(array('min_length' => 20), array('required' => 'Por favor describa su busqueda', 'min_length' => 'Por favor describa mejor su busqueda(al menos 20 caracteres) ')), 'tematica' => new sfValidatorString(), 'fecha_antes' => new sfValidatorString(array('required' => false)), 'fecha_despues' => new sfValidatorString(array('required' => false)), 'id' => new sfValidatorDoctrineChoice(array('model' => 'Busqueda', 'column' => 'id', 'required' => false)))); $this->validatorSchema->setPostValidator(new sfValidatorSchemaCompare('fecha_antes', sfValidatorSchemaCompare::LESS_THAN_EQUAL, 'fecha_despues', array(), array('invalid' => 'La primera fecha ("%left_field%") debe ser menor que la ultima ("%right_field%")'))); }
/** *$curPage 第n页 *$totNum 总数量 *$href 页面连接 *$pageSize 页面数量 *$show 默认为3,因为当页数大于等于3个的时候,连接能够正常显示,如果小于3个,则要特殊处理 *$suffix 判断是否为绝对连接,默认不是为false; * 显示格式 举例 上一页 1 2 3 4 5 6 下一页 ** */ function __construct($curPage, $totNum, $href, $pageSize = 20, $show = 3, $suffix = false) { sfcontext::getInstance()->getConfiguration()->loadHelpers('Url'); $totPage = ceil($totNum / $pageSize); //上取整,求得总页数 $prePage = $curPage - 1; //上一页 $nextPage = $curPage + 1; //下一页 $start = $curPage > $show ? $curPage - $show : 1; $end = $totPage > $show && $curPage + $show < $totPage ? $curPage + $show : $totPage; $topPage = $pageStr = ''; if ($suffix) { $curPage > 1 && ($pageStr .= '<a href="' . $href . $prePage . '.html" class="dw">上一页</a> '); } else { $curPage > 1 && ($pageStr .= '<a href="' . url_for($href . $prePage) . '" class="dw">上一页</a> '); } for ($i = $start; $i <= $end; $i++) { $active = ''; if ($i == $curPage) { $active = ' class="hover"'; } if ($suffix) { $pageStr .= '<a href="' . $href . $i . '.html"' . $active . '>' . $i . '</a> '; } else { $pageStr .= '<a href="' . url_for($href . $i) . '"' . $active . '>' . $i . '</a> '; } } if ($suffix) { $curPage < $totPage && ($pageStr .= '<a href="' . $href . $nextPage . '.html" class="dw">下一页</a> '); } else { $curPage < $totPage && ($pageStr .= '<a href="' . url_for($href . $nextPage) . '" class="dw">下一页</a> '); } $topPage .= "<span class='f_l m_r_10'>" . $curPage . '/' . $totPage . '</span>'; $curPage > 1 && ($topPage .= '<a href="' . url_for($href . $prePage) . '" class="dw">上一页</a> '); $curPage == 1 && ($topPage .= '<a href="javascript:return false;" class="dw">上一页</a> '); $curPage < $totPage && ($topPage .= '<a href="' . url_for($href . $nextPage) . '" class="dw">下一页</a> '); $curPage == $totPage && ($topPage .= '<a href="javascript:return false;" class="dw">下一页</a> '); $this->topPage = $topPage; $totPage < 2 && ($pageStr = ''); $this->totPage = $totPage; $this->pageStr = $pageStr; }
public static function errorHandler($errno, $errstr, $errfile, $errline) { $dt = date(skuleadminConst::TIMESTAMP_FORMAT); $msg = $dt . " - [error " . $errno . " at line " . $errline . " in " . $errfile . "] " . $errstr; switch ($errno) { case E_WARNING: self::sendEmailNotice("SkuleCourses PHP Error", $msg); break; case E_USER_ERROR: // cascade down to E_ERROR // cascade down to E_ERROR case E_ERROR: self::sendEmailNotice("SkuleCourses PHP Error", $msg); sfcontext::getInstance()->getActionStack()->getFirstEntry()->getActionInstance()->forward("error", "error500"); break; } }
private static function setPagerToCache($filter, $id, $pager) { $cache = sfcontext::getInstance()->getViewCacheManager()->getCache(); if ($cache != null) { $key = md5("pager_" . $id . "_" . $filter['type'] . "-" . $filter['partido'] . "-" . $filter['institucion'] . "-" . $filter['culture'] . "-" . $filter['order'] . ""); $cache->set($key, serialize($pager)); } }
public function configure() { unset($this['dm_user_id'], $this['created_at'], $this['updated_at'], $this['is_active']); $this->getObject()->setDmUserId(sfcontext::getInstance()->getUser()->getAttribute('user_id', ' ', 'dmSecurityUser')); $this->setValidators(array('titulo' => new sfValidatorString(array('min_length' => 10), array('required' => 'Debe escribir un titulo sugerente', 'min_length' => 'El titulo debe tener al menos 10 caracteres')), 'mensaje' => new sfValidatorString(array('min_length' => 20), array('required' => 'Por favor describa su pregunta', 'min_length' => 'Por favor describa mejor su pregunta(al menos 20 caracteres) ')), 'id' => new sfValidatorDoctrineChoice(array('model' => 'busqueda', 'column' => 'id', 'required' => false)))); }
/** * clear the properties of the stored schema * * @return integer * * @param \Connection $con [optional] * */ public function save($con = null) { $arr = explode("/", self::getUri()); $id = array_pop($arr); if (is_numeric($id)) { $schema = self::getSchema(); if ($schema->getLastUriId() != $id) { $schema->setLastUriId($id); $schema->save(); } } $affectedRows = parent::save($con); if (sfcontext::hasInstance()) { $schema = sfContext::getInstance()->getUser()->getCurrentSchema(); if ($schema) { /** @var Schema * */ $schema->clearProperties(); $schema->getSchemaPropertys(); } } return $affectedRows; }
<?php if ($oAppCommon->oForm->getValidator($ssFieldName)->getOption('required')) { ?> <b>*</b> <?php } echo $oAppCommon->oForm[$ssFieldName]->renderLabel(); ?> </td> <td width="85%" align="left" id="tbRowCell<?php echo $snTabindex; ?> 2" > <div id="company_state" class="fleft"> <?php $ssPara = sfcontext::getInstance()->getRequest()->getParameter($ssFormName); echo $oAppCommon->oForm['state']->render(array('onchange' => 'checkOption(this.options[this.selectedIndex].value,"company_state_text")')); ?> <?php if ($ssPara['state'] == '-1' && $oAppCommon->oForm->getObject()->isNew()) { ?> <div id='company_state_text' style="display:block;width:200px;"> <?php echo input_tag($ssFormName . '[otherState]', $ssPara['otherState']); ?> </div> <?php } ?> <?php if (!is_numeric($ssPostState) && !$oAppCommon->oForm->getObject()->isNew()) {
function rankingParams($type) { $ret = ''; $filter = sfcontext::getInstance()->getUser()->getAttribute("filter_{$type}", false); if ($filter['partido'] && $filter['partido'] != '0' && $filter['partido'] != 'all') { $ret .= '?partido=' . $filter['partido']; } if ($filter['institucion'] && $filter['institucion'] != '0' && $filter['institucion'] != 'all') { if (!$ret && $type == Politico::NUM_ENTITY) { $ret = '?partido=all'; } $ret .= ($ret ? '&' : '?') . 'institucion=' . $filter['institucion']; } if ($filter['order'] != '' && $filter['order'] != 'pd') { $ret .= ($ret ? '&' : '?') . 'o=' . $filter['order']; } return $ret; }
public function getResults($geoName = false, $sorted = true) { $aKey = "Convocatoria_" . $this->getId() . "-{$geoName}-{$sorted}"; $cache = sfcontext::getInstance()->getViewCacheManager() ? sfcontext::getInstance()->getViewCacheManager()->getCache() : false; if ($cache) { $key = md5($aKey); $data = unserialize($cache->get($key)); } else { $data = false; } if (!$data) { $res = array(); $c = new Criteria(); $c->addJoin(ListaPeer::PARTIDO_ID, PartidoPeer::ID); $c->add(ListaPeer::CONVOCATORIA_ID, $this->getId()); $c->setDistinct(); $res['partidos'] = PartidoPeer::doSelect($c); // Circus $c = new Criteria(); $c->addJoin(ListaPeer::CIRCUNSCRIPCION_ID, CircunscripcionPeer::ID); $c->addJoin(CircunscripcionPeer::GEO_ID, GeoPeer::ID); $c->add(ListaPeer::CONVOCATORIA_ID, $this->getId()); $c->addAscendingOrderByColumn(GeoPeer::NOMBRE); $c->setDistinct(); //$this->geos = GeoPeer::doSelect( $c ); $res['circus'] = CircunscripcionPeer::doSelect($c); $instituciones = $this->getEleccion()->getEleccionInstitucions(); //$this->institucionName = $instituciones[0]->getInstitucion(); $res['institucionName'] = $instituciones[0]->getInstitucion(); // Minimo de votos necesario para obtener escaño $listas = $this->getListas(); if ($geoName) { $c = new Criteria(); $c->addJoin(ListaPeer::CIRCUNSCRIPCION_ID, CircunscripcionPeer::ID); $c->addJoin(CircunscripcionPeer::GEO_ID, GeoPeer::ID); $c->add(ListaPeer::CONVOCATORIA_ID, $this->getId()); $c->add(GeoPeer::NOMBRE, $geoName); //$this->geos = GeoPeer::doSelect( $c ); $circu = CircunscripcionPeer::doSelectOne($c); $numEscanyos = $circu->getEscanyos(); } else { $numEscanyos = 0; $circuCounted = array(); foreach ($listas as $lista) { if (!in_array($lista->getCircunscripcion()->getId(), $circuCounted)) { $circuCounted[] = $lista->getCircunscripcion()->getId(); $numEscanyos += $lista->getCircunscripcion()->getEscanyos(); } } } $listaElectoral = ListaElectoral::getInstance($this->getId(), false, $geoName); $politicos = $listaElectoral->getPoliticos(); $idx = 0; //$this->minSumu = 0; $res['minSumu'] = 0; //$this->minSumd = 0; $res['minSumd'] = 0; $res['lastDate'] = null; $res['apellidos'] = ''; $res['nombre'] = ''; foreach ($politicos as $politico) { $idx++; if ($idx == $numEscanyos + 1) { $res['minSumu'] = $politico->getSumu(); $res['minSumd'] = $politico->getSumd(); $res['lastDate'] = $politico->getLastDate(); $res['apellidos'] = $politico->getApellidos(); $res['nombre'] = $politico->getNombre(); } } // Ordenar por escaños if ($sorted) { $idx = 0; $res['totalEscanyos'] = 0; foreach ($res['partidos'] as $partido) { $listaElectoral = new ListaElectoral($this->getId(), $partido->getId(), $geoName); $escanyos = $listaElectoral->getEscanyos($res['minSumu'], $res['minSumd'], $res['lastDate'], $res['apellidos']); $res['totalEscanyos'] += $escanyos; for ($j = 0; $j < $idx; $j++) { $listaElectoral2 = ListaElectoral::getInstance($this->getId(), $res['partidos'][$j]->getId(), $geoName); if ($listaElectoral2->getEscanyos($res['minSumu'], $res['minSumd'], $res['lastDate'], $res['apellidos']) < $escanyos) { $partidoTmp = clone $res['partidos'][$idx]; $res['partidos'][$idx] = $res['partidos'][$j]; $res['partidos'][$j] = $partidoTmp; } } $idx++; } } $data = $res; if ($cache) { $n = rand(0, 100); $cache->set($key, serialize($data ? $data : "zero"), 3600 * $n / 100); } } return $data == "zero" ? 0 : $data; }
public static function countUsers() { $cache = sfcontext::getInstance()->getViewCacheManager() ? sfcontext::getInstance()->getViewCacheManager()->getCache() : false; if ($cache) { $key = md5("users_counter"); $data = unserialize($cache->get($key)); } else { $data = false; } if (!$data) { //$user = sfContext::getInstance()->getUser(); //$culture = $user->getCulture(); $cuser = new Criteria(); $cuser->add(sfGuardUserPeer::IS_ACTIVE, 1); $data = sfGuardUserPeer::doCount($cuser); if ($cache) { $cache->set($key, serialize($data), 360); } } return $data; }
public function getEscanyos($minSumu, $minSumd, $lastDate, $apellidos) { $cache = sfcontext::getInstance()->getViewCacheManager() ? sfcontext::getInstance()->getViewCacheManager()->getCache() : false; if ($cache) { $aKey = "Escanyos_" . $this->convocatoriaId . "-" . $this->partidoId . "-" . $this->geoName . "-{$minSumu}-{$minSumd}-{$lastDate}-{$apellidos}"; $key = md5($aKey); $data = unserialize($cache->get($key)); } else { $data = false; } if (!$data) { //echo "($aKey-$key)"; if ($this->geoName) { if (!$this->numEscanyos) { $this->numEscanyos = 0; foreach ($this->politicos as $politico) { if ($politico->getSumu() > $minSumu || $politico->getSumu() == $minSumu && $politico->getSumd() < $minSumd || $politico->getSumu() == $minSumu && $politico->getSumd() == $minSumd && $politico->getLastDate() > $lastDate && $minSumu != 0 || $politico->getSumu() == $minSumu && $politico->getSumd() == $minSumd && $politico->getLastDate() == $lastDate && $politico->getApellidos() > $apellidos && $minSumu != 0) { //echo "(".$politico->getApellidos().",".$politico->getSumu().",".$politico->getSumd().",".$politico->getLastDate().")"; $this->numEscanyos++; } } } } else { // Circus $c = new Criteria(); $c->addJoin(ListaPeer::CIRCUNSCRIPCION_ID, CircunscripcionPeer::ID); $c->addJoin(CircunscripcionPeer::GEO_ID, GeoPeer::ID); $c->add(ListaPeer::CONVOCATORIA_ID, $this->convocatoriaId); $c->addAscendingOrderByColumn(GeoPeer::NOMBRE); $c->setDistinct(); $circus = CircunscripcionPeer::doSelect($c); $this->numEscanyos = 0; foreach ($circus as $circu) { $listaElectoral = new ListaElectoral($this->convocatoriaId, $this->partidoId, $circu->getGeo()->getNombre()); $res = $this->convocatoria->getResults($circu->getGeo()->getNombre(), false); $sum = $listaElectoral->getEscanyos($res['minSumu'], $res['minSumd'], $res['lastDate'], $res['apellidos']); $this->numEscanyos += $sum; } } $data = $this->numEscanyos; if ($cache) { $cache->set($key, serialize($data ? $data : "zero"), 3600); } } return $data == "zero" ? 0 : $data; }