/**
  * the singleton pattern
  *
  * @return Tinebase_Notes
  */
 public static function getInstance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = new Tinebase_Notes();
     }
     return self::$_instance;
 }
 /**
  * try to add a note type
  *
  */
 public function testSearchNotes()
 {
     Tinebase_Notes::getInstance()->addNote($this->_objects['note']);
     $filter = array(array('field' => 'query', 'operator' => 'contains', 'value' => 'phpunit'));
     $paging = array();
     $notes = $this->_instance->searchNotes($filter, $paging);
     $this->assertGreaterThan(0, $notes['totalcount']);
     $this->assertEquals($this->_objects['note']->note, $notes['results'][0]['note']);
     // delete note
     Tinebase_Notes::getInstance()->deleteNotesOfRecord($this->_objects['record']['model'], $this->_objects['record']['backend'], $this->_objects['record']['id']);
 }
 /**
  * try to get notes of multiple records (adding 'changed' note first)
  * 
  * @return void
  */
 public function testGetMultipleNotes()
 {
     $personasContactIds = array();
     foreach ($this->_personas as $persona) {
         $personasContactIds[] = $persona->contact_id;
     }
     $contacts = Addressbook_Controller_Contact::getInstance()->getMultiple($personasContactIds);
     // add note to contacts
     foreach ($contacts as $contact) {
         $this->_instance->addNote(new Tinebase_Model_Note(array('note' => 'very important note!', 'note_type_id' => Tinebase_Notes::getInstance()->getNoteTypes()->getFirstRecord()->getId(), 'record_id' => $contact->getId(), 'record_model' => 'Addressbook_Model_Contact')));
     }
     $this->_instance->getMultipleNotesOfRecords($contacts);
     foreach ($contacts as $contact) {
         $this->assertGreaterThan(0, count($contact->notes), 'No notes found for contact ' . $contact->n_fn);
     }
 }
 /**
  * testCreateEvent
  */
 public function testCreateEvent()
 {
     $scleverDisplayContainerId = Tinebase_Core::getPreference('Calendar')->getValueForUser(Calendar_Preference::DEFAULTCALENDAR, $this->_personas['sclever']->getId());
     $contentSeqBefore = Tinebase_Container::getInstance()->getContentSequence($scleverDisplayContainerId);
     $eventData = $this->_getEvent()->toArray();
     $tag = Tinebase_Tags::getInstance()->createTag(new Tinebase_Model_Tag(array('name' => 'phpunit-' . substr(Tinebase_Record_Abstract::generateUID(), 0, 10), 'type' => Tinebase_Model_Tag::TYPE_PERSONAL)));
     $eventData['tags'] = array($tag->toArray());
     $note = new Tinebase_Model_Note(array('note' => 'very important note!', 'note_type_id' => Tinebase_Notes::getInstance()->getNoteTypes()->getFirstRecord()->getId()));
     $eventData['notes'] = array($note->toArray());
     $persistentEventData = $this->_uit->saveEvent($eventData);
     $loadedEventData = $this->_uit->getEvent($persistentEventData['id']);
     $this->_assertJsonEvent($eventData, $loadedEventData, 'failed to create/load event');
     $contentSeqAfter = Tinebase_Container::getInstance()->getContentSequence($scleverDisplayContainerId);
     $this->assertEquals($contentSeqBefore + 1, $contentSeqAfter, 'content sequence of display container should be increased by 1:' . $contentSeqAfter);
     $this->assertEquals($contentSeqAfter, Tinebase_Container::getInstance()->get($scleverDisplayContainerId)->content_seq);
     return $loadedEventData;
 }
 /**
  * try to add a note type
  */
 public function testSearchNotes()
 {
     $contact = Addressbook_Controller_Contact::getInstance()->create(new Addressbook_Model_Contact(array('n_family' => 'Schulz')));
     $note = $this->_objects['note'];
     $note->record_id = $contact->getId();
     Tinebase_Notes::getInstance()->addNote($note);
     $filter = array(array('field' => 'query', 'operator' => 'contains', 'value' => 'phpunit'), array('field' => "record_model", 'operator' => "equals", 'value' => $this->_objects['record']['model']), array('field' => 'record_id', 'operator' => 'equals', 'value' => $contact->getId()));
     $paging = array();
     $notes = $this->_instance->searchNotes($filter, $paging);
     $this->assertGreaterThan(0, $notes['totalcount']);
     $found = false;
     foreach ($notes['results'] as $note) {
         if ($this->_objects['note']->note === $note['note']) {
             $found = true;
         }
     }
     $this->assertTrue($found, 'note not found in notes: ' . print_r($notes['results'], true));
     // delete note
     Tinebase_Notes::getInstance()->deleteNotesOfRecord($this->_objects['record']['model'], $this->_objects['record']['backend'], $contact->getId());
 }
