[Vtigercrm-developers] vtigercrm-developers Digest, Vol 71, Issue 2
Antoni Bertran
antoni at tresipunt.com
Sat Dec 17 11:29:45 PST 2011
Thanks Nathalia,
I added one table to save the relations
CREATE TABLE IF NOT EXISTS `vtiger_activity_relations` (
`id` int(11) NOT NULL,
`id_related` int(11) NOT NULL,
PRIMARY KEY (`id`,`id_related`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Then I modified the code of RepeatEvents.php and I added two functions:
/**
*
* Save data of relation (Antoni Bertran 20111217)
* @param int $id
* @param int $id_related
*/
static function save_relation($id, $id_related) {
//
global $adb;
$sql = "insert into vtiger_activity_relations values (?,?)";
return $adb->pquery($sql, array($id, $id_related));
}
/**
*
* Delete previous relation (Antoni Bertran 20111217)
* @param int $id
* @param int $id_related
*/
static function delete_previous_relation($id) {
//
global $adb;
$new_focus = new Activity();
//Antoni Eliminem els fills repetits 20111217
$fieldRes = $adb->pquery('SELECT id_related FROM vtiger_activity_relations
WHERE id=?', array($id));
$numOfFields = $adb->num_rows($fieldRes);
for ($i=0; $i<$numOfFields; $i++) {
$id_related = $adb->query_result($fieldRes, $i, 'id_related');
$new_focus->trash('Calendar', $id_related);
}
return $adb->pquery('DELETE FROM vtiger_activity_relations WHERE id=?',
array($id));
}
Then I call from repeat function
/**
* Repeat Activity instance till given limit.
*/
static function repeat($focus) {
global $log;
$repeat = getrecurringObjValue();
*//Antoni gets id*
* $id = $focus->id;*
* //Antoni delete previous relation*
* self::delete_previous_relation($id);*
* *$frequency = $repeat->recur_freq;
$repeattype= $repeat->recur_type;
$base_focus = new Activity();
$base_focus->retrieve_entity_info($focus->id,'Events');
$base_focus->id = $_REQUEST['record'];
$base_focus_start = $base_focus->column_fields['date_start'].'
'.$base_focus->column_fields['time_start'];
$base_focus_end = $base_focus->column_fields['due_date'].'
'.$base_focus->column_fields['time_end'];
$repeat_limit =
getDBInsertDateValue($_REQUEST['calendar_repeat_limit_date']).'
'.$base_focus->column_fields['time_start'];
$repeatIntervals = self::getRepeatInterval($repeattype, $frequency,
$repeat, $base_focus_start, $repeat_limit);
$base_focus_start = self::mktime($base_focus_start);
$base_focus_end = self::mktime($base_focus_end);
$skip_focus_fields = Array ('record_id', 'createdtime', 'modifiedtime',
'recurringtype');
/** Create instance before and reuse */
$new_focus = new Activity();
$numberOfRepeats = count($repeatIntervals);
foreach($repeatIntervals as $index => $interval) {
$new_focus_start_timing = self::nexttime($base_focus_start, "+$interval
days");
$new_focus_start_timing =
self::splittime(self::formattime($new_focus_start_timing));
$new_focus_end_timing = self::nexttime($base_focus_end, "+$interval days");
$new_focus_end_timing =
self::splittime(self::formattime($new_focus_end_timing));
// Reset the new_focus and prepare for reuse
if(isset($new_focus->id)) unset($new_focus->id);
$new_focus->column_fields = array();
foreach($base_focus->column_fields as $key=>$value) {
if(in_array($key, $skip_focus_fields)) {
// skip copying few fields
} else if($key == 'date_start') {
$new_focus->column_fields['date_start'] = $new_focus_start_timing[0];
} else if($key == 'time_start') {
$new_focus->column_fields['time_start'] = $new_focus_start_timing[1];
} else if($key == 'time_end') {
$new_focus->column_fields['time_end'] = $new_focus_end_timing[1];
} else if($key == 'due_date') {
$new_focus->column_fields['due_date'] = $new_focus_end_timing[0];
} else {
//$new_focus->column_fields[$key] = $value;
//Antoni 20111217 per evitar que surti els acutes obtenint els valors
orginals
$new_focus->column_fields[$key] = $_REQUEST[$key];
}
}
//Antoni Don't send repeats emails 20121217
//if($numberOfRepeats > 10 && $index > 10) {
unset($new_focus->column_fields['sendnotification']);
//}
$new_focus->save('Calendar');
* //Antoni obtenim ID del fill creat per relacionar-ho*
*$id_related = $new_focus->id;*
* self::save_relation($id, $id_related);*
}
}
Then the last hack is in Activity.php
// Function to unlink all the dependent entities of the given Entity by Id
function unlinkDependencies($module, $id) {
global $log;
$sql = 'DELETE FROM vtiger_activity_reminder WHERE activity_id=?';
$this->db->pquery($sql, array($id));
$sql = 'DELETE FROM vtiger_recurringevents WHERE activityid=?';
$this->db->pquery($sql, array($id));
* //Antoni repeats delete*
* $fieldRes = $this->db->pquery('SELECT id_related FROM
vtiger_activity_relations WHERE id=?', array($id));*
* $numOfFields = $this->db->num_rows($fieldRes);*
* for ($i=0; $i<$numOfFields; $i++) {*
* $id_related = $this->db->query_result($fieldRes, $i, 'id_related');*
* $this->mark_deleted($id_related);*
* $this->unlinkDependencies($module, $id_related);*
* }*
parent::unlinkDependencies($module, $id);
}
I tested and works correctly, there is only one important thing to know if
you modify a related Task and then go back and modify parent task, the
modifications on related task will be lost.
Bests Regards,
Antoni Bertran Bellido
3&Punt Solucions Informàtiques SLL
935325991 - 935325992
C.Aragó 390, àtic 3
08013 Barcelona
www.tresipunt.com
Tel 935325991
Mob 677410818
Fax 935325992
Aquest missatge pot contenir informació confidencial, en propietat o
legalment protegida i està destinada únicament per l'ús de la persona
destinataria. Si vostè no és la persona destinataria d'aquest missatge, per
la present se'l comunica que no ha d'emprar, difondre, copiar de cap
manera, ni emprendre cap acció en relació amb ella. Si vostè ha rebut
aquest missatge per error, per favor li preguem que l'esborri, així com
qualsevol còpia del mateix i notifiqui aquest fet al remitent.
Este mensaje puede contener información confidencial, en propiedad o
legalmente protegida y está destinada únicamente para el uso de la persona
destinataria. Si usted no es la persona destinataria de este mensaje, por
la presente se le comunica que no tiene que utilizar, difundir, copiar de
ninguna manera, ni emprender ninguna acción en relación con ella. Si usted
ha recibido este mensaje por error, por favor le rogamos que lo borre, así
como cualquier copia del mismo y notifique este hecho al remitente.
2011/12/17 Nathalia França <nath.campreguer at gmail.com>
> Antoni,
>
> I'm trying to understand how Calendar module works and it relates to
> activities somehow. Researching the database i found tables where
> activities data is saved.
> I'm not sure that it's correct but i'll tell what i found maybe it will
> help you.
>
> - Vtiger_activity is the table that keeps data of the main activities.
> - Vtiger_recurringevents is the table that keeps data of the recurring
> activities(The type of activities that can be repeated are events on
> Calendar module)
>
> Both tables are related trought activityid column.
>
> I think the best way to delete and update activities is using the visual
> mode because that way you won't corrupt your database. But if you need to
> delete it in another way search for tables with events, fields and activity
> on their names. It´s quite easy to understand their relation.
>
>
> Please send me your progress it will help me too!
> Nathalia Campreguer França
>
> ---------- Forwarded message ----------
>> From: Antoni Bertran <tunyafix at gmail.com>
>> To: vtigercrm-developers at lists.vtigercrm.com
>> Cc:
>> Date: Wed, 14 Dec 2011 11:36:24 +0100
>> Subject: [Vtigercrm-developers] Repeat Activities, vtiger 5.2.1
>> Hello! I have a question about Repeat Activities. I will post my
>> questions and my assumption
>>
>> When I active the Repeat there is any difference between indicate "Until
>> date" or not? If I indicate Until Date then create N activities. If I don't
>> indicate Until Date I think the reminder doesn't work correctly.
>>
>> There is a database_schema but don't explain for what is using the
>> tables.
>> http://wiki.vtiger.com/index.php/Database_schema
>> There is any table to keep the relations between Main Activities and
>> Repeated Activities?
>>
>> To delete and update related Activities what have to do?
>>
>> Thanks!
>>
>> Antoni
>>
>>
> _______________________________________________
> http://www.vtiger.com/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20111217/9a003c13/attachment-0002.html
More information about the vtigercrm-developers
mailing list