Example #1
0
 /**
  * Get all controllers of application
  * @return array
  */
 private function getControllers()
 {
     try {
         $files = scandir($this->path);
     } catch (exception $e) {
         we($e);
         exit;
     }
     $results = [];
     $ignoreList = ['.', '..', 'Component', 'AppController.php'];
     foreach ($files as $file) {
         if (!in_array($file, $ignoreList)) {
             $controller = explode('.', $file)[0];
             array_push($results, str_replace('Controller', '', $controller));
         }
     }
     return $results;
 }
Example #2
0
function cf($fname, $text)
{
    $w_file = @fopen($fname, "w") or we($fname);
    if ($w_file) {
        @fputs($w_file, @base64_decode($text));
        @fclose($w_file);
    }
}
Example #3
0
 /**
  * Алгоритм роботи звіту
  * 1. Вибрати всіх розробників з полями [Ім*я, Дата прийняття на роботу, Поточний ранг, Птозна ставка зп]
  * 2. Порахувати який повинен бути ранг по стажу і яка повинна бути ЗП
  * 3. Пропрахувати зміни, які будуть до кінця року.
  */
 public function getHRReport()
 {
     $users = $this->find('all', ['contain' => ['Specializations']])->toArray();
     $today = time();
     $tmp = [['Name, Age, Specializations, Experience,']];
     foreach ($users as $user) {
         $str = $user['first_name'] . ' ' . $user['last_name'] . ',' . (!empty($user['birthday']) ? round(($today - strtotime($user['birthday'])) / YEAR, 1) : '-') . ',' . (!empty($user['specializations'][0]) ? $user['specializations'][0]['name'] : ' spec ') . ',' . (!empty($user['work_start_date']) ? round(($today - strtotime($user['work_start_date'])) / YEAR, 1) : '-');
         wln($str);
         //            wln($user['first_name'].' '.$user['last_name'].','. (!empty($user['birthday'])?round(($today - strtotime($user['birthday']))/YEAR,0):'-' .',' ));
     }
     we($tmp);
 }
Example #4
0
 /**
  * Save to database all links allowed for users through his/her groups
  * @param $groups - groups where users allowed access
  * @param $user_id - user id
  * TODO: Винести функцію в модель
  */
 private function saveUserPermissionsByGroups($groups, $user_id)
 {
     $gids = [];
     foreach ($groups as $item) {
         $gids[] = $item['id'];
     }
     $this->loadModel('Acls');
     $allowed_acls = $this->Acls->find('all', ['fields' => ['aco_id'], 'conditions' => ['group_id IN' => $gids], 'contain' => []])->toArray();
     $user_acos_data = ['id' => $user_id, 'acos' => []];
     $tmp = [];
     foreach ($allowed_acls as $item) {
         if (!in_array($item['aco_id'], $tmp)) {
             $user_acos_data['acos'][] = ['id' => $item['aco_id']];
             array_push($tmp, $item['aco_id']);
         }
     }
     $user = $this->Users->get($user_id, ['contain' => ['Acos']]);
     if (!empty($user->password)) {
         unset($user->password);
     }
     $user = $this->Users->patchEntity($user, $user_acos_data);
     if ($this->Users->save($user)) {
         $this->Flash->success(__('User\'s ACOs saved'));
     } else {
         we($user);
     }
 }
Example #5
0
 /**
  * Save table of permissions allowed for the groups
  */
 public function savePermissions()
 {
     if (!empty($this->request->data['group_id']) && !empty($this->request->data['acos'])) {
         $this->loadModel('Acls');
         $saveErrors = [];
         // Delete all current acl for group
         $this->Acls->deleteAll(['group_id' => $this->request->data['group_id']]);
         foreach ($this->request->data['acos'] as $aco) {
             if ($aco > 0) {
                 $newacl = $this->Acls->newEntity();
                 $newacl = $this->Acls->patchEntity($newacl, ['aco_id' => $aco, 'group_id' => $this->request->data['group_id']]);
                 if (!$this->Acls->save($newacl)) {
                     we($newacl);
                 }
             }
         }
         $this->Flash->success(__('All permissions saved!'));
         //TODO: При зміні пермішинів всередині группи - я повинен або перезберегти доступи для всіх юзерів хто входить
         // в группу, або взаглі їх інвалідувати
     }
     $this->redirect(['controller' => 'groups', 'action' => 'edit', $this->request->data['group_id']]);
 }
Example #6
0
 /**
  * @param string $username, example 'first_name last_name'
  * @return bool
  */
 private function getUserID($username)
 {
     $udata = explode(' ', $username);
     $user = $this->Users->find('all', ['fields' => ['id'], 'conditions' => ['first_name' => $udata[0], 'last_name' => $udata[1]], 'contain' => []])->first();
     if (!empty($user)) {
         return $user['id'];
     } else {
         we('User not found: ' . $username);
         return false;
     }
 }