Exemple #6
0
 /**
  * returns multiple records prepared for json transport
  *
  * @param Tinebase_Record_RecordSet $_records Tinebase_Record_Abstract
  * @param Tinebase_Model_Filter_FilterGroup $_filter
  * @param Tinebase_Model_Pagination $_pagination needed for sorting
  * @return array data
  * 
  * @todo perhaps we need to resolveContainerTagsUsers() before  mergeAndRemoveNonMatchingRecurrences(), but i'm not sure about that
  * @todo use Calendar_Convert_Event_Json
  */
 protected function _multipleRecordsToJson(Tinebase_Record_RecordSet $_records, $_filter = NULL, $_pagination = NULL)
 {
     if ($_records->getRecordClassName() == 'Calendar_Model_Event') {
         if (is_null($_filter)) {
             throw new Tinebase_Exception_InvalidArgument('Required argument $_filter is missing');
         }
         Tinebase_Notes::getInstance()->getMultipleNotesOfRecords($_records);
         Calendar_Model_Attender::resolveAttendee($_records->attendee, TRUE, $_records);
         Calendar_Convert_Event_Json::resolveOrganizer($_records);
         Calendar_Convert_Event_Json::resolveRrule($_records);
         Calendar_Controller_Event::getInstance()->getAlarms($_records);
         Calendar_Model_Rrule::mergeAndRemoveNonMatchingRecurrences($_records, $_filter);
         $_records->sortByPagination($_pagination);
         $eventsData = parent::_multipleRecordsToJson($_records);
         foreach ($eventsData as $eventData) {
             if (!array_key_exists(Tinebase_Model_Grants::GRANT_READ, $eventData) || !$eventData[Tinebase_Model_Grants::GRANT_READ]) {
                 $eventData['notes'] = array();
                 $eventData['tags'] = array();
             }
         }
         return $eventsData;
     }
     return parent::_multipleRecordsToJson($_records);
 }
 /**
  * delete linked objects (notes, relations, ...) of record
  *
  * @param Tinebase_Record_Interface $_record
  */
 protected function _deleteLinkedObjects(Tinebase_Record_Interface $_record)
 {
     // delete notes & relations
     if ($_record->has('notes')) {
         Tinebase_Notes::getInstance()->deleteNotesOfRecord($this->_modelName, $this->_getBackendType(), $_record->getId());
     }
     if ($_record->has('relations')) {
         $this->_deleteLinkedRelations($_record);
     }
     if ($_record->has('attachments') && Tinebase_Core::isFilesystemAvailable()) {
         Tinebase_FileSystem_RecordAttachments::getInstance()->deleteRecordAttachments($_record);
     }
 }
 /**
  * (non-PHPdoc)
  * @see Tinebase_Controller_Record_Abstract::get()
  */
 public function get($_id, $_containerId = NULL)
 {
     if (!$this->_checkACLContainer($this->_backend->getNodeContainer($_id), 'get')) {
         throw new Tinebase_Exception_AccessDenied('No permission to get node');
     }
     $record = parent::get($_id);
     if ($record) {
         $record->notes = Tinebase_Notes::getInstance()->getNotesOfRecord('Tinebase_Model_Tree_Node', $record->getId());
     }
     return $record;
 }
 /**
  * add email notes to contacts with email addresses in $_recipients
  *
  * @param array $_recipients
  * @param string $_subject
  * 
  * @todo add email home (when we have OR filters)
  * @todo add link to message in sent folder?
  */
 protected function _addEmailNote($_recipients, $_subject, $_body)
 {
     $filter = new Addressbook_Model_ContactFilter(array(array('field' => 'email', 'operator' => 'in', 'value' => $_recipients)));
     $contacts = Addressbook_Controller_Contact::getInstance()->search($filter);
     if (count($contacts)) {
         $translate = Tinebase_Translation::getTranslation($this->_applicationName);
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Adding email notes to ' . count($contacts) . ' contacts.');
         $truncatedBody = extension_loaded('mbstring') ? mb_substr($_body, 0, 4096, 'UTF-8') : substr($_body, 0, 4096);
         $noteText = $translate->_('Subject') . ':' . $_subject . "\n\n" . $translate->_('Body') . ': ' . $truncatedBody;
         try {
             foreach ($contacts as $contact) {
                 $note = new Tinebase_Model_Note(array('note_type_id' => Tinebase_Notes::getInstance()->getNoteTypeByName('email')->getId(), 'note' => $noteText, 'record_id' => $contact->getId(), 'record_model' => 'Addressbook_Model_Contact'));
                 Tinebase_Notes::getInstance()->addNote($note);
             }
         } catch (Zend_Db_Statement_Exception $zdse) {
             Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' Saving note failed: ' . $noteText);
             Tinebase_Exception::log($zdse);
         }
     } else {
         Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Found no contacts to add notes to.');
     }
 }
 /**
  * converts Tinebase_Record_RecordSet to external format
  * 
  * @param Tinebase_Record_RecordSet         $_records
  * @param Tinebase_Model_Filter_FilterGroup $_filter
  * @param Tinebase_Model_Pagination         $_pagination
  *
  * @return mixed
  */
 public function fromTine20RecordSet(Tinebase_Record_RecordSet $_records = NULL, $_filter = NULL, $_pagination = NULL)
 {
     if (count($_records) == 0) {
         return array();
     }
     Tinebase_Notes::getInstance()->getMultipleNotesOfRecords($_records);
     Tinebase_Tags::getInstance()->getMultipleTagsOfRecords($_records);
     if (Tinebase_Core::isFilesystemAvailable()) {
         Tinebase_FileSystem_RecordAttachments::getInstance()->getMultipleAttachmentsOfRecords($_records);
     }
     Calendar_Model_Attender::resolveAttendee($_records->attendee, TRUE, $_records);
     Calendar_Convert_Event_Json::resolveRrule($_records);
     Calendar_Controller_Event::getInstance()->getAlarms($_records);
     Calendar_Convert_Event_Json::resolveGrantsOfExternalOrganizers($_records);
     Calendar_Model_Rrule::mergeAndRemoveNonMatchingRecurrences($_records, $_filter);
     $_records->sortByPagination($_pagination);
     Tinebase_Frontend_Json_Abstract::resolveContainersAndTags($_records, array('container_id'));
     $_records->setTimezone(Tinebase_Core::getUserTimezone());
     $_records->convertDates = true;
     $eventsData = $_records->toArray();
     foreach ($eventsData as $idx => $eventData) {
         if (!(isset($eventData[Tinebase_Model_Grants::GRANT_READ]) || array_key_exists(Tinebase_Model_Grants::GRANT_READ, $eventData)) || !$eventData[Tinebase_Model_Grants::GRANT_READ]) {
             $eventsData[$idx] = array_intersect_key($eventsData[$idx], array_flip(array('id', 'dtstart', 'dtend', 'transp', 'is_all_day_event')));
         }
     }
     return $eventsData;
 }
 /**
  * try to add a lead
  *
  */
 public function testAddLead()
 {
     $translate = Tinebase_Translation::getTranslation('Tinebase');
     $lead = $this->_objects['initialLead'];
     $lead->notes = new Tinebase_Record_RecordSet('Tinebase_Model_Note', array($this->objects['note']));
     $lead = Crm_Controller_Lead::getInstance()->create($lead);
     $GLOBALS['Addressbook_ControllerTest']['leadId'] = $lead->getId();
     $this->assertEquals($GLOBALS['Addressbook_ControllerTest']['leadId'], $lead->id);
     $this->assertEquals($this->_objects['initialLead']->description, $lead->description);
     $notes = Tinebase_Notes::getInstance()->getNotesOfRecord('Crm_Model_Lead', $lead->getId());
     //print_r($notes->toArray());
     $createdNoteType = Tinebase_Notes::getInstance()->getNoteTypeByName('created');
     foreach ($notes as $note) {
         if ($note->note_type_id === $createdNoteType->getId()) {
             $translatedMessage = $translate->_('created') . ' ' . $translate->_('by') . ' ';
             $this->assertEquals($translatedMessage . Zend_Registry::get('currentAccount')->accountDisplayName, $note->note);
         } else {
             $this->assertEquals($this->objects['note']->note, $note->note);
         }
     }
 }
 /**
  * inspect update of one record
  *
  * @param   Tinebase_Record_Interface $_record the update record
  * @param   Tinebase_Record_Interface $_oldRecord the current persistent record
  * @throws Tinebase_Exception_AccessDenied
  * @todo remove system note for updated jpegphoto when images are modlogged (@see 0000284: modlog of contact images / move images to vfs)
  */
 protected function _inspectBeforeUpdate($_record, $_oldRecord)
 {
     /** @var Addressbook_Model_Contact $_record */
     /** @var Addressbook_Model_Contact $_oldRecord */
     // do update of geo data only if one of address field changed
     $addressDataChanged = FALSE;
     foreach ($this->_addressFields as $field) {
         if ($_record->{'adr_one_' . $field} != $_oldRecord->{'adr_one_' . $field} || $_record->{'adr_two_' . $field} != $_oldRecord->{'adr_two_' . $field}) {
             $addressDataChanged = TRUE;
             break;
         }
     }
     if ($addressDataChanged) {
         $this->_setGeoData($_record);
     }
     if (isset($_record->jpegphoto) && !empty($_record->jpegphoto)) {
         // add system note when jpegphoto gets updated
         $translate = $translate = Tinebase_Translation::getTranslation('Addressbook');
         $noteMessage = $translate->_('Uploaded new contact image.');
         $traceException = new Exception($noteMessage);
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $traceException);
         }
         Tinebase_Notes::getInstance()->addSystemNote($_record, Tinebase_Core::getUser(), Tinebase_Model_Note::SYSTEM_NOTE_NAME_CHANGED, $noteMessage);
     }
     if (isset($_oldRecord->type) && $_oldRecord->type == Addressbook_Model_Contact::CONTACTTYPE_USER) {
         $_record->type = Addressbook_Model_Contact::CONTACTTYPE_USER;
     }
     if (!empty($_record->account_id) || $_record->type == Addressbook_Model_Contact::CONTACTTYPE_USER) {
         // first check if something changed that requires special rights
         $changeAccount = false;
         foreach (Addressbook_Model_Contact::getManageAccountFields() as $field) {
             if ($_record->{$field} != $_oldRecord->{$field}) {
                 $changeAccount = true;
                 break;
             }
         }
         // if so, check rights
         if ($changeAccount) {
             if (!Tinebase_Core::getUser()->hasRight('Admin', Admin_Acl_Rights::MANAGE_ACCOUNTS)) {
                 throw new Tinebase_Exception_AccessDenied('No permission to change account properties.');
             }
         }
     }
 }
 /**
  * delete linked objects (notes, relations, ...) of record
  *
  * @param Tinebase_Record_Interface $_record
  */
 protected function _deleteLinkedObjects(Tinebase_Record_Interface $_record)
 {
     // delete notes & relations
     if ($_record->has('notes')) {
         Tinebase_Notes::getInstance()->deleteNotesOfRecord($this->_modelName, $this->_getBackendType(), $_record->getId());
     }
     if ($_record->has('relations')) {
         // TODO check if this needs to be done, as we might already deleting this "from the other side"
         $this->deleteLinkedRelations($_record);
     }
     if ($_record->has('attachments') && Tinebase_Core::isFilesystemAvailable()) {
         Tinebase_FileSystem_RecordAttachments::getInstance()->deleteRecordAttachments($_record);
     }
 }
 /**
  * test send message
  */
 public function testSendMessage()
 {
     // set email to unittest@tine20.org
     $contactFilter = new Addressbook_Model_ContactFilter(array(array('field' => 'n_family', 'operator' => 'equals', 'value' => 'Clever')));
     $contactIds = Addressbook_Controller_Contact::getInstance()->search($contactFilter, NULL, FALSE, TRUE);
     $contact = Addressbook_Controller_Contact::getInstance()->get($contactIds[0]);
     $originalEmail = $contact->email;
     $contact->email = $this->_account->email;
     $contact = Addressbook_Controller_Contact::getInstance()->update($contact, FALSE);
     // send email
     $messageToSend = $this->_getMessageData('unittest@' . $this->_mailDomain);
     $messageToSend['note'] = 1;
     $messageToSend['bcc'] = array('unittest@' . $this->_mailDomain);
     //print_r($messageToSend);
     $returned = $this->_json->saveMessage($messageToSend);
     $this->_foldersToClear = array('INBOX', $this->_account->sent_folder);
     // check if message is in sent folder
     $message = $this->_searchForMessageBySubject($messageToSend['subject'], $this->_account->sent_folder);
     $this->assertEquals($message['from_email'], $messageToSend['from_email']);
     $this->assertTrue(isset($message['to'][0]));
     $this->assertEquals($message['to'][0], $messageToSend['to'][0], 'recipient not found');
     $this->assertEquals($message['bcc'][0], $messageToSend['bcc'][0], 'bcc recipient not found');
     $this->assertEquals($message['subject'], $messageToSend['subject']);
     // check if email note has been added to contact(s)
     $contact = Addressbook_Controller_Contact::getInstance()->get($contact->getId());
     $emailNoteType = Tinebase_Notes::getInstance()->getNoteTypeByName('email');
     // check / delete notes
     $emailNoteIds = array();
     foreach ($contact->notes as $note) {
         if ($note->note_type_id == $emailNoteType->getId()) {
             $this->assertEquals(1, preg_match('/' . $messageToSend['subject'] . '/', $note->note));
             $this->assertEquals(Tinebase_Core::getUser()->getId(), $note->created_by);
             $this->assertContains('teste', $note->note);
             $emailNoteIds[] = $note->getId();
         }
     }
     $this->assertGreaterThan(0, count($emailNoteIds), 'no email notes found');
     Tinebase_Notes::getInstance()->deleteNotes($emailNoteIds);
     // reset sclevers original email address
     $contact->email = $originalEmail;
     Addressbook_Controller_Contact::getInstance()->update($contact, FALSE);
 }
 /**
  * inspect update of one record
  * 
  * @param   Tinebase_Record_Interface $_record      the update record
  * @param   Tinebase_Record_Interface $_oldRecord   the current persistent record
  * @return  void
  * 
  * @todo remove system note for updated jpegphoto when images are modlogged (@see 0000284: modlog of contact images / move images to vfs)
  */
 protected function _inspectBeforeUpdate($_record, $_oldRecord)
 {
     // do update of geo data only if one of address field changed
     $addressDataChanged = FALSE;
     foreach ($this->_addressFields as $field) {
         if ($_record->{'adr_one_' . $field} != $_oldRecord->{'adr_one_' . $field} || $_record->{'adr_two_' . $field} != $_oldRecord->{'adr_two_' . $field}) {
             $addressDataChanged = TRUE;
             break;
         }
     }
     if ($addressDataChanged) {
         $this->_setGeoData($_record);
     }
     if (isset($_record->jpegphoto) && !empty($_record->jpegphoto)) {
         // add system note when jpegphoto gets updated
         $translate = $translate = Tinebase_Translation::getTranslation('Addressbook');
         $noteMessage = $translate->_('Uploaded new contact image.');
         $traceException = new Exception($noteMessage);
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $traceException);
         }
         Tinebase_Notes::getInstance()->addSystemNote($_record, Tinebase_Core::getUser(), Tinebase_Model_Note::SYSTEM_NOTE_NAME_CHANGED, $noteMessage);
     }
     if (isset($_oldRecord->type) && $_oldRecord->type == Addressbook_Model_Contact::CONTACTTYPE_USER) {
         $_record->type = Addressbook_Model_Contact::CONTACTTYPE_USER;
     }
 }
 /**
  * add notes and activities to pdf
  *
  * @param array $record
  * @param Tinebase_Record_RecordSet $_notes
  */
 protected function _addActivities($record, $_notes)
 {
     $translate = Tinebase_Translation::getTranslation('Tinebase');
     if (!empty($_notes)) {
         $noteTypes = Tinebase_Notes::getInstance()->getNoteTypes();
         $record[] = array('label' => $translate->_('Activities'), 'type' => 'separator');
         foreach ($_notes as $note) {
             if ($note instanceof Tinebase_Model_Note) {
                 $noteArray = $note->toArray();
                 $noteText = strlen($note->note) > 100 ? substr($note->note, 0, 99) . '...' : $note->note;
                 $noteType = $noteTypes[$noteTypes->getIndexById($note->note_type_id)];
                 $time = Tinebase_Translation::dateToStringInTzAndLocaleFormat($note->creation_time);
                 $createdBy = '(' . $noteArray['created_by'] . ')';
                 $record[] = array('label' => $time, 'type' => 'multiRow', 'value' => array(array('icon' => '/' . $noteType->icon), $noteText, $createdBy));
             }
         }
     }
     return $record;
 }
