Exemplo n.º 1
0
 /**
  * Return an array of field information.
  *
  * @param integer $ordering An ordering constant.
  *
  * @return array Array with fields definitions.
  */
 public function getFieldDefinition($ordering = Phprojekt_ModelInformation_Default::ORDERING_DEFAULT)
 {
     $meta = parent::getFieldDefinition($ordering);
     // If itemStatus == final then set readOnly for all fields except itemStatus
     if (4 == $this->_model->itemStatus) {
         foreach (array_keys($meta) as $key) {
             if ('itemStatus' != $meta[$key]['key']) {
                 $meta[$key]['readOnly'] = 1;
             }
         }
     }
     return $meta;
 }
Exemplo n.º 2
0
 /**
  * Return an array of field information.
  *
  * @param integer $ordering An ordering constant.
  *
  * @return array Array with fields definitions.
  */
 public function getFieldDefinition($ordering = Phprojekt_ModelInformation_Default::ORDERING_DEFAULT)
 {
     $meta = parent::getFieldDefinition($ordering);
     // If ownerId != currentUser then set readOnly for all fields except status
     if ($this->_model->ownerId && Phprojekt_Auth::getUserId() != $this->_model->ownerId) {
         foreach (array_keys($meta) as $key) {
             if ('status' != $meta[$key]['key']) {
                 $meta[$key]['readOnly'] = 1;
             }
         }
     }
     return $meta;
 }
 public function testEditDatabaseManager()
 {
     $project = new Phprojekt_Project(array('db' => $this->sharedFixture));
     $db = new Phprojekt_DatabaseManager($project, array('db' => $this->sharedFixture));
     $where = $this->sharedFixture->quoteInto('table_name = ?', 'test');
     $ids = $db->fetchAll($where);
     Zend_Registry::set('dbId', $ids[0]->id);
     $module = new Phprojekt_Module_Module();
     $where = $this->sharedFixture->quoteInto('name = ?', 'test');
     $ids = $module->fetchAll($where);
     Zend_Registry::set('moduleId', $ids[0]->id);
     // Edit
     $designerData = '{"0":{"id":' . Zend_Registry::get('dbId') . ',"tableName":"Test","formPosition":1,"formTab":1,' . '"formColumns":1,"formRegexp":null,"listAlign":"center","listUseFilter":1,"altPosition":0,"isInteger":0,' . '"isUnique":0,"tableField":"project_id","selectType":"project","tableType":"int","tableLength":5,' . '"formLabel":"Project","formType":"selectValues","formRange":"Project # id # title","defaultValue":1,' . '"listPosition":1,"status":1,"isRequired":1}}';
     $this->setRequestUrl('Core/moduleDesigner/jsonSave');
     $this->request->setParam('designerData', $designerData);
     $this->request->setParam('id', Zend_Registry::get('moduleId'));
     $this->request->setParam('name', 'test');
     $this->request->setParam('label', 'test');
     $this->request->setParam('nodeId', 1);
     $response = $this->getResponse();
     $this->assertContains('The table module was edited correctly', $response, 'Response was: ' . $response);
 }
