private static function getUnvalidated(Application $app, $home = false) { $terms = []; foreach ($app->getDataboxes() as $databox) { try { $cgus = $databox->get_cgus(); if (!isset($cgus[$app['locale']])) { throw new Exception('No CGus for this locale'); } $name = $databox->get_label($app['locale']); $update = $cgus[$app['locale']]['updated_on']; $value = $cgus[$app['locale']]['value']; $userValidation = true; if (!$home) { if (!$app->getAclForUser($app->getAuthenticatedUser())->has_access_to_sbas($databox->get_sbas_id())) { continue; } $userValidation = $app['settings']->getUserSetting($app->getAuthenticatedUser(), 'terms_of_use_' . $databox->get_sbas_id()) !== $update && trim($value) !== ''; } if ($userValidation) { $terms[$name] = ['sbas_id' => $databox->get_sbas_id(), 'terms' => $value, 'date' => $update]; } } catch (\Exception $e) { } } return $terms; }
public function getUserSetting($setting, $default = null) { if (false === $this->app->getAuthenticatedUser() instanceof User) { return $default; } return $this->app['settings']->getUserSetting($this->app->getAuthenticatedUser(), $setting, $default); }
public static function getSearchStatus(Application $app) { $structures = $stats = []; foreach ($app->getAclForUser($app->getAuthenticatedUser())->get_granted_sbas() as $databox) { $see_all = false; foreach ($databox->get_collections() as $collection) { if ($app->getAclForUser($app->getAuthenticatedUser())->has_right_on_base($collection->get_base_id(), 'chgstatus')) { $see_all = true; break; } } $status = $databox->getStatusStructure()->toArray(); if (!$see_all) { $status = array_filter($status, function ($statusbit) { return (bool) $statusbit['searchable']; }); } ksort($status); $structures[$databox->get_sbas_id()] = array('name' => $databox->get_label($app['locale']), 'status' => $status); } ksort($structures); return $structures; }
public function get_notifications() { $unread = 0; $sql = 'SELECT count(id) as total, sum(unread) as unread FROM notifications WHERE usr_id = :usr_id'; $stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql); $stmt->execute([':usr_id' => $this->app->getAuthenticatedUser()->getId()]); $row = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->closeCursor(); if ($row) { $unread = $row['unread']; } if ($unread < 3) { $sql = 'SELECT * FROM notifications WHERE usr_id = :usr_id ORDER BY created_on DESC LIMIT 0,4'; } else { $sql = 'SELECT * FROM notifications WHERE usr_id = :usr_id AND unread="1" ORDER BY created_on DESC'; } $ret = []; $stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql); $stmt->execute([':usr_id' => $this->app->getAuthenticatedUser()->getId()]); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); foreach ($rs as $row) { $type = 'eventsmanager_' . $row['type']; if (!isset($this->pool_classes[$type])) { continue; } $data = @json_decode($row['datas'], true); if (json_last_error() !== JSON_ERROR_NONE) { continue; } $datas = $this->pool_classes[$type]->datas($data, $row['unread']); if (!isset($this->pool_classes[$type]) || count($datas) === 0) { $sql = 'DELETE FROM notifications WHERE id = :id'; $stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql); $stmt->execute([':id' => $row['id']]); $stmt->closeCursor(); continue; } $ret[] = array_merge($datas, ['created_on' => $this->app['date-formatter']->getPrettyString(new DateTime($row['created_on'])), 'icon' => $this->pool_classes[$type]->icon_url(), 'id' => $row['id'], 'unread' => $row['unread']]); } return $ret; }
/** * @return set_selection */ public function get_grouping_parents() { $sql = 'SELECT r.record_id FROM regroup g INNER JOIN (record r INNER JOIN collusr c ON site = :site AND usr_id = :usr_id AND c.coll_id = r.coll_id AND ((status ^ mask_xor) & mask_and)=0 AND r.parent_record_id = 1 ) ON (g.rid_parent = r.record_id) WHERE rid_child = :record_id'; $stmt = $this->get_databox()->get_connection()->prepare($sql); $stmt->execute([':site' => $this->app['conf']->get(['main', 'key']), ':usr_id' => $this->app->getAuthenticatedUser()->getId(), ':record_id' => $this->get_record_id()]); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); $set = new set_selection($this->app); foreach ($rs as $row) { $set->add_element(new record_adapter($this->app, $this->get_sbas_id(), $row['record_id'])); } return $set; }
/** * Create a new RecordRequest from current request * * @param Application $app * @param Request $request * @param boolean $flattenStories * @param array $rightsColl * @param array $rightsDatabox * @return RecordsRequest|\record_adapter[] */ public static function fromRequest(Application $app, Request $request, $flattenStories = self::FLATTEN_NO, array $rightsColl = [], array $rightsDatabox = []) { $elements = $received = []; $basket = null; if ($request->get('ssel')) { $basket = $app['converter.basket']->convert($request->get('ssel')); $app['acl.basket']->hasAccess($basket, $app->getAuthenticatedUser()); foreach ($basket->getElements() as $basket_element) { $received[$basket_element->getRecord($app)->get_serialize_key()] = $basket_element->getRecord($app); } } elseif ($request->get('story')) { $repository = $app['repo.story-wz']; $storyWZ = $repository->findByUserAndId($app, $app->getAuthenticatedUser(), $request->get('story')); $received[$storyWZ->getRecord($app)->get_serialize_key()] = $storyWZ->getRecord($app); } else { foreach (explode(";", $request->get('lst')) as $bas_rec) { $basrec = explode('_', $bas_rec); if (count($basrec) != 2) { continue; } try { $record = new \record_adapter($app, (int) $basrec[0], (int) $basrec[1]); $received[$record->get_serialize_key()] = $record; unset($record); } catch (NotFoundHttpException $e) { continue; } } } $elements = $received; $to_remove = []; foreach ($elements as $id => $record) { if (!$app->getAclForUser($app->getAuthenticatedUser())->has_access_to_record($record)) { $to_remove[] = $id; continue; } foreach ($rightsColl as $right) { if (!$app->getAclForUser($app->getAuthenticatedUser())->has_right_on_base($record->get_base_id(), $right)) { $to_remove[] = $id; continue; } } foreach ($rightsDatabox as $right) { if (!$app->getAclForUser($app->getAuthenticatedUser())->has_right_on_sbas($record->get_sbas_id(), $right)) { $to_remove[] = $id; continue; } } } foreach ($to_remove as $id) { unset($elements[$id]); } return new static($elements, new ArrayCollection($received), $basket, $flattenStories); }
public static function updateClientInfos(Application $app, $appId) { if (!$app->getAuthenticator()->isAuthenticated()) { return; } $session = $app['repo.sessions']->find($app['session']->get('session_id')); if (!$session) { throw new SessionNotFound('No session found'); } if (!$session->hasModuleId($appId)) { $module = new SessionModule(); $module->setModuleId($appId); $module->setSession($session); $session->addModule($module); $app['orm.em']->persist($module); $app['orm.em']->persist($session); $app['orm.em']->flush(); } $appName = ['1' => 'Prod', '2' => 'Client', '3' => 'Admin', '4' => 'Report', '5' => 'Thesaurus', '6' => 'Compare', '7' => 'Validate', '8' => 'Upload', '9' => 'API']; if (isset($appName[$appId])) { $sbas_ids = array_keys($app->getAclForUser($app->getAuthenticatedUser())->get_granted_sbas()); foreach ($sbas_ids as $sbas_id) { try { $logger = $app['phraseanet.logger']($app->findDataboxById($sbas_id)); $databox = $app->findDataboxById($sbas_id); $connbas = $databox->get_connection(); $sql = 'SELECT appli FROM log WHERE id = :log_id'; $stmt = $connbas->prepare($sql); $stmt->execute([':log_id' => $logger->get_id()]); $row3 = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->closeCursor(); if (!$row3) { throw new Exception('no log'); } $applis = unserialize($row3['appli']); if (!in_array($appId, $applis)) { $applis[] = $appId; } $sql = 'UPDATE log SET appli = :applis WHERE id = :log_id'; $params = [':applis' => serialize($applis), ':log_id' => $logger->get_id()]; $stmt = $connbas->prepare($sql); $stmt->execute($params); $stmt->closeCursor(); } catch (\Exception $e) { } } } return; }
/** * Constructor * * @param Application $app * @param string $d1 the minimal date of the report * @param string $d2 the maximal date of the report * @param integer $sbas_id the id of the base where we want to connect * @param string $collist */ public function __construct(Application $app, $d1, $d2, $sbas_id, $collist) { $this->app = $app; $this->dmin = $d1; $this->dmax = $d2; $this->sbas_id = $sbas_id; $this->list_coll_id = $collist; $this->user_id = $this->app->getAuthenticatedUser()->getId(); $this->periode = sprintf('%s - %s ', $this->app['date-formatter']->getPrettyString(new \DateTime($d1)), $this->app['date-formatter']->getPrettyString(new \DateTime($d2))); $this->dbname = phrasea::sbas_labels($sbas_id, $app); $this->cor = $this->setCor(); $this->jour = $this->setDay(); $this->month = $this->setMonth(); }
/** * * @param Application $app * @param string $lst * @param integer $sstid * @param integer $storyWZid * @return set_export */ public function __construct(Application $app, $lst, $sstid, $storyWZid = null) { $this->app = $app; $download_list = []; $remain_hd = []; if ($storyWZid) { $repository = $app['repo.story-wz']; $storyWZ = $repository->findByUserAndId($this->app, $app->getAuthenticatedUser(), $storyWZid); $lst = $storyWZ->getRecord($this->app)->get_serialize_key(); } if ($sstid != "") { $repository = $app['repo.baskets']; /* @var $repository Alchemy\Phrasea\Model\Repositories\BasketRepository */ $Basket = $repository->findUserBasket($sstid, $app->getAuthenticatedUser(), false); $this->exportName = str_replace([' ', '\\', '/'], '_', $Basket->getName()) . "_" . date("Y-n-d"); foreach ($Basket->getElements() as $basket_element) { $base_id = $basket_element->getRecord($this->app)->get_base_id(); $record_id = $basket_element->getRecord($this->app)->get_record_id(); if (!isset($remain_hd[$base_id])) { if ($app->getAclForUser($app->getAuthenticatedUser())->is_restricted_download($base_id)) { $remain_hd[$base_id] = $app->getAclForUser($app->getAuthenticatedUser())->remaining_download($base_id); } else { $remain_hd[$base_id] = false; } } $current_element = $download_list[] = new record_exportElement($app, $basket_element->getRecord($this->app)->get_sbas_id(), $record_id, $Basket->getName(), $remain_hd[$base_id]); $remain_hd[$base_id] = $current_element->get_remain_hd(); } } else { $this->exportName = "Export_" . date("Y-n-d") . '_' . mt_rand(100, 999); $tmp_lst = explode(';', $lst); $n = 1; foreach ($tmp_lst as $basrec) { $basrec = explode('_', $basrec); if (count($basrec) != 2) { continue; } try { $record = new record_adapter($this->app, $basrec[0], $basrec[1]); } catch (\Exception_Record_AdapterNotFound $e) { continue; } if ($record->isStory()) { foreach ($record->get_children() as $child_basrec) { $base_id = $child_basrec->get_base_id(); $record_id = $child_basrec->get_record_id(); if (!isset($remain_hd[$base_id])) { if ($app->getAclForUser($app->getAuthenticatedUser())->is_restricted_download($base_id)) { $remain_hd[$base_id] = $app->getAclForUser($app->getAuthenticatedUser())->remaining_download($base_id); } else { $remain_hd[$base_id] = false; } } $current_element = $download_list[] = new record_exportElement($app, $child_basrec->get_sbas_id(), $record_id, $record->get_title(null, null, true) . '_' . $n, $remain_hd[$base_id]); $remain_hd[$base_id] = $current_element->get_remain_hd(); } } else { $base_id = $record->get_base_id(); $record_id = $record->get_record_id(); if (!isset($remain_hd[$base_id])) { if ($app->getAclForUser($app->getAuthenticatedUser())->is_restricted_download($base_id)) { $remain_hd[$base_id] = $app->getAclForUser($app->getAuthenticatedUser())->remaining_download($base_id); } else { $remain_hd[$base_id] = false; } } $current_element = $download_list[$basrec[0] . '_' . $basrec[1]] = new record_exportElement($app, $record->get_sbas_id(), $record_id, '', $remain_hd[$base_id]); $remain_hd[$base_id] = $current_element->get_remain_hd(); } $n++; } } $this->elements = $download_list; $display_download = []; $display_orderable = []; $this->total_download = 0; $this->total_order = 0; $this->total_ftp = 0; $this->businessFieldsAccess = false; foreach ($this->elements as $download_element) { if ($app->getAclForUser($app->getAuthenticatedUser())->has_right_on_base($download_element->get_base_id(), 'canmodifrecord')) { $this->businessFieldsAccess = true; } foreach ($download_element->get_downloadable() as $name => $properties) { if (!isset($display_download[$name])) { $display_download[$name] = ['size' => 0, 'total' => 0, 'available' => 0, 'refused' => []]; } $display_download[$name]['total']++; if ($properties !== false) { $display_download[$name]['available']++; $display_download[$name]['label'] = $properties['label']; $display_download[$name]['class'] = $properties['class']; $this->total_download++; $display_download[$name]['size'] += $download_element->get_size($name); } else { $display_download[$name]['refused'][] = $download_element->get_thumbnail(); } } foreach ($download_element->get_orderable() as $name => $properties) { if (!isset($display_orderable[$name])) { $display_orderable[$name] = ['total' => 0, 'available' => 0, 'refused' => []]; } $display_orderable[$name]['total']++; if ($properties !== false) { $display_orderable[$name]['available']++; $this->total_order++; } else { $display_orderable[$name]['refused'][] = $download_element->get_thumbnail(); } } } foreach ($display_download as $name => $values) { $display_download[$name]['size'] = (int) $values['size']; } $display_ftp = []; $hasadminright = $app->getAclForUser($app->getAuthenticatedUser())->has_right('addrecord') || $app->getAclForUser($app->getAuthenticatedUser())->has_right('deleterecord') || $app->getAclForUser($app->getAuthenticatedUser())->has_right('modifyrecord') || $app->getAclForUser($app->getAuthenticatedUser())->has_right('coll_manage') || $app->getAclForUser($app->getAuthenticatedUser())->has_right('coll_modify_struct'); $this->ftp_datas = []; if ($this->app['conf']->get(['registry', 'ftp', 'ftp-enabled']) && ($hasadminright || $this->app['conf']->get(['registry', 'ftp', 'ftp-user-access']))) { $display_ftp = $display_download; $this->total_ftp = $this->total_download; $lst_base_id = array_keys($app->getAclForUser($app->getAuthenticatedUser())->get_granted_base()); if ($hasadminright) { $sql = "SELECT Users.id AS usr_id ,Users.login AS usr_login ,Users.email AS usr_mail, FtpCredential.*\n FROM (\n FtpCredential INNER JOIN Users ON (\n FtpCredential.active = 1 AND FtpCredential.user_id = Users.id\n ) INNER JOIN basusr ON (\n Users.id=basusr.usr_id\n AND (basusr.base_id=\n '" . implode("' OR basusr.base_id='", $lst_base_id) . "'\n )\n )\n )\n GROUP BY Users.id "; $params = []; } elseif ($this->app['conf']->get(['registry', 'ftp', 'ftp-user-access'])) { $sql = "SELECT Users.id AS usr_id ,Users.login AS usr_login ,Users.email AS usr_mail, FtpCredential.*\n FROM (\n FtpCredential INNER JOIN Users ON (\n FtpCredential.active = 1 AND FtpCredential.id = Users.id\n ) INNER JOIN basusr ON (\n Users.id=basusr.usr_id\n AND Users.id = :usr_id\n AND (basusr.base_id=\n '" . implode("' OR basusr.base_id='", $lst_base_id) . "'\n )\n )\n )\n GROUP BY Users.id "; $params = [':usr_id' => $app->getAuthenticatedUser()->getId()]; } $datas[] = ['name' => $app->trans('export::ftp: reglages manuels'), 'usr_id' => '0', 'address' => '', 'login' => '', 'password' => '', 'ssl' => false, 'dest_folder' => '', 'prefix_folder' => 'Export_' . date("Y-m-d_H.i.s"), 'passive' => false, 'max_retry' => 5, 'sendermail' => $app->getAuthenticatedUser()->getEmail()]; $stmt = $app->getApplicationBox()->get_connection()->prepare($sql); $stmt->execute($params); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); foreach ($rs as $row) { $datas[] = ['name' => $row["usr_login"], 'usr_id' => $row['usr_id'], 'address' => $row['address'], 'login' => $row['login'], 'password' => $row['password'], 'ssl' => !!$row['tls'], 'dest_folder' => $row['reception_folder'], 'prefix_folder' => strlen(trim($row['repository_prefix_name'])) > 0 ? trim($row['repository_prefix_name']) : 'Export_' . date("Y-m-d_H.i.s"), 'passive' => !!$row['passive'], 'max_retry' => $row['max_retry'], 'usr_mail' => $row['usr_mail'], 'sender_mail' => $app->getAuthenticatedUser()->getEmail()]; } $this->ftp_datas = $datas; } $this->display_orderable = $display_orderable; $this->display_download = $display_download; $this->display_ftp = $display_ftp; return $this; }
public function __construct(Application $app, $env, $pos, $contId, SearchEngineInterface $search_engine = null, $query = '', SearchEngineOptions $options = null) { $number = null; $this->env = $env; $this->app = $app; $this->pos = $pos; $this->searchEngine = $search_engine; $this->query = $query; $this->options = $options; switch ($env) { case "RESULT": if (null === $search_engine) { throw new \LogicException('Search Engine should be provided'); } $results = $search_engine->query($query, (int) $pos, 1, $options); if ($results->getResults()->isEmpty()) { throw new Exception('Record introuvable'); } foreach ($results->getResults() as $record) { $number = $pos; $this->original_item = $record; $sbas_id = $record->getDataboxId(); $record_id = $record->getRecordId(); break; } break; case "REG": $contId = explode('_', $contId); $sbas_id = $contId[0]; $record_id = $contId[1]; $this->container = new record_adapter($app, $sbas_id, $record_id); $this->original_item = $this->container; if ($pos == 0) { $number = 0; } else { $children = $this->container->get_children(); foreach ($children as $child) { $sbas_id = $child->get_sbas_id(); $this->original_item = $child; $record_id = $child->get_record_id(); if ($child->getNumber() == $pos) { break; } } $number = $pos; $this->total = $children->get_count(); } break; case "BASK": $Basket = $app['converter.basket']->convert($contId); $app['acl.basket']->hasAccess($Basket, $app->getAuthenticatedUser()); /* @var $Basket Basket */ $this->container = $Basket; $this->total = $Basket->getElements()->count(); $i = 0; $first = true; foreach ($Basket->getElements() as $element) { /* @var $element BasketElement */ $i++; if ($first) { $this->original_item = $element; $sbas_id = $element->getRecord($this->app)->get_sbas_id(); $record_id = $element->getRecord($this->app)->get_record_id(); $this->name = $Basket->getName(); $number = $element->getOrd(); } $first = false; if ($element->getOrd() == $pos) { $this->original_item = $element; $sbas_id = $element->getRecord($this->app)->get_sbas_id(); $record_id = $element->getRecord($this->app)->get_record_id(); $this->name = $Basket->getName(); $number = $element->getOrd(); } } break; case "FEED": $entry = $app['repo.feed-entries']->find($contId); $this->container = $entry; $this->total = count($entry->getItems()); $i = 0; $first = true; foreach ($entry->getItems() as $element) { $i++; if ($first) { $sbas_id = $element->getRecord($this->app)->get_sbas_id(); $record_id = $element->getRecord($this->app)->get_record_id(); $this->name = $entry->getTitle(); $this->original_item = $element; $number = $element->getOrd(); } $first = false; if ($element->getOrd() == $pos) { $sbas_id = $element->getRecord($this->app)->get_sbas_id(); $record_id = $element->getRecord($this->app)->get_record_id(); $this->name = $entry->getTitle(); $this->original_item = $element; $number = $element->getOrd(); } } break; } parent::__construct($app, $sbas_id, $record_id, $number); }
protected function addItem(Application $app, \DOMDocument $document, \DOMNode $node, FeedEntry $entry) { $item = $this->addTag($document, $node, 'item'); $feed = $entry->getFeed(); if ($feed->isPublic()) { $link = $app['feed.link-generator-collection']->generatePublic($feed, FeedLinkGenerator::FORMAT_RSS); } else { $link = $app['feed.link-generator-collection']->generate($feed, $app->getAuthenticatedUser(), FeedLinkGenerator::FORMAT_RSS); } $this->addTag($document, $item, 'title', $entry->getTitle()); $this->addTag($document, $item, 'description', $entry->getSubtitle()); $author = sprintf('%s (%s)', $entry->getAuthorEmail(), $entry->getAuthorName()); $created_on = $entry->getCreatedOn()->format(DATE_RFC2822); $this->addTag($document, $item, 'author', $author); $this->addTag($document, $item, 'pubDate', $created_on); $this->addTag($document, $item, 'guid', $link->getURI()); $this->addTag($document, $item, 'link', $link->getURI()); /** * Missing : * * category Includes the item in one or more categories. More. * comments URL of a page for comments relating to the item. More. * enclosure Describes a media object that is attached to the item. More. * source The RSS channel that the item came from. More. * */ foreach ($entry->getItems() as $content) { $this->addContent($app, $document, $item, $content); } return $item; }