/**
  * Renders the edit view for a particular record
  *
  * @param string $record_id
  * @since 0.0.5 Added a check for record ID validity
  */
 public function actionEdit($record_id = null)
 {
     $record_id = intval($record_id);
     if ($record_id < 1) {
         Apollo::getInstance()->getRequest()->error(400, 'Invalid record ID!');
     }
     $breadcrumbs = [['Records', URLHelper::url('record'), true], ['Person name', null, false], ['Record name (Record ID)', null, true]];
     View::render('record.edit', 'Edit Record', $breadcrumbs);
 }
 /**
  * Shows one particular activity
  * @param null $activity_id
  */
 public function actionView($activity_id = null)
 {
     $activity_id = intval($activity_id);
     if ($activity_id < 1) {
         Apollo::getInstance()->getRequest()->error(400, 'Invalid activity ID!');
     } else {
         $breadcrumbs = [['Activities', URLHelper::url('activity/view/' . $activity_id), true], ['Activity name (Activity ID)', null, true]];
         View::render('activity.activity', 'View Activity', $breadcrumbs);
     }
 }
 public static function getFieldNames()
 {
     $organisation = Apollo::getInstance()->getUser()->getOrganisation();
     $fields = self::getRepository()->findBy(['is_hidden' => false, 'organisation' => $organisation]);
     $names = [];
     foreach ($fields as $field) {
         $names[] = $field->getName();
     }
     return $names;
 }
 /**
  * @param $id
  * @return PersonEntity|null
  */
 public static function getValidPersonWithId($id)
 {
     $org = Apollo::getInstance()->getUser()->getOrganisation();
     $people = Person::getRepository();
     $person = $people->find($id);
     if (!empty($person) && !$person->isHidden() && $person->getOrganisation() == $org) {
         return $person;
     } else {
         return null;
     }
 }
 /**
  * Returns the data field or creates it if it does not exist
  *
  * @param int $field_id
  * @return DataEntity
  * @since 0.0.7 Now takes into account the type of the field
  * @since 0.0.6
  */
 public function findOrCreateData($field_id)
 {
     /**
      * @var FieldEntity $field
      */
     $field = Field::getRepository()->find($field_id);
     $data = Data::getRepository()->findOneBy(['record' => $this->getId(), 'field' => $field_id]);
     if ($data == null) {
         $data = new DataEntity();
         $data->setRecord($this);
         $data->setField($field);
         $data->setUpdatedBy(Apollo::getInstance()->getConsole()->getEntity());
         if ($field->hasDefault()) {
             if ($field->isMultiple()) {
                 $data->setLongText(serialize([0]));
             } else {
                 $data->setInt(0);
             }
             $data->setIsDefault(true);
         } else {
             if ($field->isMultiple()) {
                 $value = [''];
                 $data->setLongText(serialize($value));
             }
         }
         DB::getEntityManager()->persist($data);
         DB::getEntityManager()->flush();
     }
     return $data;
 }
 * Created by PhpStorm.
 * User: root
 * Date: 02/03/16
 * Time: 10:38
 */
require_once 'vendor/autoload.php';
use Apollo\Apollo;
use Apollo\Components\DB;
use Apollo\Components\User;
use Apollo\Entities\OrganisationEntity;
use Apollo\Entities\PersonEntity;
use Apollo\Entities\RecordEntity;
use Apollo\Entities\UserEntity;
use Faker\Factory;
date_default_timezone_set('Europe/London');
Apollo::prepare();
$entity_manager = DB::getEntityManager();
$organisationRepo = $entity_manager->getRepository('Apollo\\Entities\\OrganisationEntity');
/**
 * @var OrganisationEntity $organisation
 */
$organisation = $organisationRepo->find(1);
$userRepo = User::getRepository();
/**
 * @var UserEntity $user
 */
