Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Extensions
civimobileapi
Commits
14d9fc64
Commit
14d9fc64
authored
Jun 26, 2020
by
BohdanDmytryshyn
Browse files
Merge branch 'release_5_2_0' into 'master'
Release 5.2.0 See merge request
!46
parents
6a8a15d7
b867bda7
Changes
79
Hide whitespace changes
Inline
Side-by-side
CRM/CiviMobileAPI/Api/CiviMobileAgendaConfig/Create.php
0 → 100644
View file @
14d9fc64
<?php
class
CRM_CiviMobileAPI_Api_CiviMobileAgendaConfig_Create
extends
CRM_CiviMobileAPI_Api_CiviMobileBase
{
/**
* Returns results to api
*
* @return array
* @throws api_Exception
*/
public
function
getResult
()
{
$agendaConfig
=
new
CRM_CiviMobileAPI_BAO_AgendaConfig
();
$agendaConfig
->
event_id
=
$this
->
validParams
[
"event_id"
];
$agendaConfig
->
find
(
TRUE
);
$agendaConfig
->
is_active
=
$this
->
validParams
[
"is_active"
];
$agendaConfig
->
save
();
return
[
[
'id'
=>
$agendaConfig
->
id
,
'is_active'
=>
$agendaConfig
->
is_active
,
'event_id'
=>
$agendaConfig
->
event_id
]
];
}
/**
* Returns validated params
*
* @param $params
*
* @return array
* @throws api_Exception
*/
protected
function
getValidParams
(
$params
)
{
if
(
!
CRM_CiviMobileAPI_Utils_Permission
::
isEnoughPermissionForCreateAgendaConfig
())
{
throw
new
api_Exception
(
'You don`t have enough permissions.'
,
'do_not_have_enough_permissions'
);
}
try
{
CRM_Event_BAO_Event
::
findById
(
$params
[
"event_id"
]);
}
catch
(
Exception
$e
)
{
throw
new
api_Exception
(
'This event does not exists.'
,
'event_does_not_exists'
);
}
return
[
'is_active'
=>
$params
[
'is_active'
],
'event_id'
=>
$params
[
'event_id'
],
];
}
}
CRM/CiviMobileAPI/Api/CiviMobileAgendaConfig/Get.php
0 → 100644
View file @
14d9fc64
<?php
class
CRM_CiviMobileAPI_Api_CiviMobileAgendaConfig_Get
extends
CRM_CiviMobileAPI_Api_CiviMobileBase
{
/**
* Returns results to api
*
* @return array
* @throws api_Exception
*/
public
function
getResult
()
{
$agendaConfig
=
new
CRM_CiviMobileAPI_BAO_AgendaConfig
();
$agendaConfig
->
event_id
=
$this
->
validParams
[
"event_id"
];
if
(
!
$agendaConfig
->
find
(
TRUE
))
{
return
[];
}
return
[
[
'id'
=>
$agendaConfig
->
id
,
'is_active'
=>
$agendaConfig
->
is_active
,
'event_id'
=>
$agendaConfig
->
event_id
]
];
}
/**
* Returns validated params
*
* @param $params
*
* @return array
* @throws api_Exception
*/
protected
function
getValidParams
(
$params
)
{
if
(
!
CRM_CiviMobileAPI_Utils_Permission
::
isEnoughPermissionForGetAgendaConfig
())
{
throw
new
api_Exception
(
'You don`t have enough permissions.'
,
'do_not_have_enough_permissions'
);
}
return
[
'event_id'
=>
$params
[
'event_id'
],
];
}
}
CRM/CiviMobileAPI/Api/CiviMobileEventSession/Create.php
0 → 100644
View file @
14d9fc64
<?php
class
CRM_CiviMobileAPI_Api_CiviMobileEventSession_Create
extends
CRM_CiviMobileAPI_Api_CiviMobileBase
{
/**
* Returns results to api
*
* @return array
* @throws api_Exception
*/
public
function
getResult
()
{
$session
=
[];
if
(
!
isset
(
$this
->
validParams
[
'id'
]))
{
$session
[
'title'
]
=
$this
->
validParams
[
"title"
];
$session
[
'start_time'
]
=
$this
->
validParams
[
"start_time"
];
$session
[
'end_time'
]
=
$this
->
validParams
[
"end_time"
];
$session
[
'event_id'
]
=
$this
->
validParams
[
"event_id"
];
if
(
isset
(
$this
->
validParams
[
"speakers"
]))
{
$session
[
'speakers'
]
=
$this
->
validParams
[
"speakers"
];
}
if
(
isset
(
$this
->
validParams
[
"venue_id"
]))
{
$session
[
'venue_id'
]
=
$this
->
validParams
[
"venue_id"
];
}
if
(
isset
(
$this
->
validParams
[
"description"
]))
{
$session
[
'description'
]
=
$this
->
validParams
[
"description"
];
}
}
else
{
$session
[
'id'
]
=
$this
->
validParams
[
'id'
];
if
(
isset
(
$this
->
validParams
[
"title"
]))
{
$session
[
'title'
]
=
$this
->
validParams
[
"title"
];
}
if
(
isset
(
$this
->
validParams
[
"start_time"
]))
{
$session
[
'start_time'
]
=
$this
->
validParams
[
"start_time"
];
}
if
(
isset
(
$this
->
validParams
[
"end_time"
]))
{
$session
[
'end_time'
]
=
$this
->
validParams
[
"end_time"
];
}
if
(
isset
(
$this
->
validParams
[
"event_id"
]))
{
$session
[
'event_id'
]
=
$this
->
validParams
[
"event_id"
];
}
if
(
isset
(
$this
->
validParams
[
"speakers"
]))
{
$session
[
'speakers'
]
=
$this
->
validParams
[
"speakers"
];
}
if
(
isset
(
$this
->
validParams
[
"venue_id"
]))
{
$session
[
'venue_id'
]
=
$this
->
validParams
[
"venue_id"
];
}
if
(
isset
(
$this
->
validParams
[
"description"
]))
{
$session
[
'description'
]
=
$this
->
validParams
[
"description"
];
}
}
$sessionBAO
=
CRM_CiviMobileAPI_BAO_EventSession
::
create
(
$session
);
return
[
[
'id'
=>
$sessionBAO
->
id
,
'title'
=>
$sessionBAO
->
title
,
'start_time'
=>
$sessionBAO
->
start_time
,
'end_time'
=>
$sessionBAO
->
end_time
,
'description'
=>
$sessionBAO
->
description
,
'venue_id'
=>
$sessionBAO
->
venue_id
]
];
}
/**
* Returns validated params
*
* @param $params
*
* @return array
* @throws api_Exception
*/
protected
function
getValidParams
(
$params
)
{
if
(
!
CRM_CiviMobileAPI_Utils_Permission
::
isEnoughPermissionForCreateEventSession
())
{
throw
new
api_Exception
(
'You don`t have enough permissions.'
,
'do_not_have_enough_permissions'
);
}
if
(
!
empty
(
$params
[
'event_id'
]))
{
try
{
$event
=
CRM_Event_BAO_Event
::
findById
(
$params
[
"event_id"
]);
}
catch
(
Exception
$e
)
{
throw
new
api_Exception
(
'This event does not exists.'
,
'event_does_not_exists'
);
}
}
if
(
!
empty
(
$params
[
'speakers'
]))
{
$params
[
'speakers'
]
=
array_unique
(
explode
(
','
,
$params
[
'speakers'
]));
}
$sessionId
=
NULL
;
if
(
empty
(
$params
[
'id'
]))
{
if
(
empty
(
$params
[
'event_id'
]))
{
throw
new
api_Exception
(
'Missed "event_id" parameter.'
,
'event_id_is_required'
);
}
if
(
empty
(
$params
[
'title'
]))
{
throw
new
api_Exception
(
'Missed "title" parameter.'
,
'title_is_required'
);
}
if
(
empty
(
$params
[
'start_time'
]))
{
throw
new
api_Exception
(
'Missed "start_time" parameter.'
,
'start_time_is_required'
);
}
if
(
empty
(
$params
[
'end_time'
]))
{
throw
new
api_Exception
(
'Missed "end_time" parameter.'
,
'end_time_is_required'
);
}
if
(
empty
(
$params
[
'venue_id'
]))
{
throw
new
api_Exception
(
'Missed "venue_id" parameter.'
,
'venue_id_is_required'
);
}
elseif
(
!
CRM_CiviMobileAPI_Utils_Agenda_Venue
::
issetVenue
(
$params
[
'venue_id'
],
$params
[
"event_id"
]))
{
throw
new
api_Exception
(
'Venue doesn`t exists.'
,
'venue_does_not_exists'
);
}
if
(
!
empty
(
$params
[
'speakers'
])
&&
!
CRM_CiviMobileAPI_Utils_Agenda_Speakers
::
issetSpeakers
(
$params
[
'speakers'
],
$params
[
"event_id"
]))
{
throw
new
api_Exception
(
'Some speakers does not exists.'
,
'speakers_does_not_exists'
);
}
$startTime
=
$params
[
'start_time'
];
$endTime
=
$params
[
'end_time'
];
}
else
{
try
{
$session
=
CRM_CiviMobileAPI_BAO_EventSession
::
findById
(
$params
[
'id'
]);
}
catch
(
Exception
$e
)
{
throw
new
api_Exception
(
'This session does not exists.'
,
'session_does_not_exists'
);
}
$sessionId
=
$session
->
id
;
if
(
strlen
(
$params
[
'title'
])
>
255
)
{
throw
new
api_Exception
(
'Title length must be less than 256.'
,
'title_length_is_too_long'
);
}
if
(
!
empty
(
$params
[
'venue_id'
])
&&
!
CRM_CiviMobileAPI_Utils_Agenda_Venue
::
issetVenue
(
$params
[
'venue_id'
],
$params
[
"event_id"
]))
{
throw
new
api_Exception
(
'Venue doesn`t exists.'
,
'venue_does_not_exists'
);
}
if
(
!
empty
(
$params
[
'speakers'
])
&&
!
CRM_CiviMobileAPI_Utils_Agenda_Speakers
::
issetSpeakers
(
$params
[
'speakers'
],
$session
->
event_id
))
{
throw
new
api_Exception
(
'Some speakers does not exists.'
,
'speakers_does_not_exists'
);
}
if
(
empty
(
$params
[
'start_time'
])
&&
empty
(
$params
[
'end_time'
]))
{
$startTime
=
$session
->
start_time
;
$endTime
=
$session
->
end_time
;
}
elseif
(
empty
(
$params
[
'start_time'
]))
{
$startTime
=
$session
->
start_time
;
$endTime
=
$params
[
'end_time'
];
}
elseif
(
empty
(
$params
[
'end_time'
]))
{
$startTime
=
$params
[
'start_time'
];
$endTime
=
$session
->
end_time
;
}
else
{
$startTime
=
$params
[
'start_time'
];
$endTime
=
$params
[
'end_time'
];
}
}
if
(
!
empty
(
$params
[
'speakers'
])
&&
CRM_CiviMobileAPI_BAO_EventSession
::
isSpeakersBusy
(
$params
[
'speakers'
],
$sessionId
,
$startTime
,
$endTime
))
{
throw
new
api_Exception
(
'Some speakers are busy on other Event Session at this time.'
,
'some_speakers_are_busy'
);
}
if
(
!
empty
(
$params
[
'venue_id'
])
&&
CRM_CiviMobileAPI_BAO_EventSession
::
isVenueBusy
(
$params
[
"venue_id"
],
$sessionId
,
$startTime
,
$endTime
))
{
throw
new
api_Exception
(
'Venue is booked.'
,
'venues_is_booked'
);
}
$startTime
=
strtotime
(
$startTime
);
$endTime
=
strtotime
(
$endTime
);
if
(
$startTime
>=
$endTime
)
{
throw
new
api_Exception
(
'Start time can`t be later than end time.'
,
'start_time_cannot_be_later_than_end_time'
);
}
elseif
(
$startTime
+
15
*
60
>
$endTime
)
{
throw
new
api_Exception
(
'Event Session duration can not be less than 15 min.'
,
'event_session_duration_must_be_longer'
);
}
if
(
$startTime
<
strtotime
(
$event
->
start_date
))
{
throw
new
api_Exception
(
'Start time can`t be early than start time on Event.'
,
'start_time_cannot_be_early_than_start_time_on_event'
);
}
if
(
$endTime
>
strtotime
(
$event
->
end_date
)
&&
$event
->
end_date
!=
NULL
)
{
throw
new
api_Exception
(
'End time can`t be later than end time on Event.'
,
'end_time_cannot_be_later_than_end_time_on_event'
);
}
foreach
(
$params
as
$key
=>
$value
)
{
if
(
empty
(
$params
[
$key
]))
{
unset
(
$params
[
$key
]);
}
elseif
(
$key
==
'speakers'
||
$key
==
'venues'
)
{
$params
[
$key
]
=
implode
(
','
,
$params
[
$key
]);
}
}
return
$params
;
}
}
CRM/CiviMobileAPI/Api/CiviMobileEventSession/Get.php
0 → 100644
View file @
14d9fc64
<?php
class
CRM_CiviMobileAPI_Api_CiviMobileEventSession_Get
extends
CRM_CiviMobileAPI_Api_CiviMobileBase
{
/**
* Cached events
*/
private
$cacheEvents
=
[];
/**
* Returns results to api
*
* @return array
* @throws api_Exception
*/
public
function
getResult
()
{
$config
=
CRM_Core_Config
::
singleton
();
$sessions
=
CRM_CiviMobileAPI_BAO_EventSession
::
getAll
(
$this
->
validParams
);
$result
=
[];
if
(
!
empty
(
$sessions
))
{
foreach
(
$sessions
as
$session
)
{
$displayInfo
=
$this
->
getDisplayInfo
(
$session
);
if
(
isset
(
$this
->
validParams
[
'is_display'
])
&&
$displayInfo
[
'is_display'
]
!=
$this
->
validParams
[
'is_display'
])
{
continue
;
}
$preparedEventSession
=
[
'id'
=>
$session
[
"id"
],
'title'
=>
$session
[
"title"
],
'start_time'
=>
$session
[
"start_time"
],
'end_time'
=>
$session
[
"end_time"
],
'event_id'
=>
$session
[
"event_id"
],
'description'
=>
$session
[
"description"
],
'speakers_names'
=>
CRM_CiviMobileAPI_Utils_Agenda_Speakers
::
getSpeakersNames
(
$session
[
"speakers"
],
$session
[
"event_id"
]),
'venue_name'
=>
$session
[
'venue_name'
],
'venue_id'
=>
$session
[
"venue_id"
],
'speakers_id'
=>
$session
[
"speakers"
],
'date_formatted'
=>
CRM_Utils_Date
::
customFormat
(
$session
[
"start_time"
],
$config
->
dateformatshortdate
),
'start_time_formatted'
=>
CRM_Utils_Date
::
customFormat
(
$session
[
"start_time"
],
$config
->
dateformatTime
),
'end_time_formatted'
=>
CRM_Utils_Date
::
customFormat
(
$session
[
"end_time"
],
$config
->
dateformatTime
),
'is_display'
=>
$displayInfo
[
'is_display'
],
'display_status'
=>
$displayInfo
[
'display_status'
],
];
if
(
CRM_Core_Session
::
getLoggedInContactID
())
{
$preparedEventSession
[
'is_favourite'
]
=
$session
[
"is_favourite"
];
}
$result
[]
=
$preparedEventSession
;
}
}
return
$result
;
}
/**
* Returns validated params
*
* @param $params
*
* @return array
* @throws api_Exception
*/
protected
function
getValidParams
(
$params
)
{
if
(
!
CRM_CiviMobileAPI_Utils_Permission
::
isEnoughPermissionForGetEventSession
())
{
throw
new
api_Exception
(
'You don`t have enough permissions.'
,
'do_not_have_enough_permissions'
);
}
foreach
(
$params
as
$key
=>
$value
)
{
if
(
!
isset
(
$params
[
$key
]))
{
unset
(
$params
[
$key
]);
}
}
return
$params
;
}
/**
* Returns Event by Id
*
* @param $eventId
* @return CRM_Event_BAO_Event
*/
private
function
getCachedEventById
(
$eventId
)
{
if
(
isset
(
$this
->
cacheEvents
[
$eventId
]))
{
return
$this
->
cacheEvents
[
$eventId
];
}
$this
->
cacheEvents
[
$eventId
]
=
CRM_Event_BAO_Event
::
findById
(
$eventId
);
return
$this
->
cacheEvents
[
$eventId
];
}
/**
* Returns display info
*
* @param $session
* @return array
*/
private
function
getDisplayInfo
(
$session
)
{
$isDisplay
=
1
;
$displayStatus
=
''
;
if
(
empty
(
$session
[
"venue_id"
]))
{
$isDisplay
=
0
;
$displayStatus
=
ts
(
'Venue does not exists in session'
);
}
$event
=
$this
->
getCachedEventById
(
$session
[
"event_id"
]);
if
(((
strtotime
(
$session
[
"end_time"
])
>
strtotime
(
$event
->
end_date
)
&&
$event
->
end_date
!=
NULL
)
||
strtotime
(
$session
[
"start_time"
])
<
strtotime
(
$event
->
start_date
))
&&
empty
(
$session
[
"venue"
])
)
{
$isDisplay
=
0
;
$displayStatus
=
ts
(
'Venue does not exists in session and session is outside of timeframe event'
);
}
elseif
((
strtotime
(
$session
[
"end_time"
])
>
strtotime
(
$event
->
end_date
)
&&
$event
->
end_date
!=
NULL
)
||
strtotime
(
$session
[
"start_time"
])
<
strtotime
(
$event
->
start_date
)
)
{
$isDisplay
=
0
;
$displayStatus
=
ts
(
'Session is outside of timeframe event'
);
}
if
(
$isDisplay
==
1
)
{
$displayStatus
=
ts
(
'Session is ready to use'
);
}
return
[
'is_display'
=>
$isDisplay
,
'display_status'
=>
$displayStatus
,
];
}
}
CRM/CiviMobileAPI/Api/CiviMobilePublicParticipant/Create.php
View file @
14d9fc64
...
...
@@ -16,6 +16,7 @@ class CRM_CiviMobileAPI_Api_CiviMobilePublicParticipant_Create extends CRM_CiviM
$result
=
civicrm_api3
(
'Participant'
,
'create'
,
[
'event_id'
=>
$this
->
validParams
[
"event_id"
],
'contact_id'
=>
$this
->
validParams
[
"contact_id"
],
'role_id'
=>
$this
->
validParams
[
"default_role_id"
]
]);
$publicKey
=
CRM_CiviMobileAPI_Utils_Participant
::
generatePublicKey
(
$result
[
'id'
]);
...
...
@@ -47,9 +48,13 @@ class CRM_CiviMobileAPI_Api_CiviMobilePublicParticipant_Create extends CRM_CiviM
throw
new
api_Exception
(
ts
(
'Event(id='
.
$params
[
'event_id'
]
.
') does not exist or is not public.'
),
'public_event_does_not_exist'
);
}
$contactId
=
$this
->
getContactId
(
$params
);
$this
->
updateContactFields
(
$contactId
,
$params
);
$result
=
[
'event_id'
=>
$params
[
"event_id"
],
'contact_id'
=>
$this
->
getContactId
(
$params
),
'contact_id'
=>
$contactId
,
'default_role_id'
=>
$event
->
default_role_id
];
return
$result
;
...
...
@@ -108,4 +113,22 @@ class CRM_CiviMobileAPI_Api_CiviMobilePublicParticipant_Create extends CRM_CiviM
return
(
int
)
$contact
[
"id"
];
}
/**
* Updates first_name and last_name for contact by contact_id
*
* @param $contactId
* @param $params
*/
private
function
updateContactFields
(
$contactId
,
$params
)
{
try
{
civicrm_api3
(
'Contact'
,
'create'
,
[
'contact_id'
=>
$contactId
,
'first_name'
=>
$params
[
"first_name"
],
'last_name'
=>
$params
[
"last_name"
],
]);
}
catch
(
CiviCRM_API3_Exception
$e
)
{
throw
new
api_Exception
(
ts
(
'Can not update Contact. Error: '
)
.
$e
->
getMessage
(),
'can_not_update_contact'
);
}
}
}
CRM/CiviMobileAPI/Api/CiviMobileSpeaker/Get.php
0 → 100644
View file @
14d9fc64
<?php
class
CRM_CiviMobileAPI_Api_CiviMobileSpeaker_Get
extends
CRM_CiviMobileAPI_Api_CiviMobileBase
{
/**
* Returns results to api
*
* @return array
* @throws CiviCRM_API3_Exception
*/
public
function
getResult
()
{
$preparedSpeakers
=
[];
$speakers
=
CRM_CiviMobileAPI_BAO_EventSessionSpeaker
::
getSpeakersBelongedToSessionsByEvent
(
$this
->
validParams
);
$participantBioFieldName
=
$customFieldName
=
"custom_"
.
CRM_CiviMobileAPI_Utils_CustomField
::
getId
(
CRM_CiviMobileAPI_Install_Entity_CustomGroup
::
AGENDA_PARTICIPANT
,
CRM_CiviMobileAPI_Install_Entity_CustomField
::
AGENDA_PARTICIPANT_BIO
);
foreach
(
$speakers
as
$speaker
)
{
try
{
$participant
=
civicrm_api3
(
'Participant'
,
'getsingle'
,
[
'event_id'
=>
$this
->
validParams
[
'event_id'
],
'id'
=>
$speaker
[
'speaker_id'
]
]);
}
catch
(
Exception
$e
)
{
continue
;
}
$preparedSpeakers
[]
=
[
'participant_id'
=>
$speaker
[
'speaker_id'
],
'contact_id'
=>
$participant
[
'contact_id'
],
'event_id'
=>
$participant
[
'event_id'
],
'display_name'
=>
$participant
[
'display_name'
],
'participant_register_date'
=>
$participant
[
'participant_register_date'
],
'participant_bio'
=>
!
empty
(
$participant
[
$participantBioFieldName
])
?
$participant
[
$participantBioFieldName
]
:
''
,
'image_URL'
=>
!
empty
(
$speaker
[
'image_URL'
])
?
$speaker
[
'image_URL'
]
:
''
,
'job_title'
=>
!
empty
(
$speaker
[
'job_title'
])
?
$speaker
[
'job_title'
]
:
''
,
'current_employer'
=>
!
empty
(
$speaker
[
'organization_name'
])
?
$speaker
[
'organization_name'
]
:
''
,
'current_employer_id'
=>
!
empty
(
$speaker
[
'employer_id'
])
?
$speaker
[
'employer_id'
]
:
''
,
'first_name'
=>
!
empty
(
$speaker
[
'first_name'
])
?
$speaker
[
'first_name'
]
:
''
,
'last_name'
=>
!
empty
(
$speaker
[
'last_name'
])
?
$speaker
[
'last_name'
]
:
''
];
}
return
$preparedSpeakers
;
}
/**
* Returns validated params
*
* @param $params
* @return array
* @throws api_Exception
*/
protected
function
getValidParams
(
$params
)
{
if
(
!
CRM_CiviMobileAPI_Utils_Permission
::
isEnoughPermissionForGetSpeaker
())
{
throw
new
api_Exception
(
'You don`t have enough permissions.'
,
'do_not_have_enough_permissions'
);
}
return
$params
;
}
}
CRM/CiviMobileAPI/Api/CiviMobileVenue/Create.php
0 → 100644
View file @
14d9fc64
<?php
class
CRM_CiviMobileAPI_Api_CiviMobileVenue_Create
extends
CRM_CiviMobileAPI_Api_CiviMobileBase
{
/**
* Returns results to api
*
* @return array
* @throws api_Exception
*/
public
function
getResult
()
{
$geoCode
=
CRM_CiviMobileAPI_Utils_Agenda_Venue
::
getVenueGeocoderData
(
$this
->
validParams
);
$this
->
validParams
[
'latitude'
]
=
$geoCode
[
'latitude'
];
$this
->
validParams
[
'longitude'
]
=
$geoCode
[
'longitude'
];
$venueId
=
CRM_CiviMobileAPI_BAO_LocationVenue
::
create
(
$this
->
validParams
)
->
id
;
$venue
=
civicrm_api3
(
'CiviMobileVenue'
,
'getsingle'
,
[
'id'
=>
$venueId
]);
return
[
$venue
];
}
/**
* Returns validated params
*
* @param $params
*
* @return array
* @throws api_Exception
*/
protected
function
getValidParams
(
$params
)
{
if
(
!
CRM_CiviMobileAPI_Utils_Permission
::
isEnoughPermissionForCreateEventVenues
())
{
throw
new
api_Exception
(
'You don`t have enough permissions.'
,
'do_not_have_enough_permissions'
);
}
if
(
!
empty
(
$params
[
'id'
]))
{
if
(
empty
(
CRM_CiviMobileAPI_BAO_LocationVenue
::
getAll
(
$params
[
'id'
])))
{
throw
new
api_Exception
(
'Wrong venue id'
);
}
}
else
{
$this
->
checkLocation
(
$params
);
$this
->
checkName
(
$params
);
if
(
empty
(
$params
[
'background_color'
])
||
empty
(
$params
[
'border_color'
]))
{
$colorParams
=
CRM_CiviMobileAPI_Utils_Agenda_Venue
::
getNextColorInListForLocation
(
$params
[
'location_id'
]);
$params
[
'background_color'
]
=
$colorParams
[
'background'
];
$params
[
'border_color'
]
=
$colorParams
[
'border'
];
}
elseif
(
strlen
(
$params
[
'background_color'
])
>
30
||
strlen
(
$params
[
'border_color'
])
>
30
)
{
throw
new
api_Exception
(
'Color has to contain less than 30 characters.'
);
}
if
(
!
isset
(
$params
[
'is_active'
]))
{
$params
[
'is_active'
]
=
1
;
}
}
if
(
isset
(
$params
[
'is_active'
])
&&
(
int
)
$params
[
'is_active'
]
!==
1
&&
(
int
)
$params
[
'is_active'
]
!==
0
)
{
throw
new
api_Exception
(
'Wrong is active parameter'
);
}
if
(
!
isset
(
$params
[
'id'
]))
{
$this
->
checkLocation
(
$params
);
$this
->
checkName
(
$params
);
}
$sameNameVenue
=
CRM_CiviMobileAPI_BAO_LocationVenue
::
getAll
([
'name'
=>
!
empty
(
$params
[
'name'
])
?
$params
[
'name'
]
:
''
,
'location_id'
=>
!
empty
(
$params
[
'location_id'
])
?
$params
[
'location_id'
]
:
''
]);
if
(
!
empty
(
$sameNameVenue
)
&&
empty
(
$params
[
"id"
])