/**
  * Edit an existing action or add a new one
  *
  * @param int $ActionID
  */
 public function Edit($ActionID = NULL)
 {
     $this->Permission('Yaga.Reactions.Manage');
     $this->AddSideMenu('action/settings');
     $this->Form->SetModel($this->ActionModel);
     $Edit = FALSE;
     $this->Title(T('Yaga.Action.Add'));
     if ($ActionID) {
         $this->Action = $this->ActionModel->GetByID($ActionID);
         $this->Form->AddHidden('ActionID', $ActionID);
         $Edit = TRUE;
         $this->Title(T('Yaga.Action.Edit'));
     }
     // This is just a list of all the images in the action icons folder
     $this->SetData('Icons', array('Happy', 'Happy2', 'Smiley', 'Smiley2', 'Tongue', 'Tongue2', 'Sad', 'Sad2', 'Wink', 'Wink2', 'Grin', 'Shocked', 'Confused', 'Confused2', 'Neutral', 'Neutral2', 'Wondering', 'Wondering2', 'PointUp', 'PointRight', 'PointDown', 'PointLeft', 'ThumbsUp', 'ThumbsUp2', 'Shocked2', 'Evil', 'Evil2', 'Angry', 'Angry2', 'Heart', 'Heart2', 'HeartBroken', 'Star', 'Star2', 'Grin2', 'Cool', 'Cool2', 'Question', 'Notification', 'Warning', 'Spam', 'Blocked', 'Eye', 'Eye2', 'EyeBlocked', 'Flag', 'BrightnessMedium', 'QuotesLeft', 'Music', 'Pacman', 'Bullhorn', 'Rocket', 'Fire', 'Hammer', 'Target', 'Lightning', 'Shield', 'CheckmarkCircle', 'Lab', 'Leaf', 'Dashboard', 'Droplet', 'Feed', 'Support', 'Hammer2', 'Wand', 'Cog', 'Gift', 'Trophy', 'Magnet', 'Switch', 'Globe', 'Bookmark', 'Bookmarks', 'Star3', 'Info', 'Info2', 'CancelCircle', 'Checkmark', 'Close'));
     // Load up all permissions
     $PermissionModel = new PermissionModel();
     $Permissions = $PermissionModel->PermissionColumns();
     unset($Permissions['PermissionID']);
     $PermissionKeys = array_keys($Permissions);
     $PermissionList = array_combine($PermissionKeys, $PermissionKeys);
     $this->SetData('Permissions', $PermissionList);
     if ($this->Form->IsPostBack() == FALSE) {
         if (property_exists($this, 'Action')) {
             $this->Form->SetData($this->Action);
         } else {
             $this->Form->SetData(array('Permission' => 'Yaga.Reactions.Add'));
         }
     } else {
         if ($this->Form->Save()) {
             if ($Edit) {
                 $Action = $this->ActionModel->GetByID($this->Form->GetFormValue('ActionID'));
             } else {
                 $Action = $this->ActionModel->GetNewestAction();
             }
             $NewActionRow = ActionRow($Action);
             if ($Edit) {
                 $this->JsonTarget('#ActionID_' . $this->Action->ActionID, $NewActionRow, 'ReplaceWith');
                 $this->InformMessage(T('Yaga.ActionUpdated'));
             } else {
                 $this->JsonTarget('#Actions', $NewActionRow, 'Append');
                 $this->InformMessage(T('Yaga.Action.Added'));
             }
         }
     }
     $this->Render('edit');
 }
