예제 #1
0
 public function discovery($entity, $entity_parent = null, $from_form = false)
 {
     $default_model = new Model\DefaultModel();
     $default_model->initialize($this->getSm());
     $default_model->setConfig($this->config);
     $default_model->setEntity('Entity\\' . $entity);
     isset($this->params['deep']) ? $default_model->setMaxDeep($this->params['deep']) : 0;
     if (!$from_form) {
         if (!$default_model->getEntity()) {
             ErrorModel::addError(array('code' => '404', 'message' => 'Error 404: %1$s %2$s not found', 'values' => array('Entity', $default_model->getEntityName())));
             return;
         }
         switch ($this->getMethod()) {
             case 'POST':
                 $data = $default_model->insert($this->params);
                 break;
             case 'PUT':
                 $data = $default_model->edit($this->params);
                 break;
             case 'DELETE':
                 $data = $default_model->delete($this->params['id']);
                 break;
             default:
                 if ($this->getViewMethod() != 'form') {
                     $id = isset($this->params['id']) ? $this->params['id'] : null;
                     $page = isset($this->params['page']) ? $this->params['page'] : 1;
                     $limit = isset($this->params['limit']) ? $this->params['limit'] : 100;
                     if ($entity_parent) {
                         $data = $default_model->getWithParent($id, $entity_parent, $page, $limit);
                     } else {
                         $data = $default_model->get($id, $page, $limit);
                     }
                     $this->rows = $default_model->getTotalResults();
                 }
                 break;
         }
     } else {
         switch ($this->getViewMethod()) {
             case 'form':
                 $data = $default_model->form($entity, $this->params);
                 break;
         }
     }
     return $data;
 }