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


PHP Artist::PROTECTED_ARTISTS方法代码示例

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


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

示例1: restEvents

 public function restEvents()
 {
     /**
      * req.get.resources.render
      *
      * Called when a GET request for when a list resources is to be rendered
      *
      * @param (Array) (data) this is an array of models representing the resources
      * @param (String) (model_name) the name of the resources model
      * @param (Array) (relations) the list of relations to include with the data
      * @param (Int) (count) the count of records to return
      */
     $this->onRest('req.get.resources.render', function ($data, $model_name, $relations, $count) {
         //Handler for GET (list resources) request
         $this->setHttpStatus($count > 0 ? 200 : 204);
         $this->renderJSON(array('type' => 'rest', 'success' => $count > 0 ? true : false, 'message' => $count > 0 ? "Record(s) Found" : "No Record(s) Found", 'totalCount' => $count, 'modelName' => $model_name, 'relations' => $relations, 'data' => $data));
     });
     /**
      * req.get.resource.render
      *
      * Called when a GET request for a single resource is to be rendered
      * @param (Object) (data) this is the resources model
      * @param (String) (model_name) the name of the resources model
      * @param (Array) (relations) the list of relations to include with the data
      * @param (Int) (count) the count of records to return (will be either 1 or 0)
      */
     $this->onRest('req.get.resource.render', function ($data, $model_name, $relations, $count) {
         //Handler for GET (single resource) request
         $this->setHttpStatus($count > 0 ? 200 : 204);
         $this->renderJSON(array('type' => 'rest', 'success' => $count > 0 ? true : false, 'message' => $count > 0 ? "Record Found" : "No Record Found", 'totalCount' => $count, 'modelName' => $model_name, 'relations' => $relations, 'data' => $data));
     });
     $this->onRest('req.post.album.', function ($data) {
         //$data is the data sent in the POST
         echo CJSON::encode(array('data' => $data));
     });
     /**
      * model.delete
      *
      * Called whenever a model resource needs deleting
      *
      * @param (Object) (model) the model resource to be deleted
      */
     $this->onRest('model.delete', function ($artist) {
         /*print_r(Artist::PROTECTED_ARTISTS());
           print_r($artist->id);
           exit;*/
         //DON'T LET USERS  DELETE PROTECTED ARTISTS
         if (in_array($artist->id, Artist::PROTECTED_ARTISTS())) {
             throw new CHttpException(403, '<i>You cannot delete </i><h4>' . $artist->name . '</h4><br> It\'s demo data.Feel free to create,update and delete  your own data.');
             exit;
         }
         $albumsDeleted = true;
         $tracksDeleted = true;
         foreach ($artist->albums as $album) {
             //delete tracks
             $albumid = $album->id;
             $tracks = Track::model()->findAllByAttributes(array('album_id' => $albumid));
             foreach ($tracks as $track) {
                 $trackDeleted = $track->delete();
                 $tracksDeleted = $tracksDeleted && $trackDeleted;
             }
             //delete album
             $albumdeleted = $album->delete();
             $albumsDeleted = $albumsDeleted && $albumdeleted;
         }
         if (!$artist->delete()) {
             throw new CHttpException(500, 'Could not delete model');
         }
         if (!$albumsDeleted) {
             throw new CHttpException(500, 'Some artist\'s albums were not deleted');
         }
         if (!$tracksDeleted) {
             throw new CHttpException(500, 'Some album tracks were not deleted');
         }
         if (!$this->unlinkArtistFromAlbums($artist->id)) {
             throw new CHttpException(500, 'Artist was not unlinked from albums.');
         }
         return $artist;
     });
     //DON'T LET USERS  UPDATE PROTECTED ARTISTS
     $this->onRest('pre.filter.model.apply.put.data', function ($model, $data, $restricted_properties) {
         if (in_array($model->id, Artist::PROTECTED_ARTISTS())) {
             throw new CHttpException(403, '<i>You cannot modify </i><h4>' . $model->name . '</h4><br> It\'s demo data.Feel free to create,update and delete  your own data.');
             exit;
         } else {
             return array($model, $data, $restricted_properties);
         }
         //Array [Object, Array, Array]
     });
     /**
      * model.subresources.save
      *
      * Called whenever a sub-resource is saved
      *
      * @param (Object) (model) the owner of the sub-resource
      * @param (String) (subresource_name) the name of the subresource
      * @param (Mixed/Int) (subresource_id) the primary key of the subresource
      *
      * @return (Object) the updated model representing the owner of the sub-resource
      */
//.........这里部分代码省略.........
开发者ID:imanifaiz,项目名称:angular-music-db,代码行数:101,代码来源:ArtistController.php

示例2: restEvents

 public function restEvents()
 {
     /**
      * req.get.resources.render
      *
      * Called when a GET request for when a list resources is to be rendered
      *
      * @param (Array) (data) this is an array of models representing the resources
      * @param (String) (model_name) the name of the resources model
      * @param (Array) (relations) the list of relations to include with the data
      * @param (Int) (count) the count of records to return
      */
     $this->onRest('req.get.resources.render', function ($data, $model_name, $relations, $count) {
         //Handler for GET (list resources) request
         $this->setHttpStatus($count > 0 ? 200 : 204);
         $this->renderJSON(array('type' => 'rest', 'success' => $count > 0 ? true : false, 'message' => $count > 0 ? "Record(s) Found" : "No Record(s) Found", 'totalCount' => $count, 'modelName' => $model_name, 'relations' => $relations, 'data' => $data));
     });
     /**
      * req.get.resource.render
      *
      * Called when a GET request for a single resource is to be rendered
      * @param (Object) (data) this is the resources model
      * @param (String) (model_name) the name of the resources model
      * @param (Array) (relations) the list of relations to include with the data
      * @param (Int) (count) the count of records to return (will be either 1 or 0)
      */
     $this->onRest('req.get.resource.render', function ($data, $model_name, $relations, $count) {
         //Handler for GET (single resource) request
         $this->setHttpStatus($count > 0 ? 200 : 204);
         $this->renderJSON(array('type' => 'rest', 'success' => $count > 0 ? true : false, 'message' => $count > 0 ? "Record Found" : "No Record Found", 'totalCount' => $count, 'modelName' => $model_name, 'relations' => $relations, 'data' => $data));
     });
     /**
      * model.delete
      *
      * Called whenever a model resource needs deleting
      *
      * @param (Object) (model) the model resource to be deleted
      */
     $this->onRest('model.delete', function ($model) {
         if (in_array($model->album->artists[0]->id, Artist::PROTECTED_ARTISTS())) {
             throw new CHttpException(403, '<i>You cannot delete </i><h4>' . $model->name . '</h4><br> It\'s demo data.Feel free to create,update and delete  your own data.');
             exit;
         } else {
             if (!$model->delete()) {
                 throw new CHttpException(500, 'Could not delete model');
             }
         }
         return $model;
     });
     $this->onRest('pre.filter.model.apply.put.data', function ($model, $data, $restricted_properties) {
         if (in_array($model->album->artists[0]->id, Artist::PROTECTED_ARTISTS())) {
             throw new CHttpException(403, '<i>You cannot modify </i><h4>' . $model->name . '</h4><br> It\'s demo data.Feel free to create,update and delete  your own data.');
             exit;
         } else {
             return array($model, $data, $restricted_properties);
         }
         //Array [Object, Array, Array]
     });
     $this->onRest('pre.filter.model.apply.post.data', function ($model, $data, $restricted_properties) {
         $album_id = $data['album_id'];
         $album = Album::model()->findByPk($album_id);
         if (in_array($album->artists[0]->id, Artist::PROTECTED_ARTISTS())) {
             throw new CHttpException(403, '<i>You cannot modify </i><h4>' . $model->name . '</h4><br> It\'s demo data.Feel free to create,update and delete  your own data.');
             exit;
         } else {
             return array($model, $data, $restricted_properties);
         }
         //Array [Object, Array, Array]
     });
 }
开发者ID:imanifaiz,项目名称:angular-music-db,代码行数:70,代码来源:TrackController.php


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