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


PHP Portfolio::validate方法代码示例

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


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

示例1: validatePortfolio

 /**
  * Validate data from form post 
  *  it's must making before saving into database
  * @param mixed $postData
  */
 public function validatePortfolio($postData)
 {
     $arrayPortfolio = array();
     foreach ($_POST['FileForm'] as $gallery_idx => $postPortfolio) {
         if (empty($postPortfolio['gallery_id'])) {
             $portfolio = new Portfolio();
         } else {
             $portfolio_id = $postPortfolio['gallery_id'];
             $portfolio = Portfolio::model()->with('photos')->findByPk($portfolio_id);
             if (!isset($portfolio)) {
                 $portfolio = new Portfolio();
             }
         }
         $portfolio->attributes = $postPortfolio;
         //assign attributes
         $valOK = $portfolio->validate();
         $arrayPhotosIds = array();
         //additional array for deleted photos search
         $deletedPhotos = array();
         //array for deleted photos
         $photos = array();
         //array of edited photos of portfolio
         $isTopPresent = false;
         //process photos array
         if (isset($postPortfolio['photos'])) {
             foreach ($postPortfolio['photos'] as $idx => $postPhoto) {
                 $photo_id = $postPhoto['photo_id'];
                 $isNewPhoto = empty($photo_id);
                 $photo = $isNewPhoto ? new Photo() : Photo::model()->findByPk($photo_id);
                 if ($isNewPhoto = !isset($photo)) {
                     $photo = new Photo();
                 }
                 $photo->attributes = $postPhoto;
                 $photo->gallery_id = $portfolio->gallery_id;
                 $photo->is_top = isset($postPortfolio['is_top']) && $idx == $postPortfolio['is_top'] ? Photo::POSITION_IS_TOP : Photo::POSITION_NO_TOP;
                 if ($photo->is_top) {
                     $isTopPresent = true;
                 }
                 //mark is_top present
                 $valOK = $photo->validate() && $valOK;
                 $arrayPhotosIds[$idx] = $postPhoto['photo_id'];
                 //add item to search array
                 $photos[$idx] = $photo;
             }
         }
         //validate photos (count)
         if ($postPortfolio['gallery_type'] == 1) {
             if (!count($photos)) {
                 $portfolio->addError('is_top', Yii::t('main', 'Portfolio must have photos'));
             } else {
                 if (!$isTopPresent) {
                     $portfolio->addError('is_top', Yii::t('main', 'In photo portfolio one of photo must be in top'));
                 }
             }
         }
         //search for deleted photos
         if (isset($portfolio->photos)) {
             foreach ($portfolio->photos as $photo) {
                 if (!in_array($photo->photo_id, $arrayPhotosIds)) {
                     $portfolio->deletedPhotos[] = $photo;
                 }
             }
         }
         $portfolio->photos = $photos;
         //add photo items to portfolio model
         $arrayPortfolio[] = $portfolio;
         //add instance of portfolio to returning array
     }
     return $arrayPortfolio;
     //returning result array of portfolio instances
 }
开发者ID:andreyantonov78,项目名称:atmosphera,代码行数:76,代码来源:PhotoPortfolioWidget.php


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