当前位置: 首页>>代码示例>>PHP>>正文


PHP Phprojekt_Loader::getModuleFromObject方法代码示例

本文整理汇总了PHP中Phprojekt_Loader::getModuleFromObject方法的典型用法代码示例。如果您正苦于以下问题:PHP Phprojekt_Loader::getModuleFromObject方法的具体用法?PHP Phprojekt_Loader::getModuleFromObject怎么用?PHP Phprojekt_Loader::getModuleFromObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Phprojekt_Loader的用法示例。


在下文中一共展示了Phprojekt_Loader::getModuleFromObject方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _saveModel

 /**
  * Help to save a model by setting the models properties.
  * Validation is based on the ModelInformation implementation.
  *
  * @param Phprojekt_Model_Interface $model  The model
  * @param array                     $params The parameters used to feed the model.
  *
  * @throws Exception If validation of parameters fails.
  *
  * @return boolean True for a sucessful save.
  */
 protected static function _saveModel(Phprojekt_Model_Interface $model, array $params)
 {
     foreach ($params as $k => $v) {
         if (isset($model->{$k})) {
             // Don't allow to set the id on save, since it is done by the ActiveRecord
             if (!in_array($k, array('id'))) {
                 $model->{$k} = $v;
             }
         }
     }
     if (empty($model->id)) {
         $newItem = true;
     } else {
         $newItem = false;
     }
     // Set the owner
     if ($newItem && isset($model->ownerId)) {
         $model->ownerId = Phprojekt_Auth::getUserId();
     }
     // Parent Project
     if (isset($model->projectId)) {
         $projectId = $model->projectId;
     } else {
         $projectId = 0;
     }
     // Checks
     $moduleName = Phprojekt_Loader::getModuleFromObject($model);
     $moduleId = Phprojekt_Module::getId($moduleName);
     if (!$model->recordValidate()) {
         $errors = $model->getError();
         $error = array_pop($errors);
         throw new Phprojekt_PublishedException($error['label'] . ': ' . $error['message']);
     } else {
         if (!self::_checkModule($moduleId, $projectId)) {
             throw new Phprojekt_PublishedException('The parent project do not have enabled this module');
         } else {
             if (!self::_checkItemRights($model, $moduleName)) {
                 throw new Phprojekt_PublishedException('You do not have access to do this action');
             } else {
                 // Set the projectId to 1 for global modules
                 if (isset($model->projectId) && Phprojekt_Module::saveTypeIsGlobal($moduleId)) {
                     $model->projectId = 1;
                 }
                 $model->save();
                 // Save access only if the user have "admin" right
                 $itemRights = Phprojekt_Loader::getLibraryClass('Phprojekt_Item_Rights');
                 $check = $itemRights->getRights($moduleId, $model->id);
                 if ($check['currentUser']['admin']) {
                     if ($moduleName == 'Core') {
                         $rights = Default_Helpers_Right::getModuleRights($params);
                     } else {
                         $rights = Default_Helpers_Right::getItemRights($params, $moduleId, $newItem);
                     }
                     if (count($rights) > 0) {
                         $model->saveRights($rights);
                     }
                 }
                 return $model;
             }
         }
     }
 }
开发者ID:joerch,项目名称:PHProjekt,代码行数:73,代码来源:Save.php

示例2: testGetModuleFromObject

 /**
  * Test getModuleFromObject
  */
 public function testGetModuleFromObject()
 {
     $object = Phprojekt_Loader::getModel('Todo', 'Todo');
     $this->assertEquals('Todo', Phprojekt_Loader::getModuleFromObject($object));
 }
开发者ID:penSecIT,项目名称:PHProjekt,代码行数:8,代码来源:LoaderTest.php

示例3: _deleteModel

 /**
  * Help to delete a model.
  *
  * @param Phprojekt_ActiveRecord_Abstract $model The model to delete.
  *
  * @throws Exception If validation fails.
  *
  * @return boolean True for a sucessful delete.
  */
 protected static function _deleteModel(Phprojekt_ActiveRecord_Abstract $model)
 {
     // Checks
     $moduleName = Phprojekt_Loader::getModuleFromObject($model);
     if (!self::_checkItemRights($model, $moduleName)) {
         throw new Phprojekt_PublishedException('You do not have access to do this action');
     } else {
         $return = $model->delete();
         if (isset($return->id) && null === $return->id || null === $return) {
             // ActiveRecord delete the model.
             return true;
         } else {
             if (is_bool($return)) {
                 // An extention returns true or false.
                 return $return;
             } else {
                 // Any other value, is wrong.
                 return false;
             }
         }
     }
 }
开发者ID:joerch,项目名称:PHProjekt,代码行数:31,代码来源:Delete.php

