本文整理汇总了PHP中Portfolio::addError方法的典型用法代码示例。如果您正苦于以下问题:PHP Portfolio::addError方法的具体用法?PHP Portfolio::addError怎么用?PHP Portfolio::addError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Portfolio
的用法示例。
在下文中一共展示了Portfolio::addError方法的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
}