Exemplo n.º 4
0
 /**
  * Deletes a module.
  *
  * Deletes the module entries, the module itself,
  * the databasemanager entry and the table itself.
  *
  * REQUIRES request parameters:
  * <pre>
  *  - integer <b>id</b> id of the item to delete.
  * </pre>
  *
  * The return is a string in JSON format with:
  * <pre>
  *  - type    => 'success'.
  *  - message => Success message.
  *  - id      => id of the deleted item.
  * </pre>
  *
  * @throws Zend_Controller_Action_Exception On missing or wrong id, or on error in the action delete.
  *
  * @return void
  */
 public function jsonDeleteAction()
 {
     $id = (int) $this->getRequest()->getParam('id');
     if (empty($id)) {
         throw new Zend_Controller_Action_Exception(self::ID_REQUIRED_TEXT, 400);
     }
     $model = $this->getModelObject()->find($id);
     if ($model instanceof Phprojekt_ActiveRecord_Abstract) {
         if (is_dir(PHPR_CORE_PATH . $model->name)) {
             throw new Zend_Controller_Action_Exception(self::CAN_NOT_DELETE_SYSTEM_MODULE, 422);
         }
         $databaseModel = Phprojekt_Loader::getModel($model->name, $model->name);
         if ($databaseModel instanceof Phprojekt_Item_Abstract) {
             $databaseManager = new Phprojekt_DatabaseManager($databaseModel);
             if (Default_Helpers_Delete::delete($model)) {
                 $return = $databaseManager->deleteModule();
             } else {
                 $return = false;
             }
         } else {
             $return = Default_Helpers_Delete::delete($model);
         }
         if ($return === false) {
             $message = Phprojekt::getInstance()->translate('The module can not be deleted');
             $type = 'error';
         } else {
             Phprojekt::removeControllersFolders();
             $message = Phprojekt::getInstance()->translate('The module was deleted correctly');
             $type = 'success';
         }
         $return = array('type' => $type, 'message' => $message, 'id' => $id);
         Phprojekt_Converter_Json::echoConvert($return);
     } else {
         throw new Zend_Controller_Action_Exception(self::NOT_FOUND, 404);
     }
 }
 /**
  * Get the length and type from the values.
  *
  * @param array $data Array $_POST values.
  *
  * @return array Array with data of the table.
  */
 private function _getTableData($data)
 {
     $tableData = array();
     foreach ($data as $field) {
         $field['tableField'] = Phprojekt_DatabaseManager::convertTableField($field['tableField']);
         $tableData[$field['tableField']] = array();
         $tableData[$field['tableField']]['null'] = true;
         $tableData[$field['tableField']]['default'] = null;
         foreach ($field as $key => $value) {
             $value = null;
             if ($key == 'tableType') {
                 $tableData[$field['tableField']]['type'] = $field['tableType'];
             } else {
                 if ($key == 'tableLength') {
                     $tableData[$field['tableField']]['length'] = $field['tableLength'];
                 }
             }
         }
     }
     return $tableData;
 }
Exemplo n.º 6
0
 /**
  * Test get model
  */
 public function testGetModel()
 {
     $project = new Phprojekt_Project(array('db' => $this->sharedFixture));
     $db = new Phprojekt_DatabaseManager($project, array('db' => $this->sharedFixture));
     $this->assertTrue($db->getModel() instanceof Phprojekt_Model_Interface);
 }
Exemplo n.º 7
0
 /**
  * Deletes a module.
  *
  * Deletes the module entries, the module itself,
  * the databasemanager entry and the table itself.
  *
  * REQUIRES request parameters:
  * <pre>
  *  - integer <b>id</b> id of the item to delete.
  * </pre>
  *
  * The return is a string in JSON format with:
  * <pre>
  *  - type    => 'success'.
  *  - message => Success message.
  *  - code    => 0.
  *  - id      => id of the deleted item.
  * </pre>
  *
  * @throws Phprojekt_PublishedException On missing or wrong id, or on error in the action delete.
  *
  * @return void
  */
 public function jsonDeleteAction()
 {
     $id = (int) $this->getRequest()->getParam('id');
     if (empty($id)) {
         throw new Phprojekt_PublishedException(self::ID_REQUIRED_TEXT);
     }
     $model = $this->getModelObject()->find($id);
     if ($model instanceof Phprojekt_Model_Interface) {
         $databaseModel = Phprojekt_Loader::getModel($model->name, $model->name);
         $databaseManager = new Phprojekt_DatabaseManager($databaseModel);
         if (Default_Helpers_Delete::delete($model) === false || $databaseManager->deleteModule() === false) {
             $message = Phprojekt::getInstance()->translate('The module can not be deleted');
         } else {
             $message = Phprojekt::getInstance()->translate('The module was deleted correctly');
         }
         $return = array('type' => 'success', 'message' => $message, 'code' => 0, 'id' => $id);
         Phprojekt_Converter_Json::echoConvert($return);
     } else {
         throw new Phprojekt_PublishedException(self::NOT_FOUND);
     }
 }
Exemplo n.º 8
0
 /**
  * Initialise a new object.
  *
  * @param Phprojekt_DatabaseManager $dbm   DatabaseManager Object.
  * @param string                    $name  Name of the field.
  * @param mixed                     $value Value of the field.
  *
  * @return void
  */
 public function __construct(Phprojekt_DatabaseManager $dbm, $name, $value = null)
 {
     $this->value = (string) $value;
     $this->_metadata = $dbm->find($name);
 }