示例4: _deleteModel

 /**
  * Help to delete a model.
  *
  * @param Phprojekt_ActiveRecord_Abstract $model The model to delete.
  *
  * @throws Exception If validation fails.
  *
  * @return boolean True for a sucessful delete.
  */
 protected static function _deleteModel(Phprojekt_ActiveRecord_Abstract $model)
 {
     // Checks
     $moduleName = Phprojekt_Loader::getModuleFromObject($model);
     if (!self::_checkItemRights($model, $moduleName)) {
         throw new Zend_Controller_Action_Exception('You do not have access to do this action', 400);
     } else {
         $return = $model->delete();
         if (is_bool($return)) {
             // An extention returns true or false.
             return $return;
         } else {
             if (is_null($return) || is_a($return, 'Phprojekt_ActiveRecord_Abstract') && is_null($return->id)) {
                 // ActiveRecord delete the model.
                 return true;
             } else {
                 // Any other value, is wrong.
                 return false;
             }
         }
     }
 }
开发者ID:RainyBlueSky,项目名称:PHProjekt,代码行数:31,代码来源:Delete.php

示例5: _deleteModel

 /**
  * Help to delete a model.
  *
  * @param Phprojekt_Model_Interface $model The model to delete.
  *
  * @throws Exception If validation fails.
  *
  * @return boolean True for a sucessful delete.
  */
 protected static function _deleteModel(Phprojekt_Model_Interface $model)
 {
     // Checks
     $moduleName = Phprojekt_Loader::getModuleFromObject($model);
     if (!self::_checkItemRights($model, $moduleName)) {
         throw new Phprojekt_PublishedException('You do not have access to do this action');
     } else {
         return $model->delete();
     }
 }
开发者ID:penSecIT,项目名称:PHProjekt,代码行数:19,代码来源:Delete.php

示例6: _saveModel

 /**
  * Help to save a model by setting the models properties.
  * Validation is based on the ModelInformation implementation.
  *
  * @param Phprojekt_Model_Interface $model  The model
  * @param array                     $params The parameters used to feed the model.
  *
  * @throws Exception If validation of parameters fails.
  *
  * @return boolean True for a sucessful save.
  */
 protected static function _saveModel(Phprojekt_Model_Interface $model, array $params)
 {
     $newItem = empty($params['id']);
     $model = self::parameterToModel($model, $params, $newItem);
     $projectId = $model->hasField('projectId') ? $model->projectId : 0;
     $userId = Phprojekt_Auth_Proxy::getEffectiveUserId();
     $moduleName = Phprojekt_Loader::getModuleFromObject($model);
     $moduleId = Phprojekt_Module::getId($moduleName);
     if (!$model->recordValidate()) {
         $errors = $model->getError();
         $error = array_pop($errors);
         throw new Zend_Controller_Action_Exception($error['label'] . ': ' . $error['message'], 400);
     }
     if (!self::_checkModule($moduleId, $projectId)) {
         throw new Zend_Controller_Action_Exception('The parent project do not have enabled this module', 400);
     }
     $rights = Default_Helpers_Right::getRights($params);
     if ($model instanceof Phprojekt_Item_Abstract) {
         if ($newItem && !Phprojekt_Module::saveTypeIsGlobal($moduleId)) {
             $project = new Project_Models_Project();
             $project->find($projectId);
             if (!$project->hasRight($userId, Phprojekt_Acl::CREATE)) {
                 throw new Zend_Controller_Action_Exception('You do not have the necessary create right', 403);
             }
             $rights[$userId] = Phprojekt_Acl::ALL;
         } else {
             if (!$model->hasRight($userId, Phprojekt_Acl::WRITE)) {
                 throw new Zend_Controller_Action_Exception('You do not have the necessary write right', 403);
             }
         }
         // Set the projectId to 1 for global modules
         // @TODO Remove the Timecard limitation
         if ($model->hasField('projectId') && Phprojekt_Module::saveTypeIsGlobal($moduleId) && Phprojekt_Module::getModuleName($moduleId) != 'Timecard') {
             $model->projectId = 1;
         }
         $model->save();
         // Save access only if the user have "admin" right
         if ($newItem || $model->hasRight(Phprojekt_Auth_Proxy::getEffectiveUserId(), Phprojekt_Acl::ADMIN)) {
             if (!Phprojekt_Auth_Proxy::isAdminUser() && count($rights) <= 0) {
                 throw new Zend_Controller_Action_Exception('At least one person must have access to this item', 400);
             }
             $model->saveRights($rights);
         }
     } else {
         $model->save();
         $model->saveRights($rights);
     }
     return $model;
 }
开发者ID:RainyBlueSky,项目名称:PHProjekt,代码行数:60,代码来源:Save.php


注:本文中的Phprojekt_Loader::getModuleFromObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。