Example #1
0
 /**
  * Remove all role-user relations
  * mostly used for testing
  *
  * @param boolean $Ensure
  *            must set to true or throws an Exception
  * @return number of deleted relations
  */
 function resetAssignments($Ensure = false)
 {
     if ($Ensure !== true) {
         throw new \Exception("You must pass true to this function, otherwise it won't work.");
         return;
     }
     $res = Jf::sql("DELETE FROM {$this->tablePrefix()}userroles");
     $Adapter = get_class(Jf::$Db);
     if ($this->isMySql()) {
         Jf::sql("ALTER TABLE {$this->tablePrefix()}userroles AUTO_INCREMENT =1 ");
     } elseif ($this->isSQLite()) {
         Jf::sql("delete from sqlite_sequence where name=? ", $this->tablePrefix() . "_userroles");
     } else {
         throw new \Exception("Rbac can not reset table on this type of database: {$Adapter}");
     }
     $this->assign("root", 1);
     return $res;
 }
Example #2
0
File: full.php Project: voxter/rbac
 /**
  * Adds a child to the beginning of a node's children
  *
  * @param Array $FieldValueArray key-paired field-values to insert
  * @param string $ConditionString of the parent node
  * @param string $Rest optional, rest of variables to fill in placeholders of condition string, one variable for each ? in condition
  * @return Integer ChildID
  */
 function insertChildData($FieldValueArray = array(), $ConditionString = null, $Rest = null)
 {
     $this->lock();
     //Find the Sibling
     $Arguments = func_get_args();
     array_shift($Arguments);
     //first argument, the array
     array_shift($Arguments);
     if ($ConditionString) {
         $ConditionString = "WHERE {$ConditionString}";
     }
     $Query = "SELECT {$this->right()} AS `Right`, {$this->left()} AS `Left`" . " FROM {$this->table()} {$ConditionString}";
     array_unshift($Arguments, $Query);
     $Parent = call_user_func_array("Jf::sql", $Arguments);
     $Parent = $Parent[0];
     if ($Parent == null) {
         $Parent["Left"] = $Parent["Right"] = 0;
     }
     Jf::sql("UPDATE {$this->table()} SET {$this->right()} = {$this->right()} + 2 WHERE {$this->right()} >= ?", $Parent["Right"]);
     Jf::sql("UPDATE {$this->table()} SET {$this->left()} = {$this->left()} + 2 WHERE {$this->left()} > ?", $Parent["Right"]);
     $FieldsString = $ValuesString = "";
     $Values = array();
     if ($FieldValueArray) {
         foreach ($FieldValueArray as $k => $v) {
             $FieldsString .= ",";
             $FieldsString .= "`" . $k . "`";
             $ValuesString .= ",?";
             $Values[] = $v;
         }
     }
     $Query = "INSERT INTO {$this->table()} ({$this->left()},{$this->right()} {$FieldsString}) " . "VALUES(?,? {$ValuesString})";
     array_unshift($Values, $Parent["Right"] + 1);
     array_unshift($Values, $Parent["Right"]);
     array_unshift($Values, $Query);
     $Res = call_user_func_array("Jf::sql", $Values);
     $this->unlock();
     return $Res;
 }
Example #3
0
 /**
  * Retrives the full tree including Depth field.
  *
  * @return 2DArray Rowset
  */
 function fullTree()
 {
     $Res = Jf::sql("SELECT node.*, (COUNT(parent.{$this->id()}) - 1) AS Depth\n            FROM {$this->table()} AS node,\n            {$this->table()} AS parent\n            WHERE node.{$this->left()} BETWEEN parent.{$this->left()} AND parent.{$this->right()}\n            GROUP BY node.{$this->id()}\n            ORDER BY node.{$this->left()}");
     return $Res;
 }