/**
  * Edits a user
  *
  * @param string $email
  */
 public function editAction($email)
 {
     if (!$this->request->isPost()) {
         $user = Users::findFirstByemail($email);
         if (!$user) {
             $this->flash->error("user was not found");
             return $this->dispatcher->forward(array("controller" => "users", "action" => "index"));
         }
         $this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_ACTION_VIEW);
         $this->view->email = $user->email;
         $this->tag->setDefault("email", $user->email);
         $this->tag->setDefault("full_name", $user->full_name);
         $this->tag->setDefault("image_path", $user->image_path);
         $this->tag->setDefault("password", $user->password);
         $this->tag->setDefault("role", $user->role);
         $this->tag->setDefault("status", $user->status);
         $this->tag->setDefault("organisation_id", $user->organisation_id);
         $userdata = $user->SecurityGroup;
         $this->view->setVar("user_security_groups", $userdata);
         $data = SecurityGroup::find("organisation_id=" . $user->organisation_id);
         $data = $data->toArray();
         foreach ($userdata->toArray() as $security_group) {
             if (($key = array_search($security_group, $data)) !== false) {
                 unset($data[$key]);
             }
         }
         $object = json_decode(json_encode($data), FALSE);
         $this->view->setVar("security_groups", $object);
         $this->view->setVar("user", $user);
     }
 }
 /**
  * Creates a new user
  */
 public function createAction()
 {
     if (!$this->request->isPost()) {
         return $this->dispatcher->forward(array("controller" => "security_group", "action" => "index"));
     }
     $security_group = new SecurityGroup();
     $security_group->name = $this->request->getPost("name");
     $security_group->description = $this->request->getPost("description");
     $security_group->organisation_id = $this->request->getPost("organisation_id");
     if (!$security_group->save()) {
         foreach ($security_group->getMessages() as $message) {
             $this->flash->error($message);
         }
         return $this->dispatcher->forward(array("namespace" => "PRIME\\Controllers", "controller" => "security_group", "action" => "index"));
     }
     $this->flash->success("Security  Group was created successfully");
     return $this->dispatcher->forward(array("namespace" => "PRIME\\Controllers", "controller" => "security_group", "action" => "index"));
 }