<?php
namespace DynCom\mysyde\common\traits;
use DynCom\mysyde\common\classes\Form;

/**
 * Created by PhpStorm.
 * User: Michael Bauer
 * Date: 7/13/2015
 * Time: 7:22 PM
 */
trait genericViewModelTrait
{

    use arrayGettableTrait;

    /**
     * @return bool
     */
    public function allFormsValid() {
        $arr = $this->getAllFieldsAsArray();
        foreach($arr as $fieldName => $fieldValue) {
            if($fieldValue instanceof Form) {
                $fieldValue->validateRequestAgainstRules();
                if (!$fieldValue->isRequestValid()) {
                    return false;
                }
            }
        }
        return true;
    }

}