/** * get Timesheet * * @param array $_data * @param boolean $_forceCreation * @return Timetracker_Model_Timeaccount */ protected function _getTimeaccount($_data = array(), $_forceCreation = false) { $defaultData = array('title' => Tinebase_Record_Abstract::generateUID(), 'description' => 'blabla'); $data = array_replace($defaultData, $_data); $ta = new Timetracker_Model_Timeaccount($data, true); if ($_forceCreation) { $taRec = $this->_json->saveTimeaccount($ta->toArray(), $_forceCreation); $this->_lastCreatedRecord = $taRec; } return $ta; }
/** * check grant for action (CRUD) * * @param Timetracker_Model_Timeaccount $_record * @param string $_action * @param boolean $_throw * @param string $_errorMessage * @param Timetracker_Model_Timeaccount $_oldRecord * @return boolean * @throws Tinebase_Exception_AccessDenied */ protected function _checkGrant($_record, $_action, $_throw = TRUE, $_errorMessage = 'No Permission.', $_oldRecord = NULL) { if ($_action == 'create' || $this->_doGrantChecks == FALSE) { // no check here because the MANAGE_TIMEACCOUNTS right has been already checked before return TRUE; } $hasGrant = Timetracker_Model_TimeaccountGrants::hasGrant($_record->getId(), Tinebase_Model_Grants::GRANT_ADMIN); switch ($_action) { case 'get': $hasGrant = $hasGrant || Timetracker_Model_TimeaccountGrants::hasGrant($_record->getId(), array(Timetracker_Model_TimeaccountGrants::VIEW_ALL, Timetracker_Model_TimeaccountGrants::BOOK_OWN, Timetracker_Model_TimeaccountGrants::BOOK_ALL, Timetracker_Model_TimeaccountGrants::MANAGE_BILLABLE)); case 'delete': case 'update': $hasGrant = $hasGrant || $this->checkRight(Timetracker_Acl_Rights::MANAGE_TIMEACCOUNTS, FALSE); break; } if ($_throw && !$hasGrant) { throw new Tinebase_Exception_AccessDenied($_errorMessage); } return $hasGrant; }
/** * returns timeaccount-contract relation * @param Sales_Model_Contract $contract * @param Timetracker_Model_Timeaccount $timeaccount */ protected function _getRelation($contract, $timeaccount) { $r = new Tinebase_Model_Relation(); $ra = array('own_model' => 'Timetracker_Model_Timeaccount', 'own_backend' => 'Sql', 'own_id' => $timeaccount->getId(), 'related_degree' => 'sibling', 'remark' => 'phpunit test', 'related_model' => 'Sales_Model_Contract', 'related_backend' => 'Sql', 'related_id' => $contract->getId(), 'type' => 'CONTRACT'); $r->setFromArray($ra); return $r; }
/** * returns account_grants of given timeaccount * - this function caches its result (with cache tag 'container') * * @param Tinebase_Model_User|int $_accountId * @param Timetracker_Model_Timeaccount|string $_timeaccountId * @param bool $_ignoreAcl * @return array */ public static function getGrantsOfAccount($_accountId, $_timeaccountId, $_ignoreAcl = FALSE) { $cache = Tinebase_Core::getCache(); $cacheId = convertCacheId('getGrantsOfAccount' . Tinebase_Model_User::convertUserIdToInt($_accountId) . ($_timeaccountId instanceof Timetracker_Model_Timeaccount ? $_timeaccountId->getId() : $_timeaccountId) . $_ignoreAcl); $result = $cache->load($cacheId); if ($result === FALSE) { $timeaccount = $_timeaccountId instanceof Timetracker_Model_Timeaccount ? $_timeaccountId : Timetracker_Controller_Timeaccount::getInstance()->get($_timeaccountId); $containerGrantsArray = Tinebase_Container::getInstance()->getGrantsOfAccount($_accountId, $timeaccount->container_id, 'Timetracker_Model_TimeaccountGrants')->toArray(); $account_grants = new Timetracker_Model_TimeaccountGrants($containerGrantsArray); $result = $account_grants->toArray(); $cache->save($result, $cacheId, array('container')); } return $result; }