Exemple #17
0
 /**
  * resolve records
  *
  * @param Tinebase_Record_RecordSet $_records
  */
 protected function _resolveRecords(Tinebase_Record_RecordSet $_records)
 {
     // get field types/identifiers from config
     $identifiers = array();
     if ($this->_config->columns) {
         $types = array();
         foreach ($this->_config->columns->column as $column) {
             $types[] = $column->type;
             $identifiers[] = $column->identifier;
         }
         $types = array_unique($types);
     } else {
         $types = $this->_resolvedFields;
     }
     // resolve users
     foreach ($this->_userFields as $field) {
         if (in_array($field, $types) || in_array($field, $identifiers)) {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Resolving users for ' . $field);
             }
             Tinebase_User::getInstance()->resolveMultipleUsers($_records, $field, TRUE);
         }
     }
     // add notes
     if (in_array('notes', $types)) {
         Tinebase_Notes::getInstance()->getMultipleNotesOfRecords($_records, 'notes', 'Sql', FALSE);
     }
     // add container
     if (in_array('container_id', $types)) {
         Tinebase_Container::getInstance()->getGrantsOfRecords($_records, Tinebase_Core::getUser());
     }
 }
 /**
  * add email notes to contacts with email addresses in $_recipients
  *
  * @param array $_recipients
  * @param string $_subject
  *
  * @todo add email home (when we have OR filters)
  * @todo add link to message in sent folder?
  */
 protected function _addEmailNote($_recipients, $_subject, $_body)
 {
     //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . print_r($_recipients, TRUE));
     $filter = new Addressbook_Model_ContactFilter(array(array('field' => 'email', 'operator' => 'in', 'value' => $_recipients)));
     $contacts = Addressbook_Controller_Contact::getInstance()->search($filter);
     if (count($contacts)) {
         $translate = Tinebase_Translation::getTranslation($this->_applicationName);
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Adding email notes to ' . count($contacts) . ' contacts.');
         $noteText = $translate->_('Subject') . ':' . $_subject . "\n\n" . $translate->_('Body') . ':' . substr($_body, 0, 4096);
         foreach ($contacts as $contact) {
             $note = new Tinebase_Model_Note(array('note_type_id' => Tinebase_Notes::getInstance()->getNoteTypeByName('email')->getId(), 'note' => $noteText, 'record_id' => $contact->getId(), 'record_model' => 'Addressbook_Model_Contact'));
             Tinebase_Notes::getInstance()->addNote($note);
         }
     } else {
         Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Found no contacts to add notes to.');
     }
 }
 /**
  * resolve multiple record fields (Tinebase_ModelConfiguration._recordsFields)
  * 
  * @param Tinebase_Record_RecordSet $_records
  * @param Tinebase_ModelConfiguration $modelConfiguration
  * @param boolean $multiple
  * @throws Tinebase_Exception_UnexpectedValue
  */
 protected function _resolveMultipleRecordFields(Tinebase_Record_RecordSet $_records, $modelConfiguration = NULL, $multiple = false)
 {
     if (!$modelConfiguration || !$_records->count()) {
         return;
     }
     if (!($resolveFields = $modelConfiguration->recordsFields)) {
         return;
     }
     $ownIds = $_records->{$modelConfiguration->idProperty};
     // iterate fields to resolve
     foreach ($resolveFields as $fieldKey => $c) {
         $config = $c['config'];
         // resolve records, if omitOnSearch is definitively set to FALSE (by default they won't be resolved on search)
         if ($multiple && !(isset($config['omitOnSearch']) && $config['omitOnSearch'] === FALSE)) {
             continue;
         }
         if (!isset($config['controllerClassName'])) {
             throw new Tinebase_Exception_UnexpectedValue('Controller class name needed');
         }
         // fetch the fields by the refIfField
         /** @var Tinebase_Controller_Record_Interface|Tinebase_Controller_SearchInterface $controller */
         /** @noinspection PhpUndefinedMethodInspection */
         $controller = $config['controllerClassName']::getInstance();
         $filterName = $config['filterClassName'];
         $filterArray = array();
         // addFilters can be added and must be added if the same model resides in more than one records fields
         if (isset($config['addFilters']) && is_array($config['addFilters'])) {
             $filterArray = $config['addFilters'];
         }
         /** @var Tinebase_Model_Filter_FilterGroup $filter */
         $filter = new $filterName($filterArray);
         $filter->addFilter(new Tinebase_Model_Filter_Id(array('field' => $config['refIdField'], 'operator' => 'in', 'value' => $ownIds)));
         $paging = NULL;
         if (isset($config['paging']) && is_array($config['paging'])) {
             $paging = new Tinebase_Model_Pagination($config['paging']);
         }
         $foreignRecords = $controller->search($filter, $paging);
         /** @var Tinebase_Record_Interface $foreignRecordClass */
         $foreignRecordClass = $foreignRecords->getRecordClassName();
         $foreignRecordModelConfiguration = $foreignRecordClass::getConfiguration();
         $foreignRecords->setTimezone(Tinebase_Core::getUserTimezone());
         $foreignRecords->convertDates = true;
         $fr = $foreignRecords->getFirstRecord();
         // @todo: resolve alarms?
         // @todo: use parts parameter?
         if ($foreignRecordModelConfiguration->resolveRelated && $fr) {
             if ($fr->has('notes')) {
                 Tinebase_Notes::getInstance()->getMultipleNotesOfRecords($foreignRecords);
             }
             if ($fr->has('tags')) {
                 Tinebase_Tags::getInstance()->getMultipleTagsOfRecords($foreignRecords);
             }
             if ($fr->has('relations')) {
                 $relations = Tinebase_Relations::getInstance()->getMultipleRelations($foreignRecordClass, 'Sql', $foreignRecords->{$fr->getIdProperty()});
                 $foreignRecords->setByIndices('relations', $relations);
             }
             if ($fr->has('customfields')) {
                 Tinebase_CustomField::getInstance()->resolveMultipleCustomfields($foreignRecords);
             }
             if ($fr->has('attachments') && Tinebase_Core::isFilesystemAvailable()) {
                 Tinebase_FileSystem_RecordAttachments::getInstance()->getMultipleAttachmentsOfRecords($foreignRecords);
             }
         }
         if ($foreignRecords->count() > 0) {
             /** @var Tinebase_Record_Interface $record */
             foreach ($_records as $record) {
                 $filtered = $foreignRecords->filter($config['refIdField'], $record->getId())->toArray();
                 $filtered = $this->_resolveAfterToArray($filtered, $foreignRecordModelConfiguration, TRUE);
                 $record->{$fieldKey} = $filtered;
             }
         } else {
             $_records->{$fieldKey} = NULL;
         }
     }
 }
 /**
  * check email note
  *
  * @param Addressbook_Model_Contact $contact
  * @param string $subject
  */
 protected function _checkEmailNote($contact, $subject)
 {
     // check if email note has been added to contact(s)
     $contact = Addressbook_Controller_Contact::getInstance()->get($contact->getId());
     $emailNoteType = Tinebase_Notes::getInstance()->getNoteTypeByName('email');
     // check / delete notes
     $emailNoteIds = array();
     foreach ($contact->notes as $note) {
         if ($note->note_type_id == $emailNoteType->getId()) {
             $this->assertContains($subject, $note->note, 'did not find note subject');
             $this->assertEquals(Tinebase_Core::getUser()->getId(), $note->created_by);
             $this->assertContains('aaaaaä', $note->note);
             $emailNoteIds[] = $note->getId();
         }
     }
     $this->assertGreaterThan(0, count($emailNoteIds), 'no email notes found');
     Tinebase_Notes::getInstance()->deleteNotes($emailNoteIds);
 }
