/** * returns record prepared for json transport * * @param Tinebase_Record_Interface $_record * @return array record data */ protected function _recordToJson($_record) { switch (get_class($_record)) { case 'Timetracker_Model_Timesheet': $_record['timeaccount_id'] = $_record['timeaccount_id'] ? $this->_timeaccountController->get($_record['timeaccount_id']) : $_record['timeaccount_id']; $_record['timeaccount_id']['account_grants'] = Timetracker_Model_TimeaccountGrants::getGrantsOfAccount(Tinebase_Core::get('currentAccount'), $_record['timeaccount_id']); $_record['timeaccount_id']['account_grants'] = $this->_resolveTimesheetGrantsByTimeaccountGrants($_record['timeaccount_id']['account_grants'], $_record['account_id']); Tinebase_User::getInstance()->resolveUsers($_record, 'account_id'); $recordArray = parent::_recordToJson($_record); break; case 'Timetracker_Model_Timeaccount': $recordArray = parent::_recordToJson($_record); // When editing a single TA we send _ALL_ grants to the client $recordArray['grants'] = Timetracker_Model_TimeaccountGrants::getTimeaccountGrants($_record)->toArray(); foreach ($recordArray['grants'] as &$value) { switch ($value['account_type']) { case Tinebase_Acl_Rights::ACCOUNT_TYPE_USER: $value['account_name'] = Tinebase_User::getInstance()->getUserById($value['account_id'])->toArray(); break; case Tinebase_Acl_Rights::ACCOUNT_TYPE_GROUP: $value['account_name'] = Tinebase_Group::getInstance()->getGroupById($value['account_id'])->toArray(); break; case Tinebase_Acl_Rights::ACCOUNT_TYPE_ANYONE: $value['account_name'] = array('accountDisplayName' => 'Anyone'); break; default: throw new Tinebase_Exception_InvalidArgument('Unsupported accountType.'); break; } } break; } return $recordArray; }
/** * returns record prepared for json transport * * @param Tinebase_Record_Interface $_record * @return array record data */ protected function _recordToJson($_record) { switch (get_class($_record)) { case 'Timetracker_Model_Timesheet': $_record['timeaccount_id'] = $_record['timeaccount_id'] ? $this->_timeaccountController->get($_record['timeaccount_id']) : $_record['timeaccount_id']; $_record['timeaccount_id']['account_grants'] = Timetracker_Model_TimeaccountGrants::getGrantsOfAccount(Tinebase_Core::get('currentAccount'), $_record['timeaccount_id']); $_record['timeaccount_id']['account_grants'] = $this->_resolveTimesheetGrantsByTimeaccountGrants($_record['timeaccount_id']['account_grants'], $_record['account_id']); Tinebase_User::getInstance()->resolveUsers($_record, 'account_id'); if (Tinebase_Core::getUser()->hasRight('Sales', 'manage_invoices') && !empty($_record['invoice_id'])) { try { $_record['invoice_id'] = Sales_Controller_Invoice::getInstance()->get($_record['invoice_id']); } catch (Tinebase_Exception_NotFound $nfe) { Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not resolve invoice with id ' . $_record['invoice_id']); } } $recordArray = parent::_recordToJson($_record); break; case 'Timetracker_Model_Timeaccount': $recordArray = parent::_recordToJson($_record); // When editing a single TA we send _ALL_ grants to the client $recordArray['grants'] = Timetracker_Model_TimeaccountGrants::getTimeaccountGrants($_record)->toArray(); foreach ($recordArray['grants'] as &$value) { switch ($value['account_type']) { case Tinebase_Acl_Rights::ACCOUNT_TYPE_USER: $value['account_name'] = Tinebase_User::getInstance()->getUserById($value['account_id'])->toArray(); break; case Tinebase_Acl_Rights::ACCOUNT_TYPE_GROUP: $value['account_name'] = Tinebase_Group::getInstance()->getGroupById($value['account_id'])->toArray(); break; case Tinebase_Acl_Rights::ACCOUNT_TYPE_ANYONE: $value['account_name'] = array('accountDisplayName' => 'Anyone'); break; default: throw new Tinebase_Exception_InvalidArgument('Unsupported accountType.'); break; } } break; } return $recordArray; }