/** * Given a person, this returns formatted information about the activities of the person * @param PersonEntity $person * @return array */ public static function getFormattedActivitiesOfPerson($person) { /** @var PersonEntity $person */ $activities = $person->getActivities(); $ret = []; foreach ($activities as $activity) { if (!$activity->isHidden()) { $ret[] = Activity::getFormattedShortData($activity); } } return $ret; }
/** * @param ActivityEntity[] $activities * @param $page * @return mixed */ public static function getFormattedActivities($activities, $page) { $response['error'] = null; $response['count'] = count($activities); for ($i = 10 * ($page - 1); $i < min($response['count'], $page * 10); $i++) { $activity = $activities[$i]; $response['activities'][] = Activity::getFormattedShortData($activity); } return $response; }
/** * Just accepts new people, adds them/deletes them from the activity * @return mixed */ public function actionActivitySavePeople() { $response['error'] = null; $data = $this->parseRequest(['activity_id' => null, 'toAdd' => null, 'toDelete' => null]); if (!$this->areFieldsEmpty($data)) { $activity = Activity::getValidActivityWithId($data['activity_id']); if ($activity) { foreach ($data['toAdd'] as $person_id) { $person = Person::getValidPersonWithId($person_id); if ($person) { $activity->addPerson($person); } } foreach ($data['toDelete'] as $person_id) { $person = Person::getValidPersonWithId($person_id); if ($person) { $activity->removePerson($person); } } try { $this->writeActivityToDB($activity); } catch (Exception $e) { $response['error'] = $this->getJSONError(4, 'Unexpected exception when saving the new data. Message: ' . $e->getMessage()); } } else { $response['error'] = $this->getJSONError(3, 'Could not find activity with given id while saving people'); } } else { $response['error'] = $this->getJSONError(1, 'Some of the fields are empty'); } return $response; }
/** * Shows all activities * * @since 0.0.1 */ public function index() { $id = Activity::getMinId(); $breadcrumbs = [['Activities', URLHelper::url('activity/view/' . $id), true], ['Activity name (Activity ID)', null, true]]; View::render('activity.activity', 'Activities', $breadcrumbs); }
<?php /** * @author Christoph Ulshoefer <*****@*****.**> * @copyright 2016 * @license http://opensource.org/licenses/gpl-license.php MIT License * @version 0.0.3 */ use Apollo\Apollo; use Apollo\Helpers\AssetHelper; use Apollo\Components\Activity; use Apollo\Helpers\URLHelper; $pattern = '/[^\\/]+$/'; preg_match($pattern, rtrim($breadcrumbs[0][1], '/'), $result); $id = $result[0]; $page = Activity::getNumSmallerIds($id) / 10 + 1; ?> @extends('layouts.extended') @section('content') <input type="hidden" name="hiddenField" value="{{$page}}"/> <div id="add-modal" style="display: none;"> <form class="form-horizontal"> <div class="form-group"> <label class="col-md-3 control-label" for="name">Name</label> <div class="col-md-8"> <input id="add-name" type="text" class="form-control input-md"> <span class="help-block">The name for the new activity</span> </div> </div> <div class="form-group">
/** * @param $alias * @return QueryBuilder */ private function getQueryValidActivities($alias) { $em = DB::getEntityManager(); $activityRepo = $em->getRepository(Activity::getEntityNamespace()); $activityQB = $activityRepo->createQueryBuilder($alias); $organisation_id = Apollo::getInstance()->getUser()->getOrganisationId(); $notHidden = $activityQB->expr()->eq($alias . '.is_hidden', '0'); $sameOrgId = $activityQB->expr()->eq($alias . '.organisation', $organisation_id); $cond = $activityQB->expr()->andX($notHidden, $sameOrgId); $activityQB->where($cond); return $activityQB; }