private function checkAuthorisation()
 {
     if (!$this->user->isAuthenticated()) {
         return false;
     }
     if (!$this->user->hasCredential("appkit.api.access") && !$this->user->hasCredential("icinga.user")) {
         return false;
     }
     return true;
 }
 /**
  * Create of update a category
  * @param array $cat
  * @return Ambigous <NULL, CronkCategory>
  */
 public function createCategory(array $cat)
 {
     AppKitArrayUtil::swapKeys($cat, self::$cat_map, true);
     $category = null;
     if ($this->agaviUser->hasCredential('icinga.cronk.category.admin') && isset($cat['cc_uid'])) {
         $category = AppKitDoctrineUtil::createQuery()->from('CronkCategory cc')->andWhere('cc.cc_uid=?', $cat['cc_uid'])->execute()->getFirst();
     }
     if (!$category instanceof CronkCategory || !$category->cc_id > 0) {
         $category = new CronkCategory();
     }
     $category->fromArray($cat);
     $category->save();
     return $category;
 }
 public function deleteCronkRecord($cronkid, $cronkname, $own = true)
 {
     if ($this->agaviUser->hasCredential('icinga.cronk.custom') === false && $this->agaviUser->hasCredential('icinga.cronk.admin') === false) {
         throw new AppKitModelException('No access to delete cronks!');
     }
     $q = AppKitDoctrineUtil::createQuery()->select('c.*')->from('Cronk c')->where('c.cronk_uid=?', array($cronkid));
     if ($own == true && $this->agaviUser->hasCredential('icinga.cronk.admin') === false) {
         $q->andWhere('c.cronk_user_id=?', array($this->user->user_id));
     }
     $cronk = $q->execute()->getFirst();
     if ($cronk instanceof Cronk && $cronk->cronk_id > 0) {
         AppKitDoctrineUtil::getConnection()->beginTransaction();
         $params = array($cronk->cronk_id);
         AppKitDoctrineUtil::createQuery()->delete('CronkCategoryCronk c')->andWhere('c.ccc_cronk_id=?')->execute($params);
         AppKitDoctrineUtil::createQuery()->delete('CronkPrincipalCronk c')->andWhere('c.cpc_cronk_id=?')->execute($params);
         AppKitDoctrineUtil::getConnection()->commit();
         $cronk->delete();
         return true;
     } else {
         throw new AppKitModelException('Could not delete cronk: ' . $cronkid);
     }
 }