本文整理汇总了PHP中collection::get_from_base_id方法的典型用法代码示例。如果您正苦于以下问题:PHP collection::get_from_base_id方法的具体用法?PHP collection::get_from_base_id怎么用?PHP collection::get_from_base_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类collection
的用法示例。
在下文中一共展示了collection::get_from_base_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: apply
public function apply(Application $app, Request $request)
{
$records = RecordsRequest::fromRequest($app, $request, false, ['candeleterecord']);
$datas = ['success' => false, 'message' => ''];
try {
if (null === $request->request->get('base_id')) {
$datas['message'] = $app->trans('Missing target collection');
return $app->json($datas);
}
if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($request->request->get('base_id'), 'canaddrecord')) {
$datas['message'] = $app->trans("You do not have the permission to move records to %collection%", ['%collection%', \phrasea::bas_labels($request->request->get('base_id'), $app)]);
return $app->json($datas);
}
try {
$collection = \collection::get_from_base_id($app, $request->request->get('base_id'));
} catch (\Exception_Databox_CollectionNotFound $e) {
$datas['message'] = $app->trans('Invalid target collection');
return $app->json($datas);
}
foreach ($records as $record) {
$record->move_to_collection($collection, $app['phraseanet.appbox']);
if ($request->request->get("chg_coll_son") == "1") {
foreach ($record->get_children() as $child) {
if ($app['acl']->get($app['authentication']->getUser())->has_right_on_base($child->get_base_id(), 'candeleterecord')) {
$child->move_to_collection($collection, $app['phraseanet.appbox']);
}
}
}
}
$ret = ['success' => true, 'message' => $app->trans('Records have been successfuly moved')];
} catch (\Exception $e) {
$ret = ['success' => false, 'message' => $app->trans('An error occured')];
}
return $app->json($ret);
}
示例2: doJob
/**
* {@inheritdoc}
*/
protected function doJob(JobData $data)
{
$app = $data->getApplication();
$task = $data->getTask();
$settings = simplexml_load_string($task->getSettings());
$baseId = (string) $settings->base_id;
$collection = \collection::get_from_base_id($app, $baseId);
$collection->empty_collection(200);
if (0 === $collection->get_record_amount()) {
$this->stop();
$this->dispatcher->dispatch(JobEvents::FINISHED, new JobFinishedEvent($task));
}
}
示例3: apply
/**
* {@inheritdoc}
*/
public function apply(base $appbox, Application $app)
{
$em = $app['orm.em'];
$sql = "SELECT date_modif, usr_id, base_id, en_cours, refuser\n FROM demand";
$rsm = new ResultSetMapping();
$rsm->addScalarResult('base_id', 'base_id');
$rsm->addScalarResult('en_cours', 'en_cours');
$rsm->addScalarResult('refuser', 'refuser');
$rsm->addScalarResult('usr_id', 'usr_id');
$rsm->addScalarResult('date_modif', 'date_modif');
$rs = $em->createNativeQuery($sql, $rsm)->getResult();
$n = 0;
foreach ($rs as $row) {
try {
$user = $em->createQuery('SELECT PARTIAL u.{id} FROM Phraseanet:User s WHERE u.id = :id')->setParameters(['id' => $row['usr_id']])->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true)->getSingleResult();
} catch (NoResultException $e) {
$app['monolog']->addInfo(sprintf('Patch %s : Registration for user (%s) could not be turn into doctrine entity as user could not be found.', $this->get_release(), $row['usr_id']));
continue;
}
try {
$collection = \collection::get_from_base_id($app, $row['base_id']);
} catch (\Exception $e) {
$app['monolog']->addInfo(sprintf('Patch %s : Registration for user (%s) could not be turn into doctrine entity as base with id (%s) could not be found.', $this->get_release(), $row['usr_id'], $row['base_id']));
continue;
}
$registration = new Registration();
$registration->setCollection($collection);
$registration->setUser($user);
$registration->setPending($row['en_cours']);
$registration->setCreated(new \DateTime($row['date_modif']));
$registration->setRejected($row['refuser']);
if ($n % 100 === 0) {
$em->flush();
$em->clear();
}
$n++;
}
$em->flush();
$em->clear();
}
示例4: postCreateFormAction
public function postCreateFormAction(Request $request)
{
$collection = \collection::get_from_base_id($this->app, $request->request->get('base_id'));
if (!$this->getAclForUser()->has_right_on_base($collection->get_base_id(), 'canaddrecord')) {
throw new AccessDeniedHttpException('You can not create a story on this collection');
}
$story = \record_adapter::createStory($this->app, $collection);
$records = RecordsRequest::fromRequest($this->app, $request, true);
foreach ($records as $record) {
if ($story->hasChild($record)) {
continue;
}
$story->appendChild($record);
}
$metadatas = [];
foreach ($collection->get_databox()->get_meta_structure() as $meta) {
if ($meta->get_thumbtitle()) {
$value = $request->request->get('name');
} else {
continue;
}
$metadatas[] = ['meta_struct_id' => $meta->get_id(), 'meta_id' => null, 'value' => $value];
break;
}
$story->set_metadatas($metadatas)->rebuild_subdefs();
$storyWZ = new StoryWZ();
$storyWZ->setUser($this->getAuthenticatedUser());
$storyWZ->setRecord($story);
$manager = $this->getEntityManager();
$manager->persist($storyWZ);
$manager->flush();
if ($request->getRequestFormat() == 'json') {
$data = ['success' => true, 'message' => $this->app->trans('Story created'), 'WorkZone' => $storyWZ->getId(), 'story' => ['sbas_id' => $story->get_sbas_id(), 'record_id' => $story->get_record_id()]];
return $this->app->json($data);
}
return $this->app->redirectPath('prod_stories_story', ['sbas_id' => $storyWZ->getSbasId(), 'record_id' => $storyWZ->getRecordId()]);
}
示例5: connect
public function connect(Application $app)
{
$app['controller.prod.story'] = $this;
$controllers = $app['controllers_factory'];
$app['firewall']->addMandatoryAuthentication($controllers);
$controllers->get('/create/', function (Application $app) {
return $app['twig']->render('prod/Story/Create.html.twig', []);
})->bind('prod_stories_create');
$controllers->post('/', function (Application $app, Request $request) {
/* @var $request \Symfony\Component\HttpFoundation\Request */
$collection = \collection::get_from_base_id($app, $request->request->get('base_id'));
if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($collection->get_base_id(), 'canaddrecord')) {
throw new AccessDeniedHttpException('You can not create a story on this collection');
}
$Story = \record_adapter::createStory($app, $collection);
$records = RecordsRequest::fromRequest($app, $request, true);
foreach ($records as $record) {
if ($Story->hasChild($record)) {
continue;
}
$Story->appendChild($record);
}
$metadatas = [];
foreach ($collection->get_databox()->get_meta_structure() as $meta) {
if ($meta->get_thumbtitle()) {
$value = $request->request->get('name');
} else {
continue;
}
$metadatas[] = ['meta_struct_id' => $meta->get_id(), 'meta_id' => null, 'value' => $value];
break;
}
$Story->set_metadatas($metadatas)->rebuild_subdefs();
$StoryWZ = new StoryWZ();
$StoryWZ->setUser($app['authentication']->getUser());
$StoryWZ->setRecord($Story);
$app['EM']->persist($StoryWZ);
$app['EM']->flush();
if ($request->getRequestFormat() == 'json') {
$data = ['success' => true, 'message' => $app->trans('Story created'), 'WorkZone' => $StoryWZ->getId(), 'story' => ['sbas_id' => $Story->get_sbas_id(), 'record_id' => $Story->get_record_id()]];
return $app->json($data);
} else {
return $app->redirectPath('prod_stories_story', ['sbas_id' => $StoryWZ->getSbasId(), 'record_id' => $StoryWZ->getRecordId()]);
}
})->bind('prod_stories_do_create');
$controllers->get('/{sbas_id}/{record_id}/', function (Application $app, $sbas_id, $record_id) {
$Story = new \record_adapter($app, $sbas_id, $record_id);
$html = $app['twig']->render('prod/WorkZone/Story.html.twig', ['Story' => $Story]);
return new Response($html);
})->bind('prod_stories_story')->assert('sbas_id', '\\d+')->assert('record_id', '\\d+');
$controllers->post('/{sbas_id}/{record_id}/addElements/', function (Application $app, Request $request, $sbas_id, $record_id) {
$Story = new \record_adapter($app, $sbas_id, $record_id);
if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($Story->get_base_id(), 'canmodifrecord')) {
throw new AccessDeniedHttpException('You can not add document to this Story');
}
$n = 0;
$records = RecordsRequest::fromRequest($app, $request, true);
foreach ($records as $record) {
if ($Story->hasChild($record)) {
continue;
}
$Story->appendChild($record);
$n++;
}
$data = ['success' => true, 'message' => $app->trans('%quantity% records added', ['%quantity%' => $n])];
if ($request->getRequestFormat() == 'json') {
return $app->json($data);
} else {
return $app->redirectPath('prod_stories_story', ['sbas_id' => $sbas_id, 'record_id' => $record_id]);
}
})->assert('sbas_id', '\\d+')->assert('record_id', '\\d+');
$controllers->post('/{sbas_id}/{record_id}/delete/{child_sbas_id}/{child_record_id}/', function (Application $app, Request $request, $sbas_id, $record_id, $child_sbas_id, $child_record_id) {
$Story = new \record_adapter($app, $sbas_id, $record_id);
$record = new \record_adapter($app, $child_sbas_id, $child_record_id);
if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($Story->get_base_id(), 'canmodifrecord')) {
throw new AccessDeniedHttpException('You can not add document to this Story');
}
$Story->removeChild($record);
$data = ['success' => true, 'message' => $app->trans('Record removed from story')];
if ($request->getRequestFormat() == 'json') {
return $app->json($data);
} else {
return $app->redirectPath('prod_stories_story', ['sbas_id' => $sbas_id, 'record_id' => $record_id]);
}
})->bind('prod_stories_story_remove_element')->assert('sbas_id', '\\d+')->assert('record_id', '\\d+')->assert('child_sbas_id', '\\d+')->assert('child_record_id', '\\d+');
/**
* Get the Basket reorder form
*/
$controllers->get('/{sbas_id}/{record_id}/reorder/', function (Application $app, $sbas_id, $record_id) {
$story = new \record_adapter($app, $sbas_id, $record_id);
if (!$story->is_grouping()) {
throw new \Exception('This is not a story');
}
return new Response($app['twig']->render('prod/Story/Reorder.html.twig', ['story' => $story]));
})->bind('prod_stories_story_reorder')->assert('sbas_id', '\\d+')->assert('record_id', '\\d+');
$controllers->post('/{sbas_id}/{record_id}/reorder/', function (Application $app, $sbas_id, $record_id) {
$ret = ['success' => false, 'message' => $app->trans('An error occured')];
try {
$story = new \record_adapter($app, $sbas_id, $record_id);
if (!$story->is_grouping()) {
//.........这里部分代码省略.........
示例6: getCollection
/**
* Returns the collection to which the feed belongs.
*
* @param Application $app
*
* @return \collection
*/
public function getCollection(Application $app)
{
if ($this->getBaseId() !== null) {
return \collection::get_from_base_id($app, $this->getBaseId());
}
}
示例7: print_preview
protected function print_preview($withtdm, $write_caption)
{
if ($withtdm === true) {
$this->print_thumbnailGrid($this->pdf, $this->records, true);
}
foreach ($this->records as $krec => $rec) {
/* @var $rec record_adapter */
$this->pdf->AddPage();
if ($withtdm === "CALCPAGES") {
$rec->setNumber($this->pdf->PageNo());
}
$lmargin = $this->pdf->GetX();
$himg = 0;
$y = 0;
$miniConv = NULL;
$LEFT__TEXT = "";
$LEFT__IMG = NULL;
$RIGHT_TEXT = "";
$RIGHT_IMG = NULL;
$LEFT__IMG = $this->app['root.path'] . "/config/minilogos/logopdf_" . $rec->get_sbas_id() . ".jpg";
if (!is_file($LEFT__IMG)) {
$databox = $rec->get_databox();
$str = $databox->get_sxml_structure();
$vn = (string) $str->pdfPrintLogo;
if ($vn * 1 == 1) {
$LEFT__TEXT = $databox->get_label($this->app['locale']);
}
}
$collection = \collection::get_from_base_id($this->app, $rec->get_base_id());
$vn = "";
if (false !== ($str = simplexml_load_string($collection->get_prefs()))) {
$vn = (string) $str->pdfPrintappear;
}
if ($vn == "" || $vn == "1") {
$RIGHT_TEXT = \phrasea::bas_labels($rec->get_base_id(), $this->app);
} elseif ($vn == "2") {
$RIGHT_IMG = $this->app['root.path'] . "/config/minilogos/" . $rec->get_base_id();
}
$xtmp = $this->pdf->GetX();
$ytmp = $this->pdf->GetY();
$this->pdf->SetFont(PhraseaPDF::FONT, '', 12);
$this->pdf->SetFillColor(220, 220, 220);
$y = $this->pdf->GetY();
$this->pdf->MultiCell(95, 7, $LEFT__TEXT, "LTB", "L", 1);
$y2 = $this->pdf->GetY();
$h = $y2 - $y;
$this->pdf->SetY($y);
$this->pdf->SetX(105);
$this->pdf->Cell(95, $h, $RIGHT_TEXT, "TBR", 1, "R", 1);
if ($LEFT__TEXT == "" && is_file($LEFT__IMG)) {
if ($size = @getimagesize($LEFT__IMG)) {
$wmm = (int) $size[0] * 25.4 / 72;
$hmm = (int) $size[1] * 25.4 / 72;
if ($hmm > 6) {
$coeff = $hmm / 6;
$wmm = (int) $wmm / $coeff;
$hmm = (int) $hmm / $coeff;
}
$this->pdf->Image($LEFT__IMG, $xtmp + 0.5, $ytmp + 0.5, $wmm, $hmm);
}
}
if ($RIGHT_IMG != NULL && is_file($RIGHT_IMG)) {
if ($size = @getimagesize($RIGHT_IMG)) {
if ($size[2] == '1') {
if (!isset($miniConv[$RIGHT_IMG])) {
$tmp_filename = tempnam('minilogos/', 'gif4fpdf');
$img = imagecreatefromgif($RIGHT_IMG);
imageinterlace($img, 0);
imagepng($img, $tmp_filename);
rename($tmp_filename, $tmp_filename . '.png');
$miniConv[$RIGHT_IMG] = $tmp_filename . '.png';
$RIGHT_IMG = $tmp_filename . '.png';
} else {
$RIGHT_IMG = $miniConv[$RIGHT_IMG];
}
$wmm = (int) $size[0] * 25.4 / 72;
$hmm = (int) $size[1] * 25.4 / 72;
if ($hmm > 6) {
$coeff = $hmm / 6;
$wmm = (int) $wmm / $coeff;
$hmm = (int) $hmm / $coeff;
}
$tt = 0;
if ($hmm < 6) {
$tt = (6 - $hmm) / 2;
}
$this->pdf->Image($RIGHT_IMG, 200 - 0.5 - $wmm, $ytmp + 0.5 + $tt);
} else {
$wmm = (int) $size[0] * 25.4 / 72;
$hmm = (int) $size[1] * 25.4 / 72;
if ($hmm > 6) {
$coeff = $hmm / 6;
$wmm = (int) $wmm / $coeff;
$hmm = (int) $hmm / $coeff;
}
$this->pdf->Image($RIGHT_IMG, 200 - 0.5 - $wmm, $ytmp + 0.5);
}
}
}
$y = $this->pdf->GetY() + 5;
//.........这里部分代码省略.........
示例8: register
public function register(Application $app)
{
$app['border-manager'] = $app->share(function (Application $app) {
$borderManager = new Manager($app);
try {
$borderManager->setPdfToText($app['xpdf.pdftotext']);
} catch (BinaryNotFoundException $e) {
}
$options = $app['conf']->get('border-manager');
$registeredCheckers = [];
if ($options['enabled']) {
foreach ($options['checkers'] as $checker) {
if (!isset($checker['type'])) {
continue;
}
if (isset($checker['enabled']) && $checker['enabled'] !== true) {
continue;
}
$className = sprintf('\\Alchemy\\Phrasea\\Border\\%s', $checker['type']);
if (!class_exists($className)) {
$app['monolog']->error(sprintf('Border manager checker, invalid checker %s', $checker['type']));
continue;
}
$options = [];
if (isset($checker['options']) && is_array($checker['options'])) {
$options = $checker['options'];
}
try {
$checkerObj = new $className($app, $options);
if (isset($checker['databoxes'])) {
$databoxes = [];
foreach ($checker['databoxes'] as $sbas_id) {
try {
$databoxes[] = $app['phraseanet.appbox']->get_databox($sbas_id);
} catch (\Exception $e) {
throw new \InvalidArgumentException('Invalid databox option');
}
}
$checkerObj->restrictToDataboxes($databoxes);
}
if (isset($checker['collections'])) {
$collections = [];
foreach ($checker['collections'] as $base_id) {
try {
$collections[] = \collection::get_from_base_id($app, $base_id);
} catch (\Exception $e) {
throw new \InvalidArgumentException('Invalid collection option');
}
}
$checkerObj->restrictToCollections($collections);
}
$registeredCheckers[] = $checkerObj;
} catch (\InvalidArgumentException $e) {
$app['monolog']->error(sprintf('Border manager checker InvalidArgumentException : %s', $e->getMessage()));
} catch (\LogicException $e) {
$app['monolog']->error(sprintf('Border manager checker LogicException : %s', $e->getMessage()));
}
}
$borderManager->registerCheckers($registeredCheckers);
}
return $borderManager;
});
$app['border-manager.mime-guesser-configuration'] = $app->share(function (Application $app) {
return new MimeGuesserConfiguration($app['conf']);
});
}
示例9: doDeliverPermalink
private function doDeliverPermalink(PhraseaApplication $app, $sbas_id, $record_id, $token, $subdef)
{
$databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id);
$record = $this->retrieveRecord($app, $databox, $token, $record_id, $subdef);
$watermark = $stamp = false;
if ($app['authentication']->isAuthenticated()) {
$watermark = !$app['acl']->get($app['authentication']->getUser())->has_right_on_base($record->get_base_id(), 'nowatermark');
if ($watermark) {
$repository = $app['EM']->getRepository('Phraseanet:BasketElement');
if (count($repository->findReceivedValidationElementsByRecord($record, $app['authentication']->getUser())) > 0) {
$watermark = false;
} elseif (count($repository->findReceivedElementsByRecord($record, $app['authentication']->getUser())) > 0) {
$watermark = false;
}
}
$response = $this->deliverContent($app['request'], $record, $subdef, $watermark, $stamp, $app);
$linkToCaption = $app->url("permalinks_caption", ['sbas_id' => $sbas_id, 'record_id' => $record_id, 'token' => $token]);
$response->headers->set('Link', $linkToCaption);
return $response;
}
$collection = \collection::get_from_base_id($app, $record->get_base_id());
switch ($collection->get_pub_wm()) {
default:
case 'none':
$watermark = false;
break;
case 'stamp':
$stamp = true;
break;
case 'wm':
$watermark = false;
break;
}
$response = $this->deliverContent($app['request'], $record, $subdef, $watermark, $stamp, $app);
$linkToCaption = $app->url("permalinks_caption", ['sbas_id' => $sbas_id, 'record_id' => $record_id, 'token' => $token]);
$response->headers->set('Link', $linkToCaption);
return $response;
}
示例10: updateAction
/**
* @param Request $request
* @param int $id
* @return Response
*/
function updateAction(Request $request, $id)
{
if ('' === ($title = trim($request->request->get('title', '')))) {
$this->app->abort(400, "Bad request");
}
$feedRepository = $this->getFeedRepository();
/** @var Feed $feed */
$feed = $feedRepository->find($id);
if (!$feed->isOwner($this->getAuthenticatedUser())) {
return $this->app->redirectPath('admin_feeds_feed', ['id' => $request->attributes->get('id'), 'error' => $this->app->trans('You are not the owner of this feed, you can not edit it')]);
}
try {
$collection = \collection::get_from_base_id($this->app, $request->request->get('base_id'));
} catch (\Exception $e) {
$collection = null;
}
$feed->setTitle($title);
$feed->setSubtitle($request->request->get('subtitle', ''));
$feed->setCollection($collection);
$feed->setIsPublic('1' === $request->request->get('public'));
$manager = $this->getObjectManager();
$manager->persist($feed);
$manager->flush();
return $this->app->redirectPath('admin_feeds_list');
}
示例11: testPostUnmountCollection
/**
* @covers Alchemy\Phrasea\Controller\Admin\Bas::unmount
*/
public function testPostUnmountCollection()
{
$this->setAdmin(true);
$collection = $this->createOneCollection();
$this->XMLHTTPRequest('POST', '/admin/collection/' . $collection->get_base_id() . '/unmount/');
$json = $this->getJson(self::$DI['client']->getResponse());
$this->assertTrue($json->success);
try {
\collection::get_from_base_id(self::$DI['app'], $collection->get_base_id());
$this->fail('Collection not unmounted');
} catch (\Exception_Databox_CollectionNotFound $e) {
}
unset($collection);
}
示例12: get_time
public function get_time()
{
$this->base_id = (int) $this->request->get('base_id');
$sql = "SELECT u.id, time_limited, limited_from, limited_to\n FROM (Users u INNER JOIN basusr bu ON u.id = bu.usr_id)\n WHERE (u.id = " . implode(' OR u.id = ', $this->users) . ")\n AND bu.base_id = :base_id";
$conn = $this->app['phraseanet.appbox']->get_connection();
$stmt = $conn->prepare($sql);
$stmt->execute([':base_id' => $this->base_id]);
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$stmt->closeCursor();
$time_limited = -1;
$limited_from = $limited_to = false;
foreach ($rs as $row) {
if ($time_limited < 0) {
$time_limited = $row['time_limited'];
}
if ($time_limited < 2 && $row['time_limited'] != $row['time_limited']) {
$time_limited = 2;
}
if ($limited_from !== '' && trim($row['limited_from']) != '0000-00-00 00:00:00') {
$limited_from = $limited_from === false ? $row['limited_from'] : ($limited_from == $row['limited_from'] ? $limited_from : '');
}
if ($limited_to !== '' && trim($row['limited_to']) != '0000-00-00 00:00:00') {
$limited_to = $limited_to === false ? $row['limited_to'] : ($limited_to == $row['limited_to'] ? $limited_to : '');
}
}
if ($limited_from) {
$date_obj_from = new \DateTime($limited_from);
$limited_from = $date_obj_from->format('Y-m-d');
}
if ($limited_to) {
$date_obj_to = new \DateTime($limited_to);
$limited_to = $date_obj_to->format('Y-m-d');
}
$datas = ['time_limited' => $time_limited, 'limited_from' => $limited_from, 'limited_to' => $limited_to];
$this->users_datas = $datas;
return ['datas' => $this->users_datas, 'users' => $this->users, 'users_serial' => implode(';', $this->users), 'base_id' => $this->base_id, 'collection' => \collection::get_from_base_id($this->app, $this->base_id)];
}
示例13: setUp
public function setUp()
{
parent::setUp();
if (null !== self::$DI) {
unset(self::$DI['app']['dbal.provider']);
}
self::$DI = new \Pimple();
ini_set('memory_limit', '4096M');
\PHPUnit_Framework_Error_Warning::$enabled = true;
\PHPUnit_Framework_Error_Notice::$enabled = true;
self::$DI['app'] = self::$DI->share(function ($DI) {
return $this->loadApp('/lib/Alchemy/Phrasea/Application/Root.php');
});
self::$DI['cli'] = self::$DI->share(function ($DI) {
return $this->loadCLI();
});
self::$DI['local-guzzle'] = self::$DI->share(function ($DI) {
return new Guzzle(self::$DI['app']['conf']->get('servername'));
});
self::$DI['client'] = self::$DI->share(function ($DI) {
return new Client($DI['app'], []);
});
self::$DI['user'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['test_phpunit']);
});
self::$DI['user_1'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['user_1']);
});
self::$DI['user_2'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['user_2']);
});
self::$DI['user_3'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['user_3']);
});
self::$DI['user_guest'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['user_guest']);
});
self::$DI['user_notAdmin'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['test_phpunit_not_admin']);
});
self::$DI['user_alt1'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['test_phpunit_alt1']);
});
self::$DI['user_alt2'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['test_phpunit_alt2']);
});
self::$DI['user_template'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['user_template']);
});
self::$DI['registration_1'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.registration']->getRepository()->find(self::$fixtureIds['registrations']['registration_1']);
});
self::$DI['registration_2'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.registration']->getRepository()->find(self::$fixtureIds['registrations']['registration_2']);
});
self::$DI['registration_3'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.registration']->getRepository()->find(self::$fixtureIds['registrations']['registration_3']);
});
self::$DI['oauth2-app-user'] = self::$DI->share(function ($DI) {
return new \API_OAuth2_Application($DI['app'], self::$fixtureIds['oauth']['user']);
});
self::$DI['oauth2-app-user_notAdmin'] = self::$DI->share(function ($DI) {
return new \API_OAuth2_Application($DI['app'], self::$fixtureIds['oauth']['user_notAdmin']);
});
self::$DI['logger'] = self::$DI->share(function () {
$logger = new Logger('tests');
$logger->pushHandler(new NullHandler());
return $logger;
});
self::$DI['collection'] = self::$DI->share(function ($DI) {
return collection::get_from_base_id($DI['app'], self::$fixtureIds['collection']['coll']);
});
self::$DI['collection_no_access'] = self::$DI->share(function ($DI) {
return collection::get_from_base_id($DI['app'], self::$fixtureIds['collection']['coll_no_access']);
});
self::$DI['collection_no_access_by_status'] = self::$DI->share(function ($DI) {
return collection::get_from_base_id($DI['app'], self::$fixtureIds['collection']['coll_no_status']);
});
if (!self::$booted) {
if (!self::$DI['app']['phraseanet.configuration-tester']->isInstalled()) {
echo "[0;31mPhraseanet is not set up[0;37m\n";
exit(1);
}
self::$fixtureIds = array_merge(self::$fixtureIds, json_decode(file_get_contents(__DIR__ . '/../fixtures.json'), true));
self::resetUsersRights(self::$DI['app'], self::$DI['user']);
self::resetUsersRights(self::$DI['app'], self::$DI['user_notAdmin']);
self::$booted = true;
}
self::$DI['lazaret_1'] = self::$DI->share(function ($DI) {
return $DI['app']['EM']->find('Phraseanet:LazaretFile', self::$fixtureIds['lazaret']['lazaret_1']);
});
foreach (range(1, 7) as $i) {
self::$DI['record_' . $i] = self::$DI->share(function ($DI) use($i) {
return new \record_adapter($DI['app'], self::$fixtureIds['databox']['records'], self::$fixtureIds['record']['record_' . $i]);
});
}
foreach (range(1, 3) as $i) {
self::$DI['record_story_' . $i] = self::$DI->share(function ($DI) use($i) {
return new \record_adapter($DI['app'], self::$fixtureIds['databox']['records'], self::$fixtureIds['record']['record_story_' . $i]);
});
//.........这里部分代码省略.........
示例14: upload
/**
* Upload processus
*
* @param Application $app The Silex application
* @param Request $request The current request
*
* parameters : 'bas_id' int (mandatory) : The id of the destination collection
* 'status' array (optional) : The status to set to new uploaded files
* 'attributes' array (optional) : Attributes id's to attach to the uploaded files
* 'forceBehavior' int (optional) : Force upload behavior
* - 0 Force record
* - 1 Force lazaret
*
* @return Response
*/
public function upload(Application $app, Request $request)
{
$datas = ['success' => false, 'code' => null, 'message' => '', 'element' => '', 'reasons' => [], 'id' => ''];
if (null === $request->files->get('files')) {
throw new BadRequestHttpException('Missing file parameter');
}
if (count($request->files->get('files')) > 1) {
throw new BadRequestHttpException('Upload is limited to 1 file per request');
}
$base_id = $request->request->get('base_id');
if (!$base_id) {
throw new BadRequestHttpException('Missing base_id parameter');
}
if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($base_id, 'canaddrecord')) {
throw new AccessDeniedHttpException('User is not allowed to add record on this collection');
}
$file = current($request->files->get('files'));
if (!$file->isValid()) {
throw new BadRequestHttpException('Uploaded file is invalid');
}
try {
// Add file extension, so mediavorus can guess file type for octet-stream file
$uploadedFilename = $file->getRealPath();
$renamedFilename = $file->getRealPath() . '.' . pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION);
$app['filesystem']->rename($uploadedFilename, $renamedFilename);
$media = $app['mediavorus']->guess($renamedFilename);
$collection = \collection::get_from_base_id($app, $base_id);
$lazaretSession = new LazaretSession();
$lazaretSession->setUser($app['authentication']->getUser());
$app['EM']->persist($lazaretSession);
$packageFile = new File($app, $media, $collection, $file->getClientOriginalName());
$postStatus = $request->request->get('status');
if (isset($postStatus[$collection->get_base_id()]) && is_array($postStatus[$collection->get_base_id()])) {
$postStatus = $postStatus[$collection->get_base_id()];
$status = '';
foreach (range(0, 31) as $i) {
$status .= isset($postStatus[$i]) ? $postStatus[$i] ? '1' : '0' : '0';
}
$packageFile->addAttribute(new Status($app, strrev($status)));
}
$forceBehavior = $request->request->get('forceAction');
$reasons = [];
$elementCreated = null;
$callback = function ($element, $visa, $code) use($app, &$reasons, &$elementCreated) {
foreach ($visa->getResponses() as $response) {
if (!$response->isOk()) {
$reasons[] = $response->getMessage($app['translator']);
}
}
$elementCreated = $element;
};
$code = $app['border-manager']->process($lazaretSession, $packageFile, $callback, $forceBehavior);
$app['filesystem']->rename($renamedFilename, $uploadedFilename);
if (!!$forceBehavior) {
$reasons = [];
}
if ($elementCreated instanceof \record_adapter) {
$id = $elementCreated->get_serialize_key();
$element = 'record';
$message = $app->trans('The record was successfully created');
$app['phraseanet.SE']->addRecord($elementCreated);
// try to create thumbnail from data URI
if ('' !== ($b64Image = $request->request->get('b64_image', ''))) {
try {
$dataUri = Parser::parse($b64Image);
$fileName = $app['temporary-filesystem']->createTemporaryFile('base_64_thumb', null, "png");
file_put_contents($fileName, $dataUri->getData());
$media = $app['mediavorus']->guess($fileName);
$app['subdef.substituer']->substitute($elementCreated, 'thumbnail', $media);
$app['phraseanet.logger']($elementCreated->get_databox())->log($elementCreated, \Session_Logger::EVENT_SUBSTITUTE, 'thumbnail', '');
unset($media);
$app['temporary-filesystem']->clean('base_64_thumb');
} catch (DataUriException $e) {
}
}
} else {
$app['dispatcher']->dispatch(PhraseaEvents::LAZARET_CREATE, new LazaretEvent($elementCreated));
$id = $elementCreated->getId();
$element = 'lazaret';
$message = $app->trans('The file was moved to the quarantine');
}
$datas = ['success' => true, 'code' => $code, 'message' => $message, 'element' => $element, 'reasons' => $reasons, 'id' => $id];
} catch (\Exception $e) {
$datas['message'] = $app->trans('Unable to add file to Phraseanet');
}
//.........这里部分代码省略.........
示例15: connect
//.........这里部分代码省略.........
$accHD = explode('_', $accHD);
if (count($accHD) == 2 && isset($accept[$accHD[0]]) && isset($options[$accHD[0]][$accHD[1]])) {
$options[$accHD[0]][$accHD[1]]['HD'] = true;
}
}
foreach ($request->request->get('watermark', []) as $wm) {
$wm = explode('_', $wm);
if (count($wm) == 2 && isset($accept[$wm[0]]) && isset($options[$wm[0]][$wm[1]])) {
$options[$wm[0]][$wm[1]]['WM'] = true;
}
}
if (count($templates) > 0 || count($deny) > 0 || count($accept) > 0) {
$cacheToUpdate = $done = [];
foreach ($templates as $usr => $template_id) {
if (null === ($user = $app['manipulator.user']->getRepository()->find($usr))) {
$app->abort(400, srpintf("User with id % in provided in 'template' request variable could not be found", $usr));
}
$cacheToUpdate[$usr] = $user;
$user_template = $app['manipulator.user']->getRepository()->find($template_id);
$collections = $app['acl']->get($user_template)->get_granted_base();
$baseIds = array_keys($collections);
$app['acl']->get($user)->apply_model($user_template, $baseIds);
foreach ($collections as $collection) {
$done[$usr][$collection->get_base_id()] = true;
}
$app['manipulator.registration']->deleteUserRegistrations($user, $collections);
}
foreach ($deny as $usr => $bases) {
if (null === ($user = $app['manipulator.user']->getRepository()->find($usr))) {
$app->abort(400, srpintf("User with id % in provided in 'deny' request variable could not be found", $usr));
}
$cacheToUpdate[$usr] = $user;
foreach ($app['manipulator.registration']->getRepository()->getUserRegistrations($user, array_map(function ($baseId) use($app) {
return \collection::get_from_base_id($app, $baseId);
}, $bases)) as $registration) {
$app['manipulator.registration']->rejectRegistration($registration);
$done[$usr][$registration->getBaseId()] = false;
}
}
foreach ($accept as $usr => $bases) {
if (null === ($user = $app['manipulator.user']->getRepository()->find($usr))) {
$app->abort(400, srpintf("User with id % in provided in 'accept' request variable could not be found", $usr));
}
$cacheToUpdate[$usr] = $user;
foreach ($app['manipulator.registration']->getRepository()->getUserRegistrations($user, array_map(function ($baseId) use($app) {
return \collection::get_from_base_id($app, $baseId);
}, $bases)) as $registration) {
$done[$usr][$registration->getBaseId()] = true;
$app['manipulator.registration']->acceptRegistration($registration, $options[$usr][$registration->getBaseId()]['HD'], $options[$usr][$registration->getBaseId()]['WM']);
}
}
array_walk($cacheToUpdate, function (User $user) use($app) {
$app['acl']->get($user)->delete_data_from_cache();
});
unset($cacheToUpdate);
foreach ($done as $usr => $bases) {
$user = $app['manipulator.user']->getRepository()->find($usr);
$acceptColl = $denyColl = [];
foreach ($bases as $bas => $isok) {
$collection = \collection::get_from_base_id($app, $bas);
if ($isok) {
$acceptColl[] = $collection->get_label($app['locale']);
continue;
}
$denyColl[] = $collection->get_label($app['locale']);
}