浏览代码

Add basic all convenience wrappers

Mark Scherer 10 年之前
父节点
当前提交
2b04e1efb4
共有 1 个文件被更改,包括 29 次插入0 次删除
  1. 29 0
      src/Model/Table/Table.php

+ 29 - 0
src/Model/Table/Table.php

@@ -15,6 +15,35 @@ use Cake\Routing\Router;
 
 class Table extends ShimTable {
 
+	/**
+	 * @param array $entities
+	 * @return bool
+	 */
+	public function validateAll(array $entities) {
+		foreach ($entities as $entity) {
+			if ($entity->errors()) {
+				return false;
+			}
+		}
+
+		return true;
+	}
+
+	/**
+	 * @param array $entities
+	 * @return bool
+	 */
+	public function saveAll(array $entities) {
+		$result = true;
+		foreach ($entities as $entity) {
+			if (!$this->save($entity)) {
+				$result = false;
+			}
+		}
+
+		return $result;
+	}
+
 /**
  * Validator method used to check the uniqueness of a value for a column.
  * This is meant to be used with the validation API and not to be called