Exemplo n.º 1
0
 function testValidations()
 {
     $app = App::i();
     $type = new MapasCulturais\Definitions\EntityType('MapasCulturais\\Entities\\Agent', 9999, 'test type');
     $app->registerEntityType($type);
     $metas = array('metaRequired' => array('label' => 'Meta Required', 'validations' => array('required' => 'required error message'), 'validValues' => array('Value', 'Loren'), 'invalidValues' => array(null, '')), 'metaEmail' => array('label' => 'Meta Email', 'validations' => array('v::email()' => 'error message'), 'validValues' => array(null, '', '*****@*****.**', '*****@*****.**', '*****@*****.**'), 'invalidValues' => array('test', 'test', 'teste#teste.com', 'alow as@teste.com')), 'metaRequiredEmail' => array('label' => 'Meta Email', 'validations' => array('required' => 'required error message', 'v::email()' => 'error message'), 'validValues' => array('*****@*****.**', '*****@*****.**', '*****@*****.**'), 'invalidValues' => array(null, '', 'test', 'test', 'teste#teste.com', 'alow as@teste.com')), 'metaUrl' => array('label' => 'Meta Url', 'validations' => array('v::url()' => 'error message'), 'validValues' => array(null, '', 'http://www.test.com', 'http://www.testing-tests.com', 'http://www.test.com/', 'https://www.test.com/', 'http://www.test.com/ok', 'https://testing.com/ok.test', 'http://test.com/ok.php', 'http://a.very.long.domain.name.com/ok.jpg?with=get%20params', 'https://www.test.com/ok'), 'invalidValues' => array('htts:///222 asd.com', 'asdasd', 'www.test.com')), 'metaRequiredUrl' => array('label' => 'Meta Url', 'validations' => array('required' => 'required error message', 'v::url()' => 'error message'), 'validValues' => array('http://www.test.com', 'http://www.testing-tests.com', 'http://www.test.com/', 'https://www.test.com/', 'http://www.test.com/ok', 'https://testing.com/ok.test', 'http://test.com/ok.php', 'http://a.very.long.domain.name.com/ok.jpg?with=get%20params', 'https://www.test.com/ok'), 'invalidValues' => array(null, '', 'htts:///222 asd.com', 'asdasd', 'www.test.com')), 'metaContact' => array('label' => 'Meta Contact', 'validations' => array('required' => 'required error message', 'v::oneOf(v::email(), v::brPhone())' => 'error message'), 'validValues' => array('*****@*****.**', '*****@*****.**', '*****@*****.**', '(11) 9876-5432', '(11) 3456-1234', '(11)34561234', '(11) 93456-1234'), 'invalidValues' => array(null, '', 'test@', 'test', 'teste#teste.com', 'alow as@teste.com', '(11)123', '(1) 123123123123-123')));
     foreach ($metas as $meta_key => $config) {
         $definition = new MapasCulturais\Definitions\Metadata($meta_key, $config);
         $app->unregisterEntityMetadata('MapasCulturais\\Entities\\Agent');
         $app->registerMetadata($definition, 'MapasCulturais\\Entities\\Agent', $type->id);
         $agent = new Agent();
         $agent->name = 'Teste';
         $agent->type = $type;
         $agent->terms['area'][] = 'Cinema';
         for ($i = 1; $i <= 2; $i++) {
             foreach ($config['validValues'] as $val) {
                 $agent->{$meta_key} = $val;
                 $errors = $agent->getValidationErrors();
                 $this->assertArrayNotHasKey($meta_key, $errors, print_r(array('type' => "assertArrayNotHasKey", 'KEY' => $meta_key, 'VALID VALUE' => $val, 'errors' => $errors), true));
             }
             foreach ($config['invalidValues'] as $val) {
                 $agent->{$meta_key} = $val;
                 $errors = $agent->getValidationErrors();
                 $this->assertArrayHasKey($meta_key, $errors, print_r(array('type' => "assertArrayNotHasKey", 'KEY' => $meta_key, 'INVALID VALUE' => $val, 'errors' => $errors), true));
             }
         }
     }
 }
 /**
  * Tries to replace the owner by the new owner.
  * 
  * If the logged in user can not perform the operation a new RequestChangeOwnership object is created.
  * 
  * 
  * @throws \MapasCulturais\Exceptions\PermissionDenied
  * @throws \MapasCulturais\Exceptions\WorkflowRequestTransport
  * 
  * @workflow RequestChangeOwnership
  */
 protected function _saveOwnerAgent()
 {
     if (!$this->owner && $this->_newOwner || $this->_newOwner && !$this->_newOwner->equals($this->owner)) {
         try {
             $this->checkPermission('changeOwner');
             $this->_newOwner->checkPermission('modify');
             $this->owner = $this->_newOwner;
         } catch (\MapasCulturais\Exceptions\PermissionDenied $e) {
             $app = App::i();
             if (!$app->isWorkflowEnabled()) {
                 throw $e;
             }
             $ar = new \MapasCulturais\Entities\RequestChangeOwnership();
             $ar->origin = $this;
             $ar->destination = $this->_newOwner;
             throw new \MapasCulturais\Exceptions\WorkflowRequestTransport($ar);
         }
     }
 }
