本文整理汇总了PHP中Project::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Project::model方法的具体用法?PHP Project::model怎么用?PHP Project::model使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Project
的用法示例。
在下文中一共展示了Project::model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCRUD
public function testCRUD()
{
//CREATE Test
$newProject = new Project();
$projectName = 'This is a Test';
$newProject->setAttributes(array('name' => $projectName, 'description' => 'This project is for test purpose only', 'start_date' => '2010-11-15 15:00:00', 'end_date' => '2010-12-06 00:00:00', 'update_user_id' => 1, 'category' => 2, 'status' => 1, 'owner' => 1));
$this->assertTrue($newProject->save(false));
//READ Test
$readProject = Project::model()->findByPk($newProject->id);
$this->assertTrue($readProject instanceof Project);
$this->assertEquals($projectName, $readProject->name);
//UPDATE Test
$updateProjectName = 'Updated Name2';
$newProject->name = $updateProjectName;
$this->AssertTrue($newProject->save(false));
$updatedProject = Project::model()->findByPk($newProject->id);
$this->assertTrue($updatedProject instanceof Project);
$this->assertNotEquals($projectName, $updatedProject->name);
//DELETE Test
$deletedProjectId = $newProject->id;
$newProject->delete();
$deletedProject = Project::model()->findByPk($newProject->id);
$this->assertEquals(Null, $deletedProject);
//GetUserVote Test
$project = Project::model()->findByPk(18);
$this->assertTrue($project->getUserVote(7) == true);
//Vote Test
$this->assertTrue($project->vote(1, 1) == 1);
}
示例2: loadModel
public function loadModel($id)
{
if (($model = Project::model()->findByPk($id)) === null) {
throw new CHttpException(404, 'Страница не найдена');
}
return $model;
}
示例3: createIfNotExists
/**
* This method creates a new db record if such a version does not exist yet.
* @param string $appversion Version string.
* @return AppVersion On success, returns AppVersion object; otherwise Null.
*/
public static function createIfNotExists($appversion, $project_id = null)
{
if ($project_id == null) {
$project_id = Yii::app()->user->getCurProjectId();
}
if ($project_id == null) {
return Null;
}
// Ensure that project_id is a valid project ID
$project = Project::model()->findByPk($project_id);
if ($project == null) {
return Null;
}
// Try to find an existing version with such a name
$criteria = new CDbCriteria();
$criteria->compare('project_id', $project_id, false, 'AND');
$criteria->compare('version', $appversion, false, 'AND');
$model = AppVersion::model()->find($criteria);
if ($model != Null) {
return $model;
}
$model = new AppVersion();
$model->project_id = $project_id;
$model->version = $appversion;
if (!$model->save()) {
return Null;
}
return $model;
}
示例4: actionShow
public function actionShow($alias)
{
$model = Project::model()->published()->with(array('galleries' => array('scopes' => 'published', 'order' => 'galleries.sort ASC', 'with' => array('images' => array('scopes' => 'published', 'order' => 'images.sort ASC'))), 'slides' => array('scopes' => 'published', 'order' => 'slides.sort ASC')))->findByAlias($alias);
if (!$model) {
throw new CHttpException(404);
}
$this->render('item', array('model' => $model));
}
示例5: testDelete
public function testDelete()
{
$project = $this->projects('project2');
$savedProjectId = $project->id;
$this->assertTrue($project->delete());
$deletedProject = Project::model()->findByPk($savedProjectId);
$this->assertEquals(NULL, $deletedProject);
}
示例6: loadModel
public function loadModel($id)
{
$model = Project::model()->findByPk((int) $id);
if ($model === null) {
throw new CHttpException(404, 'The requested page does not exist.');
}
return $model;
}
示例7: actionView
public function actionView($url)
{
$model = Project::model()->findByAttributes(array('identifier' => $url));
if (!$model) {
throw new CHttpException(404, 'Такой страницы не существует');
}
$this->pageTitle = $model->title . ' - ' . Yii::app()->name;
User::setLastProjectId($model->id);
$this->render('view', array('model' => $model));
}
示例8: _loadProject
/**
* Protected method to load the associated Project model class
*
* @param $project_id int The primary identifier of the associated project
* @return Project The Project data model based on the primary key.
* @throws CHttpException
*/
protected function _loadProject($project_id)
{
// if the project property is null, create it base on input id
if ($this->_project === null) {
$this->_project = Project::model()->findByPk($project_id);
if ($this->_project === null) {
throw new CHttpException(404, 'The requested project does not exist.');
}
}
return $this->_project;
}
示例9: getAttributeData
/**
* Returns data array of the attribute for create/update.
* @param string the attribute name
* @return array the attribute's data
*/
public function getAttributeData($attribute)
{
switch ($attribute) {
case 'companyId':
return array(null => Yii::t('t', '- Please select -')) + CHtml::listData(Company::model()->findAllActiveRecords(array($this->{$attribute})), 'id', 'title');
case 'projectId':
return array(null => Yii::t('t', '- Please select -')) + CHtml::listData(Project::model()->findAllOpenRecords(array($this->{$attribute})), 'id', 'title');
default:
return $this->{$attribute};
}
}
示例10: uniqueSlug
public function uniqueSlug($attribute, $params)
{
if ($this->isNewRecord) {
if (Project::model()->exists('location_id = :location_id AND slug = :slug', array(':location_id' => $this->location_id, ':slug' => $this->slug))) {
$this->addError($attribute, $params['message']);
}
} else {
if (Project::model()->exists('id != :project_id AND location_id = :location_id AND slug = :slug', array(':project_id' => $this->id, ':location_id' => $this->location_id, ':slug' => $this->slug))) {
$this->addError($attribute, $params['message']);
}
}
}
示例11: actionProject
public function actionProject()
{
$criteria = new CDbCriteria();
$criteria->order = "id DESC";
$count = Project::model()->count($criteria);
$pages = new CPagination($count);
// элементов на страницу
$pages->pageSize = 20;
$pages->applyLimit($criteria);
$work = Project::model()->findAll($criteria);
$this->render('project', array('project' => $work, 'pages' => $pages));
}
示例12: accessEditProject
/**
* Получает доступ к редактированию проекту если:
* Администратор, содатель проекта, участник конкретного действия.
* @param type $projectID
* @return boolean
*/
public static function accessEditProject($projectID, $taskId = NULL)
{
if (self::currentUserIsAdmin()) {
return true;
}
if (!is_null(Project::model()->find(array('select' => 'id', 'condition' => 'id=:id AND user_id=:user_id', 'params' => array(':id' => $projectID, ':user_id' => Yii::app()->user->getId()))))) {
return true;
}
if (!is_null($taskId) && !is_null(Task::model()->find(array('select' => 'id', 'condition' => 'id=:id AND project_id=:project_id AND executor=:user_id', 'params' => array(':id' => $taskId, ':project_id' => $projectID, ':user_id' => Yii::app()->user->getId()))))) {
return true;
}
return false;
}
示例13: uniqueProject
public function uniqueProject($attribute)
{
// $pattern = "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$^";
// if(!preg_match($pattern, $this->email))
// $id = Yii::app()->user->id;
// if (Yii::app()->user->level()=='3'){
// $id_member = Member::model()->find("TRIM(email) = '$id'")->id;
// }else{
// $id_member = MemberSub::model()->find("TRIM(email) = '$id'")->id_member;
// }
$model = Project::model()->find(" project_name = '{$this->project_name}' and id_member = '{$this->id_member}' ");
if (count($model) > 0) {
$this->addError($attribute, "Project for this client , already exist !");
}
}
示例14: testUserAccessBasedOnProjectRole
public function testUserAccessBasedOnProjectRole()
{
$row1 = $this->project_user_roles['row1'];
Yii::app()->user->setId($row1['user_id']);
$project = Project::model()->findByPk($row1['project_id']);
$auth = Yii::app()->authManager;
$bizRule = 'return isset($params["project"]) && $params["project"]->isUserInRole("member");';
$auth->assign('member', $row1['user_id'], $bizRule);
$params = array('project' => $project);
$this->assertTrue(Yii::app()->user->checkAccess('updateIssue', $params));
$this->assertTrue(Yii::app()->user->checkAccess('readIssue', $params));
$this->assertFalse(Yii::app()->user->checkAccess('updateProject', $params));
// now we ensure the user does not have any access to a project ther are not associated with
$project = Project::model()->findByPk(1);
$params = array('project' => $project);
$this->assertFalse(Yii::app()->user->checkAccess('updateIssue', $params));
$this->assertFalse(Yii::app()->user->checkAccess('readIssue', $params));
$this->assertFalse(Yii::app()->user->checkAccess('updateProject', $params));
}
示例15: testUserAccessBasedOnProjectRole
public function testUserAccessBasedOnProjectRole()
{
$row1 = $this->projUsrRole['row1'];
Yii::app()->user->setId($row1['user_id']);
$project = Project::model()->findByPk($row1['project_id']);
$auth = Yii::app()->authManager;
$bizRule = 'return isset($params["project"]) && $params["project"]->isUserInRole("member");';
$auth->assign('member', $row1['user_id'], $bizRule);
$params = array('project' => $project);
$this->assertTrue(Yii::app()->user->checkAccess('updateIssue', $params));
$this->assertTrue(Yii::app()->user->checkAccess('readIssue', $params));
$this->assertFalse(Yii::app()->user->checkAccess('updateProject', $params));
//Check that user can't access projects they are not assigned to
$project = Project::model()->findByPk(1);
$params = array('project' => $project);
$this->assertFalse(Yii::app()->user->checkAccess('updateIssue', $params));
$this->assertFalse(Yii::app()->user->checkAccess('readIssue', $params));
$this->assertFalse(Yii::app()->user->checkAccess('updateProject', $params));
}