$user = $userRepo->find(1);
date_default_timezone_set('Europe/London');
$date = new DateTime();
for ($i = 0; $i < 1; $i++) {
    $faker = Factory::create();
<?php

/**
 * @author Timur Kuzhagaliyev <*****@*****.**>
 * @copyright 2016
 * @license https://opensource.org/licenses/mit-license.php MIT License
 * @version 0.0.1
 */
use Apollo\Apollo;
$user = Apollo::getInstance()->getUser();
?>
@extends('layouts.extended')
@section('content')
    <div class="panel panel-primary">
        <div class="panel-heading">Information</div>
        <div class="panel-body">
            <div class="row">
                <div class="col-md-6 col-sm-12">
                    <table class="table">
                        <thead>
                        <th colspan="2">
                            Your information
                        </th>
                        </thead>
                        <tbody>
                        <tr>
                            <td>Your name:</td>
                            <td>{{ $user->getName() }}</td>
                        </tr>
                        <tr>
                            <td>Your email:</td>
 /**
  * Returns an array of all the fields of the record
  * @param RecordEntity $record
  * @param $is_essential
  * @return array
  */
 public static function getFormattedFields($record, $is_essential)
 {
     $fieldsData = [];
     $fieldRepo = Field::getRepository();
     $fields = $fieldRepo->findBy(['is_essential' => $is_essential, 'is_hidden' => false, 'organisation' => Apollo::getInstance()->getUser()->getOrganisationId()]);
     foreach ($fields as $field) {
         $fieldData = self::getFormattedField($record, $field);
         $fieldsData[] = $fieldData;
     }
     return $fieldsData;
 }
 /**
  * Page to add or delete new users to the app
  *
  * @since 0.0.5
  */
 public function actionManage()
 {
     if (!Apollo::getInstance()->getUser()->isAdmin()) {
         Apollo::getInstance()->getRequest()->sendToIndex();
     }
     Apollo::getInstance()->getRequest()->error('404', 'This page will be updated to use the UCL authorisation system.');
 }
 /**
  * Returns a list of all fields belonging to user's organisation
  *
  * @since 0.1.3
  */
 public function actionFields()
 {
     $em = DB::getEntityManager();
     $fieldRepo = $em->getRepository(Field::getEntityNamespace());
     /** @var FieldEntity[] $fields */
     $fields = $fieldRepo->findBy(['organisation' => Apollo::getInstance()->getUser()->getOrganisationId(), 'is_hidden' => false]);
     $response['error'] = null;
     $data = [];
     for ($i = 0; $i < count($fields); $i++) {
         $field = $fields[$i];
         $fieldData = [];
         $fieldData['id'] = $field->getId();
         $fieldData['essential'] = $field->isEssential();
         $fieldData['name'] = $field->getName();
         $fieldData['type'] = $field->getType();
         $subtype = 0;
         if ($field->getType() == 2) {
             if ($field->hasDefault()) {
                 if ($field->isAllowOther()) {
                     $subtype = 4;
                 } elseif ($field->isMultiple()) {
                     $subtype = 5;
                 } else {
                     $subtype = 3;
                 }
             } else {
                 if ($field->isMultiple()) {
                     $subtype = 2;
                 } else {
                     $subtype = 1;
                 }
             }
         }
         $fieldData['subtype'] = $subtype;
         $defaults = $field->getDefaults();
         $defaultsData = [];
         for ($k = 0; $k < count($defaults); $k++) {
             $defaultsData[] = $defaults[$k]->getValue();
         }
         $fieldData['defaults'] = $defaultsData;
         $data[] = $fieldData;
     }
     $response['data'] = array_reverse($data);
     echo json_encode($response);
 }
 /**
  * @todo: Consider putting this into activity component
  * @todo: I doubt this code will ever get reused anywhere else, might as well put it back where it came from
  * @param $data
  * @param $bonus
  * @return ActivityEntity
  * @since 0.0.6
  */
 private function createActivityFromData($data, $bonus)
 {
     $user = Apollo::getInstance()->getUser();
     $activity = new ActivityEntity();
     $activity->setOrganisation($user->getOrganisation());
     $activity->setName($data['activity_name']);
     $start_date = new DateTime($data['start_date']);
     $end_date = new DateTime($data['end_date']);
     $activity->setStartDate($start_date);
     $activity->setEndDate($end_date);
     if ($bonus) {
         if (!empty($bonus['people'])) {
             $activity->addPeople($bonus['people']);
         }
         if (!empty($bonus['target_group'])) {
             $activity->setTargetGroup($bonus['target_group']);
         }
         if (!empty($bonus['target_group_comment'])) {
             $activity->setTargetGroupComment($bonus['target_group_comment']);
         }
     }
     return $activity;
 }
<?php

/**
 * Layout to be used in pages visible to authorised users
 *
 * @author Timur Kuzhagaliyev <*****@*****.**>
 * @author Christoph Ulshoefer <*****@*****.**>
 * @copyright 2016
 * @license https://opensource.org/licenses/mit-license.php MIT License
 * @version 0.0.6
 */
use Apollo\Apollo;
use Apollo\Helpers\AssetHelper;
$organisation = Apollo::getInstance()->getUser()->getOrganisationName();
?>
@extends('layouts.basic')
@section('head')

    <link rel="stylesheet" href="{{ AssetHelper::css('bootstrap.min') }}" />
    <link rel="stylesheet" href="{{ AssetHelper::css('bootstrap.cosmo.min') }}" />
    <link rel="stylesheet" href="{{ AssetHelper::css('stylesheet') }}" />
    <link rel="stylesheet" href="{{ AssetHelper::css('datepicker3.min') }}" />
    <link rel="icon" type="image/png" href="{{ AssetHelper::img('favicon.png') }}" />
    <title>{{ !empty($title) ? $title . ' | ' . APP_NAME : APP_NAME }}</title>
@stop
@section('body')
    @include('templates.navbar')
    <div class="container top-buffer">
        <div class="panel panel-default">
            @if(isset($breadcrumbs))
                <div class="panel-heading" id="breadcrumbHeader">
<?php

/**
 * Apollo application entry script file
 *
 * This file load the bootstrap for namespace autoloading and
 * creates an instance of the Apollo object and starts the application.
 *
 * @author Timur Kuzhagaliyev <*****@*****.**>
 * @copyright 2016
 * @license http://opensource.org/licenses/gpl-license.php MIT License
 * @version 0.0.1
 */
require_once '../apollo/Bootstrap.php';
use Apollo\Apollo;
use Apollo\components\GlobalWebManager;
use Apollo\Components\UserFriendlyException;
try {
    Apollo::getInstance()->start();
} catch (Exception $e) {
    GlobalWebManager::printExceptionToUser($e);
} catch (Error $e) {
    $friendlyE = new UserFriendlyException("A critical error occurred.", 0, $e);
    GlobalWebManager::printExceptionToUser($friendlyE);
}
 /**
  * Given an id, returns a target group (hopefully)
  * @param $id
  * @return TargetGroupEntity
  */
 public static function getValidTargetGroupWithId($id)
 {
     $org_id = Apollo::getInstance()->getUser()->getOrganisationId();
     return TargetGroup::getRepository()->findBy(['organisation' => $org_id, 'is_hidden' => false, 'id' => $id])[0];
 }
 /**
  * Default function that is called if the requested action is not found in the controller
  *
  * @since 0.0.3
  */
 public function notFound()
 {
     $request = Apollo::getInstance()->getRequest();
     $request->error(404, 'Page not found! (Action <b>' . $request->getAction() . '</b> not found in Controller <b>' . $request->getController() . '</b>)');
 }
 /**
  * Given an id, this should return a valid ActivityEntity (that has that id).
  * @param $id
  * @return ActivityEntity
  */
 public static function getValidActivityWithId($id)
 {
     $org = Apollo::getInstance()->getUser()->getOrganisationId();
     return self::getRepository()->findBy(['id' => $id, 'is_hidden' => false, 'organisation' => $org])[0];
 }
<?php

/**
 * Navigation bar template to be included on every page
 *
 * @author Timur Kuzhagaliyev <*****@*****.**>
 * @copyright 2016
 * @license https://opensource.org/licenses/mit-license.php MIT License
 * @version 0.0.1
 */
use Apollo\Apollo;
use Apollo\Helpers\URLHelper;
$controller = Apollo::getInstance()->getRequest()->getController();
$menu_points = [['Record', 'record', 'Records'], ['Activity', 'activity', 'Activities'], ['Field', 'field', 'Fields'], ['Help', 'help', 'Help']];
?>
<nav id="navbar" class="navbar navbar-default navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse"
                    aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="{{ BASE_URL }}">{{ APP_NAME }}</a>
        </div>
        <div id="navbar-collapse" class="navbar-collapse collapse">
            <ul class="nav navbar-nav navbar-left">
                <li class="navbar-text">Signed in as {{ Apollo::getInstance()->getUser()->getName() }}</li>
            </ul>
 /**
  * Serves a file in request parameters from a certain directory relative to the "assets" folder.
  * If $allowed_extensions is an empty array then allow all extensions.
  *
  * @param string $dir
  * @param array $allowed_extensions
  * @since 0.0.1
  */
 private function serveFrom($dir, $allowed_extensions = [])
 {
     $params = Apollo::getInstance()->getRequest()->getParameters();
     $params_dir = implode('/', $params);
     $file_name = $params[count($params) - 1];
     $file_name_parts = explode('.', $file_name);
     $extension = count($file_name_parts) > 1 ? strtolower($file_name_parts[count($file_name_parts) - 1]) : '';
     if (!empty($dir)) {
         $dir .= '/';
     }
     if (count($allowed_extensions) == 0 || in_array($extension, $allowed_extensions)) {
         $path = ASSET_DIR . $dir . $params_dir;
         if (file_exists($path)) {
             switch ($extension) {
                 case 'css':
                     $mime_type = 'text/css';
                     break;
                 case 'js':
                     $mime_type = 'application/javascript';
                     break;
                 default:
                     $file_info = new finfo();
                     $mime_type = $file_info->file($path, FILEINFO_MIME_TYPE);
                     break;
             }
             if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
                 if (strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) < filemtime($path)) {
                     header('HTTP/1.1 304 Not Modified');
                     exit;
                 }
             }
             header('Content-Type: ' . $mime_type);
             readfile($path);
         } else {
             Apollo::getInstance()->getRequest()->error(404, 'The requested file was not found.');
         }
     } else {
         Apollo::getInstance()->getRequest()->error(400, 'Bad Request: The file your requested has an invalid extension.');
     }
 }