Exemplo n.º 3
0
 function delete($flush = false)
 {
     $this->checkPermission('remove');
     // ($originType, $originId, $destinationType, $destinationId, $metadata)
     $ruid = RequestAgentRelation::generateRequestUid($this->owner->getClassName(), $this->owner->id, $this->agent->getClassName(), $this->agent->id, ['class' => $this->getClassName(), 'relationId' => $this->id]);
     $requests = App::i()->repo('RequestAgentRelation')->findBy(['requestUid' => $ruid]);
     foreach ($requests as $r) {
         $r->delete($flush);
     }
     parent::delete($flush);
 }
Exemplo n.º 4
0
 protected function canUserRemove($user)
 {
     if ($user->id == $this->agent->getOwnerUser()->id) {
         return true;
     } else {
         if ($this->hasControl) {
             return $this->owner->canUser('removeAgentRelationWithControl', $user);
         } else {
             return $this->owner->canUser('removeAgentRelation', $user);
         }
     }
 }
 public function POST_createAgentRelation()
 {
     $this->requireAuthentication();
     $app = App::i();
     if (!$this->urlData['id']) {
         $app->pass();
     }
     $has_control = key_exists('has_control', $this->postData) && $this->postData['has_control'];
     $owner = $this->repository->find($this->data['id']);
     if (key_exists('agentId', $this->postData)) {
         $agent = $app->repo('Agent')->find($this->data['agentId']);
     } else {
         $agent = new \MapasCulturais\Entities\Agent();
         $agent->status = key_exists('invite', $this->postData) && $this->postData['invite'] ? Agent::STATUS_INVITED : Agent::STATUS_RELATED;
         foreach ($this->postData['agent'] as $prop => $val) {
             $agent->{$prop} = $val;
         }
         $agent->save(true);
     }
     $this->json($owner->createAgentRelation($agent, $this->postData['group'], $has_control));
 }
Exemplo n.º 6
0
 function jsonSerialize()
 {
     $json = ['id' => $this->id, 'project' => $this->project->simplify('id,name,singleUrl'), 'number' => $this->number, 'category' => $this->category, 'owner' => $this->owner->simplify('id,name,singleUrl'), 'agentRelations' => [], 'files' => [], 'singleUrl' => $this->singleUrl, 'editUrl' => $this->editUrl];
     if ($this->project->publishedRegistrations || $this->project->canUser('@control')) {
         $json['status'] = $this->status;
     }
     if ($this->canUser('view') || $this->status === self::STATUS_APPROVED || $this->status === self::STATUS_WAITLIST) {
         $related_agents = $this->getRelatedAgents();
         foreach (App::i()->getRegisteredRegistrationAgentRelations() as $def) {
             $json['agentRelations'][] = ['label' => $def->label, 'description' => $def->description, 'agent' => isset($related_agents[$def->agentRelationGroupName]) ? $related_agents[$def->agentRelationGroupName][0]->simplify('id,name,singleUrl') : null];
         }
         foreach ($this->files as $group => $file) {
             if ($file instanceof File) {
                 $json['files'][$group] = $file->simplify('id,url,name,deleteUrl');
             }
         }
     } else {
         $json['owner'] = null;
     }
     return $json;
 }
Exemplo n.º 7
0
 function setProfile(Agent $agent)
 {
     $this->checkPermission('changeProfile');
     if (!$this->equals($agent->user)) {
         throw new \Exception('error');
     }
     $this->profile = $agent;
     $agent->setParentAsNull(true);
 }
Exemplo n.º 8
0
 protected function _saveNested($flush = false)
 {
     if ($this->_newParent !== false) {
         $app = App::i();
         if (is_object($this->parent) && is_object($this->_newParent) && $this->parent->equals($this->_newParent) || is_null($this->parent) && is_null($this->_newParent)) {
             return;
         }
         try {
             $this->checkPermission('changeOwner');
             if ($this->_newParent) {
                 $this->_newParent->checkPermission('@control');
                 $this->parent = $this->_newParent;
                 $this->user = $this->_newUser;
                 $this->_newParent = false;
             }
         } catch (\MapasCulturais\Exceptions\PermissionDenied $e) {
             if (!$app->isWorkflowEnabled()) {
                 throw $e;
             }
             $destination = $this->_newParent;
             $this->_newParent = false;
             $ar = new \MapasCulturais\Entities\RequestChangeOwnership();
             $ar->origin = $this;
             $ar->destination = $destination;
             throw new \MapasCulturais\Exceptions\WorkflowRequestTransport($ar);
         }
     }
 }
Exemplo n.º 9
0
 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))";
     });
 }
Exemplo n.º 10
0
 public function canUser($action, $userOrAgent = null)
 {
     return $this->owner->canUser($action, $userOrAgent);
 }
Exemplo n.º 11
0
    ?>
                <th><?php 
    echo $def->label;
    ?>
</th>
                <?php 
    foreach ($_properties as $prop) {
        if ($prop === 'name') {
            continue;
        }
        ?>
                    <th><?php 
        echo $def->label;
        ?>
 - <?php 
        echo Agent::getPropertyLabel($prop);
        ?>
</th>
                <?php 
    }
    ?>
            <?php 
}
?>
        </tr>
    </thead>
    <tbody>
        <?php 
foreach ($entity->sentRegistrations as $r) {
    ?>
            <tr>
Exemplo n.º 12
0
 function setParent(Agent $parent = null)
 {
     if ($parent != $this->parent) {
         $this->checkPermission('changeOwner');
         $parent->checkPermission('modify');
         $this->parent = $parent;
         if (!is_null($parent)) {
             if ($parent->id == $this->id) {
                 $this->parent = null;
             }
             $this->setUser($parent->user);
         }
     }
 }