function createEvent() { $this->eventName = 'Test Event ' . uniqid(); $event = new Event(); $event->name = $this->eventName; $event->shortDescription = 'Test Event Description'; $event->ownerId = $this->app->user->profile->id; $event->save(true); return $event; }
public function canUser($action, $userOrAgent = null) { return $this->owner->canUser($action, $userOrAgent); }
function delete($flush = false) { $this->checkPermission('remove'); // ($originType, $originId, $destinationType, $destinationId, $metadata) $ruid = RequestEventOccurrence::generateRequestUid($this->event->getClassName(), $this->event->id, $this->space->getClassName(), $this->space->id, ['event_occurrence_id' => $this->id, 'rule' => $this->rule]); $requests = App::i()->repo('RequestEventOccurrence')->findBy(['requestUid' => $ruid]); foreach ($requests as $r) { $r->delete($flush); } parent::delete($flush); }
protected function _init() { $app = App::i(); /* === NOTIFICATIONS === */ // para todos os requests $app->hook('workflow(<<*>>).create', function () use($app) { if ($this->notifications) { $app->disableAccessControl(); foreach ($this->notifications as $n) { $n->delete(); } $app->enableAccessControl(); } $requester = $app->user; $profile = $requester->profile; $origin = $this->origin; $destination = $this->destination; $origin_type = strtolower($origin->entityType); $origin_url = $origin->singleUrl; $origin_name = $origin->name; $destination_url = $destination->singleUrl; $destination_name = $destination->name; $profile_link = "<a href=\"{$profile->singleUrl}\">{$profile->name}</a>"; $destination_link = "<a href=\"{$destination_url}\">{$destination_name}</a>"; $origin_link = "<a href=\"{$origin_url}\">{$origin_name}</a>"; switch ($this->getClassName()) { case "MapasCulturais\\Entities\\RequestAgentRelation": if ($origin->getClassName() === 'MapasCulturais\\Entities\\Registration') { $message = "{$profile_link} quer relacionar o agente {$destination_link} à inscrição {$origin->number} no projeto <a href=\"{$origin->project->singleUrl}\">{$origin->project->name}</a>."; $message_to_requester = "Sua requisição para relacionar o agente {$destination_link} à inscrição <a href=\"{$origin->singleUrl}\" >{$origin->number}</a> no projeto <a href=\"{$origin->project->singleUrl}\">{$origin->project->name}</a> foi enviada."; } else { $message = "{$profile_link} quer relacionar o agente {$destination_link} ao {$origin_type} {$origin_link}."; $message_to_requester = "Sua requisição para relacionar o agente {$destination_link} ao {$origin_type} {$origin_link} foi enviada."; } break; case "MapasCulturais\\Entities\\RequestChangeOwnership": $message = "{$profile_link} está requisitando a mudança de propriedade do {$origin_type} {$origin_link} para o agente {$destination_link}."; $message_to_requester = "Sua requisição para alterar a propriedade do {$origin_type} {$origin_link} para o agente {$destination_link} foi enviada."; break; case "MapasCulturais\\Entities\\RequestChildEntity": $message = "{$profile_link} quer que o {$origin_type} {$origin_link} seja um {$origin_type} filho de {$destination_link}."; $message_to_requester = "Sua requisição para fazer do {$origin_type} {$origin_link} um {$origin_type} filho de {$destination_link} foi enviada."; break; case "MapasCulturais\\Entities\\RequestEventOccurrence": $message = "{$profile_link} quer adicionar o evento {$origin_link} que ocorre <em>{$this->rule->description}</em> no espaço {$destination_link}."; $message_to_requester = "Sua requisição para criar a ocorrência do evento {$origin_link} no espaço {$destination_link} foi enviada."; break; case "MapasCulturais\\Entities\\RequestEventProject": $message = "{$profile_link} quer relacionar o evento {$origin_link} ao projeto {$destination_link}."; $message_to_requester = "Sua requisição para associar o evento {$origin_link} ao projeto {$destination_link} foi enviada."; break; default: $message = $message_to_requester = "REQUISIÇÃO - NÃO DEVE ENTRAR AQUI"; break; } // message to requester user $notification = new Notification(); $notification->user = $requester; $notification->message = $message_to_requester; $notification->request = $this; $notification->save(true); $notified_user_ids = array($requester->id); foreach ($destination->usersWithControl as $user) { // impede que a notificação seja entregue mais de uma vez ao mesmo usuário se as regras acima se somarem if (in_array($user->id, $notified_user_ids)) { continue; } $notified_user_ids[] = $user->id; $notification = new Notification(); $notification->user = $user; $notification->message = $message; $notification->request = $this; $notification->save(true); } if (!$requester->equals($origin->ownerUser) && !in_array($origin->ownerUser->id, $notified_user_ids)) { $notification = new Notification(); $notification->user = $origin->ownerUser; $notification->message = $message; $notification->request = $this; $notification->save(true); } }); $app->hook('workflow(<<*>>).approve:before', function () use($app) { $requester = $app->user; $profile = $requester->profile; $origin = $this->origin; $destination = $this->destination; $origin_type = strtolower($origin->entityType); $origin_url = $origin->singleUrl; $origin_name = $origin->name; $destination_url = $destination->singleUrl; $destination_name = $destination->name; $profile_link = "<a href=\"{$profile->singleUrl}\">{$profile->name}</a>"; $destination_link = "<a href=\"{$destination_url}\">{$destination_name}</a>"; $origin_link = "<a href=\"{$origin_url}\">{$origin_name}</a>"; switch ($this->getClassName()) { case "MapasCulturais\\Entities\\RequestAgentRelation": if ($origin->getClassName() === 'MapasCulturais\\Entities\\Registration') { $message = "{$profile_link} aceitou o relacionamento do agente {$destination_link} à inscrição <a href=\"{$origin->singleUrl}\" >{$origin->number}</a> no projeto <a href=\"{$origin->project->singleUrl}\">{$origin->project->name}</a>."; } else { $message = "{$profile_link} aceitou o relacionamento do agente {$destination_link} com o {$origin_type} {$origin_link}."; } break; case "MapasCulturais\\Entities\\RequestChangeOwnership": $message = "{$profile_link} aceitou a mudança de propriedade do {$origin_type} {$origin_link} para o agente {$destination_link}."; break; case "MapasCulturais\\Entities\\RequestChildEntity": $message = "{$profile_link} aceitou que o {$origin_type} {$origin_link} seja um {$origin_type} filho de {$destination_link}."; break; case "MapasCulturais\\Entities\\RequestEventOccurrence": $message = "{$profile_link} aceitou adicionar o evento {$origin_link} que ocorre <em>{$this->rule->description}</em> no espaço {$destination_link}."; break; case "MapasCulturais\\Entities\\RequestEventProject": $message = "{$profile_link} aceitou relacionar o evento {$origin_link} ao projeto {$destination_link}."; break; default: $message = "A requisição foi aprovada."; break; } $users = array(); // notifica quem fez a requisição $users[] = $this->requesterUser; if ($this->getClassName() === "MapasCulturais\\Entities\\RequestChangeOwnership" && $this->type === Entities\RequestChangeOwnership::TYPE_REQUEST) { // se não foi o dono da entidade de destino que fez a requisição, notifica o dono if (!$destination->ownerUser->equals($this->requesterUser)) { $users[] = $destination->ownerUser; } // se não é o dono da entidade de origem que está aprovando, notifica o dono if (!$origin->ownerUser->equals($app->user)) { $users[] = $origin->ownerUser; } } else { // se não foi o dono da entidade de origem que fez a requisição, notifica o dono if (!$origin->ownerUser->equals($this->requesterUser)) { $users[] = $origin->ownerUser; } // se não é o dono da entidade de destino que está aprovando, notifica o dono if (!$destination->ownerUser->equals($app->user)) { $users[] = $destination->ownerUser; } } $notified_user_ids = array(); foreach ($users as $u) { // impede que a notificação seja entregue mais de uma vez ao mesmo usuário se as regras acima se somarem if (in_array($u->id, $notified_user_ids)) { continue; } $notified_user_ids[] = $u->id; $notification = new Notification(); $notification->message = $message; $notification->user = $u; $notification->save(true); } }); $app->hook('workflow(<<*>>).reject:before', function () use($app) { $requester = $app->user; $profile = $requester->profile; $origin = $this->origin; $destination = $this->destination; $origin_type = strtolower($origin->entityType); $origin_url = $origin->singleUrl; $origin_name = $origin->name; $destination_url = $destination->singleUrl; $destination_name = $destination->name; $profile_link = "<a href=\"{$profile->singleUrl}\">{$profile->name}</a>"; $destination_link = "<a href=\"{$destination_url}\">{$destination_name}</a>"; $origin_link = "<a href=\"{$origin_url}\">{$origin_name}</a>"; switch ($this->getClassName()) { case "MapasCulturais\\Entities\\RequestAgentRelation": if ($origin->canUser('@control')) { if ($origin->getClassName() === 'MapasCulturais\\Entities\\Registration') { $message = "{$profile_link} cancelou o relacionamento do agente {$destination_link} à inscrição <a href=\"{$origin->singleUrl}\" >{$origin->number}</a> no projeto <a href=\"{$origin->project->singleUrl}\">{$origin->project->name}</a>."; } else { $message = "{$profile_link} cancelou o pedido de relacionamento do agente {$destination_link} com o {$origin_type} {$origin_link}."; } } else { if ($origin->getClassName() === 'MapasCulturais\\Entities\\Registration') { $message = "{$profile_link} rejeitou o relacionamento do agente {$destination_link} à inscrição <a href=\"{$origin->singleUrl}\" >{$origin->number}</a> no projeto <a href=\"{$origin->project->singleUrl}\">{$origin->project->name}</a>."; } else { $message = "{$profile_link} rejeitou o relacionamento do agente {$destination_link} com o {$origin_type} {$origin_link}."; } } break; case "MapasCulturais\\Entities\\RequestChangeOwnership": if ($this->type === Entities\RequestChangeOwnership::TYPE_REQUEST) { $message = $this->requesterUser->equals($requester) ? "{$profile_link} cancelou o pedido de propriedade do {$origin_type} {$origin_link} para o agente {$destination_link}." : "{$profile_link} rejeitou a mudança de propriedade do {$origin_type} {$origin_link} para o agente {$destination_link}."; } else { $message = $this->requesterUser->equals($requester) ? "{$profile_link} cancelou o pedido de propriedade do {$origin_type} {$origin_link} para o agente {$destination_link}." : "{$profile_link} rejeitou a mudança de propriedade do {$origin_type} {$origin_link} para o agente {$destination_link}."; } break; case "MapasCulturais\\Entities\\RequestChildEntity": $message = $origin->canUser('@control') ? "{$profile_link} cancelou o pedido para que o {$origin_type} {$origin_link} seja um {$origin_type} filho de {$destination_link}." : "{$profile_link} rejeitou que o {$origin_type} {$origin_link} seja um {$origin_type} filho de {$destination_link}."; break; case "MapasCulturais\\Entities\\RequestEventOccurrence": $message = $origin->canUser('@control') ? "{$profile_link} cancelou o pedido de autorização do evento {$origin_link} que ocorre <em>{$this->rule->description}</em> no espaço {$destination_link}." : "{$profile_link} rejeitou o evento {$origin_link} que ocorre <em>{$this->rule->description}</em> no espaço {$destination_link}."; break; case "MapasCulturais\\Entities\\RequestEventProject": $message = $origin->canUser('@control') ? "{$profile_link} cancelou o pedido de relacionamento do evento {$origin_link} ao projeto {$destination_link}." : "{$profile_link} rejeitou o relacionamento do evento {$origin_link} ao projeto {$destination_link}."; break; default: $message = $origin->canUser('@control') ? "A requisição foi cancelada." : "A requisição foi rejeitada."; break; } $users = array(); if (!$app->user->equals($this->requesterUser)) { // notifica quem fez a requisição $users[] = $this->requesterUser; } if ($this->getClassName() === "MapasCulturais\\Entities\\RequestChangeOwnership" && $this->type === Entities\RequestChangeOwnership::TYPE_REQUEST) { // se não foi o dono da entidade de destino que fez a requisição, notifica o dono if (!$destination->ownerUser->equals($this->requesterUser)) { $users[] = $destination->ownerUser; } // se não é o dono da entidade de origem que está rejeitando, notifica o dono if (!$origin->ownerUser->equals($app->user)) { $users[] = $origin->ownerUser; } } else { // se não foi o dono da entidade de origem que fez a requisição, notifica o dono if (!$origin->ownerUser->equals($this->requesterUser)) { $users[] = $origin->ownerUser; } // se não é o dono da entidade de destino que está rejeitando, notifica o dono if (!$destination->ownerUser->equals($app->user)) { $users[] = $destination->ownerUser; } } $notified_user_ids = array(); foreach ($users as $u) { // impede que a notificação seja entregue mais de uma vez ao mesmo usuário se as regras acima se somarem if (in_array($u->id, $notified_user_ids)) { continue; } $notified_user_ids[] = $u->id; $notification = new Notification(); $notification->message = $message; $notification->user = $u; $notification->save(true); } }); /* ---------------------- */ $app->hook('mapasculturais.body:before', function () { if ($this->controller && ($this->controller->action == 'single' || $this->controller->action == 'edit')) { ?> <!--facebook compartilhar--> <div id="fb-root"></div> <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/pt_BR/all.js#xfbml=1"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script> <!--fim do facebook--> <?php } }); $app->hook('view.render(<<*>>):before', function () use($app) { $this->assetManager->publishAsset('css/main.css.map', 'css/main.css.map'); $this->jsObject['assets'] = array(); $this->jsObject['templateUrl'] = array(); $this->jsObject['spinnerUrl'] = $this->asset('img/spinner.gif', false); $this->jsObject['assets']['fundo'] = $this->asset('img/fundo.png', false); $this->jsObject['assets']['instituto-tim'] = $this->asset('img/instituto-tim-white.png', false); $this->jsObject['assets']['verifiedIcon'] = $this->asset('img/verified-icon.png', false); $this->jsObject['assets']['avatarAgent'] = $this->asset('img/avatar--agent.png', false); $this->jsObject['assets']['avatarSpace'] = $this->asset('img/avatar--space.png', false); $this->jsObject['assets']['avatarEvent'] = $this->asset('img/avatar--event.png', false); $this->jsObject['assets']['avatarProject'] = $this->asset('img/avatar--project.png', false); $this->jsObject['isEditable'] = $this->isEditable(); $this->jsObject['isSearch'] = $this->isSearch(); $this->jsObject['angularAppDependencies'] = ['entity.module.relatedAgents', 'entity.module.changeOwner', 'entity.directive.editableMultiselect', 'entity.directive.editableSingleselect', 'mc.directive.singleselect', 'mc.directive.multiselect', 'mc.directive.editBox', 'mc.directive.mcSelect', 'mc.module.notifications', 'mc.module.findEntity', 'ngSanitize']; $this->jsObject['mapsDefaults'] = array('zoomMax' => $app->config['maps.zoom.max'], 'zoomMin' => $app->config['maps.zoom.min'], 'zoomDefault' => $app->config['maps.zoom.default'], 'zoomPrecise' => $app->config['maps.zoom.precise'], 'zoomApproximate' => $app->config['maps.zoom.approximate'], 'includeGoogleLayers' => $app->config['maps.includeGoogleLayers'], 'latitude' => $app->config['maps.center'][0], 'longitude' => $app->config['maps.center'][1]); $this->jsObject['mapMaxClusterRadius'] = $app->config['maps.maxClusterRadius']; $this->jsObject['mapSpiderfyDistanceMultiplier'] = $app->config['maps.spiderfyDistanceMultiplier']; $this->jsObject['mapMaxClusterElements'] = $app->config['maps.maxClusterElements']; $this->jsObject['mapGeometryFieldQuery'] = $app->config['maps.geometryFieldQuery']; $this->jsObject['labels'] = array('agent' => \MapasCulturais\Entities\Agent::getPropertiesLabels(), 'project' => \MapasCulturais\Entities\Project::getPropertiesLabels(), 'event' => \MapasCulturais\Entities\Event::getPropertiesLabels(), 'space' => \MapasCulturais\Entities\Space::getPropertiesLabels(), 'registration' => \MapasCulturais\Entities\Registration::getPropertiesLabels()); $this->jsObject['routes'] = $app->config['routes']; $this->addDocumentMetas(); $this->includeVendorAssets(); $this->includeCommonAssets(); $this->_populateJsObject(); }); $app->hook('view.render(<<agent|space|project|event>>/<<single|edit|create>>):before', function () { $this->jsObject['assets']['verifiedSeal'] = $this->asset('img/verified-seal.png', false); $this->jsObject['assets']['unverifiedSeal'] = $this->asset('img/unverified-seal.png', false); $this->assetManager->publishAsset('img/verified-seal-small.png', 'img/verified-seal-small.png'); }); $app->hook('entity(<<agent|space>>).<<insert|update>>:before', function () use($app) { $rsm = new \Doctrine\ORM\Query\ResultSetMapping(); $rsm->addScalarResult('type', 'type'); $rsm->addScalarResult('name', 'name'); $x = $this->location->longitude; $y = $this->location->latitude; $strNativeQuery = "SELECT type, name FROM geo_division WHERE ST_Contains(geom, ST_Transform(ST_GeomFromText('POINT({$x} {$y})',4326),4326))"; $query = $app->getEm()->createNativeQuery($strNativeQuery, $rsm); $divisions = $query->getScalarResult(); foreach ($app->getRegisteredGeoDivisions() as $d) { $metakey = $d->metakey; $this->{$metakey} = ''; } foreach ($divisions as $div) { $metakey = 'geo' . ucfirst($div['type']); $this->{$metakey} = $div['name']; } }); // sempre que insere uma imagem cria o avatarSmall $app->hook('entity(<<agent|space|event|project>>).file(avatar).insert:after', function () { $this->transform('avatarSmall'); $this->transform('avatarBig'); }); $app->hook('entity(<<agent|space|event|project>>).file(header).insert:after', function () { $this->transform('header'); }); $app->hook('entity(<<agent|space|event|project>>).file(gallery).insert:after', function () { $this->transform('galleryThumb'); $this->transform('galleryFull'); }); $app->hook('entity(event).save:before', function () { $this->type = 1; }); $app->hook('repo(<<*>>).getIdsByKeywordDQL.join', function (&$joins, $keyword) { $taxonomy = App::i()->getRegisteredTaxonomyBySlug('tag'); $class = $this->getClassName(); $joins .= "LEFT JOIN e.__termRelations tr\n LEFT JOIN\n tr.term\n t\n WITH\n t.taxonomy = '{$taxonomy->id}'"; }); $app->hook('repo(<<*>>).getIdsByKeywordDQL.where', function (&$where, $keyword) { $where .= " OR unaccent(lower(t.term)) LIKE unaccent(lower(:keyword)) "; }); $app->hook('repo(Event).getIdsByKeywordDQL.join', function (&$joins, $keyword) { $joins .= " LEFT JOIN e.project p\n LEFT JOIN e.__metadata m\n WITH\n m.key = 'subTitle'\n "; }); $app->hook('repo(Event).getIdsByKeywordDQL.where', function (&$where, $keyword) use($app) { $projects = $app->repo('Project')->findByKeyword($keyword); $project_ids = []; foreach ($projects as $project) { $project_ids = array_merge($project_ids, [$project->id], $project->getChildrenIds()); } if ($project_ids) { $where .= " OR p.id IN ( " . implode(',', $project_ids) . ")"; } $where .= " OR unaccent(lower(m.value)) LIKE unaccent(lower(:keyword))"; }); }
protected function canUserModify($user) { if ($user->is('guest')) { return false; } if ($user->is('admin')) { return true; } return $this->space->canUser('modify', $user) && $this->event->canUser('modify', $user); }