Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'router' => array(
- 'routes' => array(
- 'user-management.rest.projects' => array(
- 'type' => 'Segment',
- 'options' => array(
- 'route' => '/projects[/:projects_name]',
- 'defaults' => array(
- 'controller' => 'UserManagement\\V1\\Rest\\Projects\\Controller',
- ),
- ),
- ),
- 'user-management.rest.rightscontexts' => array(
- 'type' => 'Segment',
- 'options' => array(
- 'route' => '/rightscontexts[/:rightscontexts_name]',
- 'defaults' => array(
- 'controller' => 'UserManagement\\V1\\Rest\\Rightscontexts\\Controller',
- ),
- ),
- ),
- ),
- ),
- <?php
- namespace UserManagement\V1\Rest\Projects;
- use Zend\Db\Adapter\AdapterInterface;
- use Zend\Db\TableGateway\TableGateway;
- use ZF\ApiProblem\ApiProblem;
- use ZF\Rest\AbstractResourceListener;
- use BQS\Codepage\Conversion\InputToOutput;
- use Zend\Db\Sql\Select;
- use ZF\Hal\Link\Link;
- use UserManagement\V1\Rest\Rightscontexts\RightscontextsEntity;
- use UserManagement\V1\Rest\Rightscontexts\RightscontextsCollection;
- use Zend\Paginator\Paginator;
- class ProjectsResource extends AbstractResourceListener
- {
- protected $adapter;
- protected $cpcClientToDb;
- protected $cpcDbToClient;
- public function __construct(AdapterInterface $adapter, InputToOutput $cpcClientToDb, InputToOutput $cpcDbToClient)
- {
- $this->adapter = $adapter;
- $this->cpcClientToDb = $cpcClientToDb;
- $this->cpcDbToClient = $cpcDbToClient;
- }
- /**
- * Create a resource
- *
- * @param mixed $data
- * @return ApiProblem|mixed
- */
- public function create($data)
- {
- return new ApiProblem(405, 'The POST method has not been defined');
- }
- /**
- * Delete a resource
- *
- * @param mixed $id
- * @return ApiProblem|mixed
- */
- public function delete($id)
- {
- return new ApiProblem(405, 'The DELETE method has not been defined for individual resources');
- }
- /**
- * Delete a collection, or members of a collection
- *
- * @param mixed $data
- * @return ApiProblem|mixed
- */
- public function deleteList($data)
- {
- return new ApiProblem(405, 'The DELETE method has not been defined for collections');
- }
- /**
- * Fetch a resource
- *
- * @param mixed $id
- * @return ApiProblem|mixed
- */
- public function fetch($id)
- {
- $table = new TableGateway('web_project', $this->adapter);
- $rowset = $table->select(function($select) use ($id) {
- $select->columns(array('projectname' => 'projectname', 'projectdescription' => 'description', 'projectcreationdate' => 'creationdate'));
- $select->join(
- array('t1' => 'web_prjcontext'),
- 't1.fk_web_project = web_project.id',
- array('contextname' => 'name', 'contextdescription' => 'description'),
- Select::JOIN_LEFT
- );
- $select->join(
- array('t2' => 'web_prjright'),
- 't2.fk_web_prjcontext = t1.id',
- array('rightname' => 'name', 'rightmatrix' => 'matrix', 'rightdescription' => 'description'),
- Select::JOIN_LEFT
- );
- $select->where(array('projectname' => $id));
- $select->order(array('t1.name asc'));
- $select->order(array('t2.name asc'));
- });
- $dataEntity = array();
- $dataEmbedded = array();
- foreach ($rowset as $row) {
- if (!isset($data['name'])) {
- $dataEntity['name'] = $this->cpcDbToClient->convert($row->projectname);
- $dataEntity['description'] = $this->cpcDbToClient->convert(stream_get_contents($row->projectdescription));
- $dataEntity['creationDate'] = $row->projectcreationdate;
- }
- if ($row->contextname) {
- $contextName = $row->contextname;
- if (!isset($dataEmbedded[$contextName])) {
- $dataEmbedded[$contextName] = array();
- }
- if (!isset($dataEmbedded[$contextName]['name'])) {
- $dataEmbedded[$contextName]['name'] = $this->cpcDbToClient->convert($contextName);
- $dataEmbedded[$contextName]['description'] = $this->cpcDbToClient->convert($row->contextdescription);
- $dataEmbedded[$contextName]['rights'] = array();
- }
- if ($row->rightname) {
- $rightName = $row->rightname;
- $dataEmbedded[$contextName]['rights'][$rightName]['name'] = $this->cpcDbToClient->convert($rightName);
- $dataEmbedded[$contextName]['rights'][$rightName]['description'] = $this->cpcDbToClient->convert($row->rightdescription);
- $dataEmbedded[$contextName]['rights'][$rightName]['matrix']['e'] = $row->rightmatrix[0];
- $dataEmbedded[$contextName]['rights'][$rightName]['matrix']['c'] = $row->rightmatrix[1];
- $dataEmbedded[$contextName]['rights'][$rightName]['matrix']['r'] = $row->rightmatrix[2];
- $dataEmbedded[$contextName]['rights'][$rightName]['matrix']['u'] = $row->rightmatrix[3];
- $dataEmbedded[$contextName]['rights'][$rightName]['matrix']['d'] = $row->rightmatrix[4];
- }
- }
- }
- $project = new ProjectsEntity($dataEntity);
- $project->rightsContexts = new RightscontextsCollection(
- new \Zend\Paginator\Adapter\ArrayAdapter($dataEmbedded)
- );
- return $project;
- }
- /**
- * Fetch all or a subset of resources
- *
- * @param array $params
- * @return ApiProblem|mixed
- */
- public function fetchAll($params = array())
- {
- return new ApiProblem(405, 'The GET method has not been defined for collections');
- }
- /**
- * Patch (partial in-place update) a resource
- *
- * @param mixed $id
- * @param mixed $data
- * @return ApiProblem|mixed
- */
- public function patch($id, $data)
- {
- return new ApiProblem(405, 'The PATCH method has not been defined for individual resources');
- }
- /**
- * Replace a collection or members of a collection
- *
- * @param mixed $data
- * @return ApiProblem|mixed
- */
- public function replaceList($data)
- {
- return new ApiProblem(405, 'The PUT method has not been defined for collections');
- }
- /**
- * Update a resource
- *
- * @param mixed $id
- * @param mixed $data
- * @return ApiProblem|mixed
- */
- public function update($id, $data)
- {
- return new ApiProblem(405, 'The PUT method has not been defined for individual resources');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement