Browse Source

Add basic all convenience wrappers

Mark Scherer 10 years ago
parent
commit
2b04e1efb4
1 changed files with 29 additions and 0 deletions
  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