예제 #1
0
파일: Unites.php 프로젝트: bersace/strass
 function findRolesCandidats($annee)
 {
     $t = new Roles();
     $db = $t->getAdapter();
     $s = $t->select()->setIntegrityCheck(false)->from('unite_role')->join('unite_type', 'unite_type.id = unite_role.type', array())->join('unite', 'unite.type = unite_type.id', array())->joinLeft('appartenance', 'appartenance.role = unite_role.id AND ' . 'appartenance.unite = unite.id AND ' . ('(' . $db->quoteInto('appartenance.debut < ?', Strass_Controller_Action_Helper_Annee::dateFin($annee)) . ' AND ' . $db->quoteInto('(appartenance.fin IS NULL OR appartenance.fin < ?)', Strass_Controller_Action_Helper_Annee::dateFin($annee)) . ')'), array())->where('unite.id = ?', $this->id)->where('appartenance.id IS NULL');
     return $t->fetchAll($s);
 }
예제 #2
0
 function editAction()
 {
     $request = new Bolts_Request($this->getRequest());
     $roles_table = new Roles();
     $role = null;
     if ($request->has('id')) {
         if (!is_null($request->id)) {
             $role = $roles_table->fetchRow($roles_table->select()->where("id = ?", $request->id));
             if (!is_null($role)) {
                 // we do not edit the guest role
                 if ($role->shortname == "guest") {
                     $this->_redirect("/bolts/role");
                 }
                 $this->view->role = $role->toArray();
                 $this->view->role_tree = $roles_table->getRoleTree(null, $role->id);
                 $this->view->inherited_ids = $roles_table->getInheritedRoles($role->id);
             }
         }
     }
     if (is_null($role)) {
         $this->view->role_tree = $roles_table->getRoleTree();
     }
     if ($this->getRequest()->isPost()) {
         $errors = array();
         if ($request->has('inherit_role')) {
             $parents = array();
             foreach ($request->inherit_role as $inherit_role) {
                 $parents = array_merge($parents, $roles_table->getAllAncestors($inherit_role));
             }
             $inherit_ids = array();
             foreach ($request->inherit_role as $inherit_role) {
                 if (!in_array($inherit_role, $parents)) {
                     $inherit_ids[] = $inherit_role;
                 }
             }
         }
         if ($request->has('shortname')) {
             $shortname = $request->shortname;
             if (!Bolts_Validate::checkLength($request->shortname, 1, 255)) {
                 $errors[] = $this->_T("Shortname must be between 1 and 255 chars.");
             }
         } else {
             $errors[] = $this->_T("Shortname is a requried field.");
         }
         $description = $request->description;
         $isadmin = (int) $request->checkbox('isadmin');
         if (count($errors) == 0) {
             $data = array('shortname' => $shortname, 'description' => $description, 'isadmin' => $isadmin);
             //If we have an id, this is an update.
             $id = (int) $this->_request->getPost('id');
             if ($id != 0) {
                 $where = 'id = ' . $id;
                 $roles_table->update($data, $where);
             } else {
                 //We don't, this is an insert.
                 $id = $roles_table->insert($data);
             }
             $roles_table->removeInheritedRole($id);
             foreach ($inherit_ids as $in_id) {
                 $roles_table->setInheritedRole($id, $in_id);
             }
             $this->_redirect("/bolts/role");
         } else {
             $this->view->errors = $errors;
         }
     }
     if ($request->has('id')) {
         // this is an edit
         $id = $request->id;
         if ($id > 0) {
             $this->view->role = $roles_table->fetchRow('id = ' . $id)->toArray();
         }
         $this->view->inherited_ids = $roles_table->getInheritedRoles($id);
     } else {
         foreach ($roles_table->fetchAll()->toArray() as $role) {
             $role_choices[$role['id']] = $role['shortname'];
         }
         $this->view->role_choices = $role_choices;
     }
 }
예제 #3
0
 function findRolesCandidats($unite, $filter_current = true)
 {
     $t = new Roles();
     $db = $t->getAdapter();
     $s = $t->select()->setIntegrityCheck(false)->from('unite_role')->join('unite_type', 'unite_type.id = unite_role.type', array())->join('unite', 'unite.type = unite_type.id', array())->where('unite.id = ?', $unite->id);
     if ($filter_current) {
         $s->joinLeft('appartenance', 'appartenance.role = unite_role.id AND ' . 'appartenance.unite = unite.id AND ' . $db->quoteInto('appartenance.individu', $this->id), array())->where('appartenance.id IS NULL');
     }
     return $t->fetchAll($s);
 }