\Ceo\Core\ManagersContentManager

Core content manager

Managers provide a service layer in front of models. Managers implement domain specific logic, checks and initialization that would normally live in multiple controllers.

Summary

Methods
Properties
Constants
save()
getPaginator()
restDelete()
restCreate()
restUpdate()
find()
findFirst()
findFirstById()
findById()
findFirstByUrl()
findFirstByUuid()
findFirstBySrn()
findRelatedByKeywords()
findRelatedByContent()
getUrlSlug()
create()
update()
delete()
attach()
editAttachment()
importFromJSON()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

save()

save(object  $obj) : object

Save handler, because DRY

Parameters

object $obj

Model to be saved

Throws

\Ceo\Core\Managers\Exception

Json encoded string of validation errors

Returns

object —

Model

getPaginator()

getPaginator(integer  $page = 1, integer  $limit = 50) : \Ceo\Core\Managers\Ceo\Core\ModelHelpers\Paginator

Helps paginate models using the query bulder. Bit more complicated than the native array method, but works better for larger data sets

Because it's based on Phalcon's QueryBuilder, it supports a fluent filtering interface:

    $manager = $this->foo_manager;
    $items = $manager->getPaginator(1, 20)
        ->orderBy('created_at desc')
        ->where('name = :name:', array('name' => $name))
        ->andWhere('type = :type:', array('type' => $type))
        ->paginate();

    echo json_encode($items);

Parameters

integer $page

Current page

integer $limit

Per page limit

Returns

\Ceo\Core\Managers\Ceo\Core\ModelHelpers\Paginator

restDelete()

restDelete(\Ceo\Core\Managers\number  $id) : boolean

Delete an object with rest

Parameters

\Ceo\Core\Managers\number $id

Throws

\Exception

Returns

boolean

restCreate()

restCreate(array  $data) 

Create a new object

Parameters

array $data

restUpdate()

restUpdate(integer  $id, array  $data) 

Update an existing object

Parameters

integer $id
array $data

find()

find(mixed  $parameters = null) : mixed

Find content

Parameters

mixed $parameters

Returns

mixed

findFirst()

findFirst(mixed  $params = null) : mixed

Find first based on params

Parameters

mixed $params

Returns

mixed

findFirstById()

findFirstById(mixed  $params = null) : mixed

Find first content by ID

Parameters

mixed $params

Returns

mixed

findById()

findById(  $params = null) 

Parameters

$params

findFirstByUrl()

findFirstByUrl(mixed  $url) : object

Find first content item by given URL.

URL can either be a full URL slug or URL object. For example both of the following are valid:

    $content = ContentManager::findFirstByUrl('some/path');

    $url = UrlModel::findFirstBySlug('another/path');
    $content = ContentManager::findFirstByUrl($url);

Parameters

mixed $url

URL

Returns

object —

Content item

findFirstByUuid()

findFirstByUuid(string  $uuid) : object

Find first item by given UUID

Parameters

string $uuid

Returns

object —

ContentModel

findFirstBySrn()

findFirstBySrn(string  $srn) : \Ceo\Core\Models\Content

Find first instance by SRN

Parameters

string $srn

SRN

Returns

\Ceo\Core\Models\Content

findRelatedByKeywords()

findRelatedByKeywords(  $keywords = array(),   $minRank = 1.0) 

Parameters

$keywords
$minRank

findRelatedByContent()

findRelatedByContent(  $content) 

Parameters

$content

getUrlSlug()

getUrlSlug(  $content) 

Parameters

$content

create()

create(  $input, mixed  $user = false, boolean  $nopush = false) : object

Create content with given properties.

  • slug
  • version
  • abstract
  • content
  • state
  • urls
  • attachment

URLS can be provided either as a single string, or an array with:

  • url
  • is_default

For example:

$data = [
    'slug' => 'fronch-toast'.uniqid(),
    'urls' => [
        'a-test-url'.uniqid(),
        [
            'url' => 'another test url'.uniqid(),
            'is_default' => 1
        ]
    ]
];

Attachment is an array containing:

  • file - BASE64 encoded file data
  • name - original file name

Parameters

$input
mixed $user

Editing user, either ID or object

boolean $nopush

disable socket push on save

Returns

object —

ContentModel

update()

update(integer  $id,   $input, mixed  $user = false, boolean  $nopush = false) : object

Update content object.

Accepts the same properties as create, including Urls. Keep in mind that Url associations are permanent. You may only append new Urls, existing Urls will always be maintained.

Will also create a new version containing all of the current data, before save.

Additionally, sending an attachment will remove the original attachment and replace with the new file.

Parameters

integer $id

Content id

$input
mixed $user

Editing user, either ID or object

boolean $nopush

disable socket push on save

Returns

object —

ContentModel

delete()

delete(integer  $id) 

Delete content item

Parameters

integer $id

ID

Throws

\Exception

attach()

attach(integer  $id, array  $file, array  $imageMetadata = array()) : \Ceo\Core\Models\Attachment

Attach a file to a content item File is an array containing: * file - BASE64 encoded file content * name - original file name

Parameters

integer $id

Parent content id

array $file

File data

array $imageMetadata

IPTC and EXIF data will populate this array if type is image

Returns

\Ceo\Core\Models\Attachment

editAttachment()

editAttachment(  $id,   $input,   $user) 

Parameters

$id
$input
$user

importFromJSON()

importFromJSON(  $json,   $importOriginals = false) 

Parameters

$json
$importOriginals