public function saveCustomFace($face_id, $image_id, $x1, $y1, $x2, $y2, $name = '')
{
$image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($image_id);
$gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($image->gallery);
if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
throw new Horde_Exception_PermissionDenied(_("Access denied editing the photo."));
}
// Store face id db
if (!empty($face_id)) {
$sql = 'UPDATE ansel_faces SET face_name = ?, face_x1 = ?, ' . 'face_y1 = ?, face_x2 = ?, face_y2 = ? WHERE face_id = ?';
$params = array($name, $x1, $y1, $x2, $y2, $face_id);
try {
$GLOBALS['ansel_db']->update($sql, $params);
} catch (Horde_Db_Exception $e) {
throw new Ansel_Exception($e);
}
} else {
$sql = 'INSERT INTO ansel_faces (image_id, gallery_id, face_name, ' . ' face_x1, face_y1, face_x2, face_y2)' . ' VALUES (?, ?, ?, ?, ?, ?, ?)';
$params = array($image->id, $image->gallery, $name, $x1, $y1, $x2, $y2);
try {
$face_id = $GLOBALS['ansel_db']->insert($sql, $params);
} catch (Horde_Db_Exception $e) {
throw new Ansel_Exception($e);
}
}
// Process the image
$this->createView($face_id, $image, $x1, $y1, $x2, $y2);
// Update gallery and image counts
try {
$GLOBALS['ansel_db']->update('UPDATE ansel_images SET image_faces = image_faces + 1 WHERE image_id = ' . $image->id);
$GLOBALS['ansel_db']->update('UPDATE ansel_shares SET attribute_faces = attribute_faces + 1 WHERE share_id = ' . $image->gallery);
} catch (Horde_Db_Exception $e) {
throw new Ansel_Exception($e);
}
// Save signature
$this->saveSignature($image->id, $face_id);
return $face_id;
}