{"id":18338451,"url":"https://github.com/crowd-studio/ptt3","last_synced_at":"2025-06-29T08:37:52.383Z","repository":{"id":151675806,"uuid":"73709844","full_name":"crowd-studio/ptt3","owner":"crowd-studio","description":null,"archived":false,"fork":false,"pushed_at":"2016-11-14T14:15:56.000Z","size":907,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T20:44:08.453Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/crowd-studio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-14T13:58:21.000Z","updated_at":"2016-11-14T14:00:37.000Z","dependencies_parsed_at":"2023-07-13T21:46:06.969Z","dependency_job_id":null,"html_url":"https://github.com/crowd-studio/ptt3","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/crowd-studio/ptt3","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crowd-studio%2Fptt3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crowd-studio%2Fptt3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crowd-studio%2Fptt3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crowd-studio%2Fptt3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crowd-studio","download_url":"https://codeload.github.com/crowd-studio/ptt3/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crowd-studio%2Fptt3/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262565848,"owners_count":23329653,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T20:14:11.714Z","updated_at":"2025-06-29T08:37:52.364Z","avatar_url":"https://github.com/crowd-studio.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"#   Configuration\n\nAdd the bundle `Crowd\\PttBundle` to the folder `src` and register it in the `AppKernel` by adding this line in the `$bundles` array of the file:\n\n```php\n    new Crowd\\PttBundle\\PttBundle()\n```\n\nIn the `composer.json` of the project add the following libraries:\n\n```json\n    \"smottt/wideimage\" : \"dev-master\",\n    \"tpyo/amazon-s3-php-class\" : \"dev-master\"\n```\n\nAnd run the command `composer update`.\n\n###  Configuration\n\nCreate the file `app/config/ptt.yml`\n\n#### Routing\n\nAdd an array for the key `bundles`. It should contain an item for each bundle. Every item must have the keys `bundle` and `controllerClassPrefix`. This will create the routing for each controller subclass of `PttController`.\n\n```yml\n    bundles:\n        -\n            bundle : AdminBundle\n            controllerClassPrefix : App\\AdminBundle\\Controller\\\n```\n\nIf the project have different languages you may add \"_local\" prefix to your routing controller URL with requirements. Follow this example:\n```\n/**\n* @Route(\"/{_locale}/team/\", name=\"team\", requirements={\"_locale\": \"ca|es|en\"});\n* @Template()\n*/\n```\n\n#### Admin configuration\n\nFor the key `admin` create an array with the configuration properties of the backend. The `sidebar` array contains multiple items, and each item has its keys:\n\n```yml\n    admin:\n        title : 'Ptt Admin Demo'\n        default_url : post_list\n        numberOfResultsPerPage : 50\n        sidebar :\n            -\n                path : post_list\n                label : 'Posts'\n                class : 'demoClass'\n                parameters :\n                    id : 1\n            -\n                label : ‘dropdown’\n                subSections:\n                    -\n                        path : role_list\n                        label : 'Roles'\n\n```\n\nBoth 'class' and 'parameters' are optional\n\n#### Languages\n\nAdd a key/value array of languages (if needed) for the key `languages`. The key should be the ISO 639-1 code of the language. The value the label you want to display in the backend.\n\n```yml\n    languages :\n        ca : 'Català'\n        es : Español\n        en : English\n        fr : French\n```\n\n#### S3\n\nIf you want to be able to uploads contents to an S3 Amazon Server you'll need to add the key `s3` with all it's required parameters:\n\n```yml\n    s3:\n        force : true\n        accessKey : ******\n        secretKey : ******\n        bucket : example\n        dir : 'example/'\n        url : http://example.s3.amazonaws.com\n        prodUrl : http://example.cloudfront.net/\n```\n\nForce allows 'PttMediaController' to upload images inserted in the body of the contents to the S3.\n\n### SwiftMail\n\nSwift Mailer integrates into any web app written in PHP 5, offering a flexible and elegant object-oriented approach to sending emails with a multitude of features.\n\nYou should define the smtp server at parameters.yml:\n```yml\n    mailer_transport: gmail\n    mailer_host: ~\n    mailer_user: pau@crowd-studio.com\n    mailer_password: ******\n```\n\nWith this code you can send an email in a controller. You may change the subject, email from, email to. You can define a twig template for the mail or add some plane html.\n\n```php\n$message = \\Swift_Message::newInstance()\n        -\u003esetSubject('Subject goes here')\n        -\u003esetFrom('email@from.com')\n        -\u003esetTo('email@to.com')\n        -\u003esetBody($this-\u003erenderView('FrontendBundle:MailTemplates:mailtemplate.html.twig',\n                array('name' =\u003e $youCanPassVariables)));\n        $this-\u003eget('mailer')-\u003esend($message);\n```\n### Controller\n\nTo use a `PttController` in a controller add a `use` statement and subclass it.\n\n```php\n    use Crowd\\PttBundle\\Controller\\PttController;\n\n    class FooController extends PttController {\n```\n\nBy default, the `PttController` has 3 methods.\n\n####    List\n\nIt will list the entities with the same name as the controller. For example, a controller called `FooController` will list the entities called `Foo`.\n\nBy default the only field displayed in the list will be `Title`. You can change this by implementing the method `fieldsToList` in your new controller. This method must return a key/value array with the field/label to list.\n\n```php\n    protected function fieldsToList()\n    {\n        return array(\n            'title' =\u003e 'Title',\n            'relatedUrl' =\u003e 'URL',\n            'published' =\u003e 'Published'\n            );\n    }\n```\n\nImplement the method `listTitle` to override the default list title.\n\n```php\n    protected function listTitle()\n    {\n        return 'My new list Entity title';\n    }\n```\n\nIn the list, the entities will be sortered, by default, using the first element of this array. The user can change the sorting by clicking on the row title (if you use the default `Ptt` template).\n\n#### Sortable list\nTo make a list sortable by drag and drop you should add `_order` field to the entity.\n\n```\n-\n        name : _order\n        type : number\n        options :\n            label : 'Ordre'\n            attr : ~\n        validations : ~\n```\n\n```\n     /**\n     * @var integer\n     *\n     * @ORM\\Column(name=\"_order\", type=\"text\")\n     */\n    private $_order;\n\n    /**\n     * Set _order\n     *\n     * @param integer $_order\n     *\n     * @return Social\n     */\n    public function set_Order($_order)\n    {\n        $this-\u003e_order = $_order;\n\n        return $this;\n    }\n\n    /**\n     * Get _order\n     *\n     * @return integer\n     */\n    public function get_Order()\n    {\n        return $this-\u003e_order;\n    }\n```\n\n####    Delete\n\nIt will delete an entity. To decide if the deletion must continue implement the method `continueWithDeletion`. This method must return an array. The first element has to be a `boolean` indication if the deletion has to continue or not, and the second a `string` with the error message (or an empty string if there is not error).\n\n```php\n    protected function continueWithDeletion($entity)\n    {\n        if (//custom validation using $entity) {\n            //not valid\n            return array(false, 'Hey, this is an error message');\n        } else {\n            //valid\n            return array(true, '');\n        }\n    }\n```\n\nJust before the deletion the method `beforeDeletion` is called. Implement it to delete related entities.\n\n```php\n    protected function beforeDeletion($entity)\n    {\n        //remove entities related to $entity\n    }\n```\n\n#### Edit\n\nIt displays the entity form and all its fields. Read the section **Form** to understand how to create a form.\n\nImplement the method `editTitle` to override the default list title.\n\n```php\n    protected function editTitle()\n    {\n        return 'My new edit Entity title';\n    }\n```\n\n#### General\n\nYou can create your own `listAction`, `editAction` and `cancelAction` methods by implementing them in your controller.\n\nTo use a custom template create it inside the folder `Resources/views/Foo/action.html.twig`.\n\nImplement the method `entityInfo` to return basic information about the entity different to the one by default.\n\n```php\n    protected function entityInfo()\n    {\n        return array(\n            'simple' =\u003e 'Foo',\n            'lowercase' =\u003e 'foo',\n            'plural' =\u003e 'foos'\n            );\n    }\n```\n\nThe method `userIsRole($role)` returns a boolean indicating if the user has that role or not.\n\nThe method `userRole()` returns a string with the user role.\n\nThe method 'allowAccess($methodName, $entity = false)' is called before the `listAction`, `editAction` and `deleteAction`. It should return an array with two items: the first one, a boolean indicating if the access is allowed or not. The second one, the error message, if there's one.\n\n### Form\n\nThis section covers the creation of the form and its configuration.\n\n#### General methods\n\nBy default this is done in the `PttController`. That's why this is only needed if you implement the `editAction` method in your controller.\n\nTo create a form access to it as a service:\n```php\n    $pttForm = $this-\u003eget('pttForm');\n```\nTo add the entity use the method `setEntity`\n\n```php\n    $pttForm-\u003esetEntity($entity);\n```\n\nThe others methods available are:\n\n```php\n    //Returns boolean indicating if the sent data is valid or not\n    $pttForm-\u003eisValid();\n\n    //Persists and flushes the entity\n    $pttForm-\u003esave();\n\n    //Returns the success message\n    $pttForm-\u003egetSuccessMessage();\n\n    //Returns the error message\n    $pttForm-\u003egetErrorMessage();\n\n    //Returns the html code for the form\n    $pttForm-\u003ecreateView();\n```\n\n#### How to create a form\n\nCreate an entity and make it a subclass of `PttEntity`. Remember to add the `use`statement.\n\n```php\n    use Crowd\\PttBundle\\Form\\PttEntity;\n\n    class MyEntity extends PttEntity {\n```\n\nThis class now has some extra properties. In case you want to create a translatable website this entity must only have the static properties in it. Create another entity with the same name but with the sufix `Trans` for the translatable properties, for example `MyEntityTrans`, and make it a subclass of `PttTransEntity`. Again, you'll need to use the `use` statement.\n\n```php\n    use Crowd\\PttBundle\\Form\\PttTransEntity;\n\n    class MyEntityTrans extends PttTranEntity {\n```\n\nThis will make this entity have some extra properties too.\n\nProceed to create a YAML file in the folder `Form` inside the same bundle. The file name must be the same name of the entity (in this case `MyEntity.yml`. **Important**: only one file is needed, even if the entity is translatable.\n\nInside this file, create a key called `static`, and another called `trans` if needed.\n\nThere are two other optional keys that you can override for each form: `errorMessage`, which is the error message that is displayed in case the form has errors, and `successMessage`, which is displayed if the form has no error and the content can be saved.\n\n#### Input types\n\nThe way of creating inputs/fields works in the same way either if they're translatable or not. Just remember to add it to the `static` or `trans` array depending if they are inside the `MyEntity` entity or the `MyEntityTrans` entity.\n\n##### Default\n\nEach field has this default properties **always**.\n\n```yml\n    -\n        name : #the name of the property\n        type : #type of field\n        options : #array with options\n        validations : #array with validations // empty by default\n        mapped : #indicates if the field is mapped in the form // true by default\n```\n\nYou can configure each of this properties. Options is the property that is more customized because is the one that allows us to configure the field. Of course, the type and name properties are also very important. The name must match the name in the entity.\n\nBy default, there are some available `options`.\n\nThe key `label` indicates the label of the field.\nThe key `attr` is a key/value array where you can add whatever you want. The most famous attr will be `class` and custom `data-something` attributes.\n\nIt would look like:\n\n```yml\n    options:\n        label : 'Label of the field`\n        attr :\n            class : 'classOfTheInput`\n            data-something : 'somethingElse'\n```\n\nThese are the available validations:\n    - not_blank\n    - not_empty #works only in selects\n    - password\n    - email\n    - unique\n    - number\nInside the yml, you should add it as a key/value array (type of validation / message to display). For example:\n\n```yml\n    validations :\n        not_blank : 'The field is required`\n```\n\n##### Type Text\n\nSet `text` as input type.\n\nYou can set the max length with the atribute `maxLength` in `options`\n\n##### Type Autocomplete\n\nSet `autocomplete` as input type.\n\nIn `options` you must add the entity (`entity`) and the column (`searchfield`) where data is collected.\n\nYou can filter or sort the list with the properties `sortBy` and `filterBy`. Both are key/value arrays that look, for example, like this. Any of both is required.\n\n```yml\n    sortBy :\n        title : asc\n        author : asc\n    filterBy :\n        eventId : 1\n```\n\n##### Type Url\n\nSet `url` as input type.\n\nAn input type url doesn't require any extra configuration that the default one.\n\n##### Type Hidden\n\nSet `hidden` as input type.\n\nAn input type hidden doesn't require any extra configuration that the default one.\n\n##### Type Number\n\nSet `number` as input type.\n\nAn input number doesn't require any extra configuration that the default one.\n\n##### Type Checkbox\n\nSet `checkbox` as input type.\n\nAn input checkbox doesn't require any extra configuration that the default one.\n\n##### Type Password\n\nSet `password` as input type.\n\nAn input number text doesn't require any extra configuration that the default one.\n\nYou only should use it on actual password fields. If you add this field, you **must add** the `salt` property to your entity too. You don't need to add the `salt` entity to the form.\n\n##### Type File\n\nSet `file` as input type.\n\nInside the `options` array you must add the `type` property. The available types are:\n    - image\n    - file\n\n**Storage**: Set the key `s3` inside `options` to `true` to upload the file to the S3 server previously configured. Set the key `cdn` inside `options` to `true` to upload the file to the CDN server previously configured.\n\n**Editable** Set the key `delete` inside `options` to `false` to disable image changes by user.\n\n###### Image\nAdd the property `sizes` and make it an array with the sizes. These sizes will be used to create images. Each subarray has the keys `w` for width and `h` for height. If both are set to 0 the image size will be free.\n\n```yml\n    type : image\n    sizes :\n        -\n            w : 100\n            h : 100\n        -\n            w : 200\n            h : 200\n```\n\nThe name of the images will be `w-h-randomNameStoredInTheProperty.jpg`.\n\n###### File\nIf you choose `file` it will upload the file and keep the extension intact. The name of the file will be `randomNameStoredInTheProperty.jpg`.\n\n##### Type Legend\n\nSet `legend` as input type.\n\nThe `label` property inside `options` is the legend displayed. There's no need to add `validations` but it is very important to set `mapped` to `false`.\n\n##### Type Textarea\n\nSet `textarea` as input type.\n\nBy default it will display a simple textarea. You can add the property `type`inside the `options` array to configure it. The available options are:\n    - markdown\n\n######  Markdown\nIt will display an advanced markdown editor. You should add the property `data-height` inside the `attr` property inside `options` to set the height of the textarea.\n\n```yml\n    attr :\n        data-height : 300\n    type : markdown\n```\n\n##### Type Multiple\nMultiple its a sortable array of modules with different layouts. The modules should be declared as a entity with the prefix 'module'. Inside `options` you can declare a default value for the selector at `empty` parameter. You should put the different modules in `modules` tag inside `options` with the `label` that will be displayed at selector and the `entity` who referenced.\n\n```\n-\n        name : moduleSelector\n        type : multipleEntity\n        mapped : false\n        showErrors : false\n        options :\n            empty : Selecciona un element de la llista\n            label : Mòdul\n            modules :\n                -\n                    label : Text destacat\n                    entity : moduleOutstandingText\n                -\n                    label : Text amb Títol\n                    entity : moduleTitleText\n                -\n                    label : Imatge 100% amplada\n                    entity : moduleImage100\n                -\n                    label : Imatge 80% amplada\n                    entity : moduleImage80\n                -\n                    label : 2 imatges 2 columnes\n                    entity : moduleImage2col\n```\n\n##### Type Gallery\n\nSet `gallery` as input type.\n\nYou must set the `showErrors` and `mapped` to false\n\nInside `options` you must inform the entity that appears for each image loaded. That entity should have one image field named \"image\" with option type set to \"gallery\".\n\nImage field from related entity example:\n```yml\n    -\n        name : image\n        type : file\n        options :\n            label : 'Image'\n            attr : ~\n            type : gallery\n            sizes :\n                -\n                    w : 600\n                    h : 400\n                -\n                    w : 1400\n                    h : 600\n                -\n                    w : 1000\n                    h : 0\n        validations : ~\n```\n\nGallery field example:\n```yml\n    -\n        name : galleryImage\n        type : gallery\n        showErrors : false\n        mapped : false\n        options :\n            label : 'Image'\n            entity : GalleryImage\n        validations : ~\n\n```\nmapped : false\n\n##### Type Select\n\nSet `select` as input type.\n\nIt has an optional `empty` property that you can add to the `options` array. It will be the default option in the select.\n\n```yml\n    empty : 'Select one option'\n```\n\nInside the `options` array you must add the `type` property. The available types are:\n    - static\n    - entity\n\n###### static\n\nAdd the a key/value array `options` inside the `options` array. These will be the key/value options displayed in the select. For example:\n\n```yml\n    empty : Select\n    options :\n        1 : Header\n        2 : Footer\n        3 : Others\n```\n\n###### entity\n\nThe standard configuration is adding the `entity` key inside the `options` array. Add only the name of the entity and make sure that the entity is in the same bundle. You will also have to add the method `__toString` inside the entity so the select can print its name.\n\nThis entity will be displayed in the list.\n\nYou can filter or sort the list with the properties `sortBy` and `filterBy`. Both are key/value arrays that look, for example, like this. Any of both is required.\n\n```yml\n    sortBy :\n        title : asc\n        author : asc\n    filterBy :\n        eventId : 1\n```\n\nIn case you want to create a multiple relation you'll have to create the relating entity. This entity must have 2 fields, one for the current `objectId` and another for the `relatedObjectId`. The names are customizable. To enable that you'll have to add the `multiple` key to the `options` array.\n\n**Important**: if the select is multiple you have to set the `mapped` option of the field to `false`.\n\nThe properties inside `multiple are`:\n    - relatingEntity : the name of the relating entity\n    - me : the property that identifies the id of the current entity (if the form is the Event form, the eventId)\n    - them : the property that identifies the id of the related entity (if the form is the Event form, the artistId)\n\nIn case we're in a `Event` entity and want to relate it with multiple `Artist` entities, the YAML should look like.\n\n```yml\n    entity : Artist\n    multiple :\n        relatingEntity : EventArtist\n        me : eventId\n        them : artistId\n```\n\nIf you want to display that same relation but in the Artist form you'll have to switch the values. In this example it'd look like this.\n\n\n```yml\n    entity : Event\n    multiple :\n        relatingEntity : EventArtist\n        me : artistId\n        them : eventId\n```\n\n##### Type SelectMultiple\n\nAre two selectors in the second depends on the first.\n\nYou must add two more fields to the entity: [field_name]_model and [field_name]_title (the last is optional).\n\nAt the YML you should define the number of returned entities and the entities of the first selector.\n\n```yml\n    -\n        name : slider\n        type : selectMultiple\n        options :\n            label : 'Select Multiple'\n            limit : 20\n            empty : '-- Selecciona el tipo --'\n            entities :\n                -\n                    entity : Activity\n                    label : Actividad\n                -\n                    entity : Exhibition\n                    label : Exposición\n                -\n                    entity : Publication\n                    label : Publicación\n```\n\n##### Type Entity\n\nSet `entity` as input type.\n\nSet `showErrors` and `mapped` to false. Inside options fill the property `entity` with the name of the relating entity. That entity must have a `relatedId` property.\n\n#### Aditional Notes\n\nFor php 5.4 you need to specify the doctrine specific version on 2.3\n\n```json\n\"doctrine/common\": \"2.3\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrowd-studio%2Fptt3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrowd-studio%2Fptt3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrowd-studio%2Fptt3/lists"}