public function saveUsuarisSitesList($con = null) { if (!$this->isValid()) { throw $this->getErrorSchema(); } if (!isset($this->widgetSchema['usuaris_sites_list'])) { // somebody has unset this widget return; } if (null === $con) { $con = $this->getConnection(); } $c = new Criteria(); $c->add(UsuarisSitesPeer::SITE_ID, $this->object->getPrimaryKey()); UsuarisSitesPeer::doDelete($c, $con); $values = $this->getValue('usuaris_sites_list'); if (is_array($values)) { foreach ($values as $value) { $obj = new UsuarisSites(); $obj->setSiteId($this->object->getPrimaryKey()); $obj->setUsuariId($value); $obj->save(); } } }
public function setup() { $Users = UsuarisPeer::selectAllUsers(); $idU = $this->getObject()->getUsuariid(); $this->setWidgets(array('DNI' => new sfWidgetFormInput(array(), array()), 'usuari_id' => new sfWidgetFormChoice(array('choices' => $Users), array()), 'site_id' => new sfWidgetFormChoice(array('choices' => UsuarisSitesPeer::getSites($idU, $this->getOption('NEW')))), 'nivell_id' => new sfWidgetFormChoice(array('choices' => NivellsPeer::getSelect())), 'actiu' => new sfWidgetFormInputHidden())); $this->setValidators(array('DNI' => new sfValidatorString(array('required' => true), array()), 'usuari_id' => new sfValidatorPropelChoice(array('model' => 'Usuaris', 'column' => 'UsuariID', 'required' => false)), 'site_id' => new sfValidatorPropelChoice(array('model' => 'Sites', 'column' => 'site_id', 'required' => false)), 'nivell_id' => new sfValidatorPropelChoice(array('model' => 'Nivells', 'column' => 'idNivells')), 'actiu' => new sfValidatorInteger(array('min' => -128, 'max' => 127)))); $this->widgetSchema->setNameFormat('usuaris_sites[%s]'); $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema); }
/** * Inicialitzem un formulari de UsuariSite * @param $idU Usuari ID * @param $idS Site ID * @param $new Es mostra "Mostra l'opció NEW SITE al formulari" * @return UsuarisSitesForm() * */ public static function initialize($idU, $idS, $new = false) { $OO = UsuarisSitesPeer::retrieveByPK($idU, $idS); if (!$OO instanceof UsuarisSites) { $OO = new UsuarisSites(); $OO->setUsuariId($idU); $OO->setSiteId($idS); $OO->setNivellId(NivellsPeer::REGISTRAT); $OO->setActiu(true); } return new UsuarisSitesForm($OO, array('IDS' => $idS, 'NEW' => $new)); }
public function save($conn = null) { //Les dades de l'usuari que es mantenen són sempre les noves. Guardem la data d'actualització i avall.' $this->updateObject(); $OU = $this->getObject(); $OU->setActualitzacio(date('Y-m-d', time())); //Guardem la data d'actualització.' $OU->save(); //Mirem si l'usuari està relacionat amb el SITE $OUS = UsuarisSitesPeer::initialize($OU->getUsuariId(), $OU->getSiteId())->getObject(); $OUS->setNivellid($this->getValue('Nivells_idNivells')); $OUS->save(); }
/** * Select de les entitats a les que pertany un usuari. * @param $idU Identificador d'usuari * @return Array('idS'=>'Username') * */ public static function getSelectUser($idU = 0) { $RET = array(); $C = new Criteria(); $C = self::getCriteriaActiu($C); $C = UsuarisPeer::getCriteriaActiu($C, null); $C = UsuarisSitesPeer::getCriteriaActiu($C); $C->addJoin(self::SITE_ID, UsuarisSitesPeer::SITE_ID); $C->addJoin(UsuarisSitesPeer::USUARI_ID, UsuarisPeer::USUARIID); $C->add(UsuarisPeer::USUARIID, $idU); $RET['0'] = 'Escull una entitat...'; foreach (self::doSelect($C) as $OS) { $RET[$OS->getSiteId()] = $OS->getNom(); } return $RET; }
public function save($conn = null) { //Les dades de l'usuari que es mantenen són sempre les noves. Guardem la data d'actualització i avall. $DNI = trim($this->getValue('DNI')); //Corregim el DNI, i trec els espais en blanc $OUsuari = UsuarisPeer::cercaDNI($DNI); //Busco la persona que he entrat if ($OUsuari instanceof Usuaris && is_null($this->getObject()->getUsuariId()) && $this->getOption('ADMIN')) { UsuarisSitesPeer::initialize($OUsuari->getUsuariid(), $this->getObject()->getSiteId())->getObject()->save(); } else { $this->updateObject(); $OU = $this->getObject(); $OU->setActualitzacio(date('Y-m-d', time())); //Guardem la data d'actualització. $OU->save(); //Mirem si l'usuari està relacionat amb el SITE $OUS = UsuarisSitesPeer::initialize($OU->getUsuariId(), $OU->getSiteId())->getObject(); $OUS->setNivellid($this->getValue('Nivells_idNivells')); $OUS->save(); } }
/** * Aquesta funció retorna un array amb els mails dels administradors i el seu nom * @return Array('mail'=>nom) * */ public static function getAdminMails() { $RET = array(); $C = new Criteria(); $C = self::getCriteriaActiu($C, null, true); $C = UsuarisSitesPeer::getCriteriaActiu($C); $C->addJoin(UsuarisSitesPeer::USUARI_ID, self::USUARIID); $C->add(UsuarisSitesPeer::NIVELL_ID, NivellsPeer::ADMIN); $C->addGroupByColumn(UsuarisPeer::EMAIL); foreach (self::doSelect($C) as $OU) { $RET[$OU->getEmail()] = $OU->getEmail(); } return $RET; }
/** * This is a method for emulating ON DELETE CASCADE for DBs that don't support this * feature (like MySQL or SQLite). * * This method is not very speedy because it must perform a query first to get * the implicated records and then perform the deletes by calling those Peer classes. * * This method should be used within a transaction if possible. * * @param Criteria $criteria * @param PropelPDO $con * @return int The number of affected rows (if supported by underlying database driver). */ protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con) { // initialize var to track total num of affected rows $affectedRows = 0; // first find the objects that are implicated by the $criteria $objects = UsuarisPeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related AppDocumentsPermisos objects $criteria = new Criteria(AppDocumentsPermisosPeer::DATABASE_NAME); $criteria->add(AppDocumentsPermisosPeer::IDUSUARI, $obj->getUsuariid()); $affectedRows += AppDocumentsPermisosPeer::doDelete($criteria, $con); // delete related AppDocumentsPermisosDir objects $criteria = new Criteria(AppDocumentsPermisosDirPeer::DATABASE_NAME); $criteria->add(AppDocumentsPermisosDirPeer::IDUSUARI, $obj->getUsuariid()); $affectedRows += AppDocumentsPermisosDirPeer::doDelete($criteria, $con); // delete related Cessio objects $criteria = new Criteria(CessioPeer::DATABASE_NAME); $criteria->add(CessioPeer::USUARI_ID, $obj->getUsuariid()); $affectedRows += CessioPeer::doDelete($criteria, $con); // delete related Factures objects $criteria = new Criteria(FacturesPeer::DATABASE_NAME); $criteria->add(FacturesPeer::VALIDAUSUARI, $obj->getUsuariid()); $affectedRows += FacturesPeer::doDelete($criteria, $con); // delete related Matricules objects $criteria = new Criteria(MatriculesPeer::DATABASE_NAME); $criteria->add(MatriculesPeer::USUARIS_USUARIID, $obj->getUsuariid()); $affectedRows += MatriculesPeer::doDelete($criteria, $con); // delete related Missatges objects $criteria = new Criteria(MissatgesPeer::DATABASE_NAME); $criteria->add(MissatgesPeer::USUARIS_USUARIID, $obj->getUsuariid()); $affectedRows += MissatgesPeer::doDelete($criteria, $con); // delete related Personal objects $criteria = new Criteria(PersonalPeer::DATABASE_NAME); $criteria->add(PersonalPeer::IDUSUARI, $obj->getUsuariid()); $affectedRows += PersonalPeer::doDelete($criteria, $con); // delete related Reservaespais objects $criteria = new Criteria(ReservaespaisPeer::DATABASE_NAME); $criteria->add(ReservaespaisPeer::USUARIS_USUARIID, $obj->getUsuariid()); $affectedRows += ReservaespaisPeer::doDelete($criteria, $con); // delete related UsuarisApps objects $criteria = new Criteria(UsuarisAppsPeer::DATABASE_NAME); $criteria->add(UsuarisAppsPeer::USUARI_ID, $obj->getUsuariid()); $affectedRows += UsuarisAppsPeer::doDelete($criteria, $con); // delete related UsuarisMenus objects $criteria = new Criteria(UsuarisMenusPeer::DATABASE_NAME); $criteria->add(UsuarisMenusPeer::USUARI_ID, $obj->getUsuariid()); $affectedRows += UsuarisMenusPeer::doDelete($criteria, $con); // delete related UsuarisSites objects $criteria = new Criteria(UsuarisSitesPeer::DATABASE_NAME); $criteria->add(UsuarisSitesPeer::USUARI_ID, $obj->getUsuariid()); $affectedRows += UsuarisSitesPeer::doDelete($criteria, $con); // delete related Usuarisllistes objects $criteria = new Criteria(UsuarisllistesPeer::DATABASE_NAME); $criteria->add(UsuarisllistesPeer::USUARIS_USUARISID, $obj->getUsuariid()); $affectedRows += UsuarisllistesPeer::doDelete($criteria, $con); } return $affectedRows; }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's phpname (e.g. 'AuthorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = UsuarisSitesPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setUsuariId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setSiteId($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setNivellId($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setActiu($arr[$keys[3]]); } }
public function executeAjaxGetSitesUsersOptions(sfWebRequest $request) { $IDS = $request->getParameter('IDS'); $NIVELL = $request->getParameter('IDN'); return $this->renderText(UsuarisSitesPeer::getSitesUsersOptions($IDS, $NIVELL)); }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Sites is new, it will return * an empty collection; or if this Sites has previously * been saved, it will retrieve related UsuarisSitess from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in Sites. */ public function getUsuarisSitessJoinNivells($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { if ($criteria === null) { $criteria = new Criteria(SitesPeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collUsuarisSitess === null) { if ($this->isNew()) { $this->collUsuarisSitess = array(); } else { $criteria->add(UsuarisSitesPeer::SITE_ID, $this->site_id); $this->collUsuarisSitess = UsuarisSitesPeer::doSelectJoinNivells($criteria, $con, $join_behavior); } } else { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. $criteria->add(UsuarisSitesPeer::SITE_ID, $this->site_id); if (!isset($this->lastUsuarisSitesCriteria) || !$this->lastUsuarisSitesCriteria->equals($criteria)) { $this->collUsuarisSitess = UsuarisSitesPeer::doSelectJoinNivells($criteria, $con, $join_behavior); } } $this->lastUsuarisSitesCriteria = $criteria; return $this->collUsuarisSitess; }
public function setWidgetUsers() { $this->setWidget('IDU', new sfWidgetFormChoice(array('choices' => UsuarisSitesPeer::getSitesUsersSelect($this->getValue('IDS'), NivellsPeer::ADMIN)))); $this->setValidator('IDU', new sfValidatorPass(array(), array())); }
/** * Agafa tots els usuaris de l'entitat i hi guarda la línia. Els canvis s'han de repetir a Intranet * @param $accio = Quina acció ha realitzat ( Alta , baixa, etc... ) * @param $ON = A quina part de l'aplicatiu * @param $qui = Qui ha fet aquesta acció * @param $idS = Entitat que està fent l'acció * @param Accions: Contactes, Taulell, Material, Cessió, Reserva d'espais, Incidències, Horaris ( canvi ), Cursos, Matrícula, Cicle, Entrada, Usuari, email-llista, Notícia, * */ public static function addLogTimeline($accio, $ON, $qui, $idS, $idElement) { //Si estem fent una operació sobre "HOspici" marquem l'arxiu de l'Hospici. if ($idS == 0) { $time = time(); $REG = "<dades>"; $REG .= "<quan>" . $time . "</quan>"; $REG .= "<accio>" . $accio . "</accio>"; $REG .= "<lloc>" . $ON . "</lloc>"; $REG .= "<qui>" . $qui . "</qui>"; $REG .= "<site>" . $idS . "</site>"; $REG .= "<id>" . $idElement . "</id>"; $REG .= "</dades>" . PHP_EOL; file_put_contents(getcwd() . '/timelines/log_0.txt', $REG, FILE_APPEND); //Sinó marquem a tots } else { $A_OUS = UsuarisSitesPeer::getSitesUsers($idS); //Per cada usuari, guardem al seu registre foreach ($A_OUS as $OUS) { $time = time(); $REG = "<dades>"; $REG .= "<quan>" . $time . "</quan>"; $REG .= "<accio>" . $accio . "</accio>"; $REG .= "<lloc>" . $ON . "</lloc>"; $REG .= "<qui>" . $qui . "</qui>"; $REG .= "<site>" . $idS . "</site>"; $REG .= "<id>" . $idElement . "</id>"; $REG .= "</dades>" . PHP_EOL; file_put_contents(getcwd() . '/timelines/log_' . $OUS->getUsuariId() . '.txt', $REG, FILE_APPEND); } } }
public function getSiteNivell($idS) { $C = new Criteria(); $C = UsuarisPeer::getCriteriaActiu($C, $idS); $C = UsuarisSitesPeer::getCriteriaActiu($C); $C->add(UsuarisSitesPeer::SITE_ID, $idS); $C->add(UsuarisSitesPeer::USUARI_ID, $this->getUsuariid()); $OU = UsuarisSitesPeer::doSelectOne($C); //Si existeix un vincle entre el site i l'usuari, mirem si quin nivell té. //Si no existeix cap vincle, per defecte és registrat. if ($OU instanceof UsuarisSites) { if ($OU->getNivellId() == NivellsPeer::ADMIN) { return NivellsPeer::ADMIN; } else { return NivellsPeer::REGISTRAT; } } else { return NivellsPeer::REGISTRAT; } }
public function executeGConfigSuperAdmin(sfWebRequest $request) { $this->setLayout('gestio'); $this->IDS = $this->getUser()->getSessionPar('idS'); $this->accio = $request->getParameter('accio', 'C'); $RSITES = $request->getParameter('sites', array('site_id' => 1)); $this->FSITES = SitesPeer::initialize($RSITES['site_id']); $this->SITE = $request->getParameter('SITE', ''); //Cerquem per SITE, que és més fàcil //Mirem quins usuaris hi ha a un SITE relacionats com a adminstradors //Mirem quins menús tenen els usuaris d'un SITE en general (els menús del primer usuari) $OS = SitesPeer::retrieveByPK($this->SITE); if ($OS instanceof Sites) { $this->LUSERSITES = UsuarisSitesPeer::getSitesUsers($this->SITE, true); $this->LMENUSUSUARI = GestioMenusPeer::getMenusUsuariArray($this->USUARI, $this->SITE); } else { $this->USUARI = 0; $this->LUSERSITES = array(); $this->LMENUSUSUARI = array(); } $this->FMENUUSUARI = new ConfigSuperAdminMenusForm(null, array('IDS' => $this->IDS)); $this->FMENUUSUARI->bind($request->getParameter('super_admin_menus')); if ($request->hasParameter('BSAVESITE')) { $this->accio = 'SAVE_SITE'; } if ($request->hasParameter('BDELETESITE')) { $this->accio = 'DELETE_SITE'; } if ($request->hasParameter('BSAVEUSERSITE')) { $this->accio = 'SAVE_USER_SITE'; } if ($request->hasParameter('BDELETEUSERSITE')) { $this->accio = 'DELETE_USER_SITE'; } if ($request->hasParameter('BSEARCHUSERSITES')) { $this->accio = 'SEARCH_USER_SITES'; } if ($request->hasParameter('BSAVEUSERMENU')) { $this->accio = 'SAVE_USER_MENU'; } switch ($this->accio) { case 'SAVE_SITE': $this->FSITES->bind($RSITES); if ($this->FSITES->isValid()) { $this->FSITES->save(); $this->getUser()->addLogAction($this->accio, 'gConfigSuperAdmin', $this->FSITES->getObject()); $this->FSITES = SitesPeer::initialize($this->FSITES->getObject()->getSiteId()); } break; case 'DELETE_SITE': $this->FSITES->getObject()->setActiu(false)->save(); $this->getUser()->addLogAction($this->accio, 'gConfigSuperAdmin', $this->FSITES->getObject()); $this->FESPAIS = SitesPeer::initialize(0, $this->IDS); break; case 'SAVE_USER_SITE': $RP = $request->getParameter('dades'); foreach ($RP as $RS) { if ($RS['IDU'] > 0 && $RS['IDN'] > 0 && $this->SITE > 0) { $OUS = UsuarisSitesPeer::initialize($RS['IDU'], $this->SITE, false)->getObject(); $OUS->setNivellId($RS['IDN']); $OUS->setActiu(true); $OUS->save(); } } $this->LUSERSITES = UsuarisSitesPeer::getSitesUsers($this->SITE, true); break; case 'DELETE_USER_SITE': $USUARI = $request->getParameter('USUARI'); $SITE = $request->getParameter('SITE'); $OUS = UsuarisSitesPeer::initialize($USUARI, $SITE)->getObject(); if (!$OUS->isNew()) { $OUS->setActiu(false); $OUS->save(); $this->LUSERSITES = UsuarisSitesPeer::getUserSites($this->SITE); } break; case 'SAVE_USER_MENU': $LMENUS_NOVA = $request->getParameter('dades'); $LDADES = $request->getParameter('super_admin_menus'); if (!empty($LMENUS_NOVA)) { UsuarisMenusPeer::doUpdateMy($LDADES['IDU'], $LDADES['IDS'], $LMENUS_NOVA); } $this->LMENUSUSUARI = GestioMenusPeer::getMenusUsuariArray($LDADES['IDU'], $LDADES['IDS']); $this->FMENUUSUARI->setWidgetUsers(); break; case 'SEARCH_USER_SITES': $IDS = $this->FMENUUSUARI->getValue('IDS'); $IDU = $this->FMENUUSUARI->getValue('IDU'); if (!empty($IDS)) { $this->FMENUUSUARI->setWidgetUsers(); if (!empty($IDU)) { $this->LMENUSUSUARI = GestioMenusPeer::getMenusUsuariArray($IDU, $IDS); } } break; } }
/** * Agafa tots els usuaris de l'entitat i hi guarda la línia. * @param $accio = Quina acció ha realitzat ( Alta , baixa, etc... ) * @param $ON = A quina part de l'aplicatiu * @param $qui = Qui ha fet aquesta acció * @param $idS = Entitat que està fent l'acció * @param Accions: Contactes, Taulell, Material, Cessió, Reserva d'espais, Incidències, Horaris ( canvi ), Cursos, Matrícula, Cicle, Entrada, Usuari, email-llista, Notícia, * */ public static function addLogTimeline($accio, $ON, $qui, $idS, $idElement) { $A_OUS = UsuarisSitesPeer::getSitesUsers($idS); //Per cada usuari, guardem al seu registre foreach ($A_OUS as $OUS) { $time = time(); $REG = "<dades>"; $REG .= "<quan>" . $time . "</quan>"; $REG .= "<accio>" . $accio . "</accio>"; $REG .= "<lloc>" . $ON . "</lloc>"; $REG .= "<qui>" . $qui . "</qui>"; $REG .= "<site>" . $idS . "</site>"; $REG .= "<id>" . $idElement . "</id>"; $REG .= "</dades>" . PHP_EOL; file_put_contents(getcwd() . '/timelines/log_' . $OUS->getUsuariId() . '.txt', $REG, FILE_APPEND); file_put_contents(getcwd() . '/timelines/log_general.txt', $REG, FILE_APPEND); } }
/** * Retrieve object using using composite pkey values. * @param int $usuari_id * @param int $site_id * @param PropelPDO $con * @return UsuarisSites */ public static function retrieveByPK($usuari_id, $site_id, PropelPDO $con = null) { $key = serialize(array((string) $usuari_id, (string) $site_id)); if (null !== ($obj = UsuarisSitesPeer::getInstanceFromPool($key))) { return $obj; } if ($con === null) { $con = Propel::getConnection(UsuarisSitesPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $criteria = new Criteria(UsuarisSitesPeer::DATABASE_NAME); $criteria->add(UsuarisSitesPeer::USUARI_ID, $usuari_id); $criteria->add(UsuarisSitesPeer::SITE_ID, $site_id); $v = UsuarisSitesPeer::doSelect($criteria, $con); return !empty($v) ? $v[0] : null; }
/** * This is a method for emulating ON DELETE CASCADE for DBs that don't support this * feature (like MySQL or SQLite). * * This method is not very speedy because it must perform a query first to get * the implicated records and then perform the deletes by calling those Peer classes. * * This method should be used within a transaction if possible. * * @param Criteria $criteria * @param PropelPDO $con * @return int The number of affected rows (if supported by underlying database driver). */ protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con) { // initialize var to track total num of affected rows $affectedRows = 0; // first find the objects that are implicated by the $criteria $objects = NivellsPeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related UsuarisMenus objects $criteria = new Criteria(UsuarisMenusPeer::DATABASE_NAME); $criteria->add(UsuarisMenusPeer::NIVELL_ID, $obj->getIdnivells()); $affectedRows += UsuarisMenusPeer::doDelete($criteria, $con); // delete related UsuarisSites objects $criteria = new Criteria(UsuarisSitesPeer::DATABASE_NAME); $criteria->add(UsuarisSitesPeer::NIVELL_ID, $obj->getIdnivells()); $affectedRows += UsuarisSitesPeer::doDelete($criteria, $con); } return $affectedRows; }