Exemple #21
0
 /**
  * delete linked objects (notes, relations, ...) of record
  *
  * @param Tinebase_Record_Interface $_record
  */
 protected function _deleteLinkedObjects(Tinebase_Record_Interface $_record)
 {
     // delete notes & relations
     if ($_record->has('notes')) {
         Tinebase_Notes::getInstance()->deleteNotesOfRecord($this->_modelName, $this->_backend->getType(), $_record->getId());
     }
     if ($_record->has('relations')) {
         $relations = Tinebase_Relations::getInstance()->getRelations($this->_modelName, $this->_backend->getType(), $_record->getId());
         if (!empty($relations)) {
             // remove relations
             Tinebase_Relations::getInstance()->setRelations($this->_modelName, $this->_backend->getType(), $_record->getId(), array());
             // remove related objects
             if (!empty($this->_relatedObjectsToDelete)) {
                 foreach ($relations as $relation) {
                     if (in_array($relation->related_model, $this->_relatedObjectsToDelete)) {
                         list($appName, $i, $itemName) = explode('_', $relation->related_model);
                         $appController = Tinebase_Core::getApplicationInstance($appName, $itemName);
                         $appController->delete($relation->related_id);
                     }
                 }
             }
         }
     }
 }
Exemple #22
0
 /**
  * get note types
  *
  */
 public function getNoteTypes()
 {
     $noteTypes = Tinebase_Notes::getInstance()->getNoteTypes();
     $noteTypes->translate();
     return array('results' => $noteTypes->toArray(), 'totalcount' => count($noteTypes));
 }
 /**
  * update to 0.16
  * - add icon class to note types
  */
 public function update_15()
 {
     $declaration = new Setup_Backend_Schema_Field_Xml('
         <field>
             <name>icon_class</name>
             <type>text</type>
             <length>128</length>
             <notnull>true</notnull>
         </field>
     ');
     $this->_backend->addCol('note_types', $declaration);
     // delete all note types and add new ones with icon class
     $noteTypes = Tinebase_Notes::getInstance()->getNoteTypes();
     $toUpdate = array(1 => 'notes_noteIcon', 2 => 'notes_telephoneIcon', 3 => 'notes_emailIcon', 4 => 'notes_createdIcon', 5 => 'notes_changedIcon');
     foreach ($noteTypes as $type) {
         $type->icon_class = $toUpdate[$type->getId()];
         Tinebase_Notes::getInstance()->updateNoteType($type);
     }
     $this->setApplicationVersion('Tinebase', '0.16');
 }