Esempio n. 2
0
 public function InsertPermissionTable()
 {
     //      $this->LoadState();
     // Clear the permission table in case the step was only half done before.
     $this->SQL->Delete('Permission', array('RoleID <>' => 0));
     // Grab all of the permission columns.
     $PM = new PermissionModel();
     $GlobalColumns = array_filter($PM->PermissionColumns());
     unset($GlobalColumns['PermissionID']);
     $JunctionColumns = array_filter($PM->PermissionColumns('Category', 'PermissionCategoryID'));
     unset($JunctionColumns['PermissionID']);
     $JunctionColumns = array_merge(array('JunctionTable' => 'Category', 'JunctionColumn' => 'PermissionCategoryID', 'JunctionID' => -1), $JunctionColumns);
     if ($this->ImportExists('Permission', 'JunctionTable')) {
         $ColumnSets = array(array_merge($GlobalColumns, $JunctionColumns));
         $ColumnSets[0]['JunctionTable'] = NULL;
         $ColumnSets[0]['JunctionColumn'] = NULL;
         $ColumnSets[0]['JunctionID'] = NULL;
     } else {
         $ColumnSets = array($GlobalColumns, $JunctionColumns);
     }
     $Data = $this->SQL->Get('zPermission')->ResultArray();
     foreach ($Data as $Row) {
         $Presets = array_map('trim', explode(',', GetValue('_Permissions', $Row)));
         foreach ($ColumnSets as $ColumnSet) {
             $Set = array();
             $Set['RoleID'] = $Row['RoleID'];
             foreach ($Presets as $Preset) {
                 if (strpos($Preset, '.') !== FALSE) {
                     // This preset is a specific permission.
                     if (array_key_exists($Preset, $ColumnSet)) {
                         $Set["`{$Preset}`"] = 1;
                     }
                     continue;
                 }
                 $Preset = strtolower($Preset);
                 foreach ($ColumnSet as $ColumnName => $Default) {
                     if (isset($Row[$ColumnName])) {
                         $Value = $Row[$ColumnName];
                     } elseif (strpos($ColumnName, '.') === FALSE) {
                         $Value = $Default;
                     } elseif ($Preset == 'all') {
                         $Value = 1;
                     } elseif ($Preset == 'view') {
                         $Value = StringEndsWith($ColumnName, 'View', TRUE) && !in_array($ColumnName, array('Garden.Settings.View'));
                     } elseif ($Preset == $ColumnName) {
                         $Value = 1;
                     } else {
                         $Value = $Default & 1;
                     }
                     $Set["`{$ColumnName}`"] = $Value;
                 }
             }
             $this->SQL->Insert('Permission', $Set);
             unset($Set);
         }
     }
     return TRUE;
 }
Esempio n. 3
0
 public function InsertPermissionTable()
 {
     if ($this->ImportExists('Permission', 'JunctionTable')) {
         $this->_InsertTable('Permission');
         return TRUE;
     }
     // Clear the permission table in case the step was only half done before.
     $this->SQL->Delete('Permission', array('RoleID <>' => 0));
     // Grab all of the permission columns.
     $PM = new PermissionModel();
     $GlobalColumns = array_filter($PM->PermissionColumns());
     unset($GlobalColumns['PermissionID']);
     $JunctionColumns = array_filter($PM->PermissionColumns('Category', 'PermissionCategoryID'));
     unset($JunctionColumns['PermissionID']);
     $JunctionColumns = array_merge(array('JunctionTable' => 'Category', 'JunctionColumn' => 'PermissionCategoryID', 'JunctionID' => -1), $JunctionColumns);
     $ColumnSets = array($GlobalColumns, $JunctionColumns);
     $Data = $this->SQL->Get('zPermission')->ResultArray();
     foreach ($Data as $Row) {
         $Preset = strtolower(GetValue('_Permissions', $Row));
         foreach ($ColumnSets as $ColumnSet) {
             $Set = array();
             $Set['RoleID'] = $Row['RoleID'];
             foreach ($ColumnSet as $ColumnName => $Default) {
                 if (isset($Row[$ColumnName])) {
                     $Value = $Row[$ColumnName];
                 } elseif (strpos($ColumnName, '.') === FALSE) {
                     $Value = $Default;
                 } elseif ($Preset == 'all') {
                     $Value = 1;
                 } elseif ($Preset == 'view') {
                     $Value = StringEndsWith($ColumnName, 'View', TRUE);
                 } else {
                     $Value = $Default & 1;
                 }
                 $Set["`{$ColumnName}`"] = $Value;
             }
             $this->SQL->Insert('Permission', $Set);
             unset($Set);
         }
     }
     return TRUE;
 }