public/lib/library.php
/*
    * @abstract Add values to the attributes of an album. For example, add 'Good' and 'Mind-blowing' as tags to a given album.
    * @param string $attName       Name of the attribute you want to add values to
    * @param array  $attValueList  Values to add to the album for the given attribute
    * @parar int    $refcode       Refcode of the Album
    */
@abstract Add values to the attributes of an album. For example, add 'Good' and 'Mind-blowing' as tags to a given album.
@param string $attName       Name of the attribute you want to add values to
@param array  $attValueList  Values to add to the album for the given attribute
@parar int    $refcode       Refcode of the Album
@abstract Add values to the attributes of an album . For example add ' Good ' and ' Mind - blowing ' as tags to a given album . @param string $attName Name of the attribute you want to add values to @param array $attValueList Values to add to the album for the given attribute @parar int $refcode Refcode of the Album
public function addAttributeToAlbum($attName, $attValueList, $refcode) {
	$attValueList = array_diff($attValueList, ['']); 
	if(count($attValueList)>0) {
	    $temp = $attValueList;
	    $attValueList = array_map(array($this, 'mysql_escape'), $temp);
	    $sql=$this->mysqli->query("SELECT * FROM {$attName}s WHERE name IN ('" . implode("', '", $attValueList) . "')");
	    $results = [];
	    while($result_temp = $sql->fetch_array(MYSQLI_ASSOC))
		array_push($results, $result_temp);
	    $ids = array_fill(0, sizeof($attValueList), NULL); 
	    foreach($results as $result)
		$ids[array_search($result['name'], $attValueList)] = $result['id'];
	    $to_add = [];
	    foreach($ids as $index => $id)
		if(is_null($id))
		    array_push($to_add, $attValueList[$index]);
	    if(sizeof($to_add)>0) {
		$temp = $to_add;
		$to_add = array_map(array($this, 'mysql_escape'), $temp);
		$this->mysqli->query("INSERT IGNORE INTO {$attName}s (name) VALUES ('" . implode("'), ('", $to_add) . "')");
		$sql = $this->mysqli->query("SELECT LAST_INSERT_ID()");
		$last_insert_id = $sql->fetch_array(MYSQLI_ASSOC)['LAST_INSERT_ID()'];
		foreach($ids as $i=>$id)
		    if(is_null($id))
			$ids[$i] = $last_insert_id++;
	    }
	    $values = "";
	    foreach($ids as $id)
		$values = $values . "(" . $refcode  .  ", " . $id  . "), ";
	    $values = substr($values, 0, strlen($values)-2); 
	    $this->mysqli->query("INSERT IGNORE INTO library_${attName}s (library_RefCode, ${attName}_id) VALUES " . $values);
	}
    }
public function addAttributeToAlbum ( $ attName , $ attValueList , $ refcode ) { $ attValueList = array_diff ( $ attValueList , [ '' ] ) ; if ( count ( $ attValueList ) > 0 ) { $ temp = $ attValueList ; $ attValueList = array_map ( array ( $ this , 'mysql_escape' ) , $ temp ) ; $ sql = $ this -> mysqli -> query ( " SELECT * FROM  { $ attName } s WHERE name IN (' " . implode ( " ', ' " , $ attValueList ) . " ') " ) ; $ results = [ ] ; while ( $ result_temp = $ sql -> fetch_array ( MYSQLI_ASSOC ) ) array_push ( $ results , $ result_temp ) ; $ ids = array_fill ( 0 , sizeof ( $ attValueList ) , NULL ) ; foreach ( $ results as $ result ) $ ids [ array_search ( $ result [ 'name' ] , $ attValueList ) ] = $ result [ 'id' ] ; $ to_add = [ ] ; foreach ( $ ids as $ index => $ id ) if ( is_null ( $ id ) ) array_push ( $ to_add , $ attValueList [ $ index ] ) ; if ( sizeof ( $ to_add ) > 0 ) { $ temp = $ to_add ; $ to_add = array_map ( array ( $ this , 'mysql_escape' ) , $ temp ) ; $ this -> mysqli -> query ( " INSERT IGNORE INTO  { $ attName } s (name) VALUES (' " . implode ( " '), (' " , $ to_add ) . " ') " ) ; $ sql = $ this -> mysqli -> query ( " SELECT LAST_INSERT_ID() " ) ; $ last_insert_id = $ sql -> fetch_array ( MYSQLI_ASSOC ) [ 'LAST_INSERT_ID()' ] ; foreach ( $ ids as $ i => $ id ) if ( is_null ( $ id ) ) $ ids [ $ i ] = $ last_insert_id ++ ; } $ values = " " ; foreach ( $ ids as $ id ) $ values = $ values . " ( " . $ refcode . " ,  " . $ id . " ),  " ; $ values = substr ( $ values , 0 , strlen ( $ values ) - 2 ) ; $ this -> mysqli -> query ( " INSERT IGNORE INTO library_ $ { attName } s (library_RefCode,  $ { attName } _id) VALUES  " . $ values ) ; } }
@abstract Add values to the attributes of an album.
@abstract Add values to the attributes of an album .
// Remove any blanks // Check which {$attName}s are already in the database // Parallel array of db id for each {$attName} // Insert all {$attName}s into the {$attName}s table that aren't already in there // Gather all {$attName} id's for this album // Insert library/{$attName} combos into intermediary table // Remove trailing comma